Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main() {
- ConnectTCP();
- LoadModbusFunctions();
- ModbusStack_Init( MODBUS_TCP, sendModbusMessage, recvModbusMessage, currentTime);
- ModbusStack_SetSlaveId( MODBUS_SLAVE_ADDRESS );
- ModbusStack_RegisterGetValue(getModbusValue);
- for(;;) {
- ModbusStack_Loop();
- }
- }
- bool getModbusValue(const unsigned char slaveAddress, const unsigned char function,
- const unsigned short startingAddress, const unsigned short length,
- unsigned char *data, const unsigned short maxPayloadSize,
- unsigned char *errorCode)
- {
- if( slaveAddress == MODBUS_SLAVE_ADDRESS && function == MODBUS_FUNCTION_03_READ_HOLDING_REGISTERS ) {
- memcpy(data, databaseHoldingRegisters + startingAddress, length * sizeof(short));
- return true ;
- }
- return false;
- }
- void sendModbusMessage(...) {...};
- void recvModbusMessage(...) {...};
- void currentTime(...) {...};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement