There are a couple of utilities I wrote to working with a MODBUS
controller - note that these do not handle all MODBUS messages,
only the common command codes: 1-6, 15-16

The tools allow you to set/examine "coils" and "registers" on
MODBUS peripherals (PC is HOST), and provide some diagnostics of
the messages coming back from the device.

Tools can work "as is" with an RS-232 MODBUS interface. Since most
MODBUS is RS-485, the tools provide a TX control via "RTS" - RTS
is raised when transmitting, and lowered at all other times. This
can be used to control an RS-232 to RS-485 converter.


Command-line MODBUS tool:
-------------------------
Use: MODBUS [options] commands...

opts:   -H      = do not Halt on modbus errors
        -V      = Verbose mode (show serial data)
        A=0-255 = set modbus Address                            [0]
        B=speed = set Baudrate                                  [19200]
        C=1-4   = set Com port                                  [1]
        F=ms    = time to wait for First modbus data (ms)       [3000]
        S=ms    = time to wait for Subsequent modbus data       [250]

cmds:   reg=value       = Set modbus register
        ?reg            = Display modbus register
        ?low-high       = Display range of modbus registers


Interactive MODBUS tool:
------------------------
Use: MODTEST [options]

opts:   C=1-4   - select Com port                       [1]
        B=rate  - select Baudrate                       [19200]


See MODTEST on-screen key descriptions for functions.
(note: athough not shown, you can use 0-9 for direct entry of
       address/data values)



Both tools show the following error messages from the MODBUS
responses:

?too short (length)
 Received data was not long enough for a MODBUS message
 (often indicates nothing was received)


?Bad CRC (e:xx r:xx)
 MODBUS CRC failed, expected and received value are shown.

?Bad cmd (code)
 Unknown MODBUS command received.

?Bad count (a/b)
 Message count failed to match message size:
   a = count from message content
   b = count determined from message size

?Odd count
 Message count indicated an odd number of bytes
 (Modbus transactions are 16-bits)

?Bad length (length)
 Length of modbus message does not match command

?Bad data (data)
 Data for FORCE COIL should be
   0x0000 = OFF
   0xFF00 = ON
 Anything else is in error


Dunfield Development Services (DDS) offers software and firmware
development services specializing in systems and embedded applications.
For more information, visit: http://www.dunfield.com
