Advertisement
Guest User

Untitled

a guest
May 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. int main() {
  2. ConnectTCP();
  3. LoadModbusFunctions();
  4. ModbusStack_Init( MODBUS_TCP, sendModbusMessage, recvModbusMessage, currentTime);
  5. ModbusStack_SetSlaveId( MODBUS_SLAVE_ADDRESS );
  6. ModbusStack_RegisterGetValue(getModbusValue);
  7. for(;;) {
  8. ModbusStack_Loop();
  9. }
  10. }
  11.  
  12. bool getModbusValue(const unsigned char slaveAddress, const unsigned char function,
  13. const unsigned short startingAddress, const unsigned short length,
  14. unsigned char *data, const unsigned short maxPayloadSize,
  15. unsigned char *errorCode)
  16. {
  17. if( slaveAddress == MODBUS_SLAVE_ADDRESS && function == MODBUS_FUNCTION_03_READ_HOLDING_REGISTERS ) {
  18. memcpy(data, databaseHoldingRegisters + startingAddress, length * sizeof(short));
  19. return true ;
  20. }
  21. return false;
  22. }
  23.  
  24. void sendModbusMessage(...) {...};
  25. void recvModbusMessage(...) {...};
  26. void currentTime(...) {...};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement