No announcement yet.

Serial Port COM

  • Filter
  • Time
  • Show
Clear All
new posts

  • Serial Port COM

    so i"m trying since a week with my device "usb gsm" on AMS to send and receive sms
    really i find it very hard, i finally could get some result this day,
    so im using this code to conect,send command and recieve an answer

    port = "com4";
    baud = 9600
    serial =,"w+")
    n = serial:read(3);
    Input.SetText("Input1", n)
    when i send this simple command "AT" , my device always answer with an "OK" of 3 bytes,
    even an other command , the last line should be an "OK".

    but if i try to send an other commande (exmple :AT+COPS? ) , i really don't know how larg is it my bytes, and here is my big probleme
    if someone could help how to find the size of device's answer of some other methode
    i try to read it byt by byte untile i get an OK, it got an crash becose it doesn't support a multipe read.
    i try to read the whole file with serial:read("*all") or serial:read("a") it got an infinty loop
    then how can i listen to my new sms.

    thank you and sorry for my bad english

  • #2
    Are you parsing the AT results correctly?

    The correct strategy for parsing AT command output is as follows:[LIST][*]Send the AT command line (correctly terminated with "\r").[*]Read one and one character received from the modem until you have a complete line terminated with "\r\n" and then parse that line.[LIST][*]If the line equals a final result code, then all output from the command line is finished (and the modem is ready to receive new commands). This must be the first thing you test for![*]If the AT command running has a prefix for its information text response lines (almost all have) check if the line starts with that, and if so process the line else ignore it.[*]If the AT command running does not have a prefix you probably want to print everything until the final result code is received. This applies only for legacy commands like ATI, and for parsing these you might legitimately care about echo or not.[/LIST][/LIST]
    As you can see, the AT responses have boundaries and have termination data. When you are talking to devices over serial ports, or even over unix-sockets, TCP/UDP or local sockets you need to know the protocol to communicate with. That protocol usually describes how to process messages that are sent back, with usually very distinguishable boundaries and terminators.

    Bas Groothedde
    Imagine Programming :: Blog

    AMS8 Plugins
    IMXLH Compiler


    • #3
      thabk you for answrer ,
      this's exactly my problème,
      i dont know how to read one character ( for exemple character on 5th position ).
      then i understand very well your answer, but i find it hard to translat it to codes.
      and how could i listen to my device (for new sms for exemple ) with a codes in background of my ams project.