Boost logo

Boost :

From: Stefano Mora (stefano.mora_at_[hidden])
Date: 2024-06-12 10:22:42


Hello,
please I need other information about the serial port read + timeout.

Referring to the TimeoutSerial class: in the read(char*,size_t) implementation I understand that it run an async read and then it wait on timer.
The for loop the function waits on io.run_one(): I guess that both port and timer are under the io (io_context) control (by the constructors).

It is not clear what happen in some steps:at the beginning I only try to read something (just eventually to empty the queue) with a 100ms timeout.
Then I sent 2 chars (ESC ESC) to check the presence of the device.
My log is:

[WriteCommand] Write nbytes: 0
[WaitForResponse] ms 100
[WaitForResponse] or pattern: ''
RX ..
[Tos] async_read_until ..
[ToSerial][timeoutExpired] error system:0
[Tos][read] exit from run_one result: 3 = resultTimeoutExpired
[waitForResponse] catch TIMEOUT dt:0

Send ESC ESC ..
[WriteCommand] Write nbytes: 2
[WaitForResponse] ms 2000
[WaitForResponse] or pattern: '

>'
RX ..
[Tos] async_read_until ..

[ToSerial][readCompleted] - error: system:995 - bytes: 0
[Tos][read] exit from run_one result: 0

[ToSerial][readCompleted] - error: system:0 - bytes: 210
[readCompleted] success!
[Tos][read] exit from run_one result: 1
RX [207] : '[?25l********************************

'
[TP][WaitForResponse] Edn wait
End ESC ESC !!

My question is:
- on the first read correctly the timeout handler is recalled, it set the resultTimeoutExpired state and exits. The run_one() exits with value 3 and the switch selects the case where it cancels the port and throws the timeout_exception. Why the readCompleted function (aborted 995) is recalled more later, after the ESC_ESC buffer is sent and another async_read_until is rearmed?
Anyway the reply is received ..

Thanks


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk