MODBUS Communications Driver - Functions
ReadOutputStatus: Read Output Status
short status = MB_ReadOutputStatus(short Address, long Start, short Count, short Values);
status Address Start Count Values
Error Return Destination Device Address Starting Coil Number Number of Coils to Read Return Array
Integer Integer Long Integer Integer < 1950 Integer Array
This function reads the status of Output Coils (address 0xxxx) on the MODBUS device. The coil status values are returned in a "packed" format, with each bit in the return array corresponding to one output coil. If the number of coils requested is not evenly divisible by 16, unused return array bits will be set to 0.
The MODBUS Driver allows you to read up to 1950 bits in one operation, but your MODBUS device may have a lower transaction length limit.
// Return value array
short status = MB ReadOutputStatus(12, 20, 23, bits);
if (status != 0) MessageBox(NULL, MB ErrorString(status), MB_OK); _
This example reads a total of 23 bits starting at Output Coil Number 20 from the MODBUS device with address 12. In the return array bits, element 0 will contain the current values of coils 20 - 35, with Bit 0 (the LSb) corresponding to Coil 20 and Bit 15 (the MSb) corresponding to Coil 35. Element 1 of bits will contain Coils 36 - 42, with Bit 0 for Coil 36, Bit 7 for Coil 42, and Bits 8
15 set to 0.
If the function fails, the code sample displays an error Message Box, getting a string equivalent for the error code using the MB_ErrorString function.
June 6, 1998