Thread Subject: Sending data with Matlab to an external device

Subject: Sending data with Matlab to an external device

From: Jose

Date: 27 Apr, 2011 00:43:04

Message: 1 of 2

Hi, I am trying to send the number "1" to an external device in matlab using a virtual serial port provided by the device. This is the code, but it is not working. What can be the problem?

s=serial('COM3','BaudRate',9600);
fopen(s);
ledon=[1];
fwrite(s,ledon);
fclose(s);

Subject: Sending data with Matlab to an external device

From: Ankit Desai

Date: 5 May, 2011 00:55:05

Message: 2 of 2

"Jose " <jose_a_f@hotmail.com> wrote in message <ip7oqo$i52$1@fred.mathworks.com>...
> Hi, I am trying to send the number "1" to an external device in matlab using a virtual serial port provided by the device. This is the code, but it is not working. What can be the problem?
>
> s=serial('COM3','BaudRate',9600);
> fopen(s);
> ledon=[1];
> fwrite(s,ledon);
> fclose(s);


In order for serial object to correctly communicate, the properties set for the object need to match the ones on the device/instrument.

So the first thing I would try is to check if the setting on the device matches the serial object properties eg:- BaudRate, Parity, FlowControl.

Also, if you plan to write 1 as a character, you might want to use fprintf command. Here's online help for fprintf: http://www.mathworks.com/help/techdoc/ref/serial.fprintf.html

Hope this helps

-Ankit

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
serial Ankit Desai 4 May, 2011 20:58:43
virtual serial ... Jose 26 Apr, 2011 20:44:05
external device Jose 26 Apr, 2011 20:44:05
communication Jose 26 Apr, 2011 20:44:05
rssFeed for this Thread

Contact us at files@mathworks.com