Page 1 of 1
anyway to access usb_serial input/output buffer?
Posted: Wed Apr 16, 2014 8:15 am
by yushanh
Hi, is there any way to know whether there is data in the serial_usb input buffer from the host? Usually I used chSequentialStreamRead(ip, bp, n) in the while loop the get data. However, I'd like to read the data only when there really is something. How could I access the current serial_usb buffer size? Also, is the default maximal buffer size 256 bytes (SERIAL_USB_BUFFERS_SIZE)?
Thanks,
Shan
Re: anyway to access usb_serial input/output buffer?
Posted: Wed Apr 16, 2014 8:38 am
by Giovanni
Hi,
You may use TIME_IMMEDIATE as timeout, the function will exit immediately if there is no data to read.
Giovanni
Re: anyway to access usb_serial input/output buffer?
Posted: Wed Apr 16, 2014 9:47 am
by yushanh
Hi Giovanni,
When I looked into the read method, it already set the timeout as TIME_INFINITE.
Code: Select all
#define chSequentialStreamRead(ip, bp, n) ((ip)->vmt->read(ip, bp, n))
Code: Select all
static size_t read(void *ip, uint8_t *bp, size_t n) {
return chIQReadTimeout(&((SerialUSBDriver *)ip)->iqueue, bp,
n, TIME_INFINITE);
}
I wonder if it's ok to use chIQIsEmptyI()? In my application, I have some other conditions before reading data via serial_usb. Not sure if it is feasible.
Thanks,
S
Re: anyway to access usb_serial input/output buffer?
Posted: Wed Apr 16, 2014 10:12 am
by Giovanni
It is feasible but you would be assuming there are queues there, it is like a private field.
Unlikely to change anyway.
Giovanni