Last active
May 9, 2019 17:58
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(...) {...}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment