Thread Subject: Getting single value from serial port

Subject: Getting single value from serial port

From: Grace

Date: 1 Feb, 2008 06:30:19

Message: 1 of 2

Hi Everybody,

I am using a PIC chip interfaced to computer via a wireless
chip and USB-to-serial adaptor. The PIC chip is sending data
in a serial format from four sensors one by one (e.g.
sensor1 sensor2 sensor3 sensor4) with every value separated
by \n\r.

When I read this data on my hyperterminal, data is appearing
totally fine. I even made it appear fine on matlab using the
following code:


instrreset
s = serial('COM8');
set(s,'BaudRate',9600,'DataBits',8,'StopBits',1,'Parity',
'none','Terminator','CR/LF','InputBufferSize',1024);
fopen(s);

while(1)
    fprintf(s, '*IDN?');
    sensor1 = fscanf(s)
% fprintf(s, '*IDN?');
% sensor2 = fscanf(s)
% fprintf(s, '*IDN?');
% sensor3 = fscanf(s)
% fprintf(s, '*IDN?');
% sensor4 = fscanf(s)
end

fclose(s);
delete(s);
clear s;


However if I try to uncomment the above lines, data goes in
huge bunches to every variable. However I wanted every
consecutive value to go to different variables.

I have tried fscanf(s,'%u',3), but it starts giving out
wrong values somehow.

Can you suggest me a way to do this?

It is kind of urgent for my project.

Thanks a lot.
Grace


Subject: Getting single value from serial port

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 1 Feb, 2008 18:11:02

Message: 2 of 2

In article <fnue9r$f0p$1@fred.mathworks.com>,
Grace <gracee@mathworks.com> wrote:
>s = serial('COM8');
>set(s,'BaudRate',9600,'DataBits',8,'StopBits',1,'Parity',
>'none','Terminator','CR/LF','InputBufferSize',1024);
>fopen(s);
[...]
> sensor1 = fscanf(s)
[...]

Matlab does not document the meaning of calling fscanf()
without providing a format string. I cannot predict whether
you are getting a numeric result or a character result in sensor1
--
   "Okay, buzzwords only. Two syllables, tops." -- Laurie Anderson

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 port communication Grace 1 Feb, 2008 01:35:05
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com