LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-15-2006, 02:48 PM   #1
kad_79
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Rep: Reputation: 0
unsigned character recvd from serial port messy!!


Hi all,

I have a program which recvs a character from the serial port and based on that does some other operations. I have a sniffer which keeps looking at the serial port and something strange is happening. Although the device attached to the serial port sends the correct characters, my program stores it in a messed up state. Not sure whats happening. For Eg::

The device sends::
00 01 A0 5F

My app stores::
00 01 20 5F

I am storing the incoming characters in a que of 'unsigned chars' . Not sure where I am losing the bits. Any clue on what might have happened?

Another example is as below

The device sends:
08 01 FF F8

My app stores::
00 01 7F 78


Some kind of bit manipulation happening when I am storing them? Is unsigned char the proper way to store raw hex bytes coming out of the serial port. When I send the commands to the serail port things are going fine, because the response of "00 01 A0 5F" is got when I send "A0 5F 00 00 01" and this is going out properly. And these are sent by stpring them in unisgned char buffer and sending them.

What kind of storage type might have messed
A0 to 20
or
FF to 7F
or
F8 to 78
 
Old 06-15-2006, 08:37 PM   #2
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
Take a look at the termios functions, the serial port can be configured to transmit 5,6,7,8 bits per byte.
 
Old 06-16-2006, 11:58 AM   #3
kad_79
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Original Poster
Rep: Reputation: 0
randy:
thanks for the response. I had tried all those. If given any lesser than 8 bits, the complete stream is messy.

After meddling around for a bit I found out what the issue was.

For people who might face such issue, here is the solution. You can thank me when you face this problem.

there is an attribute to the serial port(infact any terminal) called "istrip". You need to disable this. istrip strips the higher bit in an incoming stream and hence I was loosing out bits.

you can use stty -istrip -F /dev/ttySx where x is your serial port number.


tata for now
KD
 
Old 06-16-2006, 12:55 PM   #4
elyk1212
Member
 
Registered: Jan 2005
Location: Chandler, AZ USA
Distribution: Mandrake/Mandriva 10.2
Posts: 186

Rep: Reputation: 30
Quote:
istrip strips the higher bit in an incoming stream and hence I was loosing out bits.

The device sends:
08 01 FF F8

My app stores::
00 01 7F 78
If that is the case, then why is the first byte 0x08, stored as 0x00? Was the first byte actually 0x80? Maybe you also lost a bit on transmission for that run.
 
Old 06-16-2006, 01:14 PM   #5
kad_79
LQ Newbie
 
Registered: Jun 2006
Posts: 10

Original Poster
Rep: Reputation: 0
elyk,

well that kinda puzzled me 4 a while too. but since the issue got resolved i just bundled my doubts and threw it in the pacific.
rest assured, if u r facing such an issue, "istrip" will resove it.
 
Old 06-17-2006, 12:01 AM   #6
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
The termios functions can also turn on/off the istrip flag. This is how the stty function does it.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
linux serial port to router console port connection? frankie_fix Linux - General 3 02-26-2007 09:32 PM
timedia 4 port serial port i/o card configuration binu_edl Linux - Hardware 0 03-09-2006 09:39 AM
Using serial port card(PCMCIA) with IPAQ running Linux, can't find ttyS0 port d2army Linux - Laptop and Netbook 0 11-12-2005 08:07 PM
convert unsigned char * to unsigned long int linux_lover2005 Programming 3 04-26-2005 11:38 PM
How to simulate incoming character in serial communication? Stor_G Programming 7 09-01-2004 02:22 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration