LinuxQuestions.org
Visit Jeremy's Blog.
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 03-08-2011, 05:13 AM   #1
truboy
Member
 
Registered: Oct 2010
Location: Switzerland
Posts: 84

Rep: Reputation: 9
Read datas after write on serial port


Hi everyone,

I'm currently developping a C program to drive a Telit GM862-GPS module using the serial port of an embedded board (SBC9261).

The communication with the module is based on AT commands : I just send my command to the module, through the RS232 line, and the module answers immediately.
Here's an example with a basic command returning the GPS's acquired position, sent with Minicom :

Code:
AT$GPSACP
$GPSACP: 104323.000,4x45.6171N,00x38.6219E,0.8,446.5,3,272.14,0.21,0.11,080311,09

OK
Then, I've been able to make my C program send those kind of AT commands, from the SBC9261 board to the Telit module. It works fine, the module answers, but something still bothers me : when I read the answer of the module, it always starts with the command I just sent.
Example :
Code:
<Declaration and initialization of the file descriptor "fd" here...>

write(fd, "AT$GPSACP\r", strlen("AT$GPSACP\r"));
read(fd, &read, 50);
printf("Reading on ttyS1 : %s\n", read);

/*Output :
AT$GPSACP
$GPSACP: 104323.000,4x45.6171N,00x38.6219E,0.8,446.5,3,272.14,0.21,0.11,080311,09

OK/*

/*Should be :
$GPSACP: 104323.000,4x45.6171N,00x38.6219E,0.8,446.5,3,272.14,0.21,0.11,080311,09

OK
*/
I guess I'm missing something in the initial configuration of the file descriptor (when setting the termios struct). I googled around and tried different settings with ICANON, but I'm still stuck. Do you guys have seen this before ?

Or do you think this could be a normal behaviour of the transmission ?

Any suggestions appreciated !
Thank you for your answers !
 
Old 03-08-2011, 07:25 AM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,750

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
It is normal behavior. The GPS module is configured to echo characters back to the terminal which is why you also see the command when using minicom. The module may have a configuration setting to disable echo back.
 
1 members found this post helpful.
Old 03-08-2011, 10:19 AM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
The echo may be coming from your local serial port, or from the GPS device itself. To determine which, use a known-good terminal emulator such as minicom or C-Kermit, and disable local-echo. Send a few commands by typing interactively, and observe the result. In most cases, the device will echo character-by-character (mimicking local-echo), or may echo the entire command prefixed to the reply. You can do this from a standard PC with a serial port; even a Windows PC running the terminal emulator that comes with Windows (can't recall what it is called).
My bet is that the device is doing the echoing, as postulated by michaelk.
--- rod.
 
1 members found this post helpful.
Old 03-08-2011, 10:46 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,750

Rep: Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928Reputation: 5928
Excerpt from the AT command reference guide
Quote:
E - Command Echo
ATE[<n>]
Set command enables/disables the command echo.
Parameter:
<n>
0 - disables command echo
1 - enables command echo (factory default) , hence command sent to the device are echoed back to the DTE before the response is given.
 
1 members found this post helpful.
Old 03-08-2011, 11:21 AM   #5
truboy
Member
 
Registered: Oct 2010
Location: Switzerland
Posts: 84

Original Poster
Rep: Reputation: 9
Quote:
Originally Posted by theNbomr View Post
... even a Windows PC running the terminal emulator that comes with Windows (can't recall what it is called).
HyperTerminal


Thank you guys, I checked and that's the echo !

You easily get forget how things work when you use them everyday...

Thank you again !
 
  


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
bash: serial port write THEN read Metermon Programming 1 08-11-2010 09:05 AM
TO write to a serial port payu21 Linux - Newbie 1 05-24-2009 09:23 AM
is there any shell command to read and write data from parallel and serial port? baosheng Linux - Hardware 2 01-13-2007 08:35 PM
Should be dead simple - read/write serial port from bash ericcarlson Linux - Software 3 10-21-2006 08:35 PM
Serial port Read Write SeanatIL Programming 2 07-14-2004 03:42 PM

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

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