# How to interface PORTs using MATLAB ??

Status
Not open for further replies.

ports in matlab

Assalamo Alaykom

How are you all my Matlab friends

here you are another problem in matlab :

I wanna learn how to communicate with PORTs ?

#### Antharax

##### Full Member level 4
gpib parallel matlab

using a Serial Port in matlab is similar to using files.

Code:
s = serial('COM1');
fopen(s)
fprintf(s,'*IDN?')
idn = fscanf(s);
fclose(s)

and there are many other usefull routines in matlab for serial port communication
and searching for "Serial Port" gives you:
and a good startpoint is the fopen page:
with links to related functions below.

Matlab help is pretty good! With lots of usefull examples, good and relevant hyperlinks on all pages, ... You should try it and learn to use it. You'll become an expert in no time ;-)

Antharax

Points: 2

#### echo47

matlab ethernet data access interface

What type of ports are you interested in? Serial, parallel, USB, PS2, firewire, ethernet, joystick, audio, GPIB, ... ?

#### yongchai

##### Junior Member level 1
using a joystick with matlab

echo47 said:
What type of ports are you interested in? Serial, parallel, USB, PS2, firewire, ethernet, joystick, audio, GPIB, ... ?
Do you have idea how MATLAB communicates with USB port? Thanks.

gpib with matlab

echo47 said:
What type of ports are you interested in? Serial, parallel, USB, PS2, firewire, ethernet, joystick, audio, GPIB, ... ?

:arrow: Currently, I am interrested with Parallel and serial port interfacing ..
But, it will be also very useful to learn how to interface with other ports.

#### samcheetah

matlab usb

yongchai said:
echo47 said:
What type of ports are you interested in? Serial, parallel, USB, PS2, firewire, ethernet, joystick, audio, GPIB, ... ?
Do you have idea how MATLAB communicates with USB port? Thanks.

i have heard that matlab cannot communicate with the USB port directly. but it can communicate with it through a driver. i dont know the details. by the way what is you application. maybe a serial connection will be enough for what you want to do.

echo47 said:
What type of ports are you interested in? Serial, parallel, USB, PS2, firewire, ethernet, joystick, audio, GPIB, ... ?

you asked me about needed ports .. and i told you that i wanna interface matlab with serial and parallel ports.. and you didnt post any reply after this ..

Thank you very much

#### nebisman

##### Full Member level 4
you can use three utilities

DAQ (data acquisition toolbox , which has parallel port interfacing)

these utilities has blocks for interfacing with any port including parallel port

#### hameeds01

how to use USB Port in Matlab ???

#### elrayes

##### Full Member level 5
to use USB in matlab you either use MATLAB VISA object, but only supports specific products from TI, NI and some other companies.
or use virtual COM port to interface it, then you can use serial interface from matlab.

#### dg123

##### Newbie level 4
If you are trying to communicate with Matlab in real-time, check out **broken link removed**. As far as I know, this is the only platform that allows real-time communication with external hardware through the serial port.

#### noman4ever

##### Newbie level 5
I am communicating with ehternet using UDP

My transmitter code is:

u1=udp('192.168.1.55', 9091,'LocalPort', 9090);
set(u1, 'OutputBufferSize', 8192)
set(u1, 'TimeOut', 10)
fopen(u1)
get(u1, 'Status')
while(1)
fwrite(u1, ubuffer(1, : ), 'double'); %ubuffer is of size 1x1024
end
fclose(u1)
delete(u1)

u=udp('192.168.1.166', 9090, 'LocalPort', 9091, 'InputBufferSize', 8192, 'TimeOut', 10);
fopen(u);
while(1)
end
fclose(u)
delete(u)

My problem is that as soon as i increase the number of elements transmitted past 64, i can only receive 64 elements at receiver. Like if i transmit 1x1024 element array, at receiver i get first 64 elements only. Like at this line of code at receiver:

i only get 'a' of size 64x1, although i should get 1024x1 size of 'a'. The value of count is also 64, it should be 1024.

To rectify this i have to use a loop and make a 2d array at receiver like 64x16 for 1024 element transmitted array. Also i get a warning "The specified amount of data was not returned in time" after reading every 64 elements. Is there any solution to receive all elements like 1024 in one go??? like i dont have to use loop just
and i get all the transmitted elements.

My second problem is that i cannot transmit complex numbers using UDP. I transmit 3 complex numbers and at receiver i only get real part of these complex numbers. Any ideas????

#### microKernel

##### Full Member level 3
Re: using a joystick with matlab

yongchai said:
Do you have idea how MATLAB communicates with USB port? Thanks.

#### philoman

##### Junior Member level 1
with instrument control toolbox installed, matlab can commumicate with many devices, such as serial/parallel ports, ethernet, GPIB and so on.
refer to Mathworks' site for more details, or type "help instrument" in matlab command window.

Status
Not open for further replies.