Reading UART with incoming data of type ushort

  • Thread starter Thread starter alphatommy_at_hotmail_dot_com
  • Start date Start date
A

alphatommy_at_hotmail_dot_com

Hi,

I need to read data coming from serial port of type ushort(16-bits,
unfortunately this can not be changed). I have tried reading using
ReadChar (32-bits) and ReadByte(8 bits) with no success. When trying
to use Port1.ReadChar() somehow the data get messed up. If I try to
use Port1.ReadByte(), I get problem when I encounter values like
0x0001 (I guess it assumes that is it reading null since it is reading
one byte at a time). Any suggestions? Thanks.
 
Hi,
Try Readexisting() into a string then parse the string.
If this works then its thanks to Richard Grier "Serial Communciations
4" ( page 229) not me.
regards
Bob
 
Hi Bob,

I tried it and could not make it work. In my DataReceive function I
added

string IncomingMsg;

IncomingMsg = PortCOM1.ReadExisting();

I could not evaluate IncomingMsg because it said that it could not be
evaulated because the expression had side effects.

Also, is there a way I could prevent my function from exiting when it
reads a null?

Thanks.
 
Hi Bob,

I tried it and could not make it work. In my DataReceive function I
added

string IncomingMsg;

IncomingMsg = PortCOM1.ReadExisting();

I could not evaluate IncomingMsg because it said that it could not be
evaulated because the expression had side effects.

Also, is there a way I could prevent my function from exiting when it
reads a null?

Thanks.
Hi,
Are you saying the IncomingMsg = PortCOM1.ReadExisting();
statement errors?
Could you post the error message please.

thanks
Bob
 
Hi Bob,

Solved the issue. The problem was that data type sent was ushort, but
the parameter passed to function call was number of bytes and not
number of ushorts.Thanks for your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top