Computing.Net > Forums > Programming > Serial port communication

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Serial port communication

Reply to Message Icon

Name: alex2000_mc
Date: May 26, 2005 at 02:38:25 Pacific
OS: Linux
CPU/Ram: pentium 256mb ram
Comment:

I have a device connected to the Serial Port and i wish to extract it's readings into a C Program. I have written a program to read and display the Serial Port Output but it gives out Garbage. Is there a need to process the output before displayin in order to get the required values in Hex? If so, how do i go about it? Thanks for your help in advance.



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: May 26, 2005 at 04:34:08 Pacific
Reply:

There are numerous reasons why the serial port might be giving you garbage.

Do you have the baud rate set correctly, are the stop bits and parity bits correct. How are you accessing the serial port, polling or interrupts.

The serial port reads pure binary numbers. If you are expecting Hex you are going to have to convert binary into Hex.

Stuart


0

Response Number 2
Name: wizard-fred
Date: May 26, 2005 at 07:52:11 Pacific
Reply:

Continuing from your previous post.

What is the device that you are trying to read? It must have some documentation of the communications protocol and data format. Most serial ports are designed to transfer whole words (normally 8 bit, but other values are possible). As previously mentioned you will have to convert your input to get HEX.

It would be easier to debug with a known working terminal program. There are some that have a diagnostic mode that displays the raw data stream. Note that some devices have non-standard protocols (Especiallly those running at low baud rates). Make sure hardware handshaking is correct if used. It's easier to test if your device can be set to continually output. Then vary your terminal settings until you get decipherable output.


0

Response Number 3
Name: alex2000_mc
Date: May 26, 2005 at 09:00:13 Pacific
Reply:

I'm working with an Inertial Measurement Unit (RS232 Interface). All i've done so far is an open followed by a read on the serial port. Here's a sample output:

Read Status is 100
@Ð !!!!¬þ 1!!¬¥ü !%!±ü !!'±ü !!'±ü !!!±ü !%±ü !%'¬þ
Read Status is 55
'±ü !!%±ü !±ü !% ±ü !!';
±ü !!!±ü !%±ü !%'¬þ
Read Status is 21
@Ð !!%±ü %54 !±ü !% ±ü !!';
±ü !!!±ü !%±ü !%'¬þ

If possible, could anyone send me an example of wat i shud ideally be looking for or an example of how to read the serial port using C Programming? Sorry about the trouble and thanks a lot for your patience and help.



0

Response Number 4
Name: StuartS
Date: May 26, 2005 at 09:32:43 Pacific
Reply:

If you were to look at the numbers and not their ASCII equivalent then it might make a little more sense. What you have is like looking at a programme file with a text editor - is doesn't mean much. In amongst the data are some characters that are outside the normal ASCII range so it is not ASCII that is being transmitted.

There is a lot of repetition there which if you could establish a pattern will give you some idea of what is happening.

Stuart


0

Response Number 5
Name: alex2000_mc
Date: May 27, 2005 at 03:55:44 Pacific
Reply:

The repition is acceptable because the INS is stationary. So i presume those symbols correspond to the output of the INS wen it is stable. If i were to move it about, then the readings would change. I still cant find a way to interpret those readings. If i just execute a read on the serial port, should it not be giving out values in binary unless there is a prob with the serial port itself, which there doesnt seem to be! I cant find a solution to this anywhere on the web or in a book. Please Help!


0

Related Posts

See More



Response Number 6
Name: Wolfbone
Date: May 27, 2005 at 07:41:47 Pacific
Reply:

It is giving readings in binary. As wizard-fred pointed out, you should have/get the documentation telling you the format of each frame/string the device spits out. Otherwise you'll have to guess or deduce it from experiment.


0

Response Number 7
Name: wizard-fred
Date: May 27, 2005 at 09:30:17 Pacific
Reply:

I did a guick google on IMU's. Little data on military stuff, plenty on commercial stuff especially those using Analog Devices Chip. Serial Devices are common using the higher baud rates of 19.2k to 460k. Data Stream Is A Set Of Packets (ID, Header, Status, Data, Trailer). One vendor uses 25 bytes for 6 channels. Two successive bytes for 16 bit data from ADC. Big-Endian.

Obviously you are very short on documentation. There are SDK's available from many vendors. (C, Delphi, Etc.)

I still think your communications is off.
In the example you should be getting a repeating pattern of 25 bytes with no motion.


0

Response Number 8
Name: alex2000_mc
Date: May 27, 2005 at 11:06:39 Pacific
Reply:

Thanks a lot for all your help guys. I will check my communications again and pray it works. i will update you on my results. Once again, i really appreciate your help.


0

Response Number 9
Name: alex2000_mc
Date: June 3, 2005 at 05:15:45 Pacific
Reply:

I seem to have fixed the problem and am getting output as below. However, the read status, which is the number of bytes read in keeps changing even when the instrument is stationary? Is this normal or have i made a mistake in programming again? the buffer i have defined is an integer buffer and i am also concerned because of th negative values below. please advice. thanks

Read Status is 44
-826734246
-1632040547
1498044829
1503484330
1234913708
1504467290
-826734230
-1631990627
1504336285
1503484314
176310700
1233865132
1505515866
7212122
-1631990776
1498044829
1502435674
1234913724
1504467274
-826734230
-1632040547
1504336285
1503484346
1234913692
1504467290
0


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Serial port communication

Remote Serial Port Communications www.computing.net/answers/programming/remote-serial-port-communications/7737.html

Input from Serial Port in Java/C++ www.computing.net/answers/programming/input-from-serial-port-in-javac/11868.html

Problem Serial port communication www.computing.net/answers/programming/problem-serial-port-communication/6842.html