CANBUS ModBus App Notes Modbus protocol for CRC calculation and response events -v49.03. Added MODBUS protocol to handle CRC calculation and response events. Modbus RTU is available on RS2, RS4, AS1, AS2 - v49.32. More than one of these can be active at the same time if required. Setup example: SETUP(RS2) { baud = 19200; parity = N; rxi = Y; txi = Y; proto = ModbusRTU; //define modbus as the protocol to use } All low level handling of Modbus requests and responses are handled by the TFT firmware and the 'interface' to the itronSMART code is via system variables (xxx refers to the interface name: RS2, RS4, AS1 or AS2): Name Type Use MB_xxx_MODE U8 Modbus mode (0=master, 1=slave) MB_xxx_REGS PTR Pointer to a U16 array to hold read / write registers MB_xxx_COILS PTR Pointer to a U8 array to hold read / write coil bit values MB_xxx_SLAVEID U8 Slave address MB_xxx_FUNC U8 Modbus function code (1/3/15/16) MB_xxx_REGOFF U16 Offset into U16 register array for read / write action MB_xxx_REGCNT U16 Number of registers to read / write (or have been read / written) MB_xxx_COILOFF U16 Offset into U16 coil register array for read / write action MB_xxx_COILCNT U16 Number of coil registers to read / write (or have been read / written) MB_xxx_STATUS U8 Modbus status (0=idle, 1=tx, 1=rx, 2+ error) MB_xxx_TIMEOUT U16 Response timeout in milliseconds MB_xxx_DATAOK PTR Pointer to function that is called after a successful transaction MB_xxx_DATAERR PTR Pointer to function that is called after an error has occurred COIL data is converted from bits to bytes to make itronSMART access easier. For example a Modbus request to read 12 coils (2 Modbus data bytes) with offset of 6 will result in bytes 6 – 17 in the U8 coil registers being used.
Master operation
|