ADU RS232 Pipe
The AduHid DLL provides a pipe to transmit data between an application program and the
RS232 port on the ADU device.
Data sent to the ADU device via the RS232 pipe is forwarded out on the DB9-RS232
connector. Data coming in from the DB9-RS232 connector is forwarded back to the host PC
via the RS232 pipe.
An application opens an ADU RS232 Pipe with the OpenAdu232
function.
Outbound data is written to the RS232 pipe with WriteAdu232.
Inbound data is read from the RS232 pipe with ReadAdu232.
When finished close the RS232 pipe with CloseAdu232.
Note: all RS232 pipe functions include "Adu232" in their name
Command-Response Behavior
The RS232 pipe is a half-duplex connection that can handle one message in one direction
at a time.
Thus an application that issues a responsive command must read the response before
issuing another command. If two responsive commands are written to the RS232 pipe without
an intervening read, then the two responses may corrupt one another.
For example the RD command sent to an ADR2010 board responds with the ASCII values of
the 8 analog converters on the board. Every write of an RD command must be followed by a
read of the response.
WriteAdu232(handle, "RD", 2, 0, 0);
memset(sResponse, 0, sizeof(sResponse));
ReadAdu232(handle, sResponse, 40, 0, 0);
// sResponse contains valid data
If two commands are sent sequentially, then a subsequent read of the RS232 pipe may
return corrupted data.
WriteAdu232(handle, "RD", 2, 0, 0);
WriteAdu232(handle, "RD", 2, 0, 0);
memset(sResponse, 0, sizeof(sResponse));
ReadAdu232(handle, sResponse, 40, 0, 0);
// sResponse may contain corrupted data
The recommended approach for an application program is to create a single thread that
controls communication with the ADU device. Thus the sequence of writing commands and
reading responses can be enforced.
|