NE-4100 Series User’s ManualDIO Commands
C code example: |
|
void WriteSingleDIO(int port, int mode, int status) | |
{ |
|
DIOPacketStruct packet; |
|
packet.header.command = 2; | // write single DIO command |
packet.header.version = 2; | // DIO protocol version |
packet.header.length = 3; | // data length |
packet.data[0] = (char)port; | // number of the DIO |
packet.data[1] = (char)mode; | // DIO mode |
packet.data[2] = (char)status; | // DIO status; |
send(SocketFd, (char *)&packet, sizeof(DIOHeaderStruct)+3, 0); //Send TCP packet //Process the returned data here
}
3. Reading Multiple DIOs
Parameter:
Command code: 5(hex)
Version: 2(hex)
Command status: doesn’t matter
Length of data: 2(hex); represents two bytes.
data[0]: Number of the DIO you wish to access first.
data[1]: The last number of the DIO you wish to access. Return:
Command Status : Check the Command Status code on the previous page.
Length of data:
data[0]: mode of start DIO
data[1]: status of start DIO
data[2]: mode of (start+1) DIO
data[3]: status of (start+1) DIO ….
C code example: |
| |
BOOL | ReadMultipleDIO(int start, int end, int *mode, int *status) | |
{ | DIOPacketStruct packet; |
|
|
| |
| packet.header.command = 5; | // Read Multiple DIO Commands |
| packet.header.version = 2; | // DIO protocol command version |
| packet.header.length = 2; | // data length |
| packet.data[0] = start; | // start of the DIO number |
| packet.data[1] = end; | // end of the DIO number |
send(SocketFd, (char *)&packet, sizeof(DIOHeaderStruct)+2, 0); //Send TCP packet //Process the returned data here
return TRUE;
}