Libserial, read serial port
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Libserial, read serial port

  1. #1
    Join Date
    Apr 2014
    Posts
    4

    Libserial, read serial port

    I am using libserial library to interact with a modem using c++. The C++ code sends an AT command:

    Code:
    my_serial_stream << "AT+CSQ" << '\r' ;
    The modem responds with a response, either ERROR or OK,

    The c++ code to read the response:

    Code:
    while( serial_port.rdbuf()->in_avail() > 0 )
    {
        char next_byte;
        serial_port.get(next_byte);
        std::cerr << std::hex << (int)next_byte << " ";
    }
    std::cerr << std::endl;
    i would like to handle the response such that if the response is OK, the modem sends another command and if the response is ERROR, the modem resends the first command.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,605

    Re: Libserial, read serial port

    Use std::string variable to accumulate the text received from modem and see if it contains "OK" or "ERROR"...
    Victor Nijegorodov

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center