Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Matlab serial port communication

122 views
Skip to first unread message

Vikram

unread,
Mar 5, 2010, 1:59:23 PM3/5/10
to
Hi !
I would like to transfer some data to PIC micro controller using serial port. I'm using an usb-serial converter cable.. (with a FTDI RS232R chip).When I set up the serial port.. ie using serial command some times it works and sometimes it does not.... Is there a better way to do this or do I need to have the devices that are recognized by Matlab to do serial communication.. I have gone through all the documentation for serial communication.
My question is whether the matlab communicates with any serial port or is it device specific.? Like the one on VISA toolbox?


Thanks,
Vikram

Trent Jarvi

unread,
Mar 5, 2010, 2:59:43 PM3/5/10
to

"Vikram " <vikyp...@aol.com> wrote in message
news:hmrkab$bth$1...@fred.mathworks.com...


Hi

The MATLAB Serial external interface is suitable for communication with any
EIA232 device. Note that if you want to send precise bytes to the device,
it is often easier to start with FWRITE and FREAD at first. FPRINTF and
FSCANF use a Terminator character that can cause confusion in more generic
communication.

The VISA interface provided by the Instrument Control Toolbox product also
uses Terminator characters which may be related to your comment. FWRITE and
FREAD don't do anything unusual though.


Vikram

unread,
Mar 9, 2010, 7:42:05 PM3/9/10
to
"Trent Jarvi" <tja...@mathworks.com> wrote in message <hmrnrf$ofd$1...@fred.mathworks.com>...
Hi Trent!
I tried again . I get The serial port on COM3 on my comnputer.
I program it the following way

s=serial('COM3');
fopen(s);

Sometimes it accepts this and sometime I get the following error

Port: COM3 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the
requested device.

Can you help please. Is there something wrong the way I'm trying to communicate? I'm going by the manual.


-Thanks.
Virkam

Timothy

unread,
Mar 9, 2010, 8:52:23 PM3/9/10
to
%I've seen the same problem (it's not limited to USB/Ser converters) and have %successfully used the following code to work around. I think Matlab gets hung up if %you don't close every serport that you open. Try the following to clear existing %ports BEFORE you try to open a new one.

priorPorts = instrfind % finds any existing Serial Ports in MATLAB
delete(priorPorts) % and deletes them

Trent Jarvi

unread,
Mar 10, 2010, 10:04:23 AM3/10/10
to

"Vikram " <vikyp...@aol.com> wrote in message
news:hn6pst$d25$1...@fred.mathworks.com...

I can think of two possible problems.

MATLAB serial does not support hot plug events. That means the first time
you try to use serial ports, MATLAB looks at whats available and assumes
that is the case in the future. To avoid this issue, plug the serial port
in prior to your MATLAB session and do not remove it during your session.

The second possible issue is that you already have a serial port open. In
this case, the suggestsd solution of deleting the prior serial object will
resolve the problem. If you have the Instrument Control Toolbox product
installed, there is a handy 'INSTRRESET' command that will clean up all
those objects. Otherwise you can use INSTRFIND and delete the objects
found.


Dave Robinson

unread,
Mar 10, 2010, 12:44:04 PM3/10/10
to
"Trent Jarvi" <tja...@mathworks.com> wrote in message <hn8cdn$fj$1...@fred.mathworks.com>...

>
> "Vikram " <vikyp...@aol.com> wrote in message
> news:hn6pst$d25$1...@fred.mathworks.com...
> > "Trent Jarvi" <tja...@mathworks.com> wrote in message
> > <hmrnrf$ofd$1...@fred.mathworks.com>...
> >>
> >> "Vikram " <vikyp...@aol.com> wrote in message
> >> news:hmrkab$bth$1...@fred.mathworks.com...
> >> > Hi !
> >> > I would like to transfer some data to PIC micro controller using
> >> > serial port. I'm using an usb-serial converter cable.. (with a FTDI
> >> > RS232R chip).When I set up the serial port.. ie using serial command
> >> > some times it works and sometimes it does not.... Is there a better way
> >> > to do this or do I need to have the devices that are recognized by
> >> > Matlab to do serial communication.. I have gone through all the
> >> > documentation for serial communication. My question is whether the
> >> > matlab communicates with any serial port or is it device specific.?
> >> > Like the one on VISA toolbox?
> >> >
> >>

I have seen an analogous fault - with a FORTH development board. It normally defaults to COM3 , but if you reset the board, and don't reset the development environment, the board renegotiates a new virtual com port and becomes COM4; and of course you end up wih an error message almost identical to the one you are describing. You should check this on Control Panel. The solution is to reset the Com ports as discussed in the previous responses.

Regards

Dave Robinson

0 new messages