Schneider Electric TSX SCM 22 Modbus Protocol / En Instruction Sheet
Annons
Annons
Contents
Modbus
®
Protocol
Section
1 Introduction to Modbus ® Protocol
2 Protocol Emulation
3 Programming the Module as a Slave
4 Programming the Module as a Master
5 I/O Bits and Words
Sub-section
1.1
Definition of a Protocol
1.2
Modbus ® Protocol Applications
1.3
Principle of Modbus ® Exchanges
2.1
Modbus ® Data Objects
2.2
Master/Slave Exchanges
2.3
Processor/Slave Exchanges
2.4
Processor/Master Exchanges
2.5
Functions Performed by the Module
2.6
Description of the Main Functions
2.7
Description of the Complementary
Functions
3.1
Configuring the Module
3.2
Exchanges Through the Message
Interface
3.3
Request Codes Available
3.4
Module Operating Modes
4.1
Configuring the Module
4.2
Exchanges Through the Message
Interface : Main Functions
4.3
Exchanges Through the Message
Interface : Complementary Functions
4.4
Request Codes Available
4.5
Module Operating Modes
5.1
Definition of Discrete I/O Bits
5.2
Definition of Register Words
6 Additional Programming Information 6.1
Fault Bits
7 Programming Examples 7.1
Programming a Slave in TSX 47-30 or TSX 67/87
7.2
Programming a Slave in TSX 47-20
7.3
Programming a Master in TSX 47-30 or TSX 67/87
8 Appendix 8.1
Response Time of the Slave
8.2
Response Time of the Master
8.3
Processor/Slave Exchanges Through the Register Interface
Page
2
3
4
5
6
8
10
11
12
13
16
28
47
52
66
56
63
64
19
23
24
26
33
37
39
40
43
46
Modbus ® is a registered trademark of Gould Modicon.
1
1 Introduction to Modbus ® Protocol
1.1
Definition of a Protocol
General
A protocol is a set of rules which defines how data is to be be formatted to allow two or more devices to communicate with each other.
For purposes of mutual comprehension and error checking of all the devices concerned, the data to be exchanged is enclosed in a frame which is generally composed as follows :
Header ":" Address Request Data Check End
Each protocol defines the presence, format and contents of the different groups of variables enclosing the data zone.
This structure permits the definition of the start of the message, the address to which the message is to be sent, the type of function requested, the length of the message, the data to be exchanged, the checking system, and an end of message code.
However, the contents and structure of the frame are different for each type of protocol.
The Modbus ® Frame
In the Remote Terminal Unit (RTU) mode, the frame of the Modbus ® protocol has no header nor end of message code, it is therefore composed as follows :
Address Request Data CRC 16
CRC 16 : Cyclic Redundancy Check.
In the ASCII mode, the frame of the Modbus
®
protocol is complete and is composed as follows :
Header ":" Address Request Data LRC End "CR LF"
LRC : Longitudinal Redundancy Check,
CR : Carriage Return,
LF : Line Feed.
Modbus ® is a registered trademark of Gould Modicon.
2
1 Introduction to Modbus ® Protocol
1.2
Modbus
®
Protocol Applications
The Modbus ® protocol can be used to exchange data between two or more devices connected by a common multidrop bus. The protocol creates a hierarchical system of communication in which one device is the master and the other devices are slaves. Two types of dialogue are possible between the master and the slaves :
. The master interrogates a slave and waits for its reply,
. The master broadcasts information to all the slaves and does not wait for a reply.
TSX
MASTER
SLAVE i
SLAVE j
SLAVE k
The exchange of data is initiated and controlled by the master, which interrogates each slave in turn to see if it has data to transmit. If the slave does not respond within a specific time, the master considers that the slave is absent and goes on to interrogate the next slave. Only one device can transmit data on the line at a time, and the slaves cannot transmit without being invited to do so by the master.
SLAVE j
SLAVE i SLAVE k
The principle of the master/slave dialogue can therefore be schematized as a series of point-to-point links, with the master turning an imaginary selector switch to the number of each slave in succession, as shown below :
Slave to slave communication is therefore not possible unless the application software in the master is designed to allow the reception of data from one slave and its transmission to another slave.
TSX
3
1 Introduction to Modbus ® Protocol
1.3
Principle of Modbus
®
Exchanges
The Modbus ® protocol permits the exchange of data, in the form of bits and words, between the master and the slaves. Bit memory zones and word memory zones must therefore be defined in each slave so that they can be read or written by the master.
The master can be a TSX Series 7 PLC equipped with a TSX SCM 22 module, or any other programmed or programmable device that supports Modbus ® protocol.
Each slave can be a TSX Series 7 PLC equipped with a TSX SCM 22 module, or any other programmed or programmable device that supports Modbus ® protocol.
Theoretically, up to 255 slaves can be logically connected to a Modbus ® line, but in practice the maximum number of slaves is defined by the type of data link, as follows :
RS232C : 1 slave max., 20mA CL : 16 slaves max., RS422A/RS485 : 32 slaves.
Since the protocol is already defined, it is simply necessary to assign a Modbus ® address to each data object (bit or word) so that they can be exchanged. In a TSX
Series 7 PLC, these Modbus ® addresses are assigned during the configuration of the SCM module.
An input object (bit or word) can be read but not written.
An output object (bit or word) can be read or written.
MASTER
P
U
R
O
S
G
E
R
R
A
M
Transmission table
Reception table
Modbus ® address
Output bits
Input words
Output words
Slave i
Slave j
Input bits
Slave k
4
2 Protocol Emulation
2.1
Modbus
®
Data Objects
Definition
The Modbus ® protocol defines four types of accessible data objects as follows:
. Input bits,
. Output bits,
. Input words,
. Output words.
Each slave device connected to a Modbus ® line has a number of objects of each type, defined by the configuration and identified by consecutive addresses.
A TSX SCM 22 slave module converts the Modbus ® address into a memory address in the processor of the slave PLC.
The table of correspondence is established during the configuration of the slave module. All the data objects that are accessible via Modbus ® are located in the internal word (Wi) zone of the slave PLC.
Bit Objects
For the bit objects, the module knows the address i of the internal word Wi containing the first bit, defined in position 0 (the bit concerned therefore has the image Wi,0), and its corresponding Modbus ® address.
The Modbus
®
address of the first bit configured must therefore correspond to the first bit (bit 0) of an internal word. The other bits follow in consecutive order.
Example : Input bits
Modbus ® addresses
0100
0101
...
0115
0116
Processor addresses
50
50
..
50
51
Processor objects
W50,0
W50,1
...
W50,F
W51,0
Physical objects
TXT1,D
T2,R
...
M3,S
I10,4
Word Objects
For the word objects, the module knows the address j of the first internal word Wj and its corresponding Modbus ® address. All the word objects are located in the internal word zone of the slave PLC.
Example : Input words
Modbus ® addresses
Processor addresses
8000
8001
8002
...
200
201
202
...
Processor objects
W200
W201
W202
...
Physical objects
IW2,1
TXT2,V
W202
...
5
2 Protocol Emulation
2.2
Master/Slave Exchanges
Principle
The master initiates the exchanges. It interrogates a slave by transmitting a message containing four types of information :
. The address of the slave,
. The function requested,
. The data zone (which varies according to the function requested),
. The error check.
The master waits for the reply from the slave before sending the next message, thus avoiding any conflict of access to the line. This procedure therefore authorizes half-duplex operation.
Error checking
When a slave is interrogated by the master, it responds by sending back either : a message containing data, a message saying that it has no data to send, or an exception response saying that it has not understood or cannot process the message received. An exception response may be caused either by an error in the message received from the master, or by a failure in the slave. After receiving an exception response, the master decides whether or not to repeat the message.
The error checking procedure is transparent to the user program of the slave, which is not informed of the errors detected and processed by its SCM module.
Monitoring of the slave
MASTER
SLAVE
Ch0
OK
SLAVE
TSX
Ch1
For diagnostic purposes, the master can obtain access to certain information in the SCM slave module by using special function codes. This information includes the contents the slave module’s error and events counters, which memorize the number of messages :
. Received on the line,
. Received by the module,
. Received by the module with checksum error,
. Transmitted by the module with an exception response code,
. Transmitted by the module to its processor without receiving a reply.
All these variables can be accessed by the master in a manner that is totally transparent to the user of the slave.
However, the user program of a slave PLC can also read these counters if required.
6
2 Protocol Emulation
Master/Slave Exchanges (Cont'd.)
Monitoring of the master
MASTER
TSX
Ch0
Ch1
OK
SLAVE
The error and events counters of the master module can monitor :
. The exchanges between the master module and its processor,
. The exchanges between the master and the slaves.
These counters can be read by the user program of the master PLC by using the message mode (text function blocks).
The counters memorize the following information :
. The number of processor requests received,
. The number of processor requests refused. The master module examines the processor request and transmits a refusal in the following cases :
- Slave address incorrect,
- Function number unknown,
- Function illegal in general broadcast mode,
- Number of objects to be accessed too high,
- Implicit length of the processor request incorrect.
. Number of slave responses correctly received,
. Number of slave responses received with an exception code,
. Number of messages without reply from the slave,
. Number of slave responses received with checksum error,
. Number of incoherent slave responses received. The master module examines the message received from the slave and declares it incoherent when :
- The message received is inconsistent with the request transmitted to the slave (the slave address, function number or number of objects is different),
- The implicit length of the message received is incorrect.
The master module reiterates the message to the slave in the following cases :
- The message has not been replied to (within the configured delay),
- The message has been received with a checksum error,
- The message received is incoherent,
- The message contains a reception fault.
The master module stops reiterating the message in the following cases :
- The permitted response time is exceeded during reception,
- The replies from the slave are received with a reception fault.
7
2 Protocol Emulation
2.3
Processor/Slave Exchanges
Principle
MASTER
Asynchronous link
Ch0
OK
SLAVE
TSX
Ch1
The processor of the slave PLC sets the TSX SCM 22 module to the reception mode. When a message is received from the master, the slave module analyzes the message and transmits it to the processor of the slave PLC in the form of a request.
The user program of the slave PLC then performs the required operation (writing of tables, transfer of tables, etc.) and requests the transfer of the data and the resetting of the module to the reception mode after the data has been transmitted.
The slave module then replies asynchronously to the master by sending the following four types of information :
. The number of the slave,
. The type of function,
. The data zone,
. The error check.
The slave module is then reset to the reception mode and awaits a message from the master, so that the exchange cycle described above can be repeated.
Methods of the exchange
The TSX SCM 22 module offers the user two methods of exchanging data with the processor of the PLC through its standard interface (which is composed of a discrete interface, a message interface and a register interface).
The first method consists in passing all the exchanges through the message interface by the use of Text blocks. This is the simplest method, since it involves using only four access codes, or requests.
The second method consists in passing certain exchanges through the register interface and the others through the message interface. This method has the advantage of improving certain response times. It is detailed in the Appendix.
8
2 Protocol Emulation
Processor/Slave Exchanges (Cont'd.)
Principle
PLC processor
TSX SCM 22 module
Modbus ® line
Physical objects
User program
Accessible objects program
User program
Standard interface
Modbus ® access processing
Processing by Slave Module
The slave module performs the following operations :
. Reception and analysis of the message from the master,
. Conversion of the Modbus ® addresses of the message into the corresponding internal memory addresses of the slave PLC, and transmission of the message to the processor,
. Conversion of the internal memory addresses of the processor’s reply into the corresponding Modbus ® addresses, with the addition of the error code, and transmission of the response to the master.
Processing by the program of the PLC
The user program must therefore be designed to permit :
. Reception of the requests received by the module,
. Access to the required data in the table of accessible objects,
. Transfers between the table of accessible objects and the associated physical objects (I/O modules, function block values, etc.).
9
2 Protocol Emulation
2.4
Processor/Master Exchanges
Principle
MASTER
TSX
Ch0
Ch1
OK
Asynchronous link SLAVE
The processor of the master PLC has the initiative. It transmits a request to its TSX
SCM 22 module which then transmits a message to the slave concerned. This message contains the following four types of information :
. The number of the slave,
. The type of function requested,
. The data zone,
. The error code.
After receiving a reply from the slave, the master transmits to its processor :
. A report of execution of the request,
. The data received from the slave (converted from Modbus ® addresses to internal memory addresses).
This ends the exchange cycle between the processor and the master module. The master module is then ready to process another request from its processor.
Method of Exchange
The dialogue between the processor and the TSX SCM 22 module takes place through the message interface (i.e. by Text blocks). The request code is the same as the Modbus ® function code.
The data are exchanged by means of transmission and reception tables associated with the Text block.
Processing by the Master Module
The master module performs the following operations :
. Checking of the validity of the processor request,
. Emulation of the message to be transmitted to the slave,
. Transmission of the message to the slave and reiteration if necessary,
. Emulation of the slave’s reply for transmission to the processor.
Processing by the program of the PLC
The user program must therefore be designed to handle :
. The information necessary for the exchange :
- The number of the slave,
- The Modbus ® function code,
- The Modbus ® addresses of the objects accessed,
- The values of the objects to be transferred.
. The transmission of requests to access the module, by the transmission of text blocks,
. The processing of the reply to the request.
10
2 Protocol Emulation
2.5
Functions performed by the Module
The TSX SCM 22 module performs the Modbus ® emulation functions listed below.
These are the only Modbus ® functions performed by the module. Any other function that is requested will be rejected.
However, when the TSX SCM 22 module is used as a master, the request
"Transparent Modbus " permits the generation of any function number from 1 to
255. In this case, the user program sends to the module the whole of the message to be transmitted, except for the error code which is added by the module.
The Modbus ® functions comprise :
. The main functions, which permit the exchange of a Modbus ® object,
. The complementary functions, which are used by the master to obtain information about its slaves and to monitor the exchanges.
The TSX SCM 22 module can be installed in a TSX 47-20, TSX 47-30 or TSX 67/
87 PLC, but the numbers of bits and words that can be exchanged depends on the capacity of the PLC’s Text block (which in the case of a TSX 47-20 is limited to 30 bytes). The maximum number of bits or words that can be exchanged by one
Text block is therefore given below for the TSX 47-30/TSX 67/87 and the TSX 47-
20.
The functions below (read, write, etc.) are seen from the master side.
The functions marked "B" can be broadcast to all the slaves.
Code Function
01
02
03
04
05
06
07
Read N output bits
Read N input bits
Read N output words
Read N input words
Write an output bit
Write an output word
Read status register
08/xx Diagnostics
11 Read events counter
12
15
Read events log
Write N output bits
16
17
Write N output words
Read slave identification
Broadcast Maximum number
TSX 47-30/67/87 TSX 47-20
1920
1920
120
120
208
208
14
14
B
B
B
B
1920
120
144
10
11
2 Protocol Emulation
2.6
Description of the Main Functions
General
The output bits and words defined in the memory of the slave PLC can be read and written by the master.
The input bits and words defined in the memory of the slave PLC can be read by the master, but not written.
Read N Output Bits
Code : 01
This function allows the master to read the status of the output bits in the memory of the slave.
Read N Input Bits
Code : 02
This function allows the master to read the status of the input bits in the memory of the slave.
Read N Output Words
Code : 03
This function allows the master to read the output words in the memory of the slave.
Read N Input Words
Code : 04
This function allows the master to read the input words in the memory of the slave.
Write an Output Bit
Code : 05
This function allows the master to set an output bit to 0 or 1 in the memory of the slave.
Write an Output Word
Code : 06
This function allows the master to write a word of 16 output bits in the memory of the slave.
Write N output bits
Code : 15
This function allows the master to write the output bits in the memory of the slave.
Write N output words
Code : 16
This function allows the master to write the output words in the memory of the slave.
12
2 Protocol Emulation
2.7
Description of the Complementary Functions
Read Status Register
Code : 07
This function allows the master to read 8 status bits which contain the record of certain events which have occurred in the slave. If the slave is a TSX Series 7 PLC, these bits are the high order bits of the output register word OWxy,6. The assignment of these 8 bits is defined by the user. They are generally used to hold information concerning the status of the application.
Echo Check
Code : 08/00
This function returns to the master, for checking purposes, the message received by the slave. The message returned should be identical to the message received.
Restart Communication
Code : 08/01
This function reinitializes the communication channel. Any messages in progress on the channel are cancelled, but the configuration of the channel is preserved.
Read Diagnostic Register
Code : 08/02
This function allows the master to read a 16-bit word containing information concerning the status of the slave. If the slave is a TSX Series 7 PLC, the structure of the status word is as follows :
. Bit 0 = Slave in PWF (Power Failure) mode,
. Bit 1 = Slave in CPUF (CPU Failure) mode,
. Bit 2 = Slave in LOM (Listen Only) mode.
The other bits are not significant.
Change ASCII Separator
Code : 08/03
In the ASCII mode, each byte is replaced by two ASCII characters coded in hexadecimal. The successive messages are separated by the character H’0A’
(Line Feed). This function (08/03) allows the slave to change the separator to any other character. This function is not available in the master module.
Force to Listen Only Mode (LOM)
Code : 08/04
This function forces the slave to the Listen Only Mode (LOM). In this mode, the slave receives all the messages that are addressed to it, but cannot reply. If the slave is a TSX Series 7 PLC, the change to the Listen Only Mode is indicated to the processor by bit A of the input word register IWxy,1.
Reset Counters
Code : 08/0A
This function resets all the slave’s communication monitoring counters to zero, and also the diagnostic register. However, if the slave is a TSX Series 7 PLC, the diagnostic word is not reset to zero since, for the master, it is an input word and therefore cannot be written.
13
2 Management of the Protocol
Description of the Complementary Functions (Cont'd.)
Read Line Message Counter
Code : 08/0B
This function allows the master to read the contents of a 16-bit counter (incremented from 0 to FFFF) which totalizes the number of messages the slave has received on the line and processed since the last restart or power up.
Read Checksum Error Counter
Code : 08/0C
This function allows the master to read the contents of a 16-bit counter which totalizes the number of messages the slave has received on the line with a checksum error since the last restart or power up.
Read Exception Error Counter
Code : 08/0D
This function allows the master to read the contents of a counter which totalizes the number of replies containing an exception error code that the slave has sent to the master.
Read Slave’s Message Counter
Code : 08/0E
This function allows the master to read the contents of a counter which totalizes the number of messages that have been addressed to the slave (irrespective of the type of message).
Read Slave’s No reply Counter
Code : 08/0F
This function allows the master to read the contents of a counter which totalizes the number of times the processor of the slave has failed to reply to a request. If the slave is a TSX Series 7 PLC, this counter is incremented only in the case of a CPU failure.
Read Event Counter
Code : 11
This function allows the master to read a 16-bit status word and a 16-bit event counter. If the slave is a TSX Series 7 PLC, the first word (status) is always set to zero, whereas the second word (event counter) is incremented for every message (form and contents) that is correctly received by the slave, excluding exception responses and read counter requests.
Read Event Log
Code : 12
This function allows the master to read :
. The status word and event counter (identical to Code 11 above),
. The line message counter (identical to Code 08/0B above),
. The contents of the trace buffer (64 bytes maximum).
If the slave is a TSX Series 7 PLC, the trace buffer is a LIFO stack containing a maximum of 64 bytes (or the number of updated bytes). The bytes are entered in chronological order. The last byte received is the first to be transmitted (i.e. LIFO
: Last In First Out).
14
2 Management of the Protocol
Description of the Complementary Functions (Cont'd.)
The trace buffer bytes may be of four types :
1. Slave receive, the byte is updated when a message is received by the slave and before it is processed :
7 6 5 4 3 2 1 0
1 x x 0 0 0 x 0
Bit 1 = 1 if communication error,
Bit 5 = 1 if in listen only mode (LOM),
Bit 6 = 1 if the message is being broadcast.
2. Slave send, the byte is updated at the end of transmission of a response, or at the end of processing in the case of a listen only or broadcast message :
7 6 5 4 3 2 1 0
0 1 x 0 0 0 x x
Bit 0 = 1 if exception code 1, 2 or 3,
Bit 1 = 1 if exception code 4,
Bit 5 = 1 if in listen only mode (LOM).
3. Entered Listen Only Mode (Hexadecimal value = H’20').
4. Communication restart (Hexadecimal value = H’xx’).
Read Slave Identification
Code : 17
This function allows the master to obtain the following information from a slave :
. the identity of the slave,
. its operating status,
. the list of information concerning the status and configuration of the slave.
If the slave is a TSX Series 7 PLC, the reply includes :
. The type of the TSX Series 7 PLC :
- Value H’87' for a TSX 67/87 or TSX 47-30,
- Value H’47' for a TSX 47-20.
. The operating status of the PLC :
- Value H’00' for CPUF or PWF,
- Value H’FF’ for OK.
. The list of Modbus ® objects configured, i.e. 8 words as follows :
- Number of output bits,
- Modbus ® address of the first output bit,
- Number of input bits,
- Modbus ® address of the first input bit,
- Number of output words,
- Modbus ® address of the first output word,
- Number of input words,
- Modbus ® address of the first input word.
15
3 Programming the Module as a Slave
3.1
Configuring the Module
General
Each channel of the TSX SCM 22 module is configured separately by transferring a configuration table from the user program to the module by means of a Text function block.
Only channel 1 of the TSX SCM 22 module can be configured for Modbus ® slave protocol. This channel can also be configured for other protocols or for the character string mode. Channel 0 is reserved for half-duplex operation in the character string mode.
All the information concerning the configuration of channel 1 for Modbus ® slave protocol is transferred from the user program to the module by means of a Text function block containing the configuration table below. This table is composed of 15 words (30 bytes) which can be written in the internal word zone (Wi) or constant word zone (CWi) of the user memory.
Configuration Table
Wi
Wi + 1
Wi + 2
Wi + 3
Wi + 4
Wi + 5
Wi + 6
Wi + 7
Wi + 8
Wi + 9
Wi + 10
Wi + 11
Wi + 12
Wi + 13
Wi + 14
F
Type of function
C B
Number of bits
8 7
Parity
Transmission speed (baud rate)
4
Type of exchange Number of the station
Physical address of the first word of the output bit zone
3
Number of output bits
Modbus ® address corresponding to the first bit
Physical address of the first word of the input bit zone
Number of input bits
Modbus ® address corresponding to the first bit
Physical address of the first output word
Number of output words
Modbus ® address corresponding to the first word
Physical address of the first input word
Number of input words
Modbus ® address corresponding to the first word
Stop bits
0
The first three words defined in the configuration table are coded in BCD (Binary
Coded Decimal).
All the others are binary values with 16 significant bits.
16
3 Programming the Module as a Slave
Configuring the Module (Cont’d.)
Configuration Parameters
Type of function
Defines the mode of operation of the channel. Only the configuration for Modbus ® protocol (master and slave) is defined in this manual.
Number of bits
Defines the format of the characters exchanged on the line.
Parity
Defines the parity.
2 = Modbus ® slave protocol
7 = ASCII transmission
8 = RTU transmission
0 = no parity
1 = odd parity
2 = even parity
Number of stop bits
Defines the number of stop bits that are used to delimit a character.
Important note :
1 = one stop bit
2 = two stop bits
The three parameters described above define the transmission format, which is determined by the functional possibilities of the TSX
SCM 22 module. Only the eight possibilities listed above can be used, to the exclusion of all others. The length of the data field (7 or 8 bits) implicitly defines the ASCII mode or the RTU (Remote Terminal Unit) mode.
ASCII mode RTU mode
(Remote Terminal Unit mode)
. 7 bits + even parity + 1 stop bit
. 7 bits + even parity + 2 stop bits
. 7 bits + odd parity + 1 stop bit
. 7 bits + even parity + 2 stop bits
. 8 bits + even parity + 1 stop bit
. 8 bits + odd parity + 1 stop bit
. 8 bits + 1 stop bit
. 8 bits + 2 stop bits
Transmission speed (baud)
The transmission speed is expressed in four figures coded in BCD, except for the speed of 19200 baud which is coded :
H’1920'.
The transmission speeds available for each channel are shown above. However, when both channels are used, the following limitations must be respected :
Channel 0 19200 9600 4800 2400
1200 600 300 150
Channel 1 19200 9600 4800 2400
1200 600 300 75
. A speed of 19200 baud on one channel limits the speed of the second channel to a maximum of 4800 baud,
. A speed of 9600 baud on one channel limits the speed of the second channel to a maximum of 9600 baud.
17
3 Programming the Module as a Slave
Configuring the Module (Cont’d.)
Type of exchange
Defines in which mode the data will be transferred for the following functions :
. H’05' : writing of an output bit,
. H’07' : writing of an output word.
0 = Message mode
1 = Register mode
Number of the station
This number, or "slave address", enables the module to recognize the messages that are addressed to it by the master. The address, expressed by three figures coded in BCD, can have a value of 1 to 247.
B’001' to B’247'
The address 0 corresponds to messages that are broadcast by the master to all the slaves.
Tables of correspondence
PLC addresses
Modbus ® addresses
Four tables of correspondence are defined for the following four types of accessible data objects :
. Output bits,
. Input bits,
. Output words,
. Input words.
Each table of correspondence is composed of three parameters, each of which is coded on a word. These parameters define :
. The physical address of the first data object in the memory of the PLC, which must be located in the internal word memory zone.
Example : The address W125 is represented by the binary value 125.
. The total number of data objects used,
. The Modbus ® address corresponding to the first data object. This address must correspond to the address transmitted on the line by the master to access the first address in the memory of the PLC (physical address).
18
3 Programming the Module as a Slave
3.2
Exchanges through the Message Interface
Description
The transfer of data between the slave module and the PLC memory is effected in the form of messages that are transmitted and received by means Text blocks.
At the start of the exchanges, the user program sends a request to the module by using a «Transmission/Reception» type Text block. This allows the slave module to receive the messages transmitted by the master.
The exchange cycle between the slave module and its processor proceeds in four steps as follows :
Step 1
On receipt of a Modbus ® message, the module checks and analyzes it and (if it is correct) interprets the function requested by the master. It then transfers to the user program, in the reception table of the Text block, the access code and the information to be processed by the processor.
Four access codes are possible :
. Read N words : Access code 01 (Modbus ® functions 03 and 04),
. Write N words : Access code 02 (Modbus ® functions 06 and 16),
. Read N bits : Access code 03 (Modbus ® functions 01 and 02),
. Write N bits : Access code 04 (Modbus ® functions 05 and 15).
These codes must be considered as read or write requests as seen from the master.
Step 2
The user program accepts the message and accesses the data requested by the slave module.
Step 3
The user program then transmits a Transmission/Reception type Text block with the following parameters :
. For a read request : the values requested by the master in the form of a
Modbus ® read request code (TXTi,C = H’80'),
. For a write request : the Modbus ® “end of writing” request code (TXTi,C = H’81') without any data.
Step 4
The slave module then processes the request received from its processor and transmits the reply to the master.
The Text block in the user program is then reset to the reception mode so that it can receive a new message from the master.
19
3 Programming the Module as a Slave
Exchanges through the Message Interface (Cont'd.)
Reading of N Words
Format of the reception and transmission tables :
Reception table
Access code = 1
Address of first word to be read
Number of words to be read
Transmission table
Value of the first word addressed
Address of first word to be read
Number of words to be read
Variables
Request code sent to the module : TXTi,C = H’80'
Length of the transmission table : TXTi,L = 2 x (number of words to be read).
Writing of N Words
Reception table
Access code = 2
Address of first word to be written
Number of words to be written
Value of the first word
Value of the second word
Value of the third word
Transmission table empty
Variables
Request code sent to the module : TXTi,C = H’81' (end of writing)
Length of the transmission table : TXTi,L = 0.
Reading of N Bits
Reception table
Access code = 3
Address of first word to be read
Number of words to be read
Transmission table
Value of the first word addressed
Value of the second word addressed
Etc.
Variables
Request code sent to the module : TXTi,C = H’80'
Length of the transmission table : TXTi,L = 2 x (number of words to be read).
20
3 Programming the Module as a Slave
Exchanges through the Message Interface (Cont’d.)
Writing of N Bits
Reception table
Access code = 4
Address of first word to be written
Number of words to be written
Mask of the first word = MSK1
Mask of the last word = MSK2
Value of the first word
Value of the second word
Etc.
Transmission table empty
Variables
Request code sent to the module : TXTi,C = H’81'
Length of the transmission table : TXTi,L = 0.
The bit string that the master wants to write is located in a series of words, the first of which (which contains the first bits) is defined by its address.
Before being written, the bit string must first be reset to zero, then a logical OR operation must be effected between the old and new tables.
Two masks MSK1 and MSK2 are defined at the beginning and end of the word table so as to delimit the zone of the bit string.
Wj Wj - 1 Wi + 1 Wi
Bit string to be written
MSK1 and MSK2 are used with a logical AND to reset the bit string to zero.
MSK1 = L ’ 0 0 0 0 ... 0 1 1 1 1 ' bits accessed in the first word (Wi),
MSK2 = L ’ 1 1 1 1 ... 1 0 ... 0 0 0 ' bits accessed in the last word (Wj).
21
3 Programming the Module as a Slave
Exchanges through the Message Interface (Cont’d.)
Examples
Reading of words W128 to W130
Reception table
Wi = 1
Wi + 1 = 128
Wi + 2 = 3
Transmission table
Wj = W128
Wj + 1 = W129
Wj + 2 = W130
Writing of word W100 to the value 125 and word W101 to the value -79
Reception table
Wi = 2
Wi + 1 = 100
Wi + 2 = 2
Wi + 3 = 125
Wi + 4 = -79
Reading of bits W110,A to W111,2
Reception table
Wi = 3
Wi + 1 = 110
Wi + 2 = 2
Transmission table
Wj = W110
Wj + 1 = W111
Writing of bits W150,B to W151,4 to L’11010 00101'
Reception table
Wi = 4
Wi + 1 = 150
Wi + 2 = 2
Wi + 3 = H’07FF’ = L’0000 0111 1111 1111'
Wi + 4 = H’FFE0' = L’1111 1111 1110 0000'
Wi + 5 = H’2800' = L’0010 1000 0000 0000'
Wi + 6 = H’001A’ = L’0000 0000 0001 1010'
User program processing
W150 AND Wi+3 —> W150 (resetting to zero of the accessed bits),
W151 AND Wi+4 —> W151 (resetting to zero of the accessed bits),
W150 OR
W151 OR
Wi+5 —> W150 (loading of the new values),
Wi+6 —> W151 (loading of the new values).
22
3 Programming the Module as a Slave
3.3
Request Codes Available
Write Configuration
Request code
Positive report
Negative report
TXTi,C = H’40'
TXTi,V = H’FE’
TXTi,V = H’FD’
This request permits the transmission of the configuration of the channel.
Read Configuration
Request code
Positive report
Negative report
TXTi,C = H’41'
TXTi,V = H’71'
TXTi,V = H’FD’
This request permits the reading of the configuration of the channel.
The Text block used must have a reception table length of at least 30 bytes in order to contain the configuration parameters.
Read Counters
Request code
Positive report
Negative report
TXTi,C = H’70'
TXTi,V = H’A0'
TXTi,V = H’FD’
Read Modbus ®
This request enables the processor to read the exchange monitoring counters.
The reception table contains the following seven words :
. Wi = number of messages received on the line,
. Wi+1 = number of messages received by the module with checksum error,
. Wi+2 = number of messages transmitted with an exception code,
. Wi+3 = number of messages received by the module,
. Wi+4 = number of messages transmitted to the processor without response,
. Wi+5 = number of events,
. Wi+6 = diagnostic register.
Request code
Positive report
Negative report
TXTi,C = H’80'
TXTi,V = H’B0'
TXTi,V = H’FD’
This request has two uses :
. If the channel is stopped, it allows the channel to be set to RUN and the module to be set to the waiting for reception mode (providing the RUN channel command is present).
The negative report appears if this request is sent when the RUN channel command is absent.
. If the channel is running, this request constitutes the reply to a request from the master to read N bits or N words.
End of Write Modbus ®
Request code
Positive report
TXTi,C = H’81'
TXTi,V = H’B0'
This is the reply to a request from the master to write N bits or N words.
23
3 Programming the Module as a Slave
3.4
Module Operating Modes
Status Chart
The status chart below represents the operation of channel 1 of the TSX SCM 22 module after it has been configured for Modbus ® slave protocol.
CPUF
Init
Channel OK
Channel not configured
Configuration OK
Channel configured
RUN command and Modbus ® read request
Channel running
Reception of a message
Analysis of the message
RUN command and Modbus ® read request
Channel running
Reception of a message
Analysis of the message
Reception of a message
Message
OK
Important : The Modbus ® messages cannot be processed until the "RUN channel 1" command (bit OWxy,1,9) and the "Read Modbus ® " request have been received. The RUN bit associated with the channel is then set to 1 (bit IWxy,1,9).
24
3 Programming the Module as a Slave
Module Operating Modes (Cont’d.)
Effect of a CPUF Failure Signal
In the presence of a CPU Failure signal (IWxy,1,7), the module no longer awaits messages from the processor.
All Modbus ® functions requiring a response or access to the processor are answered by the exception response code 04 (CPU failure).
When the CPUF signal disappears, the module immediately returns to normal operation. The module has no CPUF operating mode as such, and no acknowledgement of CPUF is required by the user program. The CPUF signal is simply copied into the input register IWxy,1.
Effect of a PWF Failure Signal
When a PWF signal occurs, the failure information is available (IWxy,1,F = 1), but the module has no PWF operating mode as such and no acknowledgement of
PWF is required by the user program. In general, any restart of the module after initialization, unplugging, or resetting to zero of the module’s memory will cause bit IWxy,1,F to be set to 1. But this condition does not cause a stoppage and no acknowledgement is required. However, the bit can be reset to zero by using
OWxy,1.F.
Timing Diagram
IWxy,0,3
IWxy,1,F
IWxy,0,9
OWxy,1,F
Restarting of the module
End of module self-tests
Set to 1 by program
25
4 Programming the Module as a Master
4.1
Configuring the Module
General
Each channel of the TSX SCM 22 module is configured separately by transferring a configuration table from the user program to the module by means of a Text function block.
Only channel 1 of the TSX SCM 22 module can be configured for Modbus ® master protocol. This channel can also be configured for other protocols or for the character string mode. Channel 0 is reserved for half-duplex operation in the character string mode.
All the information concerning the configuration of channel 1 for Modbus ® master protocol is transferred from the user program to the module by means of a Text function block containing the configuration table below. This table is composed of 4 words (8 bytes) which can be written in the internal word zone (Wi) or constant word zone (CWi) of the user memory.
Configuration Table
Wi
Wi + 1
Wi + 2
Wi + 3
F
Type of function
C B
Number of bits
8 7
Parity
Transmission speed (baud rate)
Time envelope
0 0 0
4 3
Stop bits
Reiteration
0
The first three words defined in the configuration table are coded in BCD (Binary
Coded Decimal).
Configuration Parameters
Type of function
Defines the mode of operation of the channel. Only the configuration for Modbus ® protocol (master/slave) is dealt with in this manual.
Number of bits
Defines the format of the characters exchanged on the line.
Parity
Defines the parity.
4 = Modbus ® master protocol
7 = ASCII transmission
8 = RTU transmission
0 = no parity
1 = odd parity
2 = even parity
Number of stop bits
Defines the number of stop bits that are used to delimit a character.
1 = one stop bit
2 = two stop bits
Important note : The three parameters described above define the transmission format, which is determined by the functional possibilities of the TSX
SCM 22 module.
26
4 Programming the Module as a Master
Configuring the Module (Cont’d.)
Only the eight possibilities listed above can be used, to the exclusion of all others.
The length of the data field (7 or 8 bits) implicitly defines the ASCII mode or the
RTU (Remote Terminal Unit) mode :
ASCII mode
. 7 bits + even parity + 1 stop bit
. 7 bits + even parity + 2 stop bits
. 7 bits + odd parity + 1 stop bit
. 7 bits + even parity + 2 stop bits
RTU mode
(Remote Terminal Unit mode)
. 8 bits + even parity + 1 stop bit
. 8 bits + odd parity + 1 stop bit
. 8 bits + 1 stop bit
. 8 bits + 2 stop bits
Transmission speed (baud)
The transmission speed is expressed in four figures coded in BCD, except for the speed of 19200 baud which is coded :
H’1920'. The transmission speeds available for each channel are shown above.
However, when both channels are used, the following limitations must be respected :
Channel 0 19200 9600 4800 2400
1200 600 300 150
Channel 1 19200 9600 4800 2400
1200 600 300 75
. A speed of 19200 baud on one channel limits the speed of the second channel to a maximum of 4800 baud,
. A speed of 9600 baud on one channel limits the speed of the second channel to a maximum of 9600 baud.
Time envelope
This is the time that the master allows to the slave to reply to a request. If the slave has not replied by the end of this time, the master considers the slave has not received the request. This time must always be more than the longest response time of all the various slaves connected to the line.
The time envelope is coded in BCD on one word and can be fixed between 20ms and 99.99s (i.e. 1 minute 40 seconds).
The values B’0000', B’0001' and B’0002' fix the response time at 20ms.
B’0000' to B’9999' increments of the time base (10 ms).
Number of reiterations
This parameter defines the number of times the master can reiterate a request to which the slave has not replied, or has replied with an error code. The request is reiterated after the time envelope defined above has elapsed. If the number of reiterations is fixed at zero, the master does not reiterate any of its requests.
B’0' to B’9'
27
4 Programming the Module as a Master
4.2
Exchanges through the Message Interface : Main Functions
Description
The transfer of data between the memory of the PLC and the master module is effected in the form of messages that are transmitted and received by means of
Text blocks. The requests sent to the master module are coded in the variable
TXTi,C of the Text block and have the same number as the Modbus ® function concerned.
The user program positions the parameters associated with each request in the transmission table of the Text block. These parameters include :
. The number of the slave,
. The Modbus ® address of the objects to be processed,
. The number of objects, etc.
After processing the reply from the slave, the master module completes the reception table of Text block with the data necessary for the interpretation of the request by the user program.
Only the main Modbus ® functions that permit the exchange of a Modbus ® object are described below.
Read N output bits - Read N input bits
Transmission table
Number of the slave
Modbus ® address of the 1st bit
Number of bits to be read
Reception table
Number of words read
Mask of the last word = MSK
Value of the 1st word
Value of the 2nd word
Etc.
Variables
Request code sent to the module : TXTi,C = H’01' (Output bits)
Length of the transmission table
H’02' (Input bits)
: TXTi,L = 6
The first bit of the string to be read by the master always corresponds to the least significant bit of the first word.
The mask of the last word permits the identification of the last significant bits of the string.
MSK = L ’ 1 1 1 1 ... 1 0 ... 0 0 0 ' bits accessed in the last word (Wj).
28
4 Programming the Module as a Master
Exchanges through the Message Interface : Main Functions (Cont’d.)
Read N output words - Read N input words
Transmission table Reception table
Number of the slave
Modbus ® address of the 1st word
Number of words to be read
Number of words read
Value of the 1st word
Value of the 2nd word
Etc.
Variables
Request code sent to the module : TXTi,C = H’03' (Output words)
H’04' (Input words)
Length of the transmission table : TXTi,L = 6
Write an output bit
Transmission table
Number of the slave
Modbus ® address of the output bit
Value to be written
Reception table empty
The value to be written is equal to :
. H’0000' to write the bit at zero,
. H’00FF’ to write the bit at one.
Request code sent to the module : TXTi,C = H’05'
Length of the transmission table : TXTi,L = 6
Write an output word
Transmission table
Number of the slave
Modbus ® address of the output word
Value to be written
Reception table empty
Variables
Request code sent to the module : TXTi,C = H’06'
Length of the transmission table : TXTi,L = 6
29
4 Programming the Module as a Master
Exchanges through the Message Interface : Main Functions (Cont’d.)
Write N output bits
Reception table
Number of the slave
Modbus ® address of the 1st bit
Mask of the first word = MSK1
Mask of the last word = MSK2
Value of the first word
Value of the second word
Etc.
Transmission table empty
The bit string that the master wants to write is located in a series of words. Two masks MSK1 and MSK2 are defined at the beginning and end of the word table so as to delimit the zone of the bits accessed.
Wj Wj - 1
Bit string to be written
Wi + 1 Wi
MSK1 = L ’ 0 0 0 0 ... 0 1 1 1 1 ' bits accessed in the first word (Wi),
MSK2 = L ’ 1 1 1 1 ... 1 0 ... 0 0 0 ' bits accessed in the last word (Wj).
MSK1 and MSK2 are used by the module to define the number of bits to be written and to position the bit string to be written on the first bit, defined by its Modbus ® address.
Request code sent by the couple : TXTi,C = H’0F’
Length of the transmission table : TXTi,L = 10 + 2 (number of words to be written)
30
4 Programming the Module as a Master
Exchanges through the Message Interface : Main Functions (Cont’d.)
Write N output bits
Reception table
Number of the slave
Modbus ® address of the 1st word
Number of words to be written
Value of the first word
Value of the second word
Etc.
Transmission table empty
Request code sent by the coupler : TXTi,C = H’10'
Length of the transmission table : TXTi,L = 6 + 2 (number of words to be written)
31
4 Programming the Module as a Master
Exchanges through the Message Interface : Main Functions (Cont’d.)
Examples
Reading of the input words with Modbus ® addresses 8100 and 8101 of slave 32.
Transmission table Reception table
Wi = 32
Wi+1 = 8100
Wi+2 = 2
Wj = 2
Wj+1 = slave object with Modbus ® address 8100
Wj+2 = slave object with Modbus ® address 8101
Writing of the output words with Modbus ® addresses 4105, 4106 and 4107 of slave 45 with the values 38, -342 and 2154 respectively.
Transmission table
Wi = 45
Wi+1 = 4105
Wi+2 = 3
Wi+3 = 38
Wi+4 = -342
Wi+5 = 2154
Reading of 18 output bits of slave 228, the first of which has the Modbus ® address
202.
Transmission table Reception table
Wi = 228
Wi+1 = 202
Wi+2 = 18
Wj = 2
Wj+1 = H’FFFC’
Wj+2 = slave bits with Modbus ® addresses 202 to 217
Wj+3 = slave bits with Modbus ® addresses 218 to 233
Writing of 12 output bits of slave 191, the first of which has the Modbus ® address
118.
For the purposes of this example, it is assumed that the 12 bits to be written are bits W50,E to W51,9 of the processor in the master.
Transmission table
Wi = 191
Wi+1 = 118
Wi+2 = 2
Wi+3 = H’3FFF’ = L’0011111111111111'
Wi+4 = H’FC00' = L’1111110000000000'
Wi+5 = W50
Wi+6 = W51
32
4 Programming the Module as a Master
4.3
Exchanges through the Message Interface : Complementary Functions
Read status register
Transmission table
Number of the slave
Reception table
Status register of the slave
Request code sent to the module : TXTi,C = H’07'
Length of the transmission table : TXTi,L = 2
Echo check
Transmission table
Number of the slave
Diagnostic code = 0
Data
Reception table empty
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 6
Restart communication
Transmission table
Number of the slave
Diagnostic code = 1
Data
Reception table empty
The data can take any of the following two values :
. H’00FF’ : continue if there is an error.
In this case, the trace buffer which records the connection events will be erased.
. H’0000' : stop if there is an error.
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 6
33
4 Programming the Module as a Master
Exchanges through the Message Interface : Complementary Functions
(Cont’d)
Read diagnostic register
Transmission table
Number of the slave
Diagnostic code = 2
Reception table
Diagnostic register of the slave
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 4
Force to listen only mode (LOM)
Transmission table
Number of the slave
Diagnostic code = 4
Reception table empty
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 4
Reset counters
Transmission table
Number of the slave
Diagnostic code = 10
Reception table empty
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 4
Read line message counter
Transmission table
Number of the slave
Diagnostic code = 11
Reception table
Number of messages received
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 4
34
4 Programming the Module as a Master
Exchanges through the Message Interface : Complementary Functions
(Cont’d)
Read checksum error counter
Transmission table
Number of the slave
Diagnostic code = 12
Reception table
Number of checksum errors
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 4
Read exception error counter
Transmission table
Number of the slave
Diagnostic code = 13
Reception table
Number of exception responses
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 4
Read slave’s message counter
Transmission table
Number of the slave
Diagnostic code = 14
Reception table
Number of messages sent to the slave
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 4
Read slave’s no reply counter
Transmission table
Number of the slave
Diagnostic code = 15
Reception table
Number of no replies from CPU
Request code sent to the module : TXTi,C = H’08'
Length of the transmission table : TXTi,L = 4
35
4 Programming the Module as a Master
Exchanges through
the Message Interface : Complementary Functions
(Cont’d)
Read event counter
Transmission table
Number of the slave
Request code sent to the module : TXTi,C = H’0B’
Length of the transmission table : TXTi,L = 2
Reception table
Status word
Event counter
Read event log
Transmission table
Number of the slave
Reception table
Status word
Event counter
Line message counter
Number of bytes in the trace buffer
1st & 2nd bytes of the trace buffer
3rd & 4th bytes of the trace buffer
Etc.
Request code sent to the module : TXTi,C = H’0C’
Length of the transmission table : TXTi,L = 2
Read slave identification
Transmission table
Number of the slave
Reception table
Slave identifier
Operating status
Number of bytes that follow
1st & 2nd bytes
3rd & 4th bytes
Etc.
Request code sent to the module : TXTi,C = H’11'
Length of the transmission table : TXTi,L = 2
36
4 Programming the Module as a Master
4.4
Request Codes Available
Write Configuration
Request code
Positive report
TXTi,C = H’40'
TXTi,V = H’FE’
Negative report TXTi,V = H’FD’
This request permits the transmission of the configuration to the module.
A negative report is returned when :
. The channel is not stopped, or
. The parameters of the request are incorrect.
Read Configuration
Request code
Positive report
TXTi,C = H’41'
TXTi,V = H’71'
Negative report TXTi,V = H’FD’
This request permits the reading of the configuration of the channel.
A negative report is returned if the channel is not configured.
Read Counters
Request code
Positive report
Negative report
TXTi,C = H’70'
TXTi,V = H’A0'
TXTi,V = H’FD’
This request enables the processor to read the exchange monitoring counters.
The reception table contains the following 12 words :
. Wi = number of processor requests accepted by the module,
. Wi+1 = number of processor requests refused by the module,
. Wi+2 = number of slave replies correctly received,
. Wi+3 = number of slave replies received with an exception code,
. Wi+4 = number of master messages sent without replies (time envelope elapsed),
. Wi+5 = number of slave replies received with checksum error,
. Wi+6 = number of slave replies received that are incoherent,
. Wi+7 = number of master messages reiterated,
. Wi+8 = number of reiteration procedures abandoned,
. Wi+9 = number of time envelopes elapsed during reception,
. Wi+10 = number of slave replies received with a reception fault,
. Wi+11 = diagnostic register.
Transparent Modbus ®
Request code
Positive report
TXTi,C = H’81'
TXTi,V = H’FE’
Negative report TXTi,V = H’17'
This request enables the processor to generate a request that is different from the
Modbus ® requests generated by the module.
The user program prepares the message to be transmitted in a Text block, the first byte of which is the number of the destination slave. The module then checks the number of the slave. If it is not correct, the module returns a negative report. If it is correct, the module calculates the redundancy code and transmits the complete message.
If the number of the slave is null (i.e. general broadcast), the module transmits the message and sends a positive report to the processor without waiting for a reply.
37
4 Programming the Module as a Master
Request Codes available (Cont’d.)
Modbus ® functions
Request codes
Positive reports
TXTi,C = number of the Modbus ® function
TXTi,V = H’FE’
TXTi,V = H’19' (request addressed to a slave that is in the Listen Only Mode)
Negative reports can arise from two sources :
. From the master module, if it has detected an error in the processor request or if it has not received a reply from the slave.
. From the slave module, if it has detected an error in the request received from the master or if it cannot process the request received from the master.
In this case, the slave returns an exception response comprising :
. The address of the slave,
. The function code received by the slave, to which it adds the value H’80',
. The exception code indicating the type of error,
. The exchange monitoring code.
The master module then transmits to its processor the exception code received from the slave as the negative report to the request, as shown below.
Negative report (TXTi,V)
H’01' (exception response)
H’02' (exception response)
H’03' (exception response)
H’04' (exception response)
H’05' (exception response)
H’06' (exception response)
H’07' (exception response)
H’15'
H’17'
H’18'
H’FD’
Significance
Function number not defined in the slave
Modbus ® address unknown to the slave
Illegal value for the Modbus ® address indicated
Slave processor failed
Acknowledged: the slave processor has accepted and is processing the request from the master
Slave processor busy
Negative acknowledgement
No correct reply from the slave after reiterations
Incorrect request parameters
Channel stopped
Unknown Modbus ® function
38
4 Programming the Module as a Master
4.5
Module Operating Modes
Status Chart
The status chart below represents the operation of channel 1 of the TSX SCM 22 module after it has been configured for Modbus ® master protocol.
STOP command
Init
Channel OK
Channel not configured
Configuration OK
Channel configured
RUN command and Modbus ® read request
Channel running, exchange with slave
End of Modbus ® exchange
Channel running, awaiting request
Modbus ® request
STOP command
The channel starts running on receiving the first Modbus ® request accompanied by the “RUN Channel 1” request (bit OWxy,1,9).
The RUN bit associated with the channel is then set to 1 (bit IWxy,1,9).
The channel can be stopped at any time by setting bit OWxy,1,9 to zero.
Effect of a CPUF signal
The CPU failure signal (IWxy,1,7) has no effect on the master module.
Effect of a PWF signal
For the effect of this signal and the timing diagram, see Section 3.4.
39
5 I/O Bits and Words
5.1
Definition of discrete I/O Bits
Discrete Interface
The discrete interface of the TSX SCM 22 module enables the user program to control the transmission and reception on each channel of the module. This interface comprises :
. 8 input bits : Ixy,0 to Ixy,7
These bits reflect the states of the input signals of the line adaptors.
. 8 output bits : Oxy,0 to Oxy,7
These bits set the output signals of the line adaptors to 0 or 1.
The input bits and output bits numbered 0 to 3 are assigned to the line adaptor of channel 0, and the bits numbered 4 to 7 are assigned to the line adaptor of channel 1.
Each of these I/O bits has a specific definition according to the type of line adaptor that is used. Certain of these bits are not simply recopied by the module, but also act directly on the operation of the channel. The assignment of these I/O bits and their affect on the operation of the channel are described below for each type of adaptor.
A logic state of 0 (zero) indicates an active signal.
A logic state of 1 (one) indicates an inactive signal.
Type 1 Adaptor : RS 232 C - 6 signals
7/3 6/2 5/1 4/0
. Output bit
DTR = Data terminal ready
DTR
This output signal does not act directly on the operation of the line, but is used to control the modem (or peripheral) connected to the adaptor. The request to transmit is controlled by the Modbus ® protocol software in the module and is totally transparent to the user.
F/8 E/A D/9 C/8
. Input bits
CTS = Clear to send
CD CTS
: A logic state 1 (inactive signal) on this input blocks the transmission circuit.
CD = Carrier detection : A logic state 1 (inactive signal) on this input blocks the reception circuit.
When these signals are not wired, the resistors in the adaptor impose a logic state of zero, the signals are therefore active.
40
5 I/O Bits and Words
Definition of discrete I/O Bits (Cont’d.)
Type 2 Adaptor : Current Loop
7/3 6/2
. Output bit
PSR = Phase of signal reception 0 = multipoint mode,
1 = point-to-point mode.
5/1 4/0
PSR
The state of this bit inverses the logic of the reception circuit of the current loop.
It must be set by the user program to 0 if the multipoint mode is used, or to 1 if the point-to-point mode is used.
. Input bit
F/8 E/A D/9 C/8
PSR
This bit is the image of the PSR output bit, and therefore allows the user to read the state of the output bit.
Type 3 Adaptor : RS323 - Modem
7/3 6/2 5/1 4/0
. Output bits DSRS DTR
DTR = Data terminal ready
This signal, which is used to control the mode, has no effect on the operation of the channel. The request to send is controlled by the the Modbus ® protocol and is therefore transparent to the user.
DSRS = Data signal rate selection 0 = the channel operates at the configured speed,
1 = the channel operates at the configured speed divided by 2.
If the type of modem used offers this possibility, this signal can be used to operate at reduced speed when repeated errors of transmission are detected.
F/8 E/A D/9 C/8
. Input bits RI CD DSR CTS
CTS = Clear to send
DSR = Data set ready
CD = Carrier detection
RI = Ring indicator
Note :
1 = transmission circuit disabled,
No effect on channel operation,
1 = reception circuit disabled,
No effect on channel operation.
When these signals are not used, they are set to 1 by the adaptor; the transmission and reception circuits are therefore disabled.
41
5 I/O Bits and Words
Definition of discrete I/O Bits (Cont’d.)
Type 4 Adaptor : RS 232 A / RS 485
This adaptor does not have any transmission monitoring signals. In the RS-485 mode, the transmitter validation bit that switches the transmitter from or to the high-impedance state is controlled by the Modbus ® protocol and is transparent to the user.
Type 5 Adaptor : RS 232 C Simplified
This adaptor does not have any transmission monitoring signals, but only the transmission and reception lines. In this case, the discrete I/O bits therefore have no significance.
42
5 I/O Bits and Words
5.2
Definition of Register Words
Description
The register interface of the TSX SCM 22 module comprises :
. 8 input registers IWxy,0 to IWxy,7
These words define the operation of the module and of each of its channels.
. 8 output registers OWxy,0 to OWxy,7
These words are used to acknowledge or reset the messages exchanged on each channel.
Input Register IWxy,0
This word contains information concerning the general operation of the module.
The bits are significant when they are at state 1.
BIT
0
1
2
3
FUNCTION
Not assigned
Not assigned
Resetting in progress
Module available
DESCRIPTION
4
5
6
7
8
9
General fault
Blocking fault
Module fault
Application fault
Blocking fault
Resetting to zero by the system of the message in progress on both channels.
Indicates the end of the self-tests and consequently that the module is available.
This bit is set to 1 for any type of fault. It performs the logical OR of bits
5, 6, 7 and 8 of this register.
Fault in the RAM memory extension module.
Fault during the self-tests of the serial data links of the module. These tests are run on each power up.
Fault during the execution of a request on one of the channels (error of parity in reception, absence of echo, echo incorrect, etc.).
Blocking fault in the RAM, EPROM or internal logic of the module. The module must be replaced. This fault is indicated by the Fault light on the front of the module.
This bit indicates that the module self-tests are in progress. The module cannot be programmed while these tests are running.
E
F
C
D
A
B
Module self-tests in progress
Not assigned
Module not configured
Module running
Reserved
Not assigned
Not assigned
1 = neither of the channels has been configured,
0 = one channel has been configured
A request is being executed on one or other of the two channels
43
5 I/O Bits and Words
Definition of Register Words (Cont'd.)
Input Register IWxy,1
This word contains information concerning the operating status of each of the channels of the module. The information concerning channel 1 is valid for
Modbus ® operation only. (Only channel 1 can be used for Modbus ® ).
2
3
4
5
6
BIT
0
1
7
FUNCTION
Not assigned
RUN/STOP of channel 0
Transmission/reception of channel 0
Configuration of channel 0
Channel 0 adaptor code
CPUF
DESCRIPTION
0 = Channel 0 stopped (waiting for a request),
1 = Channel 0 running (executing a request).
This bit is significant if the channel is running :
0 = Channel 0 in reception mode,
1 = Channel 0 in transmission mode.
0 = Channel 0 not configured,
1 = Channel 0 configured (for character string).
The type of adaptor fitted on the channel is coded on these three bits as follows :
001 = Type 1 adaptor (RS 232 C - 6 signals),
010 = Type 2 adaptor (current loop),
101 = Type 3 adaptor (RS 232 - modem),
011 = Type 4 adaptor (RS 422/RS485),
000 = Type 5 adaptor (RS 232 - simplified),
111 = No adaptor.
This bit is common to both channels :
1 = The module cannot transfer data to the PLC because of a
CPU failure, or PLC stopped.
8
9
A
B
C
D
E
F
Not assigned
RUN/STOP of channel 1
Channel 1 in listen only mode
Configuration of channel 1
Channel 1 adaptor code
PWF
0 = Channel 1 stopped (waiting for a request),
1 = Channel 1 running (Modbus ® protocol).
0 = Channel 1 in slave recption/transmission mode,
1 = Channel 1 in slave listen only mode
0 = Channel 1 is not configured,
1 = Channel 1 configured.
The type of adaptor fitted on the channel is coded on these three bits as follows :
001 = Type 1 adaptor (RS 232C - 6 signals),
010 = Type 2 adaptor (current loop),
101 = Type 3 adaptor (RS 232 - modem),
011 = Type 4 adaptor (RS 422/RS485),
000 = Type 5 adaptor (RS 232 - simplified),
111 = No adaptor.
This bit is common to both channels :
1 = A power break/return has occurred. (For information only, no acknowledgement is required, but the bit stays at 1 until reset by program).
Input registers IWxy,2 to 4
These registers are not used with Modbus ® protocol on channel 1.
Input registers IWxy,5 to 7
These registers are used by the Modbus ® slave protocol when the processor/ module exchanges are made through the register interface (see Appendix).
44
5 I/O Bits and Words
Definition of Register Words (Cont’d.)
Output Register OWxy,0
The bit OWxy,0,2 of this word is used to reset the message system of the module to zero (both channels).
Output Register OWxy,1
This word contains the RUN/STOP control bits for both channels :
7
8
5
6
2
3
4
9
C
D
E
A
B
F
BIT
0
1
FUNCTION
Not assigned
Reset exchange on channel 0
Not assigned
Not assigned
Not assigned
Not assigned
Not assigned
Not assigned
Not assigned
RUN/STOP of channel 1
Not assigned
Not assigned
Not assigned
Not assigned
Not assigned
PWF
DESCRIPTION
Stops and cancels the ongoing request. The request data is lost.
Must be followed by a reset of the Text block.
0 = STOP channel 1,
1 = RUN channel 1.
Permits the resetting to zero of IWxy,1,F after a power cut. This bit is common to both channels.
Output registers OWxy,2 to 4
Not used with Modbus ® protocol on channel 1.
Output registers OWxy,5 to 7
These registers are used by the Modbus ® slave protocol when the processor/ module exchanges are made through the register interface (see Appendix).
45
6 Additional Programming Information
6.1
Fault Bits
General
Faults are indicated by 48 fault bits which can be read in the message mode by the standard request (common to all intelligent modules) : «Read fault bits».
The fault bits are then received in the reception table of the Text block :
. Request code TXTi,C = H’47'
. Variable TXTi,L = 0
. Transmission table
. Reception table
Not used
At least 6 bytes
State of the variables at the end of the exchange :
. Number of bytes received TXTi,S = 6
. Report TXTi,V = H’77'
Organization of the Table
First word
BLOCKING FAULTS
0 : Checksum fault
1 : RAM memory fault
2 : Logic circuit fault
3 : Reserved
4 : Reserved
5 : Reserved
6 : Reserved
7 : Reserved
BLOCKING FAULTS
8 : Not significant
9 : Not significant
A : Not significant
B : Not significant
C : Not significant
D : Not significant
E : Not significant
F : Not significant
Second word
MODULE FAULTS ON CHANNEL 0
0 : T/R feedback loop fault
1 : Not significant
2 : Not significant
3 : Not significant
4 : Not significant
5 : Not significant
6 : Not significant
7 : Not significant
MODULE FAULTS ON CHANNEL 1
8 : T/R feedback loop fault
9 : DTR/DSR feedback loop fault
A : RTS/CTS feedback loop fault
B : Not significant
C : Not significant
D : Not significant
E : Not significant
F : Not significant
Third word
APPLICATION FAULTS ON CHANNEL 0
0 : Echo incorrect after 3 tries
1 : Echo absent after 3 tries
2 : Time envelope elapsed after a READ request
3 : Time envelope elapsed after a WRITE request
4 : Time envelope elapsed after a WRITE/READ request
5 : Reception parity fault
6 : Not significant
7 : PWF without init. during exchange
APPLICATION FAULTS ON CHANNEL 1
8 : Receiver overflow fault
9 : Not significant
A : Not significant
B : Not significant
C : Not significant
D : Reception parity fault
E : Reception format fault
F : Not significant
46
7 Programming Examples
7.1
Programming a Slave in TSX 47-30 or TSX 67/87
Description
In this example, a slave TSX 87 equipped with a
TSX SCM 22 module is linked to a master using
Modbus protocol. The station number of the slave is 4.
The program described below ensures the configuration of the module and the processing of the Modbus slave protocol.
TSX TSX
TSX
For a given application, 4 zones of bits and words (i.e. the accessible Modbus objects) must be defined in the slave. In this example, the fifty words from W50 onwards are used for this purpose and are defined as follows :
W50 to W59
W60 to W79
W80 to W95
W96 to W99 table of 160 input bits, table of 20 input words, table of 256 output bits, table of 4 output words.
The start of each table corresponds to a Modbus master address (values defined for a given master) :
Input bits
Input words
Output bits
Output words
W50 has the corresponding Modbus address 200,
W60 has the corresponding Modbus
address 4200,
W80 has the corresponding Modbus address 1200,
W96 has the corresponding Modbus
address 5200.
Note : The user must of course also define the corresponding physical objects
(discrete I/O, etc.) as required, and write the application program linking these physical objects to the accessible Modbus
objects.
47
7 Programming Examples
Programming a Slave in TSX 47-30 or TSX 67/87 (Cont’d.)
Organization
The main program organizes the transfer of the configuration of both channels and then authorizes the processing of the Modbus slave protocol on channel 1.
Start
Configuration request
Initialization of module
NO
Authorization of Modbus
protocol
YES
Initialization of the module
End
Transfer of the configuration
Program Listing
Initialization and STOP of TSX SCM 22 module
Configuration request
Modbus
slave protocol processing
Configuration of the Text Blocks
48
7 Programming Examples
Programming a Slave in TSX 47-30 or TSX 67/87 (Cont’d.)
Definition of the Objects
TXT1 : configuration and transfer of Modbus
messages on channel 1,
B0 : configuration request and authorization of Modbus protocol,
B1 : transmission of the configuration,
B2 : validation of the transmission request.
Constants
Definition of the constant words containing the configuration parameters of channel 1 of the module :
Channel 1 (Modbus
protocol in RTU mode) CW0 to CW14
Subroutine 0
Control of the operating modes of the module and transmission of the configuration of channel 1 on each power break/return.
Transmission of the configuration of channel 1
Configuration check
49
7 Programming Examples
Programming a Slave in TSX 47-30 or TSX 67/87 (Cont’d.)
Subroutine 1
This subroutine converts the Modbus
function codes into module access codes.
These codes are contained in the first word of the reception table of Text block
TXT1, as follows :
. Read N words,
. Write N words,
. Read N bits,
. Write N bits.
Each code is processed as shown in the following listings. At the end of the processing, the processor replies to the slave module which then sends the reply to the master.
Processing of access codes
NO
Start
Processing of Modbus
data
Reading of
N words
NO
Writing of
N words
NO
Reading of
N bits
NO
Writing of
N bits
NO
End
YES
YES
YES
YES
L10
L20
L10
L30
Listing
Request reading of N words
Request writing of N words
Request reading of N bits
Request writing of N bits
50
7 Programming Examples
Programming a Slave in TSX 47-30 or TSX 67/87 (Cont’d.)
Subroutine 1 (Cont’d)
Reading of N words or N bits
Access code = 1 or 3
Address of 1st word to be read
Number of words to be read
Reading of N words or N bits
Transfer of N words or bits to transmission table
End of processing
Writing of N words
Access code = 2
Address of 1st word to be written
Number of words to be written
Value of the 1st word
Value of the 2nd word
Value of the 3rd word
Etc.
Writing of N bits
Access code = 4
Address of 1st word to be written
Number of words to be written
Mask of the 1st word = MSK1
Mask of the 2nd word = MSK2
Value of the 1st word
Value of the 2nd word
Etc.
Writing of N words
Transfer of N words to table of accessible objects
End of processing
Writing of N bits
Reset with MSK1 and writing of bits of 1st word
Writing of "intermediate" words
Reset with MSK2 and writing of bits of last word
End of processing
51
7 Programming Examples
7.2
Programming a Slave in TSX 47-20
Description
In this example, a slave TSX 47-20 equipped with a TSX SCM 22 module is linked to a master using Modbus protocol. The application is the same as for the TSX 87, but in this case the slave
TSX 47-20 is station number 1 and the program is written in Ladder as shown in the listings below.
TSX TSX
TSX
Definition of the Objects
TXT0
TXT1
B0
: configuration of channel 1,
: transfer of Modbus
messages on channel 1,
: authorization of Modbus protocol.
Configuration
CW0
CW1
CW2
CW3
CW4
CW5
CW6
= H’2802' : Modbus
,RTU mode, no parity, 2 stop bits
= H’9600' : speed 9600 baud
= 1
= 60
= 240
= 0
= 75
: slave station number 1
: output bit zone
: 240 bits from W60 to W74
: Modbus
address of the 1st output bit : 0
: input bit zone
CW7
CW8
CW9
= 240
= 0
= 90
CW10 = 15
CW11 = 0
CW12 = 105
CW13 = 15
CW14 = 0
: 240 bits from W75 to W89
: Modbus
: Modbus
address of the 1st input bit : 0
: output word zone
: 15 words from W90 to W104
address of the 1st output word : 0
: input word zone
: 15 words from W105 to W119
: Modbus address of the 1st input word : 0
52
7 Programming Examples
Programming a Slave in TSX 47-20 (Cont’d.)
Program Listing
LABEL : 1 "CONFIG CH1"
!SY1 t 0 IW2,1, OW2,1,9
! +========+ B
+-] [--+------+-+ R D +--+--------] [--+------+------+------+---( )----
! ! ! !
! !CW0 ! !
!SY1 IW2,1, !<-->CPL ! !OW2,1,
! B ! ! !9 +=======================+
+-]/[--+-]/[--+-+ S^ E +--+ +-] [--+------+-+H'0080' -> TXT1,C +-
! ! ! ! ! +=======================+
! ! ! LOCAL ! !
! ! ! M=H0201! !
! ! ! ! ! +=======================+
+ +-+ O ! +------+-+0 -> W50 +-
! ! ! ! +=======================+
! ! ! O=H0040!
! ! !LG=30 !
! ! ! !
+ +-+ I !
! +========+
LABEL : 2 "MODBUS TR/REC"
!OW2,1, t 1 4
!9 +========+ +========+
+-] [--+------+------+------+-+ R D +--+------+-+W10 = 1+--+---( J )----
! ! ! ! +========+ !
! !W10[30] ! ! !
!OW2,1, B0 !<-->CPL ! ! !
!9 ! ! ! +========+ !
+-] [--+-] [--+------+------+-+ S^ E +--+ +-+W10 = 3+--+
! ! ! ! ! +========+
! ! ! LOCAL ! !
! ! ! M=H0201! ! 6
! ! ! ! ! +========+
+ +-+ O ! +-+W10 = 2+--+---( J )----
! ! ! ! ! +========+
! ! ! O=H0080! !
! ! !LG=2 ! ! 8
! ! ! ! ! +========+
+ +-+ I ! +-+W10 = 4+--+---( J )----
! +========+ +========+
LABEL : 3 "END"
! 13 !
! !
+------+------+------+------+------+------+------+------+------+---( J )----+
! !
! !
LABEL : 4 "SR0 READ WORDS"
! !
! +========+ +=======================+ !
+-+W12 > 0+--+------+------+------+------+------+-+W0(W11) -> W25(W50) +-+
! +========+ ! +=======================+ !
! ! !
! ! !
! ! !
! ! +=======================+ !
+ +-+W11 + 1 -> W11 +-+
! ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+W12 - 1 -> W12 +-+
! ! +=======================+ !
! !
! !
! +=======================+ !
+------+------+------+------+------+------+------+-+W50 + 1 -> W50 +-+
! +=======================+ !
! !
53
7 Programming Examples
Programming a Slave in TSX 47-20 (Cont’d.)
LABEL : 5 ""
! !
! +========+ +=======================+ !
+-+W12 = 0+--+------+------+------+------+------+-+W50 * 2 -> TXT1,L +-+
! +========+ ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ ! +H'0080' -> TXT1,C +-+
! ! +=======================+ !
! ! !
! ! 13 !
! ! !
+ +------+------+---( J )----+
! !
! !
! 4 !
! !
+------+------+------+------+------+------+------+------+------+---( J )----+
! !
LABEL : 6 "SR1 WRITE WORDS"
! +========+ +=======================+ !
+-+W12 > 0+--+------+------+------+------+------+-+W13(W50) -> W0(W11) +-+
! +========+ ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ !+-W11 + 1 -> W11 +-+
! ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ !+-W50 + 1 -> W50 +-+
! ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ !+-W12 - 1 -> W12 +-+
! ! +=======================+ !
LABEL : 7 ""
! !
! +========+ +=======================+ !
+-+W12 = 0+--+------+------+------+------+------+-+H'0081' -> TXT1,C +-+
! +========+ ! +=======================+ !
! ! !
! ! 13 !
! ! !
+ +------+------+---( J )----+
! !
! !
! 6 !
! !
+------+------+------+------+------+------+------+------+------+---( J )----+
! !
LABEL : 8 "SR2 WRITE BITS"
! +========+ +=======================+ !
+------+------+-+W12 <> 0+--+------+------+------+-+W0(W11) ->W53 +-+
! +========+ ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ !+-W53 AND W13 -> W53 +-+
! ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ !+-W53 OR W15 -> W0(W11) +-+
! ! +=======================+ !
! ! !
54
7 Programming Examples
Programming a Slave in TSX 47-20 (Cont’d.)
LABEL : 9 "MASK 1"
! !
! +========+ +=======================+ !
+------+------+-+W12 <> 0+--+------+------+------+-+W11[2] -> W51[2] +-+
! +========+ ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+W11 + 1 -> W11 +-+
! ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+W12 - 1 -> W12 +-+
! +=======================+ !
LABEL : 10 "INTER.WORDS"
! !
! +========+ +=======================+ !
+-+W12 > 1+--+------+------+------+------+------+-+W16(W0) -> W0(W11) +-+
! +========+ ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+W12 - 1 -> W12 +-+
! ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+W50 + 1 -> W50 +-+
! ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+W11 + 1 -> W11 +-+
! +=======================+ !
LABEL : 101 ""
! 10 !
! +========+ !
+-+W12 > 1+--+------+------+------+------+------+------+------+---( J )----+
! +========+ !
! !
LABEL : 11 "MASK 2"
! !
! +========+ +=======================+ !
+-+W12 > 0+--+------+------+------+------+------+-+W0(W11) -> W53 +-+
! +========+ ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+W53 AND W14 -> W53 +-+
! ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+W16(W50) -> W54 +-+
! ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+W53 OR W54 -> W0(W11) +-+
! +=======================+ !
LABEL : 12 ""
! !
! +========+ +=======================+ !
+-+W12 > 0+--+------+------+------+------+------+-+0 -> W12 +-+
! +========+ ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+H'0081 -> TXT1,C +-+
! +=======================+ !
! !
LABEL : 13 "BR END"
!TXT1,D !
! +========+ +=======================+ !
+-] [--+-+W12 > 0+--+------+------+------+------+-+0 -> W10 +-+
! +========+ ! +=======================+ !
! ! !
! ! !
! ! +=======================+ !
+ +-+0 -> W50 +-+
! ! +=======================+ !
! ! !
! ! B0 !
! ! !
+ +------+------+---( )----+
!
!
55
7 Programming Examples
7.3
Programming a Master in TSX 47-30 or TSX 67/87
Description
TSX
In this example, a master TSX 87 equipped with a
TSX SCM 22 module is connected on a Modbus line to two slave stations numbered 1 and 2.
SLAVE 1 SLAVE 2
The application described in this example consists, for the master, in controlling and monitoring a piece/part program executed by two slaves.
The program in the master includes :
. The initialization of the two slaves, including the definition of the following information :
- The type of part,
- The number of parts to be made,
- The parameters necessary for the processing of each slave,
. The transmission of the start command to slave 1, and the monitoring of its end of cycle,
. The transmission of the start command to slave 2, and the monitoring of its end of cycle.
The programs in the 2 slaves must include :
. The processing of the Modbus
protocol,
. The detection of the start command from the master,
. The application program necessary to manufacture the part.
Only the master program is described in this example.
56
7 Programming Examples
Programming a Master in TSX 47-30 or TSX 67/87 (Cont’d.)
Organization
The flowchart below describes the sequence of tests and actions of the master program.
Start
Initialization of module
NO
YES
Manufacturing in progress
YES
NO
Slave interrogation
1
NO
Part finished
YES
Start slave 2
2
Slave
NO
Part finished
YES
Number of parts attained
NO
YES
Start slave 1
Manufacturing ended
Manufacturing command
YES
NO
Initialization of slave 1
Transfer of the configuration
Initialization of slave 2
Configuration request
Start slave 1
Manufacturing in progress
End
57
7 Programming Examples
Programming a Master in TSX 47-30 or TSX 67/87 (Cont’d.)
Modbus
objects
Correspondence between the Modbus
addresses and the objects accessed by the 2 slaves :
Objects Modbus
address Designation
Input bits
Output bits
Input words
Output words
200
400
1300
1500
Not used
Start slave
Report slave activity
(H’FF’ = activity ended)
Piece/part program parameters
Definition of TSX 87 objects
B9
B10
B11
B12
B13
B14
B15
B5
B6
B7
B8
B1
B2
B3
B4
TXT0
TXT1
C0
T0
T1
W50
B0
: Configuration of channel 1
: Modbus
exchanges on channel 1
: Downcounting of the number of parts still to be manufactured
: Timer monitoring the period of interrogation of slave 1
: Timer monitoring the period of interrogation of slave 2
: Number of the slave whose manufacturing cycle is in progress
: Module configuration request
: Transmission of the configuration of channel 1
: Manufacturing in progress
: Manufacturing command
: Transmission of parameters to slave 1
: Transmission of parameters to slave 2
: Start slave 1
: End of the “start manufacturing” sequence
: Interrogation of slave 1
: Test of slave 1 for “part finished”
: Part manufacturing by slave 2
: Interrogation of slave 2
: Test of slave 2 for “part finished”
: Part manufacturing by slave 1
: Validation of the interrogation of slave 1
: Validation of the interrogation of slave 2
Constants
Configuration of channel 1 :
CW0 = H’4801' Modbus
master, RTU mode, no parity, 1 stop bit
CW1 = H’9600' Speed : 9600 baud
CW2
CW3
= H’0040' Time envelope : 400 ms
= H’0003' 3 reiterations
Definition of the piece/part program :
CW4
CW5
= 5
= 10
Type of part
Number of parts
CW6 to 8
CW9 to 10
Specific parameters for slave 1
Specific parameters for slave 2
Monitoring period of the slaves :
CW11
CW12
= 5
= 10
Period of slave 1 (5 seconds)
Period of slave 2 (10 seconds)
Configuration of Text blocks
TXTi NETWORK
0
1
LOCAL
LOCAL
LOCAL
TYPE
CPL
CPL
ADDR
MODE
DIR
DIR
ADDR
W200
RECEPT
BUFFER LENGTH
CW0 0
100
58
7 Programming Examples
Programming a Master in TSX 47-30 or TSX 67/87 (Cont’d.)
Program listing
INITIALIZATION AND STOP OF THE MODULE
CONFIGURATION OF THE MODULE
APPLICATION AT REST : NO MANUFACTURING AND NO COMMAND
START OF AN APPLICATION : MANUFACTURING COMMAND
PERIODIC MONITORING OF SLAVE 1
PERIODIC MONITORING OF SLAVE 2
Subroutine 0
Configuration of the module on each power return :
TRANSMISSION OF THE CONFIGURATION TO CHANNEL 1
CONFIGURATION CHECK
59
7 Programming Examples
Programming a Master in TSX 47-30 or TSX 67/87 (Cont’d.)
Subroutine 1
Initialization of the application by transmission of the piece/part parameters to both slaves, and then starting of slave 1.
Writing of N bits
Number of the slave
Modbus
address of the 1st word
Number of words
Value of the first word
Etc.
TRANSMISSION OF PART PARAMETERS TO SLAVE 1
TRANSMISSION OF PART PARAMETERS TO SLAVE 2
Writing of a bit
Number of the slave
Modbus
address of the bit
Value of the bit
START SLAVE 1
MANUFACTURING IN PROGRESS ON SLAVE 1
60
7 Programming Examples
Programming a Master in TSX 47-30 or TSX 67/87 (Cont’d.)
Subroutine 2
Monitoring of slave 1 and starting of slave 2 when slave 1 has finished its piece/ part.
Reading of N words
Number of the slave
Modbus
address of the 1st word
Number of words
INTERROGATION OF SLAVE 1
Writing of a bit
Number of the slave
Modbus
address of the bit
Value of the bit
PART IN PROGRESS
PART FINISHED : START SLAVE 2
MANUFACTURING OF A PART BY SLAVE 2
61
7 Programming Examples
Programming a Master in TSX 47-30 or TSX 67/87 (Cont’d.)
Subroutine 3
Monitoring of slave 2.
When it has finished its part, processing of the next part starts, or manufacturing is stopped if all the parts have been manufactured.
Reading of N words
Number of the slave
Modbus
address of the 1st word
Number of words
INTERROGATION OF SLAVE 2
1
Writing of a bit
Number of the slave
Modbus
address of the bit
Value of the bit
PART IN PROGRESS
MANUFACTURING ENDED : LAST PART
FINISHED
PART FINISHED : START SLAVE 1
MANUFACTURING OF A PART BY SLAVE 1
62
8 Appendix
8.1
Response Time of the Slave
Calculating the Response Time
It is necessary to calculate the slave response times in order to configure the master (i.e. to define the time envelope after which the master polls the next slave if there is no reply from the first one), and also to evaluate the overall performance of the communication system. The times given below are valid in the most unfavorable cases (e.g. a read request, which takes longer for the slave to process than a write request).
The response time of a slave is the sum of the following transfer times :
. The time to receive a message of N characters from the master (Trm)
Trm = 1000 x N x (number of bits per character) / (baud rate).
. The time for the module to process the message (Tre + Tam)
- Tre = time to recognize the end of the message, i.e. a minimum delay of 3.5
characters between 2 messages (i.e. 3.5 ms at 9600 baud),
- Tam = time to analyze the message and transmit a request to the processor
(Tam = 4.5 ms to read 32 non-consecutive bits).
. The time for the processor to reply (Tpr)
- Tpr = 2 x (PLC scan time) for exchanges by Text block,
- Tpr = 1 x (PLC scan time) for exchanges by registers.
. Time for the module to process the reply (Tmr)
- Tmr = 1 ms to read 32 non-consecutive bits.
. Time for the module to transmit a message of M characters to the master (Tmt)
- Tmt = 1000 x M x (number of bits per character) / (baud rate).
Example
On a link with a speed of 9600 baud and a character format of 1 start bit, 8 data bits, 1 parity bit and 1 stop bit (i.e. 11 bits per character), the master requests the reading of 32 bits.
The exchanges are made via the message interface (i.e. by Text block) and the scan time of the PLC is 80 milliseconds.
Trm = 1000 x 8 x 11 / 9600
Tre = 1000 x 3.5 x 11 / 9600
Tam
Tpr = 2 x 80
Tmr
Tmt = 1000 x 8 x 11 / 9600
=
=
=
=
=
=
9.2 ms
4.0 ms
4.5 ms
160.0 ms
1.0 ms
9.2 ms
Total time = 187.9 ms
The time envelope of the master (i.e. the time the master waits for a reply before polling the next slave) could therefore be fixed at 200 milliseconds.
63
8 Appendix
8.2
Response Time of the Master
Calculating the Response Time
The response time of the master (i.e. of one complete Modbus ® question-andanswer transaction) is the sum of the following transfer times (the times given below are valid with a TSX slave and in the most unfavorable cases) :
. The time for the module to receive a request from the processor (Trr)
Trr = 1 x (PLC scan time).
. The time to prepare the message to be transmitted to the slave (Tpm). This time depends on the Modbus ® function requested, number of objects, etc.
Tpm = < 10 ms in the most unfavorable case.
. The time to transmit a message of N characters to a slave (Ttt)
Ttt = 1000 x N x (number of bits per character) / (baud rate).
. The time for slave to prepare its reply (Trs)
Trs = slave response time less slave transmission time.
. The time for the slave to transmit its reply of M characters (Tst)
Tst = 1000 x M x (number of bits per character) / (baud rate).
. The time for the master to process the reply (Tpr). This time depends on the
Modbus ® function requested, number of objects, etc.
Tpr = < 10 ms in the most unfavorable case.
. The time to send the reply to the processor (Tsr)
Tsr = 1 x (PLC scan time).
64
8 Appendix
Response Time of the Master (Cont’d.)
Examples
In these examples, the data link has a speed of 9600 baud and a character format of 1 start bit, 8 data bits, 1 even parity bit and 1 stop bit (i.e. 11 bits per character) and the scan time of the PLC is 60 milliseconds.
. Writing of 16 words :
Trr
Tpm
Ttt = 1000 x 41 x 11 / 9600
= 60.0 ms
= 10.0 ms max.
= 47.0 ms
Trs : response time of the slave (less transmission time)
Tst = 1000 x 8 x 11 / 9600 = 9.2 ms
Tpr
Tsr
=
=
10.0 ms max.
60.0 ms
Total time = 196.2 ms + (slave response time - transmission time)
. Reading of 256 bits :
Trr = 60.0 ms
Tpm
Ttt = 1000 x 8 x 11 / 9600
=
=
10.0 ms max.
9.2 ms
Trs = response time of the slave (less transmission time)
Tst = 1000 x 37 x 11 / 9600
Tpr
Tsr
= 42.4 ms
= 10.0 ms max.
= 60.0 ms
Total time = 191.6 ms + (slave response time - transmission time)
65
8 Appendix
8.3
Processor/Slave Exchanges Through the Register Interface
General
Two methods are available to the user for organizing the exchanges between the
TSX SCM 22 slave module and the PLC processor. The exchanges through the message interface have already been described (see Sub-section 3.2). The second method uses both the message interface and the register interface of the module. The exchanges through the register interface are used for only two
Modbus ® functions, the others being dealt with by the message interface.
Certain master systems do not have the Modbus ® functions 15 and 16 (writing of
N bits and writing of N words). Instead of these functions, they translate the writing of N objects into N writings of an object, which naturally increases the number of exchanges and consequently the overall response times.
By using the register interface, the response times can be halved (one scan cycle for exchanges through the register interface against two scan cycles through the message interface) for the Modbus ® functions 05 and 06 (writing of a bit and writing of a word).
Description of the Exchanges
The type of exchange (message mode or register mode) is defined by the configuration of the module (see Sub-section 3.1). When the register mode is selected, it includes the exchanges via the message zone by distinguishing the
Modbus ® functions 05 and 06, which instead of being transmitted to the PLC processor in the form of requests are transmitted by registers, thus reducing the exchange times.
Modbus ® functions
F 05
F 05
F 06
Access codes
H’50'
H’51'
H’06'
Type of access
Resetting a bit to 0
Setting a bit to 1
Writing a word
The validation of a new access request is effected by the incrementation of a counter (performed by the module) in the high order byte of the register word containing the access code.
Resetting to 0 of a bit
The resetting of a bit is obtained by performing the logical AND between the word containing the bit and the mask defined in the register zone.
Setting to 1 of a bit
The setting of a bit is obtained by performing the logical OR between the word containing the bit and the mask defined in the register zone.
66
8 Appendix
Processor/Slave Exchanges Through the Register Interface (Cont’d.)
Definition of the Register Words
The register words used by the slave during its exchanges with the processor through the register interface are described below. The definition of the discrete
I/O bits and the other register words used are described in Section 5.
Input register word IWxy,5 :
This register contains the code of the function requested, and the reception counter which is incremented on each new exchange in the register mode.
IWxy,5 Reception counter Access code
Input register word IWxy,6 :
This register contains the address of the word concerned in the case of writing a word, or the address of the word containing the bit in the case of writing a bit. This address is seen from the processor side; for example, the value 50 represents the word W50.
IWxy,6 Physical address of the first object
Input register word IWxy,7 :
This register gives the value of the word that was addressed by the preceding register, or the mask necessary to set a bit to 1 or 0.
IWxy,7 Value or mask
Output register word OWxy,5 :
This register permits the acknowledgement of the write request from the master.
It is then simply necessary to transfer the contents of the input register into the corresponding output register.
OWxy,5 Acknowledgement code Access code
Output register word OWxy,6 :
This register permits the rapid exchange of a byte through its most significant bits.
OWxy,6 Status register X X X X X X X X
Output register word OWxy,7 : not used.
67
8 Appendix
Processor/Slave Exchanges Through the Register Interface (Cont’d.)
Resetting an Output Bit to 0
Contents of the input registers
IWxy,5 = access code = H’xx50'
IWxy,6 = address of the word
IWxy,7 = mask for AND
Setting an Output Bit to 1
Contents of the input registers
Contents of the response
OWxy,5 = H’xx50'
IWxy,5 = access code = H’xx51'
IWxy,6 = address of the word
IWxy,7 = mask for OR
Writing an Output Word
Contents of the input registers
IWxy,5 = access code = H’xx06'
IWxy,6 = address of the word
IWxy,7 = value of the word
Contents of the response
OWxy,5 = H’xx51'
Contents of the response
OWxy,5 = H’xx06'
Note : The counter represented by xx in the input register IWxy,5 is incremented on each access request by the module, thus indicating to the user program the arrival of new data. The response OWxy,7 must therefore contain, in addition to the access code, the same value of the counter xx so that the module can acquire this value. To do this, it is simply necessary to transfer the input register IWxy,5 to the output register OWxy,5.
Examples
The examples below show three successive write requests from the TSX SCM 22 module to the PLC processor.
Resetting to 0 of bit W200,4
State of the register words on reception of the request :
IWxy,5 = H’1250'
IWxy,6 = 200
IWxy,7 = H’FFEF’ = L’1111 1111 1110 1111'
Acknowledgement
OWxy,5 = H’1250'
Setting to 1 of bit W125,A
State of the register words on reception of the request :
IWxy,5 = H’1351'
IWxy,6 = 125
IWxy,7 = H’0400' = L’0000 0100 0000 0000'
Acknowledgement
OWxy,5 = H’1351'
Writing of word W123 to the value H’1357'
State of the register words on reception of the request :
IWxy,5 = H’1406'
IWxy,6 = 123
IWxy,7 = H’1357'
Acknowledgement
OWxy,5 = H’1406'
68
Ladda ner
Annons