Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-23-2008, 03:34 AM   #1
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 220

Rep: Reputation: 32
Hello, doubt with serial port............


I hava some threads, and one of them is to receive commands from other PC with serial port.

The configuration of serial port is:

tcgetattr(fd, &options_new);

cfsetispeed(&options_new, B38400);
cfsetospeed(&options_new, B38400);

options_new.c_cflag |= (CLOCAL | CREAD);

options_new.c_cflag &= ~PARENB;
options_new.c_cflag &= ~CSTOPB;
options_new.c_cflag &= ~CSIZE;
options_new.c_cflag |= CS8;

options_new.c_cflag &= ~(IXON | IXOFF | IXANY);

options_new.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

options_new.c_cc[VMIN] = 0;
options_new.c_cc[VTIME] = 0;

tcsetattr(fd, TCSANOW, &options_new);
I supposed that raw input allow me to receive all values without any problem, but when I send this comand for example:

0x01 0x04 0x11 0x45 0x1f 0x67 crc
The problem is that 3 byte is backspace I my program receive this:

0x01 0x04 0x45 0x1f 0x67 crc
In few words, byte 0x11 (backspace) delete one byte.
How can I configure serial port to receive all charcaters without theese problems.

Best regards.
Old 10-24-2008, 11:58 AM   #2
Registered: Dec 2005
Distribution: just replace windows with linux
Posts: 38

Rep: Reputation: 15
the best way is to check with minicom what is going on.
if somethings is eating BS you have a filter enabled use cfmakeraw() is our prg
and stty -a </dev/ttyS0 to check.
are you sure that nothing else is access the port ? it can have some complicated consequences.
(see: mgetty and friends)
Old 10-24-2008, 12:46 PM   #3
Registered: Apr 2008
Location: Toulon (France)
Distribution: FEDORA CORE
Posts: 493

Rep: Reputation: 50
If I well remember, the serial port is mainly used for as a terminal IO, it means that some character (or characters sequence) have special purpose... You can disabled these "special" characters interpretation, but I don't remember how... Maybe add the flag O_NOCTTY when opening the device, or take a look to the field "c_cc" (control characters) of the termios structure.
Hope this help...
Old 10-24-2008, 01:11 PM   #4
Senior Member
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,125
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
easiest way is to use cfmakeraw(&new_options) and then set any additional parameters you want.
Old 10-27-2008, 09:22 AM   #5
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 220

Original Poster
Rep: Reputation: 32
Originally Posted by estabroo View Post
easiest way is to use cfmakeraw(&new_options) and then set any additional parameters you want.
Thank you very much,

I have found my problem:
// chosee raw output
options_new.c_oflag &= ~OPOST;
I did not change this, then some character have special purpose. But with this option, I can send data in raw mode.

Sorry for it, perhaps I coudl fix it if I look for more information in the net.

Best regards


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 10:32 PM
Parallel Port & Serial Port device identification helpmeforlinux Linux - Hardware 3 01-02-2007 02:15 AM
timedia 4 port serial port i/o card configuration binu_edl Linux - Hardware 0 03-09-2006 10: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 09:07 PM
Using an USB port as a standard DB9 Serial Port Lsteele Linux - Newbie 1 10-22-2005 10:48 AM > Forums > Linux Forums > Linux - Newbie

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

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