Thanks Mark,
I found that
static int fnMODBUSsimulator(int iType, MODBUS_RX_FUNCTION *modbus_rx_function)
{
switch (iType) {
case SERIAL_ROUTE_FROM_SLAVE:
{
unsigned char ucTest[7]; // the message to be sent must have the address at the start and 2 additional bytes space at the end for a check sum to be added. Do not use const data!
ucTest[0] = modbus_rx_function->ucSourceAddress; // our address
ucTest[1] = modbus_rx_function->ucFunctionCode;
ucTest[2] = 2;
ucTest[3] = 0; // our address
ucTest[4] = modbus_rx_function->ucSourceAddress; // our address
return (fnMODBUS_transmit(modbus_rx_function, ucTest, (sizeof(ucTest)))); // answer with pre-defined response
}
}
return 0;
}
Did what I wanted (Note your example didn't quite work, its byte count was wrong and only returned 1 byte not 2).
All I had to do was define the slave to be a gateway as below
(MODBUS_MODE_RTU | MODBUS_SERIAL_SLAVE | MODBUS_RS485_POSITIVE | MODBUS_SERIAL_GATEWAY), // default to RTU mode as slave - serial port 0
Cheers
Martin