MODBUS RTU compatible master and slave driver for High Performance Controllers



Similar documents
RS-485 Protocol Manual

The Answer to the 14 Most Frequently Asked Modbus Questions

Process Control and Automation using Modbus Protocol

Introduction: Implementation of the MVI56-MCM module for modbus communications:

Modbus Communications for PanelView Terminals

Modbus and ION Technology

Programming and Using the Courier V.Everything Modem for Remote Operation of DDF6000

RcWare SoftPLC Modbus server mapping editor User manual

How to setup a serial Bluetooth adapter Master Guide

TRP-C31M MODBUS TCP to RTU/ASCII Gateway

MODBUS TCP to RTU/ASCII Gateway

Modbus Protocol. PDF format version of the MODBUS Protocol. The original was found at:

RS-232 Communications Using BobCAD-CAM. RS-232 Introduction

Omron I/O Driver (Series 2) Programmable Serial Interface Card

CONCEPT1 RS232 COMMUNICATION

Modbus and ION Technology

Objectives. Basics of Serial Communication. Simplex vs Duplex. CMPE328 Microprocessors (Spring ) Serial Interfacing. By Dr.

MBP_MSTR: Modbus Plus Master 12

LINDY ELECTRONICS LIMITED & LINDY-ELEKTRONIK GMBH - SECOND EDITION

4511 MODBUS RTU. Configuration Manual. HART transparent driver. No. 9107MCM100(1328)

User Manual. AS-Interface Programmer

EZ-View Network Communications Guide

Single channel data transceiver module WIZ2-434

Programming Flash Microcontrollers through the Controller Area Network (CAN) Interface

OFF-LINE COMMUNICATIONS WITH CINCINNATI EQUIPMENT Pg. 1 of 5

ENET-710. ENET Ethernet Module ENET-710 JAN / 06 FOUNDATION

Nemo 96HD/HD+ MODBUS

WHQL Certification Approval...2 User Interface...3 SUNIX s COMLab..4

But for compatibility reasons the basic structure of the data area or the addressing mechanism of the protocol retained.

RS-422/485 Multiport Serial PCI Card. RS-422/485 Multiport Serial PCI Card Installation Guide

The Secrets of RS-485 Half-duplex Communication

Why you need to monitor serial communication?

HOST Embedded System. SLAVE EasyMDB interface. Reference Manual EasyMDB RS232-TTL. 1 Introduction

White Paper. Technical Capabilities of the DF1 Half-Duplex Protocol

MODBUS TCP to RTU/ASCII Gateway. User s Manual

Technical Note A007 Modbus Gateway Vantage Pro2 25/09/2009 Rev. A 1 de 7

Keep it Simple Timing

Technical Support Bulletin Nr.18 Modbus Tips

MTS Master Custom Communications Protocol APPLICATION NOTES

BIT COMMANDER. Serial RS232 / RS485 to Ethernet Converter

S88XPressNetLI v1.0. Installation, user and reference manual KDesign Electronics, PCB design by RoSoft

1.Eastron SDM220Modbus Smart Meter Modbus Protocol Implementation V1.0

Using Logix5000 Controllers as Masters or Slaves on Modbus

RS232 Programming and Troubleshooting Guide for Turbo Controls

PRODUCTIVITY THROUGH INNOVATION 600 CONTROL DIRECT DRIVE TECHNICAL/OPERATION MANUAL

Industrial Networks & Databases

Softstarters. Type PSTX Fieldbus communication, Built-in Modbus RTU. 1SFC132089M0201 April SFC132089M0201 1

