[ASIO] serial_port read seems to lost packets
Hi, I'm sure that is a my issue but I need your help.. In my project I have to talk with a modem. In answer to my AT command it responds: +CMGS: 0 OK +CMGS: 0,4,26 +CTSDSR: 40,123,0,456,0,152 231270F2204AAADC1234663E8DE77708FC5F3E where the +CTSDSR arrives some milliseconds after the last +CMGS. The problem is that I catch the two +CMGS but i miss completely the +CTSDSR and I don't know why! the reading code is: void SerialPort::read_start() { // Start an asynchronous read _serialPort.async_read_some(boost::asio::buffer(_buf, m_buffer_size), boost::bind(&SerialPort::read_complete, this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); }; void SerialPort::read_complete(const boost::system::error_code& error, size_t bytes_transferred) { // the asynchronous read operation has now completed if (!error) { // saving data to vector _read_buffer.append(_buf, bytes_transferred); cout << _read_buffer << endl; } // start waiting for another asynchronous read again read_start(); }; Could someone give me some suggestions? Thanks! Daniele.
void SerialPort::read_complete(const boost::system::error_code& error, size_t bytes_transferred) { // the asynchronous read operation has now completed if (!error) { // saving data to vector _read_buffer.append(_buf, bytes_transferred); cout << _read_buffer << endl; } // start waiting for another asynchronous read again read_start(); };
What if you move "if (!error)" condition down and put it before read_start()?
Igor R ha scritto:
void SerialPort::read_complete(const boost::system::error_code& error, size_t bytes_transferred) { // the asynchronous read operation has now completed if (!error) { // saving data to vector _read_buffer.append(_buf, bytes_transferred); cout << _read_buffer << endl; } // start waiting for another asynchronous read again read_start(); };
What if you move "if (!error)" condition down and put it before read_start()?
Hi Igor! I didn't think! Now it seems to work!! Thanks again. Cheers, Daniele.
participants (2)
-
Daniele Barzotti
-
Igor R