M221 Modbus Master Example
M221 Modbus Master Example
Example Guide
Modbus Master on Serial Line via
SR2MOD01 modem
11/2014
xSample_Modbus_Master_SL_via_SR2MOD01_Modem.smbe
EIO0000002086.00
www.schneider-electric.com
The information provided in this documentation contains general descriptions and/or technical
characteristics of the performance of the products contained herein. This documentation is not intended as a
substitute for and is not to be used for determining suitability or reliability of these products for specific user
applications. It is the duty of any such user or integrator to perform the appropriate and complete risk
analysis, evaluation and testing of the products with respect to the relevant specific application or use
thereof. Neither Schneider Electric nor any of its affiliates or subsidiaries shall be responsible or liable for
misuse of the information contained herein. If you have any suggestions for improvements or amendments
or have found errors in this publication, please notify us.
No part of this document may be reproduced in any form or by any means, electronic or mechanical,
including photocopying, without express written permission of Schneider Electric.
All pertinent state, regional, and local safety regulations must be observed when installing and using this
product. For reasons of safety and to help ensure compliance with documented system data, only the
manufacturer should perform repairs to components.
When devices are used for applications with technical safety requirements, the relevant instructions must be
followed.
Failure to use Schneider Electric software or approved software with our hardware products may result in
injury, harm, or improper operating results.
2 EIO0000002086 11/2014
Table of Contents
EIO0000002086 11/2014 3
V
Safety Information
Important Information
NOTICE
Read these instructions carefully, and look at the equipment to become familiar with the device before trying
to install, operate, or maintain it. The following special messages may appear throughout this documentation
or on the equipment to warn of potential hazards or to call attention to information that clarifies or simplifies a
procedure.
The addition of this symbol to a Danger or Warning safety label indicates that an
electrical hazard exists, which will result in personal injury if the instructions are not
followed.
This is the safety alert symbol. It is used to alert you to potential personal injury
hazards. Obey all safety messages that follow this symbol to avoid possible
injury or death.
DANGER
DANGER indicates an imminently hazardous situation which, if not avoided, will result in death or
serious injury.
WARNING
WARNING indicates a potentially hazardous situation which, if not avoided, can result in death or
serious injury.
CAUTION
CAUTION indicates a potentially hazardous situation which, if not avoided, can result in minor or
moderate injury.
NOTICE
NOTICE is used to address practices not related to physical injury.
4 EIO0000002086 11/2014
PLEASE NOTE
Electrical equipment should be installed, operated, serviced, and maintained only by qualified personnel. No
responsibility is assumed by Schneider Electric for any consequences arising out of the use of this material.
A qualified person is one who has skills and knowledge related to the construction and operation of electrical
equipment and the installation, and has received the safety training necessary to recognize and avoid the
hazards involved.
EIO0000002086 11/2014 5
V
The example described in this document is intended for learning purpose only; it must not be used directly
on products that are part of a machine or process.
WARNING
UNINTENDED EQUIPMENT OPERATION
Do not include the code from this example in your machine or process without thoroughly testing your entire
application.
Failure to follow these instructions can result in death, serious injury, or equipment damage.
This document and its related SoMachine Basic project file focus on specific functions and function blocks of
the Schneider Electric libraries and on specific features of SoMachine Basic. They are intended to help you
understand how to develop, test, commission, and integrate applicative software of your own design in your
control systems.
The example is intended for qualified persons who are new SoMachine Basic users.
Validity Note
This document is valid for SoMachine Basic V1.3 or later.
WARNING
UNINTENDED EQUIPMENT OPERATION
• Only use software approved by Schneider Electric for use with this equipment.
• Update your application program every time you change the physical hardware configuration.
Failure to follow these instructions can result in death, serious injury, or equipment damage.
6 EIO0000002086 11/2014
WARNING
LOSS OF CONTROL
• The designer of any control scheme must consider the potential failure modes of control paths and, for
certain critical control functions, provide a means to achieve a safe state during and after a path failure.
Examples of critical control functions are emergency stop and overtravel stop, power outage and restart.
• Separate or redundant control paths must be provided for critical control functions.
• System control paths may include communication links. Consideration must be given to the implications
of unanticipated transmission delays or failures of the link.
• Observe all accident prevention regulations and local safety guidelines.1
• Each implementation of this equipment must be individually and thoroughly tested for proper operation
before being placed into service.
Failure to follow these instructions can result in death, serious injury, or equipment damage.
1
For additional information, refer to NEMA ICS 1.1 (latest edition), "Safety Guidelines for the Application,
Installation, and Maintenance of Solid State Control" and to NEMA ICS 7.1 (latest edition), "Safety
Standards for Construction and Guide for Selection, Installation and Operation of Adjustable-Speed Drive
Systems" or their equivalent governing your particular location.
EIO0000002086 11/2014 7
Introduction V
Introduction
Before You Begin
Your specific application requirements may be different from those assumed for this and any related
examples described herein. In that case, you will have to adapt the information provided in this and other
related documents to your particular needs. To do so, you will need to consult the specific product
documentation of the hardware and/or software components that you may add or substitute for any
examples specified in this documentation. Pay particular attention and conform to any safety information,
different electrical requirements and normative standards that would apply to your adaptation.
WARNING
REGULATORY INCOMPATIBILITY
Be sure that all equipment applied and systems designed comply with all applicable local, regional and
national regulations and standards.
Failure to follow these instructions can result in death, serious injury, or equipment damage.
The use and application of the information contained herein require expertise in the design and
programming of automated control systems. Only you, the user, machine builder or system integrator, can
be aware of all the conditions and factors present during installation and setup, operation, and maintenance
of the machine or process, and can therefore determine the automation and associated equipment and the
related safeties and interlocks which can be effectively and properly used. When selecting automation and
control equipment, and any other related equipment or software, for a particular application, you must also
consider any applicable local, regional or national standards and/or regulations.
Some of the major software functions and/or hardware components used in the proposed architectures and
examples described in this document cannot be substituted without significantly compromising the
performance of your application. Further, any such substitutions or alterations may completely invalidate any
proposed architectures, descriptions, examples, instructions, wiring diagrams and/or compatibilities between
the various hardware components and software functions specified herein and in related documentation.
You must be aware of the consequences of any modifications, additions or substitutions.
CAUTION
EQUIPMENT INCOMPATIBILITY
Read and thoroughly understand all device and software documentation before attempting any component
substitutions or other changes related to the application examples provided in the document.
Failure to follow these instructions can result in injury or equipment damage.
8 EIO0000002086 11/2014
Introduction
CAUTION
EQUIPMENT OPERATION HAZARD
• Verify that all installation and set up procedures have been completed.
• Before operational tests are performed, remove all blocks or other temporary holding means used for
shipment from all component devices
• Remove tools, meters, and debris from equipment.
Failure to follow these instructions can result in injury or equipment damage.
Verify that the completed system, including the functional safety system, is free from all short circuits and
temporary grounds, except those grounds installed according to local regulations. If temporary high-potential
voltage testing is necessary, follow the recommendations in equipment documentation to help prevent injury or
equipment damage.
WARNING
UNGUARDED MACHINERY CAN CAUSE SERIOUS INJURY
• Do not use this software and related automation equipment on equipment which does not have point-of -
operation protection.
• Do not reach into machinery during operation.
Failure to follow these instructions can result in death, serious injury, or equipment damage.
Ensure that appropriate safeties and mechanical/electrical interlocks related to point-of-operation protection
have been installed and are operational before placing the equipment into service. All interlocks and safeties
related to point-of-operation protection must be coordinated with the related automation equipment and
software programming.
NOTE: Coordination of safeties and mechanical/electrical interlocks for point-of-operation protection is
outside the scope of the examples and implementations suggested herein. It is sometimes possible
to adjust the equipment incorrectly and this may produce unsatisfactory or unsafe operation. Always
use the manufacturer instructions as a guide to functional adjustments. Personnel who have access
to these adjustments must be familiar with the equipment manufacturer instructions and the
machinery used with the electrical equipment.
Only those operational adjustments actually required by the machine operator should be accessible to the
operator. Access to other controls should be restricted to help prevent unauthorized changes in operating
characteristics.
EIO0000002086 11/2014 9
Modbus Master via SR2MOD01 Example Description V
Example Description
Overview
This template example helps you to program a Modbus master M221 Logic Controller to access a
remote device through PSTN (Public Switched Telephone Network) modem.
The template example is applied using an SR2MOD01 modem available from Schneider Electric.
Although another modem may be used in its place, the example herein is particular to the
SR2MOD01 modem and the code of the example, and in particular the initialization of the modem,
will necessarily need to be modified. In all cases, consult the documentation delivered with your
modem for more information.
The present template example describes the requirements for the M221 Logic Controller configured
as a master. There is another document, SoMachine Basic Example Guide - Modbus Slave on Serial
Line via SR2MOD01 modem, which describes the M221 configuration and modem setup required for
a M221 Logic Controller configured as a slave.
The template example program has been designed to be easily integrated into your application. How
to integrate the template example is described in the comments of the objects used in the template.
Animation tables have been provided within the template example to assist you in the integration and
use of it:
• monitor the template
• configure the communication information (phone number and slave address)
• diagnose the modem connection
• how to read and write data to the slave logic controller with which you are connected by
adapting this example to your needs.
10 EIO0000002086 11/2014
Example Description
Modem Configuration
To configure a new SR2MOD01 modem used for the first time "out of the box", you must first perform
the primary initialization. This primary initialization is saved to the non-volatile memory of the modem.
After that, the initialization string (Init command) can be simplified.
The following Init command allows you to configure a new SR2MOD01 modem:
ATE0L0X0&C0&D0&K0\N0%C0S37=13N0#P0$SB19200&W
You can send this Init command either with the software delivered with the modem or by the M221
Logic Controller. When using the M221 Logic Controller to configure the modem, you can use
SoMachine Basic to define the Serial line communication parameters and the Init command.
Under the Configuration tab, select the SL1 (Serial line) port and set the parameters as
follows:
EIO0000002086 11/2014 11
Modbus Master via SR2MOD01 Example Description V
To perform the primary initialization, connect your modem to the M221 Logic Controller Serial port 1
and SoMachine Basic to the M221 Logic Controller programming port.
To send the primary Init command, set the system bit %S105 to 1.
After performing the primary initialization, you can simplify the Init command for any further use of
the modem:
12 EIO0000002086 11/2014
Example Description
If you need to verify the configuration of your modem, you can use an external software tool such as
Windows Hyperterminal. Sending the command at&v0 via Hyperterminal, you will see the following
information:
See the Appendix for the detailed information concerning the required configuration of the modem.
EIO0000002086 11/2014 13
Modbus Master via SR2MOD01 Example Description V
The values of the constant words are used at the first scan of the application once the logic
controller has been put into a RUNNING state or after a cold start. The constant values are
transferred to memory words, and the memory words are then used to transfer the call
information to the modem (see Modifying the template example). You can modify this table
of constants to establish the correct call information for your application.
NOTE: If you need to call different, multiple phone numbers, you can modify the memory
words programmatically as necessary.
To facilitate the testing of the communication between the M221 Logic Controller master and
the modem, or simply to monitor the communication initialization when you run the program
containing the template example, you can use the Modem->PLC_Sts animation table:
Once you set the system bit %S105 to 1 (either manually or programmatically) the Init
command contained in the configuration of the logic controller is sent to the modem. The
modem responds by returning a coded reply into system word %SW167:
0 = indicates that the modem is present, configured properly and is waiting for
the dial-up command
4 = indicates a configuration mismatch between the modem and the logic
controller
65535 = indicates that either the modem is not connected or not under power
14 EIO0000002086 11/2014
Example Description
The Control animation table allows you to monitor the progression of the call. While running
the program containing the template example, the following information is presented:
NOTE: Set the memory bit %M10 to 1 to start the procedure for dialing the remote
modem, given the value of %MW99 is 0.
EIO0000002086 11/2014 15
Modbus Master via SR2MOD01 Example Description V
The following state diagram presents the logical flow of the template example program:
WaitingConnect
(SR4)
Connected
Quit
ASCII
mode
ReinitSequenceOnError Exchanges
MODBUS
SetASCIIConnect
(SR1)
Hang up
(SR3)
Quit
ASCII
mode
Initial states
16 EIO0000002086 11/2014
Example Description
The call information is established at the first scan, and is contained in a table of memory
words derived from a table of constant words (See Using the template example). You can
view and monitor the call information by using the Online Custom animation table.
If you need to modify the phone number to dial from that established by the constant words,
you can either do so manually in the animation table or programmatically within your
application.
After the correct call information for the distant modem is established, you are ready to have
the master make the call. However, the objective of making the call is to read and/or write
data between the logic controllers. To do this, you must specify the memory words (%MW) to
read and/or write by modifying the read and write function blocks to correspond to the memory
allocation of your application.
For the purposes of the present template example, the memory word %MW10 in the slave
M221 logical controller increments by 1 every second. This is the word that is read from the
slave by the master M221 Logic Controller.
EIO0000002086 11/2014 17
Modbus Master via SR2MOD01 Example Description V
In the example below, the %READ_VAR function block is programmed to read starting at
%MW10 for length of 1 word. This would need to be modified for your application to start the
read of the slave at the intended starting word and numbers of words to read.
18 EIO0000002086 11/2014
Appendix
Appendix
In compliance with the logic controller and the RS-232 specifications, the used modem should be pre-configured
via an external tool or via SoMachine Basic before using the template example:
E0 Disable Echo commands received by DTE
Q0 Enable result codes to DTE
&C0 ignore DCD (always ON)
&D0 Ignore DTR signals
&K0 Disable flow control
V1 Format of Result Code = VERBOSE
S0=1 Accept incoming call after 1 ring
S2 Escape code Character =43
X0 Disable error codes during call progress
&W Write current configuration
EIO0000002086 11/2014 19
Appendix V
20 EIO0000002086 11/2014