LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Read datas after write on serial port (https://www.linuxquestions.org/questions/programming-9/read-datas-after-write-on-serial-port-867170/)

truboy 03-08-2011 05:13 AM

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 !

michaelk 03-08-2011 07:25 AM

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.

theNbomr 03-08-2011 10:19 AM

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.

michaelk 03-08-2011 10:46 AM

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.

truboy 03-08-2011 11:21 AM

Quote:

Originally Posted by theNbomr (Post 4282899)
... 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 !


All times are GMT -5. The time now is 08:39 PM.