1

I have written a program that comminucates serially with a USB 3g Modem. When I open the port and write the AT command

AT

To the modem, I get the normal "OK" response and can read it using a serial read function. In a terminal, when I write the command

AT^SYSINFO

I get the following response:

^SYSINFO:#,#,#,#,#,#

With the #'s being numbers. However, when I attempt to write the same command serially using my program, I read only this reponse:

AT^SYSINFO

I try to then read another line of incoming data, but no data comes. Can anyone help me with this? There is information in the ^SYSINFO message that I need to extract.

Cornel Verster
  • 1,664
  • 3
  • 27
  • 55
  • 2
    How does your serial port read function work? Sounds like perhaps it's grabbing more data than it should, and discarding it, or something like that. Without seeing your code, it's almost impossible to say (and it may not be easy WITH code either, since these things can be quite subtle). – Mats Petersson Jan 28 '14 at 07:38
  • I use a very basic read function that can be found with my write function [here](http://pastebin.com/YKeNPZMd). – Cornel Verster Jan 28 '14 at 08:12
  • 1
    And the code calling readline? – Mats Petersson Jan 28 '14 at 08:15
  • You can find that [here](http://pastebin.com/DmnmnnMk) – Cornel Verster Jan 28 '14 at 08:57
  • I did some more testing and realized that the commands never send properly using this form of writing. Do you think it has something to do with asio or is putting a '\n' at the end of the write not enough?? – Cornel Verster Jan 28 '14 at 12:12
  • You may need to explicitly send "\r\n"... – Mats Petersson Jan 29 '14 at 08:17
  • Hey Mats! I found out that simply sending '\r' is sufficient. You have to do a whole bunch of serial reads though to clear through all the newlines and OKs sent as replies to your commands. Also, the modem always echoes your command as a first reply. Thanks for the help! – Cornel Verster Jan 29 '14 at 09:25
  • Could you update the question to contain the code in pastebin? (Pastebin might not be around forever, and it limits search possibilities here on SO, and it requires extra effort for people reading the question) – hlovdal Feb 01 '14 at 21:36
  • 1
    By posting links to pastebin you seem to be implying that SO is a personal helpdesk, solely for solving your problem for you right now! It's not. It's a Q&A database. Your question should contain whatever [testcase](http://sscce.org) is required for the question to make sense. – Lightness Races in Orbit Feb 01 '14 at 22:38

1 Answers1

2

You MUST terminate an AT command line with \r and nothing else (unless you have modified ATS3, but you should not)1. To quote the V.250 specification:

5.2.1   Command line general format

A command line is made up of three elements: the prefix, the body, and
the termination character. The command line prefix consists of the
characters "AT" or "at", or, to repeat the execution of the previous
command line, the characters "A/" or "a/". The body is made up of
individual commands as specified later in this Recommendation. Space
characters are ignored and may be used freely for formatting purposes,
unless they are embedded in numeric or string constants (see 5.4.2.1
or 5.4.2.2). The termination character may not appear in the body. The
DCE shall be capable of accepting at least 40 characters in the body.
The termination character may be selected by a user option (parameter S3),
the default being CR (ASCII value 13).

DCE means modem.

(I removed the IA5 references in the quote above as that is only confusing)


1 Terminating with \r\n will usually work, but that is only because of the 125ms abort timeout delay that makes the extra \n not abort the command.

hlovdal
  • 26,565
  • 10
  • 94
  • 165