Read & write AT command to serial port in C -


I am trying to switch the modem in command mode, write the AT command and parse the response, but with C Not very good and I do not understand what is wrong. The code I am calling is:

  zero switch_to_command_man (int yuat) {current_command_type = BTCommandTypeSwitchToATMode; Four switch CMD [] = "\ x2F \ x2F \ x2F"; Four empty symbol [] = ""; Four checkat [] = "at \ r"; Ssize_t lane = 0; Write (Uate, Empty Symbol, Stellen (Empty Symbol)); Sleep (1); Write (UET, Switch CMD, Stellon (Switch CMD)); Sleep (1); Write (Uyert, Czech, Stalin (Czechat)); Four buffer [255]; / * Input buffer * / four * bufptr; / * Currently buffer * / int nbytes; Bufptr = buffer; While (ioctl (uart, fionread, (unsigned long) and len) == 0 & amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp; amp & nbsp; ln; 2) {warnx ("wait"); usleep (1000); } While ((nbytes = read (uart, bufptr, buffer + size (buffer) - bufptr - 1))> 0) {bufptr + = nbytes; Warning ("buffer% s", buffer); If (bufptr [-1] == '\ n' || bufptr [-1] == '\ r'); } Warning ("last buffer:% s", buffer); If (strncmp (buffer, "ok", 2) == 0) {warnx ("great success!"); }}   

What I get as a console output:

  At the buffer waiting at ATOIP4 buffer AT OK, last buffer : According to the documentation for AT BT module, the response  and lt; CR & gt; & Lt; LF & gt; OK & Lt; CR & gt; & Lt; LF & gt;  should be in the form .  

Any guidance on why this is happening but what I can do with it will be highly appreciated.

PS I was already already.

A "string" in C.- 0 -terminated.

If they are not before processing (printed here) the program runs in undefined behavior. Whatever "trash" can be printed.

To easily start buffer used before using all the 0 s to fix it:

  Four buffer [255] = "";   

Also read () returns ssize_t not int . You can do better:

  ssize_t nbytes;    

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -