Windmill Software Ltd
Windows Engineering Software

Interfacing Modbus Device
February 2007

Interfacing
a Modbus Device

Home
Newsletters
Catalogue
Search

Modbus devices connect to the PC over a serial line using the Modbus protocol. Our free comDebug software lets you troubleshoot your Modbus connection. You can also use it to check whether the Windmill Modbus driver will work with your device.

  1. Download the free comDebug Modbus software.
  2. Unzip the software using WinZip or similar, and run setup.exe to install.
  3. Run comDebug
  4. If you haven't purchased the COMIML Modbus driver, choose to use the program as a Terminal Utility. See the on-line Help for more details.
  5. Enter the necessary settings into the Prompt Grid, as detailed below.

comDebug supports any mix of digital and analogue inputs and outputs. These can be distributed across any set of Modbus slave devices. You can configure the slave device address and the parameter number (register number) for each channel individually.

The Modbus protocol defines two modes of transmission: ASCII and RTU (Remote Terminal Unit). comDebug supports both modes. In ASCII mode each 8-bit byte in a message is sent as two ASCII characters. It allows intervals of up to 1 second between characters, without causing an error. Messages start with a colon and end with a Carriage Return followed by a Linefeed. The RTU mode uses binary coding.

Each message comprises four parts: device address, function code, data, error check.

The Device Address identifies your instrument. It contains one byte of information. In ASCII it is coded with two hexadecimal characters, in RTU with one byte. Valid addresses are between 0 and 247.

The Function Code specifies the type of message. It contains one byte of information. In ASCII it is coded with two hexadecimal characters, in RTU with one byte.


Modbus Communications Settings

ASCII
Start Bit = 1
Data Bits=7
If Parity is even or off then Stop Bits = 1
If Parity is none then Stop Bits = 2

RTU
Start Bit = 1
Data Bits=8
If Parity is even or off then Stop Bits = 1
If Parity is none then Stop Bits = 2


Modbus Message Settings when using comDebug

Use the prompt grid in the Terminal screen to send commands and data to your Modbus device. If you are sending binary rather than ASCII messages, use the NonPrint menu to enter addresses, codes, etc. For example, to enter a device address, select NonPrint Decimal from the NonPrint menu. Type the device address into the blue box. Address 1, for example, would be shown as Char 001 and Hex 01.

To Read a Single Modbus Register

Byte 1 = device address
Byte 2 = Modbus function code: 03 or 04
Byte 3 = msb of register
Byte 4 = lsb of register
Byte 5 = msb of number of bytes to read: normally 0
Byte 6 = lsb of number of bytes to read: for example 2
Byte 7 = CRC: use the CRC menu

Modbus Settings in comDebug
Entering Modbus settings into comDebug

Note: The function code 03 reads the holding register. This comprises two bytes and may be used to return measured values such as temperature. 04 reads the input registers.

The Reply Comprises

Byte 1 = device address
Byte 2 = function code
Byte 3 = number of bytes read
Byte 4 = 1st word, msb
Byte 5 = 1st word, lsb
Byte 6 = 2nd word, msb
Byte 7 = 2nd word, lsb
   :
   :
Byte n = CRC

To Write to a Register

Byte 1 = device address
Byte 2 = Modbus function code: 6
Byte 3 = address of word, msb
Byte 4 = address of word, lsb
Byte 5 = value of word, msb
Byte 6 = value of word, lsb
Byte 7 = CRC

The Reply Comprises

Byte 1 = device address
Byte 2 = function code: 6
Byte 3 = address of word, msb
Byte 4 = address of word, lsb
Byte 5 = value of word, msb
Byte 6 = value of word, lsb
Byte 7 = CRC

Logging, Charting and Analysing Data

To log and chart data, or to send it to other programs like Excel for analysis, you need to buy the COMIML Modbus driver. This is available from our internet catalogue.


Home | Windmill Programs | Monitor | On-Line Shop | Free Literature and Software Demos | Contents | Search

Copyright Windmill Software Ltd 2001
PO Box 58, North District Office, Manchester, M8 8QR, UK.
E-mail: sales@windmill.co.uk, Tel: +44 161 833 2782
http://www.windmill.co.uk/modbussettings.html
Data Acquisition News Feed (RSS) Free measurement news feed...
Designed by Studholme.net
Related Topics: