Skip to content

Asynch serial: read #7360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pilotak opened this issue Jun 28, 2018 · 5 comments
Closed

Asynch serial: read #7360

pilotak opened this issue Jun 28, 2018 · 5 comments

Comments

@pilotak
Copy link
Contributor

pilotak commented Jun 28, 2018

Description

Lets consider following code

rs232.read(rs232_rx_buffer, 8, event_callback_t(rs232RxCb), SERIAL_EVENT_RX_ALL);

with this code i don't get SERIAL_EVENT_RX_COMPLETE until i receive 8 bytes, but if only 7 bytes are sent (by mistake for example) can i get them with some kind of SERIAL EVENT? otherwise next 8 bytes sent will follow and obviosly i get SERIAL_EVENT_RX_OVERFLOW because there was 1 byte missing to complete and 7 left are overflow.

Issue request type

[X] Question
[ ] Enhancement
[ ] Bug

@0xc0170
Copy link
Contributor

0xc0170 commented Jun 28, 2018

The driver waits for 8 characters. There's no serial event for this (I can't think of what type of event this would be? We do not have time bounded callback here - no timeout).

You can use your own timeout (use Timeout object or other similar functionality). if you haven't received 8 characters within defined time, abort (should flush rx fifo to discard characters that has been received) and restart the read.

@pilotak
Copy link
Contributor Author

pilotak commented Jun 28, 2018

Ok thank you, maybe timeout could be an enhancement? or possibly fire event when read starts?

@ciarmcom
Copy link
Member

ARM Internal Ref: MBOTRIAGE-963

@kjbracey
Copy link
Contributor

kjbracey commented Jul 5, 2018

I would not recommend the asynchronous serial API as it stands, as it has the limitations you describe. It's ill-suited for general stream comms traffic.

And that API is a HAL API - revising it means revising every platform's HAL. I believe some serial HAL API work is planned, and this is a known issue which would be addressed, but for now I would suggest avoiding the asynchronous API.

Your best bet for serial input is to use UARTSerial, which will use the single-character synchronous HAL API from interrupt and present that to you as a stream via the FileHandle API. This is used by all network-type drivers like Wifi modules using AtCmdHandler, or PPP-based cellular modems, and is solid and pretty efficient, even if not capable of the same sort of theoretical speed as the asynchronous API.

Although I believe the asynchronous HAL API is actually implemented via interrupt-based PIO rather than DMA on most platforms, due to the hardware having similar lack-of-timeout limitations, so the performance difference isn't as large as you might think.

@pilotak
Copy link
Contributor Author

pilotak commented Jul 5, 2018

Thank you. That explains, why there is no official documentation available. I will have a look on UARTSerial, the reason why i used asynch was because it doesn't block code until everything is sent. I send out 255 chars at 9600 which takes ages - i use Modbus protocol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants