LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 10-23-2008, 02:34 AM   #1
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

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


Hello,

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

The configuration of serial port is:

Quote:
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:

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

Quote:
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, 10:58 AM   #2
grumpf
Member
 
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, 11:46 AM   #3
jf.argentino
Member
 
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, 12:11 PM   #4
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
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, 08:22 AM   #5
webquinty
Member
 
Registered: Apr 2008
Location: Espaņa
Distribution: Suse
Posts: 227

Original Poster
Rep: Reputation: 32
Quote:
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:
Quote:
//********************************************************
// 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
 
  


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
Parallel Port & Serial Port device identification helpmeforlinux Linux - Hardware 3 01-02-2007 01:15 AM
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
Using an USB port as a standard DB9 Serial Port Lsteele Linux - Newbie 1 10-22-2005 09:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:25 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