Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unwanted carriage return character on COM port

Status
Not open for further replies.

NewtownGuy

Technical User
Jul 27, 2007
146
US
Hello,

I'm creating command strings that I sent out ttyS0 to control a robot. The strings are less than 10 bytes long and have binary data.

The problem is that every time I output a byte that happens to be 0x0A -- line feed -- a leading carriage return -- 0x0D -- gets added somewhere. This wrecks the command string.

I'm running Fedora Core 3. I'm guessing that the problem is with outputting the binary string through the COM1 / ttyS0 port because the binary log files we create are correct. If the COM port is the problem, how should we fix it ?

Here's how we configure the COM port at bootup in rc.local:

Code:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

setserial /dev/ttyS0 divisor 12
setserial /dev/ttyS0 spd_cust
setserial /dev/ttyS0 baud_base 115200
setserial /dev/ttyS0 close_delay 50
setserial /dev/ttyS0 closing_wait 100

chown root:apache /dev/ttyS0
chmod 666 /dev/ttyS0

We used divisor and spd_cust to get 9600 baud because the port kept running at 115,200 when we used baud_base 9600 with the default divisor. The chown line is shown because we provide the command strings through IE through apache, and we print the command strings to /dev/ttyS0.

Thank you.

-- NewtownGuy
 
TO: thedaver,

It's the standard rc.local script that runs at startup, to which we've added COM port initialization and two properties lines. The comment is the standard one from the Fedora Core 3 distribution.

-- NewtownGuy
 
Hello NewtownGuy,

I remember having done something like that years ago on some flavour of Unix, and I suppose it should work in a similar way for Linux:
In your manual pages for stty pay attention to -inlcr. Not sure if the same goal may be achieved with setserial or other commands.

hope this helps
 
TO: hoinz (MIS)

Thank you ! Using "stty --file=/dev/ttyS0 -onlcr -ocrnl" fixed the problem ! (I added protection for both LF and CR.)

-- NewtownGuy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top