How To Set Up A Modbus Cda On A Pc Or Maca (Powerline) With A Powerline (Powergen) And A Powergen (Powerbee) (Powernet) (Operating System) (Control Microsci

1-Port R422/485 Serial PCIe Card

PLC Master / Slave Example

Modbus TCP / DALI converter

Virtual Integrated Design Getting started with RS232 Hex Com Tool v6.0

PFB366 Profibus-DP Gateway User Manual

Aquadyne TechTip TITLE: TROUBLESHOOTING PC COM PORT AND MODEM PRODUCTS AFFECTED SYMPTOMS POSSIBLE CAUSES

ALL-USB-RS422/485. User Manual. USB to Serial Converter RS422/485. ALLNET GmbH Computersysteme Alle Rechte vorbehalten

VSCOM USB PRO Series Industrial I/O Adapters

1.1 Connection Direct COM port connection. 1. Half duplex RS232 spy cable without handshaking

PRODUCT MANUAL SKX OPEN SKX ADVANCE ZN1RX-SKXOPEN. Edition 2 Version 1.1

ESPA Nov 1984 PROPOSAL FOR SERIAL DATA INTERFACE FOR PAGING EQUIPMENT CONTENTS 1. INTRODUCTION 2. CHARACTER DESCRIPTION

F2103 GPRS DTU USER MANUAL

DVPPF02-H2. PROFIBUS DP Slave Communication Module Application Manual

Programming the BetaBrite Classic LED electronic sign

MEMOBUS/Modbus Communications

TruePort Windows 2000/Server 2003/XP User Guide Chapter

LS-101 LAN to Serial Device server. User s Manual

Modicon Modbus Protocol Reference Guide. PI MBUS 300 Rev. J

MODBUS over Serial Line. Specification & Implementation guide V1.0

8 data bits, least significant bit sent first 1 bit for even/odd parity (or no parity) 1 stop bit if parity is used; 1 or 2 bits if no parity

WHQL Certification Approval...2 User Interface K software FIFO 4 Universal PCI Interface...5 Ready for 64-bit System...5

User Manual Revision English Converter / Adapter Ethernet to RS232 / RS485 (Order Code: HD HD M HD HD M)

PCS0100en Persy Control Services B.V. Netherlands

Bluetooth HC-06 with serial port module Easy guide

MANUAL FOR RX700 LR and NR

Profinet to EDV111 Series LED Signs Siemens Function Block Software Manual

PRT3 Printer Module: ASCII Protocol Programming Instructions

TCP/IP MODULE CA-ETHR-A INSTALLATION MANUAL

Troubleshooting and Diagnostics

How To Connect A Directsofl To A Powerpoint With An Acd With An Ctel With An Dm-Tel Modem On A Pc Or Ipad Or Ipa (Powerpoint) With A Powerline 2 (Powerline

Time Synchronization & Timekeeping

User manual Compact Web PLC WP240 series IEC-line

RS232C < - > RS485 CONVERTER S MANUAL. Model: LD15U. Phone: / 97 / 98 (M)

Modbus RTU Master Communications

MODBUS APPLICATION PROTOCOL SPECIFICATION V1.1b3 CONTENTS

Bluetooth to Serial Adapter

Wireless LAN g USB Adapter

MCB3101 (Class I) WiRobot Serial Bluetooth Wireless Module User Manual

RS485 & Modbus Protocol Guide

NMEA 0183 INSTALLATION AND OPERATING GUIDELINES

MDM192 MULTI-DROPS DIGITAL MODEM FOR PRIVATE LINE. USER GUIDE Document reference :

BLUETOOTH SERIAL PORT PROFILE. iwrap APPLICATION NOTE

PCMCIA 1 Port RS EDITION OCTOBER 1999

STIM202 Evaluation Kit

FINS Gateway For OMRON PLCs

KV-10_80RW/TW CPU Direct Driver

PLC training panel (Twido version)

PNSPO! Modbus Solution CP1H / CP1L / CJ1 / CJ2 / CS1. Version /18/2009

Remote Access Server - Dial-Out User s Guide

How-To Set Custom Scale Format for FedEx Ship Manager

Technical Manual. For use with Caller ID signaling types: Belcore 202, British Telecom, & ETSI

Transcription:

MODBUS RTU compatible master and slave driver for High Performance Controllers Book E26 - Version 2.12

MODBUS RTU compatible master and slave driver E26 Version 2.12 Table of contents Chapter 1 Introduction 3 1 Overview... 3 2 Required... hardware 3 3 Required... software 3 4 Required... option lock 4 5 Cabling... 4 Chapter 2 Installation of the driver 5 Chapter 3 1 Initialization... of the serial port 5 2 Installing... a MODBUS master 5 3 Installing... a MODBUS slave 7 4 Uninstalling... a MODBUS slave 9 Do reads and writes with the MODBUS master 10 Chapter 4 More about numbers and types of variables 13 1 Mapping... table of ED&A digital inputs to modbus numbers (using standard i/o configuration) 14 2 Mapping... table of ED&A digital outputs to modbus numbers (using standard i/o configuration) 15 3 Mapping... table of ED&A analogue inputs to modbus numbers (using standard i/o configuration) 16 4 Mapping... table of ED&A analogue outputs to modbus numbers (using standard i/o configuration) 16 Chapter 5 Broadcasting 18 Chapter 6 Protocol details 19 Chapter 7 Troubleshooting guide 24 1 Does... MODBUS master send messages? 24 2 Does... the slave receive these messages? 25 3 Does... the slave react to the messages? 25 4 Does... the answers go from the slave to the master? 26 5 Are... the answers OK or do they contain error codes? 26 6 Do... cable problems cause interruptions? 27 Chapter 8 Examples 28 1 Modsla1.epl... 28 2 Modmas1.epl... 29 3 Modmas2.epl... 30 4 Modmas3.epl... 32 5 Modmas4.epl... 33 1

MODBUS RTU compatible master and slave driver E26 Version 2.12 6 Modsla4.epl... 34 Chapter 9 Versions book 26 36 2

1 Introduction Because communication between industrial controllers and interface equipment is becoming ever more important, E.D.&A. has implemented the MODBUS protocol in their HPC's. MODBUS is a fail safe, multiclient and easy to use protocol that makes communication possible between HPC's or between HPC's and arbitrary MODBUS masters or slaves of other manufacturers. 1.1 Overview This manual describes the use of this MODBUS protocol implementation for all HPC's using the EPL programming language. For details concerning the E.D.&A. HPC hardware and programming, please refer to the E.D.&A. technical reference manuals. There are two MODBUS implementations: a MODBUS master driver, a MODBUS slave driver. The MODBUS master implementation is really the master of the serial line, it reads data from, and writes data to one or more connected slave systems. There is always one MODBUS master on a serial line, but there can be one or more slave systems. The MODBUS slave only listens to the master and sends answers back if it receives valid requests. The driver can be installed multiple times on a HPC, which allows it to communicate through multiple serial ports at the same time, each connecting one or more other systems. Only RTU mode is implemented, this means that data is transferred in binary mode, using a CRC-16 error check sequence. ASCII mode is not supported. 1.2 Required hardware The use of the MODBUS software requires a serial port and an option lock. This option lock is a security key that allows the use of optional software. The hardware reference manuals of each HPC model describe the placement of the option locks: These MODBUS drivers can be used on any serial port of the HPC's, the desired port number must be chosen when the protocol is installed by the HPC program. 1.3 Required software To use the MODBUS driver software, the HPC must have a certain minimum system software version. There are some additions to the MODBUS slave driver that are available from a later system software version. These additions are: reading and writing of char and long variables, relaxed timing capability for communication through modems, RS485 multipoint capability, increased maximum transfers of 512 bools and 64 shorts, and a deinstall() function. This table shows what minimum system software version is required to use a given capability: Capability V5-2xx/3xx V10-2xx V50-2xx MODBUS slave driver v1.30 v1.23 v1.33 MODBUS slave additions v1.36 v2.02 v2.01 MODBUS master driver v1.32 v1.29 v1.33 MODBUS master broadcast v1.36 v2.02 v2.01 The EWB programming software must be version 2.04 or newer. 3

1.4 Required option lock One option lock is required for each installation of a MODBUS master or slave driver. When, for example, a driver must run on 4 serial ports, it must be installed 4 times, which requires 4 options. One MODBUS master driver communicating with multiple slaves requires only one option lock. The hardware reference manuals of each HPC system describe the installation and use of the option locks in detail. 1.5 Cabling The MODBUS protocol can run on RS232, RS422, RS485 or current-loop serial communication ports. No handshake signals are required. Their state is ignored, even if they are connected through the serial line. The use of a shielded cable is recommended to avoid interference problems. For RS232, a simple 3-wire cable is sufficient for distances up to 15 meters. For RS485 multipoint cabling, we've got a few rules-of-thumb: When using speeds up to 9600 bps, cables up to 450 meters can be used without termination. When using thin cable (0.14mm²/AWG26), the use of terminators may prevent the network from working because the terminators draw so much current that the cable's resistance causes too much voltage loss. When using longer cables, terminators are required and therefore thicker cable (0.5mm²/AWG20) must be used to keep voltage loss low. The hardware reference manuals for the different HPC's describe the pinning and interconnections of the cables. 4

2 Installation of the driver To use the MODBUS driver, two things must be done: 1. first open a serial port, 2. then install the driver on it. 2.1 Initialization of the serial port Two functions can be used to open a serial port on a HPC: ComOpen() and ComOpenq(). ComOpen(): Is simpler to use, but it configures the port with the default buffer sizes of 256 bytes for the transmit buffer and 128 bytes for the receive buffer, which are rather large for MODBUS. This works fine but may be a problem when many serial ports are used because they all need there transmit and receive buffers. Example: open com port 1 for 9600 baud, no parity, 8 data bits and 1 stop bit. Store the return value in the variable S1: S1 = ComOpen( 1, "9600,n,8,1"); ComOpenq(): Is a bit more complex, but it allows the programmer to control the sizes of the queues (buffers) and therefore use more serial ports without running out of memory. Example: open serial port 1 for 9600 baud, no parity, 8 data bits and 1 stop bit. Allocate a 100-byte queue for transmission and a 50-byte queue for reception. Store the return value in the variable S1: S1 = ComOpenq( 1, "9600,n,8,1", 100, 50); The number of data bits MUST be 8 for MODBUS. The other parameters: baud rate, parity- and stop bits can be chosen freely. It's necessary however that they are the same for the master and all the slaves on the serial line. It's possible to use the programming port of the HPC. This serial port can be used as serial port 0. The port must be in "communication" mode and not in "programming" mode. The hardware manuals describe the settings of the programmer port. 2.2 Installing a MODBUS master Purpose: Installs a MODBUS master driver on a serial port. Other functions must then be used to initiate read and write operations to connected slaves. The MODBUS master driver must be installed and initialized before it can be used. The operational parameters like timeout and number of retries in case of an error, are specified with this installation. Notation: 5

short InstallModbusMas( short comnr, short buffer, short timeout, short tries); Parameters: comnr: Parameter of the type short. Number of the serial port where the MODBUS master is installed on. buffer: Parameter of the type short. The size of the buffer that the driver uses to build the requests that it transmits and to store the answers that it receives. See the remarks below on how to choose the size of the buffer that is required for your application. timeout: Parameter of the type short. The time that the driver allows for a slave to respond, in milliseconds. If the slave does not answer in time, the request has failed. An other request is started then if the number of retries is bigger the 0. tries: Parameter of the type short. The number of times that the driver will try to send each request to a slave. If all these attempts fail, the request will be returned to the user program with status 'failed'. Return value: InstallModbusMas() returns 1 if the installation was successful. Negative values indicate an error: -41: means that one of the initialization parameters is wrong. -45: means there are no more option locks free to allow the use of the driver. -47: means the serial port is not available or not initialized. Remarks: The parameters are used for all the subsequent reads and writes through this port, they are permanent and cannot be changed without restarting the HPC. To install more MODBUS master drivers, simply call the same function for the other serial ports. The serial port must be initialized first with the ComOpen() or ComOpenq() function. How to determine the required buffer size: The worst case for reading or writing registers is 9 fixed bytes + 2 bytes per 16-bit register. When transferring Boolean variables (bool), 1 byte is needed per 8 Boolean variables. The 9 fixed bytes are also needed. For example, read 20 registers from a slave: 8 bytes needed to transmit the read request. The answer containing the data can be received with a buffer of 9+2*20 = 49 bytes. Rounded to 50 bytes will do fine. In the included examples, a buffer of 100 bytes is configured, which allows reading or writing 45 registers in one transfer. A MODBUS master does not have a number, because it is the only node that initiates requests, and answers are always directed to the master. Only slaves have numbers. 6

Only one MODBUS master can be active in a network. A master can not communicate with another master. A HPC can be MODBUS master and slave at the same time on different serial ports. Example: Install the driver on COM port 1, use a buffer of 100 bytes, allow a response time of 1 second, which agrees with 1000 milliseconds, and try 3 times before giving up. Store the return value in the variable S1: S1 = InstallModbusMas( 1, 100, 1000, 3); 2.3 Installing a MODBUS slave Purpose: Install a MODBUS slave driver on a serial port. Once installed, the driver will automatically work in the background and process incoming request. The MODBUS slave driver must be installed and initialized before it can be used. The slave number to which the driver will respond is also specified when the driver is installed. Notation: short InstallModbus( short comnr, short slavenr, short options); Parameters: comnr: Parameter of the type short. Number of the serial port where the MODBUS slave is installed on. slavenr: Parameter of the type short. This number defines the slave number to which the driver will respond. Each slave must have a unique number on a serial line. The master sends its request to a certain slave number, and only that slave will answer. There are two ways to define the slave number: If slavenr is zero will the HPC address be taken as slave number. The adjustment of the address number is described in the hardware manual. The slavenr parameter is taken as slave number directly if the number is greater the zero. option: Parameter of the type short. The options parameter, that normally = o, is a bit pattern by which several options of the modbus slave driver can be switched on. If you want to switch on several options together, the sum of the option values has to be inserted. Option value 1: MODBUS slave will work with a minor strict timing (relaxed timing). The timeout that indicates the end of a message is now 40 character times instead of 4 character times. This allows the use of a modem in a serial line. Only point to point connections are possible with this relaxed timing. Multipoint RS485 is not possible. Option value 2: this is only available for the recent HPCs. All the markers and the short variables are accessible via modem instead of only the first 9000. The digital inputs are no longer approachable from marker 9001 and the analog outputs are no longer approachable 7

from short 9001. Return value: InstallModbus() returns 1 if the installation was successful. Negative values indicate an error: -41: means that one of the initialization parameters is wrong. -45: means there are no more option locks free to allow the use of the driver. -47: means the serial port is not available or not initialized. Remarks: The MODBUS slave driver runs automatically. Nothing must be done besides initializing a serial port and installing the protocol driver on that port. Because it's a slave driver, it will automatically answer all read or write requests from the MODBUS master. The number of variables that can be read or written in one read or write request is limited: variables of type 'bool': maximum 512 variables of type 'short': maximum 64 variables of type 'char': maximum 128 variables of type 'long': maximum 32. The data that are read or written with the MODBUS protocol, are processed between two cycles of the program: If the MODBUS master reads data are this data placed in a buffer and then transmitted to the master. If the MODBUS master writes data to the HPC, are this data placed in a buffer until the complete messages is received. All the data are then written to the variables of the user program at once, just before the user program starts a new cycle. In this way is it impossible that during a cycle of the user program data is read or written by the MODBUS master. Example 1: These statements initialize serial port 1 for 9600 baud, no parity, 8 data bits and 1 stop bit and install a MODBUS slave on that serial port with slave number 1. Store the return value of the ComOpen() function in the variable S1: S1 = ComOpen( 1, "9600,N,8,1"); InstallModbus( 1, 1, 0); The return value of the InstallModbus() function is not stored in a variable. On a V5-2xx and a V5-3xx HPC, specify 0 as serial port number with the comopen() and installmodbus() functions. The parameters for the serial port (baud rate, parity and stop bits) must always be the same for the MODBUS master and slave. The number of data bits must always be 8 for MODBUS. Example 2: Install modbus on 2 serial ports. On com3 with even parity and slave number 1. On com4 without parity, as slave number the HPC address that was adjusted via the dip switches is taken. All the markers and short variables are made accessible. 8

init() { S1 = ComOpen( 3, "9600,E,8,1"); S2 = InstallModbus( 3, 1, 0); } S3 = ComOpen( 4, "9600,N,8,1"); S4 = InstallModbus( 4, 0, 2); 2.4 Uninstalling a MODBUS slave Purpose: Remove a MODBUS slave driver from a serial port. This allows the application program to use the serial port for other purposes. The MODBUS slave driver can be re-installed using the normal InstallModbus() function. Notation: short DeinstallModbus( short comnr); Parameters: comnr: Parameter of the type short. Number of the serial port where the MODBUS will be removed from. Return value: DeinstallModbus() returns 1 if the removal was successful. Negative values indicate an error: -41: means that the removal failed because no MODBUS slave driver was installed on the port. Example: Remove the MODBUS slave driver if it was previously installed on port 1. Store the return value in the variable S1: S1 = DeInstallModbus( 1); 9

3 Do reads and writes with the MODBUS master Purpose: Do read and write actions to the MODBUS slaves. The MODBUS master can communicate with all the slaves on the serial line. There's a function to read values from a slave, ModbusRead(), and a function to write values to a slave, ModbusWrite(). A MODBUS master driver must be previously installed on the serial port. Notation: short ModbusRead( bool *startflag, short comnr, long *transferblock); short ModbusWrite( bool *startflag, short comnr, long *transferblock); Parameters: startflag: Parameter of the type 'pointer to bool' or 'address of bool'. This is a marker to indicate that the ModbusRead() or ModbusWrite() function must do its data transfer. The user program must set this flag (set the marker to 1). The transfer will be done as soon as the port becomes available. The flag remains set while the function waits for the port to become available, and while the transfer is actually done. When the transfer is done, the startflag is automatically set to 0 by the ModbusRead() or ModbusWrite() function. If the user sets this startflag to 0, the transfer will be canceled. comnr: Parameter of the type short. This is the serial port number on which the read or write action must be done. transferblock: Parameter of the type 'pointer to long' or 'address of long'. The beginning of a block of 5 long variables. These contain more details about the transfer; such as slave number and which variables are transferred. See below for more information. Return value: The function returns a value that indicates whether the transfer is busy or finished, and whether the transfer was successful or not. Negative values indicate an error. The return value is also placed in the fourth long of the transfer block (see below). This makes it easy to verify whether a transfer was successful. All you have to do is display the fourth long of the transferblock. The return values have the following meaning: 2 Indicates a successful transfer has been done. 1 Indicates the function is waiting for the port to become available, or it is actually doing the transfer. 0 Indicates that the function is not active. It is just waiting for the startflag to become set. -100 No MODBUS driver on the com port. -101 The number of the variable is invalid. This indicates an error in the second long of the transferblock. -102 The buffer is too small for the transfer of the requested number of variables. You need to lower the number of variables specified in the third long of the transferblock, or specify a larger buffer during installation of the MODBUS master driver. -103 Timeout, the master did not receive a valid answer from the slave. The serial port is in "programmer" mode and not in "communication" mode. A jumper connection on the 10

programming connector can cause this, or a dip switch that puts com port 0 into programming mode, like dip switch 6 on the V5-1xxx HPC's. -104 Checksum error. -110 Protocol error: an invalid reply message was received from the slave. -111 Protocol error: the slave replied with exception code 01, 'illegal function'. This means that it did not understand the function code in the request message. -112 Protocol error: the slave replied with exception code 02, 'invalid address'. This means that the request message had an invalid variable address, invalid length, or that address + length goes past the last variable of the slave. -113 Protocol error: the slave replied with exception code 03, 'illegal data'. This means that the master attempted to write an invalid value into a variable. -114 Protocol error: The slave replied with exception code 04 "Slave device failure". For some reason, the slave can not execute the command. Check the documentation of the slave. -116 Protocol error: the slave replied with exception code 06, 'busy'. This means that it is busy. The request could not be processed. -117 Protocol error: The slave replied with exception code 07 "Nak-negative acknowledgement". For some reason, the slave can not execute the command. Check the documentation of the slave. -120 Protocol gateway error: The gateway replied with exception code 10 "Gateway path unavailable". Can occur when the modbus communication passes through a gateway. The gateway doesn't know how to forward the modbus command to the slave. -121 Protocol gateway error: The gateway replied with exception code 11 "Gateway path unavailable". Can occur when the modbus communication passes through a gateway. The gateway has forwarded the modbus command to the slave, but did not receive a response from that slave. Remarks: The MODBUS master driver must be installed on a serial port first, by calling the function InstallModbusMas(). Multiple read or write transfers can be started at the same time. The system will automatically do one transfer after another. Startflag must be unique for each transfer; different start markers must be used for each read or write request. It's very important that the ModbusRead() or ModbusWrite() statements are executed in every cycle of the program when a read of write action is in progress. This means that the following example is wrong: if( ^/b5s) /* read every 5 seconds */ { m20 = 1; S1 = ModbusRead( &m20, 1, &L100); /* WILL NOT WORK!! */ } But this is correct: if( ^/b5s) /* read every 5 seconds */ { m20 = 1; } S1 = ModbusRead( &m20, 1, &L100); /* WORKS */ The return value is stored in the variable S1. The transfer block: This is a block of 5 longs, which contain the details of the read or write actions. 11

First long: The slave number: values between 1 and 250 are permitted. Second long: Variable number in the slave. This defines the type and the exact number of variable that will be written to, or read from the slave. See below for more information on how to specify the variable number. Third long: The number of variables that are read or written. The maximum number of variables that can be transferred in a single read or write transaction is limited: variables of type 'bool': maximum 512 variables of type 'short': maximum 64 These maximums can be lower if the slave device has lower maximums. Fourth long: The status of the last action remains in this variable. This number is the same as the return value of the ModbusRead() or ModbusWrite() functions. Fifth long: Contains the address of the HPC variable(s) where the data from the read action must be stored, or where the data for the write action must come from. Transfer block example: When this block is used for a READ action, it reads registers 10 up to 19 from slave number 1, and stores the data in this HPC's short S20 up to S29. When this block is used for a WRITE action, it writes into registers 10 up to 19 of slave number 1, and the data comes from this HPC's short S20 up to S29. L100 = 1; L101 = 40010; L102 = 10; L103 = 0; L104 = (long)&s20; 12

4 More about numbers and types of variables MODBUS has its own way to define the different types of variables. All the types of variables (markers, inputs, outputs, numerical registers, ) are indicated with a number between 1 and 49999: a list that contains all types of variables. E.D.&A. HPC's work differently, each type of variable has its own listing (e.g. E1.1, S1, M1, ). To be compatible, E.D.&A. HPC's do a conversion between the MODBUS names and their own names. In MODBUS masters, including the E.D.&A. MODBUS master, the MODBUS name (number between 1 and 49999) usually must be used. The following table indicates what the MODBUS numbers stand for: Variable number in MODBUS form Name in E.D.&A. EPL HPC's Type 00001 01000 M1 M1000 internal digital flag (marker) 09001 09256 A1.1 A16.16 digital output 10001 10256 E1.1 E16.16 digital input 30001 30128 AE1.1 AE16.8 analog input 40001 40500 S1 S500 internal numerical register (short) 49001 49064 AA1.1 AA16.4 analog output See also the 4 mapping tables below. These give the standard mapping of the modbus i/o variables to the ED&A variables for the standard i/o configuration. These tables can not be used if the number of inputs or outputs of the i/o cards are different! This list is correct for all E.D.&A. HPC's that use the EPL programming language. The HPC's that use the ABC programming language have other names for their variables. They can be used with the MODBUS master but the mapping table of the ABC slaves has to be used (see book E25). The maximum usable MODBUS variable numbers are restricted to the capabilities of the MODBUS slave. For an E.D.&A. HPC MODBUS slave, this depends on the number of variables that are configured by the memory configuration of the HPC application program. For example, the short variables have a standard configuration of S1 to S500. This means that the MODBUS variable number has a valid range from 40001 to 40500. If another configuration is used that defines more or less short variables, the valid variable number range will grow of shrink equally. Inputs and outputs are numbered linear in the MODBUS protocol: they are numbered in the order of the HPC i/o configuration. So modbus input 10001 maps to input E1.1. Modbus input 10018 maps to input E1.18 if E1 has 18 or more inputs, or it may map to E2.2 if E1 has 16 inputs. Remarks: Char and long variables can not be read or written by the MODBUS master. Only E.D.&A. HPC slaves support this. The only MODBUS master that can use these extra features is the E.D.&A. MODBUS master driver for PC's. Example 1: Read from a slave with number 1, read S1 up to S40, which are 40 registers, store in S101 to S140: L200 = 1; L201 = 40001; L202 = 40; L203 = 0; L204 = (long)&s101; 13

Example 2: Read from a slave with number 12, read M400 up to M450, which are 51 flags or coils, store in M400 to M450: L200 = 12; L201 = 400; L202 = 51; L203 = 0; L204 = (long)&m400; 4.1 Mapping table of ED&A digital inputs to modbus numbers (using standard i/o configuration) V5-2xx V5-3xx V5-12xx V5-13xx V5-14xx V5-22xx V5-23xx V5-24xx V10-210 V10-22x V10-23x V50-20x V50-22x RCC30-20 RCC30-40 E1.1 10001 (E1.1-26) 10001 (E1.1-26) 10001 (E1.1-18) 10001 (E1.1-16) 10001 (E1.1-16) 10001 (E1.1-16) E2.1 10027 (E2.1-18) 10019 (E2.1-16) 10017 (E2.1-16) 10017 (E2.1-16) 10017 (E2.1-16) E3.1 10045 (E3.1-16) 10035 (E3.1-16) 10033 (E3.1-16) 10033 (E3.1-16) 10033 (E3.1-16) E4.1 10061 (E4.1-16) 10051 (E4.1-16) 10049 (E4.1-16) 10049 (E4.1-16) 10049 (E4.1-16) E5.1 10077 (E5.1-16) 10067 (E5.1-16) 10065 (E5.1-16) 10065 (E5.1-16) 10065 (E5.1-16) E6.1 10093 (E6.1-16) 10083 (E6.1-16) 10081 (E6.1-16) 10081 (E6.1-16) 10081 (E6.1-16) E7.1 10109 (E7.1-16) 10099 (E7.1-16) 10097 (E7.1-16) 10097 (E7.1-16) 10097 (E7.1-16) E8.1 10125 (E8.1-16) 10115 (E8.1-16) 10113 (E8.1-16) 10113 (E8.1-16) 10113 (E8.1-16) E9.1 10131 (E9.1-16) 10129 (E9.1-16) 10129 (E9.1-16) 10129 (E9.1-16) E10.1 10147 (E10.1-16) 10145 (E10.1-16) 10145 (E10.1-16) 10145 (E10.1-16) E11.1 10163 (E11.1-16) 10161 (E11.1-16) 10161 (E11.1-16) E12.1 10179 (E12.1-16) 10177 (E12.1-16) 10177 (E12.1-16) E13.1 10195 (E13.1-16) 10193 (E13.1-16) 10193 (E13.1-16) E14.1 10211 (E14.1-16) 10209 (E14.1-16) 10209 (E14.1-16) E15.1 10227 (E15.1-16) 10225 (E15.1-16) 10225 (E15.1-16) 14

E16.1 10243 (E16.1-16) 10241 (E16.1-16) 10241 (E16.1-16) 4.2 Mapping table of ED&A digital outputs to modbus numbers (using standard i/o configuration) V5-2xx V5-3xx V5-12xx V5-13xx V5-14xx V5-22xx V5-23xx V5-24xx V10-210 V10-22x V10-23x V50-20x V50-22x RCC30-20 RCC30-40 A1.1 9001 (A1.1-16) 9001 (A1.1-8) 9001 (A1.1-8) 9001 (A1.1-8) 9001 (A1.1-16) 9001 (A1.1-8) A2.1 9009 (A2.1-8) 9009 (A2.1-8) 9009 (A2.1-8) 9017 (A2.1-16) 9009 (A2.1-6) A3.1 9017 (A3.1-8) 9017 (A3.1-8) 9017 (A3.1-8) 9033 (A3.1-16) 9015 (A3.1-8) A4.1 9025 (A4.1-8) 9025 (A4.1-8) 9025 (A4.1-8) 9049 (A4.1-16) 9023 (A4.1-8) A5.1 9033 (A5.1-8) 9033 (A5.1-8) 9033 (A5.1-8) 9065 (A5.1-16) 9031 (A5.1-8) A6.1 9041 (A6.1-8) 9041 (A6.1-8) 9041 (A6.1-8) 9081 (A6.1-16) 9039 (A6.1-8) A7.1 9049 (A7.1-8) 9049 (A7.1-8) 9049 (A7.1-8) 9097 (A7.1-16) 9047 (A7.1-8) A8.1 9057 (A8.1-8) 9057 (A8.1-8) 9057 (A8.1-8) 9113 (A8.1-16) 9055 (A8.1-8) A9.1 9065 (A9.1-8) 9065 (A9.1-8) 9129 (A9.1-16) 9063 (A9.1-8) A10.1 9073 (A10.1-8) 9073 (A10.1-8) 9145 (A10.1-16) 9071 (A10.1-8) A11.1 9081 (A11.1-8) 9081 (A11.1-8) 9161 (A11.1-16) A12.1 9089 (A12.1-8) 9089 (A12.1-8) 9177 (A12.1-16) A13.1 9097 (A13.1-8) 9097 (A13.1-8) 9193 (A13.1-16) A14.1 9105 (A14.1-8) 9105 (A14.1-8) 9209 (A14.1-16) A15.1 9113 (A15.1-8) 9113 (A15.1-8) 9225 (A15.1-16) A16.1 9121 (A16.1-8) 9121 (A16.1-8) 9241 (A16.1-16) 15

4.3 Mapping table of ED&A analogue inputs to modbus numbers (using standard i/o configuration) V5-2xx V5-3xx AE1.1 30001 (AE1.1-4) V5-12xx V5-13xx V5-14xx 30001 (AE1.1-8) AE2.1 30009 (AE2.1-4) AE3.1 30013 (AE3.1-4) AE4.1 30017 (AE4.1-4) AE5.1 30021 (AE5.1-4) AE6.1 30025 (AE6.1-4) AE7.1 30029 (AE7.1-4) AE8.1 30033 (AE8.1-4) V5-22xx V5-23xx V5-24xx 30001 (AE1.1-8) 30009 (AE2.1-8) 30017 (AE3.1-8) 30025 (AE4.1-8) 30033 (AE5.1-8) 30041 (AE6.1-8) 30049 (AE7.1-8) 30057 (AE8.1-8) V10-210 V10-22x V10-23x 30001 (AE1.1-8) 30009 (AE2.1-8) 30017 (AE3.1-8) 30025 (AE4.1-8) 30033 (AE5.1-8) 30041 (AE6.1-8) 30049 (AE7.1-8) 30057 (AE8.1-8) V50-20x V50-22x 30001 (AE1.1-8) 30009 (AE2.1-8) 30017 (AE3.1-8) 30025 (AE4.1-8) 30033 (AE5.1-8) 30041 (AE6.1-8) 30049 (AE7.1-8) 30057 (AE8.1-8) AE9.1 30065 (AE9.1-8) AE10.1 30073 (AE10.1-8) AE11.1 30081 (AE11.1-8) AE12.1 30089 (AE12.1-8) AE13.1 30097 (AE13.1-8) AE14.1 30105 (AE14.1-8) AE15.1 30113 (AE15.1-8) AE16.1 30121 (AE16.1-8) RCC30-20 RCC30-40 30001 (AE1.1-4) 30005 (AE2.1-4) 30009 (AE3.1-4) 30013 (AE4.1-4) 30017 (AE5.1-4) 30021 (AE6.1-4) 30025 (AE7.1-4) 30029 (AE8.1-4) 4.4 Mapping table of ED&A analogue outputs to modbus numbers (using standard i/o configuration) V5-2xx V5-3xx V5-12xx V5-13xx V5-14xx V5-22xx V5-23xx V5-24xx V10-21x V10-22x V10-23x V50-20x V50-22x RCC30-20 RCC30-40 16

AA1.1 49001 (AA1.1) 49001 (AA1.1-4) AA2.1 49005 (AA2.1-2) AA3.1 49007 (AA3.1-2) AA4.1 49009 (AA4.1-2) AA5.1 49011 (AA5.1-2) AA6.1 49013 (AA6.1-2) AA7.1 49015 (AA7.1-2) AA8.1 49017 (AA8.1-2) 49001 (AA1.1-4) 49005 (AA2.1-2) 49007 (AA3.1-2) 49009 (AA4.1-2) 49011 (AA5.1-2) 49013 (AA6.1-2) 49015 (AA7.1-2) 49017 (AA8.1-2) 49001 (AA1.1-2) 49003 (AA2.1-2) 49005 (AA3.1-2) 49007 (AA4.1-2) 49009 (AA5.1-2) 49011 (AA6.1-2) 49013 (AA7.1-2) 49015 (AA8.1-2) 49001 (AA1.1-4) 49005 (AA2.1-4) 49009 (AA3.1-4) 49013 (AA4.1-4) 49017 (AA5.1-4) 49021 (AA6.1-4) 49025 (AA7.1-4) 49029 (AA8.1-4) AA9.1 49033 (AA9.1-4) AA10.1 49037 (AA10.1-4) AA11.1 49041 (AA11.1-4) AA12.1 49045 (AA12.1-4) AA13.1 49049 (AA13.1-4) AA14.1 49053 (AA14.1-4) AA15.1 49057 (AA15.1-4) AA16.1 49061 (AA16.1-4) 49001 (AA1.1-2) 49003 (AA2.1-2) 49005 (AA3.1-2) 49007 (AA4.1-2) 49009 (AA5.1-2) 49011 (AA6.1-2) 49013 (AA7.1-2) 49015 (AA8.1-2) 17

5 Broadcasting Broadcasting is a mechanism that makes it possible for a MODBUS master to write variables in all connected slaves at once. This is achieved by sending a write function to slave number 0, which is accepted by all slaves. The slaves won't send an answer back to the master to confirm the write request. The broadcast mechanism is useful if you need to send the same data to several slaves. Remember that a broadcast does not require an acknowledge and therefore is not repeated in case of line interference! Therefore it's best to broadcast data periodically to make sure it arrives in all slaves. Broadcasting a read request makes no sense because none of the slaves will answer. Example: Once per second, broadcast the shorts S20..S29 to all slaves into registers 40010..40019. the return value is placed in the variable S1: if( ^/b1s) { L100 = 0; L101 = 40010; L102 = 10; L103 = 0; L104 = (long)&s20; m20 = 1; } S1 = ModbusWrite( &m20, 1, &L100); 18

6 Protocol details This chapter is intended for those who need to know about the functions and addresses that are used in the internals of the protocol! The following list shows which functions are used in the MODBUS protocol to read and write variables: Function number Function type Range (16-bit address field) function 01 Read coils Read 00001 09999 function 02 Read inputs Read 10001 19999 function 03 Read holding registers Read 40001 49999 function 04 Read input registers Read 30001 39999 function 15 Write coils Write 00001 09999 function 16 Write holding registers Write 40001 49999 function 65 (E.D.&A. extension) function 66 (E.D.&A. extension) function 67 (E.D.&A. extension) function 68 (E.D.&A. extension) Read character variables Write character variables Read long variables Write long variables Which modbus function codes are generated by ModbusRead() and ModbusWrite() The ModbusRead() and ModbusWrite() functions automatically generate a modbus function code from the variable that has to be read or written. This table shows what function codes and addresses are generated: Variable Function code in modbus query message Read 00001.. 09999 01 (Read coils) 0000.. 9998 Read 10001.. 19999 02 (Read inputs) 0000.. 9998 Read 40001.. 49999 03 (Read holding registers) 0000.. 9998 Read 30001.. 39999 04 (Read input registers) 0000.. 9998 Write 00001.. 09999 15 (Write coils) 0000.. 9998 Write 40001.. 49999 16 (Write holding registers) 0000.. 9998 Function 03: Read holding registers: The query message: Address in modbus query message <ADR><FUNC><OFFSET-H><OFFSET-L><LEN-H><LEN-L><CRC-H><CRC-L> ADR: the slave address FUNC: function code 03 OFFSET-H, OFFSET-L: data address, this is actually an offset, and therefore starts at zero for the first variable! LEN-H, LEN-L: the number of variables to read CRC-H, CRC-L: the CRC 19

The response message: <ADR><FUNC><BYTECOUNT><DATA1-H><DATA1-L><DATA2-H><DATA2-L>...<CRC-H><CRC-L> ADR: the slave address that sent the response FUNC: echo of the function code 03 BYTECOUNT: the number of data bytes that follow, equal to the number of requested variables * 2 DATAx-H, DATAx-L: high/low data bytes of each 16-bit word read, 2 bytes per word CRC-H, CRC-L: the CRC Example: Read the 10 first 16-bit registers from slave 1 (S1..S10) ADR: 01 FUNC: 03 OFFSET-H, OFFSET-L: 00 00 LEN-H, LEN-L: 00 0A CRC-H, CRC-L: C5 CD Query message: 0x01 0x03 0x00 0x00 0x00 0x0A 0xC5 0xCD Possible response message: 0x01 0x03 0x14 0x00 0x01 0x00 0x02 0x00 0x03 0x00 0x04 0x00 0x05 0x00 0x06 0x00 0x07 0x00 0x08 0x00 0x09 0x00 0x0A 0x8F 0x16 meaning Reg0=0x0001, Reg1=0x0002,... Function 65(dec): Read character registers (8-bit): (ED&A extension) The query message: <ADR><FUNC><OFFSET-H><OFFSET-L><LEN-H><LEN-L><CRC-H><CRC-L> ADR: the slave address FUNC: function code 65 decimal or 41 hex OFFSET-H, OFFSET-L: data address, this is actually an offset, and therefore starts at zero for the first variable! LEN-H, LEN-L: the number of variables to be read CRC-H, CRC-L: the CRC The response message: <ADR><FUNC><BYTECOUNT><DATA1><DATA2><DATA3>...<CRC-H><CRC-L> ADR: the slave address that sent the response FUNC: echo of the function code 65 BYTECOUNT: the number of data bytes that follow, equal to the number of requested variables DATAx: data bytes of each character read, 1 byte per character CRC-H, CRC-L: the CRC Function 66(dec): Write character registers (8-bit): (ED&A extension) 20

The query message: <ADR><FUNC><OFFSET-H><OFFSET-L><LEN-H><LEN-L><BYTECOUNT><DATA1><DATA2>...<CRC- H><CRC-L> ADR: the slave address FUNC: function code 66 decimal or 42 hex OFFSET-H, OFFSET-L: data address, this is actually an offset, and therefore starts at zero for the first variable! LEN-H, LEN-L: the number of variables to be written BYTECOUNT: the number of data bytes that follow, equal to the number of variables to be written DATAx: data byte for each character to be written, 1 byte per character CRC-H, CRC-L: the CRC The response message: <ADR><FUNC><OFFSET-H><OFFSET-L><LEN-H><LEN-L><CRC-H><CRC-L> ADR: the slave address that sent the response FUNC: echo of the function code 66 OFFSET-H, OFFSET-L: echo of value in the query message LEN-H, LEN-L: echo of value in the query message CRC-H, CRC-L: the CRC Function 67(dec): Read long registers (32-bit): (ED&A extension) The query message: <ADR><FUNC><OFFSET-H><OFFSET-L><LEN-H><LEN-L><CRC-H><CRC-L> ADR: the slave address FUNC: function code 67 decimal or 43 hex OFFSET-H, OFFSET-L: data address, this is actually an offset, and therefore starts at zero for the first variable! LEN-H, LEN-L: the number of variables to be read CRC-H, CRC-L: the CRC The response message: <ADR><FUNC><BYTECOUNT><DATA1-H><DATA1-M><DATA1-N><DATA1-L><DATA2-H><DATA2- M><DATA2-N><DATA2-L>...<CRC-H><CRC-L> ADR: the slave address that sent the response FUNC: echo of the function code 67 BYTECOUNT: the number of data bytes that follow, equal to the number of requested variables * 4 DATA1-H, DATA1-M, DATA1-N, DATA1-L: data bytes of each character read, 4 bytes per long, big endian format CRC-H, CRC-L: the CRC Function 68(dec): Write long registers (32-bit): (ED&A extension) The query message: <ADR><FUNC><OFFSET-H><OFFSET-L><LEN-H><LEN-L><BYTECOUNT><DATA1-M><DATA1- N><DATA1-L><DATA2-H><DATA2-M><DATA2-N><DATA2-L>...<CRC-H><CRC-L> 21

ADR: the slave address FUNC: function code 68 decimal or 44 hex OFFSET-H, OFFSET-L: data address, this is actually an offset, and therefore starts at zero for the first variable! LEN-H, LEN-L: the number of variables to be written BYTECOUNT: the number of data bytes that follow, equal to the number of variables to be written * 4 DATAx-H, DATAx-M, DATAx-N, DATAx-L: data bytes of each long to write, 4 bytes per long, big endian format CRC-H, CRC-L: the CRC The response message: <ADR><FUNC><OFFSET-H><OFFSET-L><LEN-H><LEN-L><CRC-H><CRC-L> ADR: the slave address that sent the response FUNC: echo of the function code 68 OFFSET-H, OFFSET-L: echo of value in the query message LEN-H, LEN-L: echo of value in the query message CRC-H, CRC-L: the CRC Exception responses: A MODBUS slave, including the HPC MODBUS slave driver, can return exception codes instead of the requested data in case of an error. The ModbusRead() or ModbusWrite() functions will return a negative value if the slave returns an exception code. Exception code Description Return value of ModbusRead( ) or ModbusWrite( ) 01 "Illegal function": if the request message has an illegal function number. 02 "Invalid address": if the request message has an invalid data address, invalid length, or if address + length goes past the last variable. 03 "Illegal data": if the master attempted to write an invalid value into a variable. 04 "Slave device failure": For some reason, the slave can not execute the command. Check the documentation of the slave. 06 "Busy": the slave is busy, the request could not be processed. 07 "Nak-negative acknowledgement". For some reason, the slave can not execute the command. Check the documentation of the slave. 10 "Gateway path unavailable": Can occur when the modbus communication passes through a gateway. The gateway doesn't know how to forward the modbus command to the slave. 11 "Gateway path unavailable": Can occur when the modbus communication passes through a gateway. The gateway has forwarded the modbus command to the slave, but did not -111-112 -113-114 -116-117 -120-121 22

receive a response from that slave. 23

7 Troubleshooting guide In case the communication between a MODBUS master and slave isn't working, what points can be checked? Summary: 1. Is the MODBUS master sending requests? 2. Does the slave receive the requests? 3. Does the slave react to the requests? 4. Do the answers of the slave get to the master? 5. Are the answers good or do they contain an error code? 6. Cable problems causing intermittent failures? This guide is based on the status LED's that are available on all the serial ports of the E.D.&A. HPC's. If other equipment is being used it might be helpful to use an RS232 test tool with LED's. First, make sure that the MODBUS master program sends packets on a regular base (each second e.g.). The second program example, modmas1.epl, can be used for this. 7.1 Does MODBUS master send messages? Does the transmit data LED (TxD) of the MODBUS master flash once per second? This is a red LED on all E.D.&A HPC's. A flashing TxD LED indicates that the MODBUS master is sending data packets to the slave. The slave will not react as long as the master isn't transmitting data packets, so make sure the master's TxD LED is flashing before proceeding to the next step! Verify the following items if the LED isn't flashing: Check the external power supply of the used serial port if present. Corresponds the serial port where the cable is connected to with the serial port number that is used in the program? The serial port number must be used with the ComOpen() function and the with the InstallModbusMas() function. The serial port of the V5 HPC and the serial port on the CPU boards of the different HPC's is always COM 0 (null)! Check the return value of the ComOpen() function. Negative values indicate an error if the port could not be opened. Check the return value of the InstallModbusMas() function. Negative values indicate an error if the driver could not be installed. The return value of InstallModbusMas() is described in chapter 2.2. The serial port must already be opened when the MODBUS driver is installed because it needs to know the baud-rate to calculate its timing requirements. The install can also fail if the required option lock is not available. Remove the serial cable and see whether the TxD LED flashes now. It might indicate a problem with the cable if the LED flashes now. There could be a short-circuit inside the cable or the cable is a programmer cable which places the serial port in "programming" mode: The serial port is not in "communication" mode but in "programming" mode. The PP-80 programmer cable, or any other cable that is used to send a program to the HPC, puts the serial 24

port automatically in "programmer" mode because there is a little extra wire inside the connector. These cables can therefore not be used to communicate with MODBUS on a serial port that also works as a programmer port (= the serial port of the V5-xxx and the port on the CPU of the V10 and V50). It's also possible to force the programmer port in "programmer" mode with a jumper or dip-switch on most HPC systems. The used cable has no influence then on the mode of the serial port: it will always be in "programming" mode. The hardware manuals give a detailed description of this possibility. The user program and MODBUS have no control over the serial port as long as it is in "programmer" mode, so make sure the port is not in "programmer" mode. The ModbusRead() and ModbusWrite() functions give the return value 103 if the serial port is in "programmer" mode. Is the HPC in RUN mode? A HPC that is not in RUN mode is not executing the user program, so the serial communication with MODBUS isn't working either. 7.2 Does the slave receive these messages? If the TxD LED of the master works, check the receive data LED (RxD) of the MODBUS slave. This is a yellow or red LED on E.D.&A. HPC's. This RxD LED should flash with the same rate as the TxD LED on the master. This LED indicates that the data from the MODBUS master arrives at the slave. This LED won't flash if the TxD LED of the master isn't flashing! Check the following points if the receive data LED (RxD) does not flash: Check the external power supply of the used serial port if present. Most serial ports on E.D.&A. HPC's can work in a RS232 and a RS485 mode. The receive data LED (RxD) will not lighten if the serial port is in the wrong mode. The hardware manuals describe the jumpers or dip-switches that set the mode of the serial port. The mode of the port of master and slave must be the same. The cable can be wrong. The connections inside the cables are described in the hardware manuals. It's still possible that the serial cable is wrong when the RxD LED flashes! Especially if: the "signal ground line" and one of the "signal lines" are reversed in an RS232 cable the two wires of a RS485 cable are reversed The RxD LED might flash while the HPC receives garbage data in these cases. 7.3 Does the slave react to the messages? If the slave's receive data LED (RxD) flashes, it receives the request from the MODBUS master. Now the slave should send an answer back. The answer is visible on the red transmit data LED (TxD) of the slave. This LED should lighten shortly after the RxD LED. The TxD LED will only lighten if the RxD LED is working! There are some reasons why this might not be happening: Corresponds the serial port where the cable is connected to with the serial port number that is used in the program? The serial port number must be used with the ComOpen() function and the with the InstallModbusMas() function. The serial port of the V5 HPC and the serial port on the CPU boards of the different HPC's is always COM 0 (null)! Check the return value of the ComOpen() function. Negative values indicate an error if the port could not be opened. Check the return value of the InstallModbus() function. Negative values indicate an error if the driver could not be installed. The return value of InstallModbus() is described in chapter 2.3. The serial port must already be opened when the MODBUS driver is installed because it needs to 25

know the baud-rate to calculate its timing requirements. The install can also fail if the required option lock is not available. The slave number of the MODBUS slave is not correct: the master sends his request to a specific slave number, so the slave must be set to that slave number. This can be done with dip-switches on the MODBUS slave or with the InstallModbus() function. A detailed description of the dipswitches is available in the hardware reference manual of each HPC. The initialization parameters of the 2 serial ports (master and slave) are not identical: baud-rate, parity and number of stop bits must be the same. The number of data bits must be 8 for MODBUS. The serial port is not in "communication" mode but in "programming" mode. The user program has no control over the serial port as long as it is in "programmer" mode, so don't use a programmer cable on a serial port that is a programmer port also. Is the HPC in RUN mode? A HPC that is not in RUN mode is not executing the user program, so the serial communication with MODBUS isn't working either. The MODBUS slave reacts only to valid MODBUS requests. These are the packets of data that the MODBUS master normally sends. An arbitrary print statement to the serial port of the master will result in an active TxD LED on the master and an active RxD LED on the slave but the MODBUS slave doesn't recognize this arbitrary data, so it doesn't answer. The E.D.&A. HPC's only process binary or RTU mode requests. Requests in ASCII mode are ignored and will therefore not be answered. The MODBUS master is sending broadcasting packets. A MODBUS slave doesn't answer when it receives broadcasting packets, so the TxD LED won't lighten. 7.4 Does the answers go from the slave to the master? If the slave's transmit data LED TxD flashes, it responds to the request of the MODBUS master. The receive data LED (RxD) of the master should also flash. This indicates that the answers from the slave arrive at the MODBUS master. This can be wrong if the RxD LED of the master isn't working: The serial port of the MODBUS master can be in a wrong mode. Most serial ports on E.D.&A. HPC's can work in a RS232 and a RS485 mode. The transmit data LED (TxD) of the master will work normally, but the receive data LED (RxD) remains out in such a case. Check the jumpers or dip-switches that set the mode of the serial port. The mode of the port of master and slave must be the same. The receive data line in the cable might be broken or short-circuited. Again, if the "signal ground line" and one of the "signal lines" are reversed (for RS232) or when the two wires are reversed (RS485), the RxD LED might lighten while the HPC gets garbage data. 7.5 Are the answers OK or do they contain error codes? If the RxD LED of the master flashes, the master's program should now indicate that the MODBUS slave reacted to the request of the master. It's still possible that the slave responds with an error code instead of the requested data, but that is a software or configuration problem. In such a case the master might report a 'protocol error' message. If the MODBUS master is an E.D.&A. HPC, its read or write functions will show an error in their return and status values: 110-116. If possible, check the request function number, especially if the MODBUS master is not an E.D.&A. apparatus. Return value 111 indicates an unsupported function code in a request. The data address can be too large or the MODBUS master might ask too much data at once. This results in the return value 112. The master might be trying to write an illegal value into a variable. Some slaves accept only a limited range of values. Writing illegal values results in the return value 113. For example, E.D.&A. HPC's programmed in the ABC language accept numerical values in the range from 0 to 9999 only. 26

7.6 Do cable problems cause interruptions? Cabling problems may result in permanent or intermittent failures. In an RS485 network, there might be a termination or topology problem. In theory, a communications line should be terminated at both ends and no terminations should appear in-between. In practice, using thin cables may result in other problems. Topology problems may exist if a multipoint network is not built as a bus-topology. Bus topology means one cable hopping from each node to the next, whiteout shunts in between. Star-topology requires the use of repeaters. A communication error because of poor line quality is also possible. This might result in CRC errors or timeouts. One solution is reducing the speed of the MODBUS master and slave to 1200 or 300 baud and see if the communication works then. A better, shielded cable can also solve the problem. Increasing the number of tries of the master may improve things as well. It's much easier to find a problem with the serial line if the communication speed is temporary reduced to 1200 or even 300 baud on the master and the slave system. It will take much more time now for a packet to travel over the serial line, so the transmit and receive LED's will be active longer. It's possible to simulate a MODBUS master with a simple test program on an EPL HPC. This program regularly sends out a row of characters that look just like a request of a real MODBUS master, so the slave will react on it and send an answer back. Pay attention, this program sends a request to SLAVE NUMBER 1. Serial port 1 simulates the MODBUS master; the MODBUS slave is installed on serial port 2. The program is attached as program example 'modsla1.epl'. The easiest way to test this is by connecting the transmit data line (TxD) of serial port 1, (pin 4 on DB9 connectors, pin 2 on DB25 connectors), to the receive data line (RxD) of serial port 2, (pin 2 on DB9 connectors, pin 3 on DB25 connectors). The ground connection is made inside the HPC if the two serial ports are in the same system. The two serial ports must be RS232 ports. It's also possible to use the program if the serial ports are from two different HPC's. A serial communication cable between the two systems is needed then. It's possible to use the same program for the two HPC systems. The LED indicators of the slave serial port show what happens: A flashing receive data LED (RxD), yellow or red: serial port 2 receives the request A flashing transmit data LED (TxD), always red: serial port 2 transmits the answer. So, the MODBUS slave is working properly if its TxD LED flashes. It answers to the requests of the master. 27

8 Examples The example programs can be used on any E.D.&A. EPL HPC. Modmas4.epl and Modsla4.epl are specifically written for the V5-2xx HPC: they use the character display of this HPC. Modsla1.epl Emulation of a MODBUS master on COM 1 A MODBUS slave on COM 2. Sends a test message once per second. Modmas1.epl Modmas2.epl Modmas3.epl Modmas4.epl and Modsla4.epl Simple program with one ModbusRead(). Reads data from one slave, once per second. Program with two MODBUS masters and one MODBUS slave. Program with one MODBUS master that reads data from 3 different slaves. This program reads the data at the highest available speed. Demo program for connecting two V5 HPC's. Uses arrays of longs to store the transfer blocks. 8.1 Modsla1.epl /* modsla1.epl * * Example program installing 1 modbus slave driver on COM2, * and transmitting test requests on COM1. * To test the modbus slave on COM2 in RS232 mode, connect a * test wire from COM1 TxD to COM2 RxD. The modbus slave now * receives the requests and will respond. This is indicated * by flashing of the COM2 TxD LED. */ #include <stdcfg.h> #include <kernel.h> main() { if( ^/b1s) comprintnc( 1, "\0x01\0x03\0x00\0x00\0x00\0x0A\0xC5\0xCD", 8); } init() { S1 = comopen( 1, "9600,n,8,1"); } S2 = comopen( 2, "9600,n,8,1"); S3 = installmodbus( 2, 1, 0); 28

8.2 Modmas1.epl /* modmas1.epl * * Example program using 1 MODBUS master driver. * From slave 1: read registers 257..260 and store in s23..s26. */ #include <stdcfg.h> #include <kernel.h> main() { /* Each second: set the start flag */ if( ^/b1s) m20 = 1; /* ModbusRead arguments: start, comport, block */ s20 = ModbusRead( &m20, 1, &L100); if( s20==2) /* count success */ s21++; if( s20 < 0) /* count fails */ s22++; } a1.1 = m20; /* put startflag on output */ init() { /* Use s1 as indicator to verify all open's and install's */ s1 = 0; /* Open com port 1, transmit and receive buffer * are 100 bytes. */ if( comopenq( 1, "9600,n,8,1", 100, 100) < 0) s1 = s1 + 1; /* Install MODBUS master driver on com1, with * 100 bytes buffer, * 1000 millisec timeout, * 3 attempts. */ if( InstallModbusMas( 1, 100, 1000, 3) < 0) s1 = s1 + 2; /* Init MODBUS block: Slave, Variable, Count, Status, Data */ L100 = 1; L101 = 40257; 29

} L102 = 4; L103 = 0; L104 = (long)&s23; 8.3 Modmas2.epl /* modmas2.epl * Example program using 2 MODBUS master drivers, and 1 slave driver. * Master drivers on com1 and com5, slave driver on com6. * * From slave 1 on com1, read registers 10..13 and store in s23..s26. * To slave 1 on com5, write registers 10..13 with data from s23..s26. * From slave 1 on com5, read coils 201..250, store in m201..m250. * * The slave driver can be used to connect to another MODBUS master * system, such as an operator terminal or supervisory computer. */ #include <stdcfg.h> #include <kernel.h> main() { /* Set the start flags periodically: each 500ms */ } if( ^/b5t) { m20 = 1; m21 = 1; } if( ^/b1s) m22 = 1; /* Read on com 1 from slave 1 */ s20 = ModbusRead( &m20, 1, &L100); /* Write on com 5 to slave 1 */ s30 = ModbusWrite( &m21, 5, &L110); /* Read on com 5 from slave 1 */ s40 = ModbusRead( &m22, 5, &L120); init() { /* Use s1 as indicator to verify all open's and install's */ s1 = 0; 30

/* Open com ports, transmit and receive buffers are 100 bytes */ if( comopenq( 1, "2400,n,8,1", 100, 100) < 0) s1 = s1 + 1; if( comopenq( 5, "2400,n,8,1", 100, 100) < 0) s1 = s1 + 2; if( comopenq( 6, "9600,n,8,1", 100, 100) < 0) s1 = s1 + 4; /* Install MODBUS master drivers, with * 100 byte buffers, * 500 millisec timeout, * 3 attempts. */ if( InstallModbusMas( 1, 100, 500, 3) < 0) s1 = s1 + 8; if( InstallModbusMas( 5, 100, 500, 3) < 0) s1 = s1 + 16; /* Install MODBUS slave driver, * on com6, * as slave number 10. */ if( InstallModbus( 6, 10, 0) < 0) s1 = s1 + 32; /* Init MODBUS blocks: Slave, Variable, Count, Status, Data */ L100 = 1; L101 = 40010; L102 = 4; L103 = 0; L104 = (long)&s23; L110 = 1; L111 = 40010; L112 = 4; L113 = 0; L114 = (long)&s23; } L120 = 1; L121 = 201; L122 = 50; L123 = 0; L124 = (long)&m201; 31

