Need help with Serial port - PLEASE

  • Thread starter Thread starter ampeloso
  • Start date Start date
A

ampeloso

Hello,
I am having a tough time reading from a serial port.
My code allows me to ask the device for 255 bytes at 9600 baud.I have
to do this many times to get all the data.
1. I make a call to the device.
2.Read the the data using Read ----> _serialPort.Read(rxFrame, 4,
rxLengthCRC);
3.and put it in a Byte Array (rxFrame)

The problem is Im getting alot of bad data(I know what it should look
like).
But Im not sure if the buffer is full has all 255 bytes when I go to
transfer it.
It doesnt seem like it

I tried using a System.Threading.Thread.Sleep but that doesnt
work.Should it?

Will a ReadByte work Better?
If so, What is wrong with this.(if not what is better)

for (int i = 4; i< rxLengthCRC - 1 ;i ++)
{

rxFrame=_serialPort.ReadByte();

}


I can realy use some help here.

Many Thanks
Mike
 
A TI Microcontroler.
I communicate fine sending commands,but Im trying to read back data.And
Im having problems.


Charlie said:
Mike, it will be useful to know what type of device you are reading
from.


Hello,
I am having a tough time reading from a serial port.
My code allows me to ask the device for 255 bytes at 9600 baud.I have
to do this many times to get all the data.
1. I make a call to the device.
2.Read the the data using Read ----> _serialPort.Read(rxFrame, 4,
rxLengthCRC);
3.and put it in a Byte Array (rxFrame)

The problem is Im getting alot of bad data(I know what it should look
like).
But Im not sure if the buffer is full has all 255 bytes when I go to
transfer it.
It doesnt seem like it

I tried using a System.Threading.Thread.Sleep but that doesnt
work.Should it?

Will a ReadByte work Better?
If so, What is wrong with this.(if not what is better)

for (int i = 4; i< rxLengthCRC - 1 ;i ++)
{

rxFrame=_serialPort.ReadByte();

}


I can realy use some help here.

Many Thanks
Mike
 
Hi,

I'd need to see more of your code to know what to suggest. I do what you
are doing frequently (and have detailed examples in my book -- see below,
though not for the microcontroller that you are using).

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
Back
Top