Thread Subject: Send through Serial

Subject: Send through Serial

From: Rami AbouSleiman

Date: 27 May, 2008 19:30:20

Message: 1 of 5

I am trying to send numbers from 0-65535 or 0-FFFF through
the serial port.

I need to get the hex value on the other side but I am
getting garbage how can I fix it?

I am using fwrite() command/

For example if I send a 0 I get a 00 08 00 on the otherside.
Thanks in advance
Rami
rdabousl@oakland.edu

Subject: Send through Serial

From: AJ

Date: 27 May, 2008 21:40:18

Message: 2 of 5

"Rami AbouSleiman" <rdabousl@oakland.edu> wrote in message
<g1hngc$k10$1@fred.mathworks.com>...
> I am trying to send numbers from 0-65535 or 0-FFFF
through
> the serial port.
>
> I need to get the hex value on the other side but I am
> getting garbage how can I fix it?
>
> I am using fwrite() command/
>
> For example if I send a 0 I get a 00 08 00 on the
otherside.
> Thanks in advance
> Rami
> rdabousl@oakland.edu

I'm guessing the data type is being confused. Try explicity
defined the data type as 'uint8' as an argument to fwrite:
  fwrite(fid,[0 1 2 3 4 5 6 7],'uint8')
You could also try casting your data,
  fwrite(fid,uint8(0:65535))

HTH,
AJ

Subject: Send through Serial

From: Trent Jarvi

Date: 27 May, 2008 21:43:32

Message: 3 of 5


"Rami AbouSleiman" <rdabousl@oakland.edu> wrote in message
news:g1hngc$k10$1@fred.mathworks.com...
>I am trying to send numbers from 0-65535 or 0-FFFF through
> the serial port.
>
> I need to get the hex value on the other side but I am
> getting garbage how can I fix it?
>
> I am using fwrite() command/
>
> For example if I send a 0 I get a 00 08 00 on the otherside.
> Thanks in advance
> Rami
> rdabousl@oakland.edu

s=serial('/dev/ttyS0');
s.OutputBufferSize=65536*16;
fopen(s);
fwrite(s,[0:65535],'uint16');


Subject: Send through Serial

From: Rami AbouSleiman

Date: 28 May, 2008 00:43:02

Message: 4 of 5

"Trent Jarvi" <tjarvi@mathworks.com> wrote in message
<g1hva4$duo$1@fred.mathworks.com>...
>
> "Rami AbouSleiman" <rdabousl@oakland.edu> wrote in
message
> news:g1hngc$k10$1@fred.mathworks.com...
> >I am trying to send numbers from 0-65535 or 0-FFFF
through
> > the serial port.
> >
> > I need to get the hex value on the other side but I am
> > getting garbage how can I fix it?
> >
> > I am using fwrite() command/
> >
> > For example if I send a 0 I get a 00 08 00 on the
otherside.
> > Thanks in advance
> > Rami
> > rdabousl@oakland.edu
>
> s=serial('/dev/ttyS0');
> s.OutputBufferSize=65536*16;
> fopen(s);
> fwrite(s,[0:65535],'uint16');
>
>
Thank you Trent for the reply,
but my hex received is now reversed , life i get EF FF for
65519,
any clue?
Thank you again

Subject: Send through Serial

From: Rami AbouSleiman

Date: 28 May, 2008 14:20:03

Message: 5 of 5

"Rami AbouSleiman" <rdabousl@oakland.edu> wrote in message
<g1i9qm$77e$1@fred.mathworks.com>...
> "Trent Jarvi" <tjarvi@mathworks.com> wrote in message
> <g1hva4$duo$1@fred.mathworks.com>...
> >
> > "Rami AbouSleiman" <rdabousl@oakland.edu> wrote in
> message
> > news:g1hngc$k10$1@fred.mathworks.com...
> > >I am trying to send numbers from 0-65535 or 0-FFFF
> through
> > > the serial port.
> > >
> > > I need to get the hex value on the other side but I am
> > > getting garbage how can I fix it?
> > >
> > > I am using fwrite() command/
> > >
> > > For example if I send a 0 I get a 00 08 00 on the
> otherside.
> > > Thanks in advance
> > > Rami
> > > rdabousl@oakland.edu
> >
> > s=serial('/dev/ttyS0');
> > s.OutputBufferSize=65536*16;
> > fopen(s);
> > fwrite(s,[0:65535],'uint16');
> >
> >
> Thank you Trent for the reply,
> but my hex received is now reversed , life i get EF FF
for
> 65519,
> any clue?
> Thank you again


FIXED just change the obj setting to bigEndian

Tags for this Thread

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.

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