8.4 Modmas3.epl /* modmas3.epl * * Example program requesting data from 3 slaves connected to com1. * From slave 10, read first 10 registers and store in s50..s59. * From slave 11, read first 10 registers and store in s60..s69. * From slave 12, read first 10 registers and store in s70..s79. */ #include <stdcfg.h> #include <kernel.h> main() { /* To get the highest speed, we keep the startflags set */ m20 = 1; m21 = 1; m22 = 1; /* ModbusRead arguments: start, com port, block */ } s20 = ModbusRead( &m20, 1, &L100); s21 = ModbusRead( &m21, 1, &L105); s22 = ModbusRead( &m22, 1, &L110); init() { /* Use s1 to verify all open's and install's */ s1 = 0; /* Open com port 1, buffers are 100 bytes */ if( comopenq( 1, "9600,n,8,1", 100, 100) < 0) s1 = s1 + 1; /* Install MODBUS master driver on com1, with * 100 bytes buffer, * 300 millisec timeout, * 3 attempts. */ if( InstallModbusMas( 1, 100, 300, 3) < 0) s1 = s1 + 2; /* Init MODBUS block: Slave, Var, number of variables, Stat, Data */ L100 = 10; L101 = 40001; L102 = 10; L103 = 0; L104 = (long)&s50; 32

