This command causes a stream of characters to be read in from the serial port buffer. The number of characters is specified in io_Length.
The Query function can be used to check how many characters are currently waiting in the serial port buffer. If more characters are requested than are currently available, the ioRequest will be queued until it can be satisfied.
The best way to handle reads is to first Query to get the number of characters currently in the buffer. Then post a read request for that number of characters (or the maximum size of your buffer).
If zero characters are in the buffer, post a request for 1 character. When at least one is ready, the device will return it. Now start over with another Query.
Before the program exits, it must be sure to
AbortIO() then WaitIO() any outstanding ioRequests.
Having multiple outstanding read IORequests at any one time will probably fail. Starting with 43.5, this should work.
Previous to 43.5 characters could be lost if a read terminated early due to status or error conditions.
Due to hardware deficiency, the character immediately following a break may be trashed or an extra character may be recognized containing garbage.
Old documentation mentioned a mode where io_Length was set to -1 for 0-terminated reads.
Starting with 43.5, 0-terminated reads are supported. io_Actual will include the trailing 0 byte.
SDCMD_QUERY will report all bytes in the buffer. A CMD_READ may still abort early to report status/error conditions that occurred at a specific byte. Note that subsequent status/error conditions are ignored until the current one has been "read".