static byte tx_buf[MODBUS_TX_BUFSIZE];
static u16 tx_size;
static u16 tx_pos;
+static byte pending_error;
static bool check_frame(void);
static void process_frame(void);
ERR_ILLEGAL_FUNCTION = 0x01,
ERR_ILLEGAL_DATA_ADDRESS = 0x02,
ERR_ILLEGAL_DATA_VALUE = 0x03,
+ ERR_SLAVE_DEVICE_FAILURE = 0x04,
};
static uint read_remains(void)
tx_buf[0] = MODBUS_OUR_ADDRESS;
tx_buf[1] = rx_buf[1];
tx_size = 2;
+ pending_error = 0;
switch (func) {
case FUNC_READ_COILS:
report_error(ERR_ILLEGAL_FUNCTION);
}
+ // Is there a deferred error pending?
+ if (pending_error)
+ report_error(pending_error);
+
// Finish reply frame
write_u16(crc16(tx_buf, tx_size));
}
+
+void modbus_slave_error(void)
+{
+ pending_error = ERR_SLAVE_DEVICE_FAILURE;
+}
void modbus_init(void);
void modbus_loop(void);
+// If a call-back wants to signal a slave error in the reply
+void modbus_slave_error(void);
+
// Callbacks
bool modbus_check_discrete_input(u16 addr);