When implementing a Modbus RTU slave...
I have all NULL pointers passed to the fnInitialiseMODBUS_port() function so I get an user callback.
static int fnMODBUSSlaveuserFunction(int iType, MODBUS_RX_FUNCTION *modbus_rx_function)
Using the code below I determine which Modbus command was received and handle accordingly.
switch(iType){
case USER_RECEIVING_MODBUS_UNDEFINED_FUNCTION:
switch (modbus_rx_function->ucFunctionCode){
case MODBUS_WRITE_SINGLE_REGISTER:// 0x06
...
fnMODBUS_transmit(modbus_rx_function,modbus_HostBuf,8);
return 0;
case MODBUS_WRITE_MULTIPLE_REGISTERS:// 0x10
} // switch Modbus message type
} // switch
1) The problem I have is that I get two calls to the function.
The first time when receiving the incoming message and the second time after my reply was sent.
In the read request message I checked the MODBUS_RX_FUNCTION fields to detect the reply,
BUT in the MODBUS_WRITE_SINGLE_REGISTER the reply is exactly the same as the incoming message.
How can I differentiate between the reply and the incoming callbacks?
2) I receive the MODBUS_WRITE_MULTIPLE_REGISTERS message as 0x90 instead of 0x10.
I can not find out why?
Thanks
David Kaplan