L105 = 11; L106 = 40001; L107 = 10; L108 = 0; L109 = (long)&s60; } L110 = 12; L111 = 40001; L112 = 10; L113 = 0; L114 = (long)&s70; 8.5 Modmas4.epl /* modmas4.epl and modsla4.epl * * 2 example programs for V5 HPC's where one is master and the * other is slave. * The master HPC reads E1.25 and E1.26 from the slave and * puts this on its outputs A1.1 and A1.2. * The state of E1.25 and E1.26 from the master HPC are written * to the slave on A1.1 and A1.2. */ #include <stdcfg.h> #include <kernel.h> #include <display.h> bool comok; bool Doread; bool DoWrite; long WriteVar[5]; long ReadVar[5]; main() { short status; if(comok==false) DispPrints(2,1,"Uit bedrijf"); else DispPrints(2,1,"In bedrijf "); DoRead=1; DoWrite=1; status=modbusread(&doread,0,readvar); if(status==2) comok=true; 33

if(status<0) comok=false; status=modbuswrite(&dowrite,0,writevar); } if(status==2) comok=true; if(status<0) comok=false; init() { DispClear(); DispPrints(1,1,"Master HPC"); S1 = ComOpen(0,"9600,n,8,1"); S2 = InstallModbusMas(0,200,100,3); ReadVar[0]=1; /* In Slave 1 */ ReadVar[1]=10025; /* Read E1.25 */ ReadVar[2]=2; /* and E1.26 */ ReadVar[3]=0; ReadVar[4]=(long)&a1.1; /* Store at a1.1 */ } WriteVar[0]=1; /* In Slave 1 */ WriteVar[1]=9001; /* Write A1.1 */ WriteVar[2]=2; /* and A1.2 */ WriteVar[3]=0; WriteVar[4]=(long)&e1.25;/* Read e1.25 */ 8.6 Modsla4.epl /* modsla4.epl * * slave program to use with modmas4.epl */ #include <stdcfg.h> #include <kernel.h> #include <display.h> main() { } init() { DispClear(); 34

DispPrints(1,1,"Slave HPC"); } S1 = ComOpen(0,"9600,n,8,1"); S2 = InstallModbus(0,1,0); 35

9 Versions book 26 Version number Date Modifications 2.08 2.09 28/10/2003 New option value added. InstallModbus 7 function. 2.10 14/07/2004 Complete check manual 2.11 11/08/2006 Added detailed descriptions of some modbus query and response messages 2.12 21/5/2007 Added description of more modbus exception codes and error codes of the Modbusread() and modbuswrite() functions. Added the chapter "Which modbus function codes are generated by ModbusRead() and ModbusWrite()" 36

MODBUS RTU compatible master and slave driver E26 Versie 2.12 Index - D - DEINSTALLMODBUS 9 - I - INSTALLMODBUS 7 INSTALLMODBUSMAS 5 - M - MODBUSREAD 10 MODBUSWRITE 10 37