473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Need help with Serial port - PLEASE

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[i]=_serialPort.ReadByte();

}
I can realy use some help here.

Many Thanks
Mike

Oct 6 '06 #1
3 1241
Mike, it will be useful to know what type of device you are reading
from.
am******@gmail.com wrote:
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[i]=_serialPort.ReadByte();

}
I can realy use some help here.

Many Thanks
Mike
Oct 6 '06 #2
A TI Microcontroler.
I communicate fine sending commands,but Im trying to read back data.And
Im having problems.
Charlie Brown wrote:
Mike, it will be useful to know what type of device you are reading
from.
am******@gmail.com wrote:
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[i]=_serialPort.ReadByte();

}
I can realy use some help here.

Many Thanks
Mike
Oct 6 '06 #3
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.
Oct 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: McBooCzech | last post by:
Hi I am just trying to analyze (parse) data from the serial port (I have connected GPS receiver to the ttyS0, so I can read ASCII characters in the CSV form on the serial port 1). I am doing this...
5
by: Confused User | last post by:
I am working on device that utilizes a Motorola 68HC16 microcontroller. I am using an old unsupported piece of crap Whitesmith's / Intermetrics / Tasking compiler. The embedded compiler business...
1
by: pei_world | last post by:
Hi there, I have search the web for serial port programming for age. I found some example codes. but I don't know how to test then. I don't have any idea how such program what undernearth. Can...
1
by: Srinivasa Ra via .NET 247 | last post by:
(Type your message here) I am writing an application that does lot of read/write's withcomputer's serial port. The application as a whole is workingfine. Current Approach: I have a Timer that...
1
by: bill | last post by:
Good Day, I am developing an application that utilizes the serial port. I have looked through the news groups and seen some examples. Here is my dilemna: I am creating a processing...
20
by: Jason Dravet | last post by:
Some time ago I wrote an application that controls the projectors in our classrooms(turn on, turn off, and volume control). This application is written in VB.net 2003. It was working perfectly...
1
by: David | last post by:
I have written an application in VB.NET 2003 that uses the SAX serial component for RS232 communications with hardware. The program sets up 2 serial ports so that it can talk to 2 different...
15
by: xkenneth | last post by:
Hi, I'm writing a couple python applications that use the serial port (RS-232) quite extensively. Is there any way I can monitor all activity on the serial port and have it printed as the...
0
by: ghjk | last post by:
I want to read sms from GSM modem using C# in serial communication. I wrote the code. But i want to do it automatically. I put my code here and please tell me how can i do it automatically. ...
3
by: akshaycjoshi | last post by:
IT"S A LONG QUESTION.PLEASE BE PATIENT TO READ IT. I HAVE EXPLAINED IT TO MY MAXIMUM CAPACITY. I am making one app. in which i need to create a seperate access database for each day. Its a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.