Moxa Technologies NE-4100 User Manual

Page 82

Advertising
background image

NE-4100 Series User’s Manual

DIO Commands

C-2

//define DIO Packet format
//Used for Command and ACK packet
typedef struct _DIO_Packet_Struct {
DIOHeaderStruct

header;

char

data[255];

} DIOPacketStruct, *pDIOPacketStruct;

Command Code Usage

1. Reading Single DIO
Parameters:
Command code: 1(hex)
Version: 2(hex)
Command Status: doesn’t matter

Length of data: 1(hex), represents one byte.

data[0]: Fill in the number of the DIO you wish to access. The DIO number starts from 0(hex).

Return:

Command Status: Check the Command Status code on the previous page.

Length of data: 3(hex). Must be 3 bytes of return code in this mode.

data[0]:

The

number

of the DIO you wish to access.

data[1]: DIO mode(hex), 0 for IN, 1 for OUT

data[2]: DIO status(hex), 0 for LOW, 1 for HIGH


C code example:
BOOL ReadSingleDIO(int port, int *mode, int *status)
{
DIOPacketStruct packet;

packet.header.command = 1; // read single DIO command
packet.header.version = 2; // DIO protocol version
packet.header.length = 1; // data length
packet.data[0] = (char)port; // Number of the DIO
send(SocketFd, (char *)&packet, sizeof(DIOHeaderStruct)+1, 0); //Send TCP Packet
// Process the returned data here.
return TRUE;
}

2. Writing a Single DIO

Parameters:

Command code: 2(hex)

Version: 2(hex)
Command Status: doesn’t matter

Length of data: 3(hex); represents three bytes.

data[0]: The number of the DIO you wish to access.

data[1]: DIO mode(hex), 0 for IN, 1 for OUT

data[2]: DIO status(hex), 0 for LOW, 1 for HIGH

Return:

Command Status: Check the Command Status code on the previous page.

Length of data: 3(hex). Must be 3 bytes of return code in this mode.

data[0]:

The

number

of the DIO you wish to access.

data[1]: DIO mode(hex), 0 for IN, 1 for OUT

data[2]: DIO status(hex), 0 for LOW, 1 for HIGH

Advertising