Example Description. Schneider Electric SoMachine Basic
تبلیغات
تبلیغات
SoMachine Basic Example Guide
Example Description
EIO0000002401 06/2016
Example Description
Chapter 1
Example Description
What Is in This Chapter?
This chapter contains the following sections:
Section
1.1
1.2
Introduction
Example Detailed Description
Topic Page
EIO0000002401 06/2016
13
Example Description
Introduction
Section 1.1
Introduction
What Is in This Section?
This section contains the following topics:
Topic
Overview
Automatic Conversion of Twido COMM Macros to SoMachine Basic EXCH Instructions
How to Modify EXCH Instructions of the Conversion
Page
14
EIO0000002401 06/2016
Example Description
Overview
General
The Example guide and its corresponding project template, included with SoMachine Basic, help you to adapt the code generated after importing a Twido project into SoMachine Basic. In particular, it shows how to replace EXCH communication macros by M221 communication function blocks. The use of communication function blocks allows additional features to be included, such as error management.
This document explains:
Automatic conversion of a Twido application into a SoMachine Basic application.
How to modify the resulting EXCH instructions of the automatic conversion of the Twido
communication macros.
How to, instead, replace EXCH instructions with communication function blocks.
In fact, you have the option to by-pass the conversion of the Twido communication macros into
EXCH instructions prior to conversion of the application. With that, you can replace the communication macros directly by manually substituting with the M221 communication function blocks.
EIO0000002401 06/2016
15
Example Description
The objective of the example is illustrated below:
16
EIO0000002401 06/2016
Example Description
Automatic Conversion of Twido COMM Macros to SoMachine Basic EXCH Instructions
Twido Project Example Using COMM Macros
This figure presents the hardware configuration of a Twido project that implements the communication macros and communicates with a slave:
The TwidoSuite project file named Example_COMM_Macros.xpr
is available for you to implement this example. The following graphics present this Twido project.
EIO0000002401 06/2016
17
Example Description
Initialization of the macros:
18
EIO0000002401 06/2016
Example Description
EIO0000002401 06/2016
19
Example Description
Call of the macros:
20
This project:
Initializes the memory words when %M6 is set to TRUE. The addresses and the default values
are set.
Reads one bit when %M0 is set to TRUE. The result is stored in %MW107 .
Writes one bit when %M3 is set to TRUE. The value to write is stored in %MW124 .
Reads one word when %M1 is set to TRUE. The result is stored in %MW117 .
Writes one word when %M4 is set to TRUE. The value to write is stored in %MW134 .
Reads 4 words when %M2 is set to TRUE. The result is stored in %MW147 to %MW149 .
Writes 18 words when %M5 is set to TRUE. The values to write are stored in %MW306 to %MW323 .
EIO0000002401 06/2016
Example Description
Automatic Conversion of a Twido Project to SoMachine Basic
If you open the Twido project with SoMachine Basic, it is automatically converted. The following graphics presents the rungs from this project which correspond to the rungs of the Twido project.
Initialization of the Modbus exchange parameters and values (no difference from Twido):
EIO0000002401 06/2016
21
Example Description
22
EIO0000002401 06/2016
Modbus exchange requests (equivalent to macro calls):
Example Description
EIO0000002401 06/2016
23
Example Description
24
EIO0000002401 06/2016
Example Description
EIO0000002401 06/2016
25
Example Description
26
EIO0000002401 06/2016
Example Description
This project is functionally equivalent to the Twido project. It:
Initializes the memory words when %M6 is set to TRUE. The addresses and the default values
are set.
Reads one bit when %M0 is set to TRUE. The result is stored in %MW107 .
Writes one bit when %M3 is set to TRUE. The value to write is stored in %MW124 .
Reads one word when %M1 is set to TRUE. The result is stored in %MW117 .
Writes one word when %M4 is set to TRUE. The value to write is stored in %MW134 .
Reads 4 words when %M2 is set to TRUE. The result is stored in %MW147 to %MW149 .
Writes 18 words when %M5 is set to TRUE. The values to write are stored in %MW306 to %MW323 .
However, this project does not contain macro calls. The automatic conversion keeps the initialization part exactly the same, but converts each macro to a rung containing a single EXCH instruction.
As shown in the graphics, each macro is converted to instructions that fill up a table, which is called an exchange table. This table consists of at least 8 words (more when reading/writing multiple words). When this table is filled, the EXCH instruction is called and the communication occurs.
Exchange Table Examples
In the following exchange table, you can find an example of reading 4 words and writing 18 words.
This example will help you to understand the exchange table. For other types of exchange, you can consult How to Modify EXCH Instructions of the Conversion
( see page 30 )
Exchange Table for a Read Operation
The following information is transmitted in the Modbus exchanges for a read operation:
The master requests...
Slave address
The slave responds with...
Address of the slave
Type of the operation (function code) Function code
Address of the first register/bits requested Number of registers/bits to follow
Number of registers/bits requested Values of registers/bits requested
EIO0000002401 06/2016
27
Example Description
The following table presents a read operation of 4 registers on slave 21. The data read is stored starting at the address %MW147 with an EXCH instruction (11 memory words are used, starting from
%MW140 ):
28
After filling the Control table and the Transmission table, it is possible to call the EXCH instruction using the following syntax:
11 memory words are used in total, starting from %MW140 . Calling the EXCH instruction uses these
11 memory words to execute the communication.
EIO0000002401 06/2016
Example Description
Exchange Table for a Write Operation
For a write operation (multiple registers or bits), the information to be transmitted is:
The master requests...
Slave address
Type of the operation (function code)
Address of the first register/bits
Number of registers/bits to be sent
Values of the registers/bits
The slave responds with...
Address of the slave
Function code
Starting address of registers/bits that are overwritten
Number of registers/bits that are overwritten
–
The following table presents a write operation of 18 registers on slave 21 at the address %MW1 with
EXCH instruction (27 memory words are used starting from %MW300 ):
Writing one particular register or bit follows different procedures, see the graphics in the following pages and also refer to
Modbus Master/Jbus Master/Ethernet TCP/IP Modbus Protocols Manual
(11-2 Modbus Master requests)
for more information.
EIO0000002401 06/2016
29
Example Description
How to Modify EXCH Instructions of the Conversion
Introduction
The following explains how to use EXCH instructions in the SoMachine Basic application, to obtain the same behavioral logic of the Twido COMM macros.
The following graphics present a SoMachine Basic application that implements the Twido COMM macros prior to conversion and are included here to give you a better understanding of the EXCH instruction. With these graphics and the two exchange tables from the previous section, you can modify existing exchange tables and further create your own exchange tables.
In the following examples, areas highlighted in red must not be modified. Areas highlighted in green can be adapted to your application requirements.
Green areas correspond to the slave address, the number of registers, the values to write, or the size of the exchange table.
C_RD1W and C_RDNW Equivalents
Reading one word ( C_RD1W equivalent) and reading four words ( C_RDNW equivalent):
30
EIO0000002401 06/2016
C_RD1B Equivalent
Reading one bit ( C_RD1B equivalent):
Example Description
EIO0000002401 06/2016
31
Example Description
C_WR1W and C_WR1B Equivalents
Writing one word ( C_WR1W equivalent) and writing one bit ( C_WR1B equivalent):
32
EIO0000002401 06/2016
C_WRNW Equivalent
Writing multiple words ( C_WRNW equivalent):
Example Description
NOTE: This is a simplified graphic presenting a write operation of 4 memory words only.
Unlike the previous graphics, these graphics present how to manually reproduce a Twido COMM macro in SoMachine Basic, but they are not limited to this operation. For example, it is possible to read or write multiple bits.
Always fill the Control and Transmission tables and verify that the Reception table is filled with the data sent by the slave. The number of bytes in the first word is updated according to the amount of received data. The values read from the slave are found in the Reception table area of the exchange table.
Although you can use EXCH instructions, use Read Var and Write Var function blocks to create more readable code that is adapted to your application.
EIO0000002401 06/2016
33
Example Description
Example Detailed Description
Section 1.2
Example Detailed Description
What Is in This Section?
This section contains the following topics:
Topic
How to Replace Twido COMM Macros or EXCH Instructions by Function Blocks in SoMachine
Basic
Read Var Function Block
Write Var Function Block
Page
34
EIO0000002401 06/2016
Example Description
How to Replace Twido COMM Macros or EXCH Instructions by Function Blocks in
SoMachine Basic
Hardware Configuration Used Within the Example
This example presents an M221 Logic Controller as the equipment with a Modbus interface, that is, as the slave.
The setup is shown below:
The setup used in the project template comprises:
An M221 Logic Controller, for example, TM221CE16T as slave.
An M221 Logic Controller, for example, TM221CE40T as master.
A PC with SoMachine Basic V1.4 SP1 or later to program the M221 master controller and monitor the application example.
A PC with another instance of SoMachine Basic V1.4 SP1 or later to program and monitor the
M221 slave controller.
EIO0000002401 06/2016
35
Example Description
The example uses an M221 Logic Controller as slave. However, another equipment that supports the Modbus protocol can be used. If this is the case, refer to the equipment documentation to verify that the Modbus registers used by this example are compatible. Adapt the configuration and the code of the example as necessary.
The other SoMachine Basic project used in the slave for this example is also provided to allow you to reproduce the template ( xSample_M221_COMM_Conv_Slave ). You can also find the graphics corresponding to this project in the appendices.
The template is designed to be integrated into your application. Comments in each object provide explanations on how to integrate the example into your application. Animation tables are provided within the template example to assist you with integration and deployment.
This example is prepared assuming that you have prior knowledge of using Twido COMM macros and that you have a working, functional TwidoSuite project.
Opening Your Example
From this point onwards, open the example and follow this document with it. To open the example template, click on the Start Page icon ( ), located in the top left corner, select xSample_Twido_Marco_COMM_Conversion.smbe
, and click Open Template.
The following figure shows the location of the example in SoMachine Basic:
36
EIO0000002401 06/2016
Example Description
Software Configuration
Verify that the Serial Line communication configuration for both M221 controllers is identical (the
Modbus settings will differ between Master, Slave and Addressing). Set the correct parameters for
Modbus communications on a serial line (SL1 or SL2). The Modbus protocol needs to be configured with the following settings for both M221 controllers.
Settings for the M221 master controller in SoMachine Basic Configuration tab:
Settings for the M221 slave controller in SoMachine Basic Configuration tab (the difference is that it is configured as a slave):
EIO0000002401 06/2016
37
Example Description
Program Structure, Variables, and Function Blocks Used
The SoMachine Basic example is divided into a number of POUs and rungs to facilitate identifi cation of the parts corresponding to individual Twido macros. You can delete rungs that are not required for your application.
This figure shows the organization of the SoMachine Basic example:
38
POU 1 reads one bit or one word ( C_RD1B and C_RD1W , respectively)
POU 2 writes one bit or one word ( C_WR1B and C_WR1W , respectively)
POU 3 reads or writes multiple words ( C_RDNW and C_WRNW , respectively)
POU 4 initializes the values that will be read or written. Each rung corresponds to the initialization of a different function block (for example, a macro).
POU 5 reads or writes multiple bits
POU 6 performs continuous execution
EIO0000002401 06/2016
Example Description
There are also a number of animation tables. The first 4 animation tables relate to the basic functionalities. The INITIALIZATION table is to initialize the first 3 animation tables. The other tables are independent and correspond to POUs 5 and 7 respectively.
This figure shows the provided animation tables:
Function Block Principles
Since the proposed method for converting COMM macros involves function blocks in SoMachine
Basic, it is necessary to know how to use function blocks.
A function block is an object with inputs, outputs, and parameters. Depending on the values of the inputs and parameters, it produces predetermined output values. Read the documentation for each function block before using it.
A Ladder diagram in SoMachine Basic can only contain one function block in each rung. However, every function block type can have multiple copies (instances), each of which can be configured differently.
This figure shows an example function block:
The function blocks used in this example are Read Var and Write Var which are located in the
Communication Objects section of the Tools tree. There is also another function block available called Write Read Var which can read and write within a single function block instance.
EIO0000002401 06/2016
39
Example Description
This figure shows the communication function blocks in SoMachine Basic:
40
EIO0000002401 06/2016
Example Description
Read Var Function Block
Introduction
This function block is used to replace the Twido macros C_RD1B , C_RD1W , and C_RDNW .
Reading a single bit:
With SoMachine Basic, you can use this function to read different types of objects. ObjType is the parameter that manages this:
ObjectTypeMW reads the holding registers (memory word objects ( %MW ) on the M221 Logic
Controller) of the slave by sending function code 0x03 .
ObjectTypeM reads the holding bits (memory bit objects ( %M ) on the M221 Logic Controller) of the slave. This parameter needs to be changed to bits (Mbs Fct1). With this configuration, the function code 0x01 is sent.
The IndexData parameter always corresponds to the holding registers of the master. Therefore, even if a bit is read, its value is stored in a word. When reading only one bit, the value of IndexData corresponds (in decimal) to the value of the bit read. In binary, the value is stored in the least significant bit.
This figure illustrates the above operation which is valid also for Write Var .
EIO0000002401 06/2016
41
Example Description
Upon initialization, the value in IndexData for all the read functions is set to 0xFFFF. This value can then be set to any value, so if you read a known value from the slave, you can verify that the communication is successful.
Even though the EXCH instruction still exists in SoMachine Basic, Read Var is more powerful.
First, it is less restrictive than EXCH and conforms to the Modbus specifications by allowing a maximum of 125 words, compared to 114 words in Twido. Second, it combines a Modbus request and error management in a single instruction, making the MSG function block obsolete. Also you can save memory words ( %MW ) in your application since the instruction does not need an exchange table.
Allow reserved memory after IndexData when you are reading multiple words. The amount of reserved memory should correspond to the Quantity value. Otherwise, as written in the comments of the example, the data stored will be overwritten. This is an example:
Memory Word
%MW412
%MW413
%MW414
...
%MW456
%MW457
%MW458
Value Read
140
150
155
160
155
140
Corresponds to:
IndexData
IndexData+1
IndexData+2
IndexData+Quantity-2
IndexData+Quantity-1
IndexData+Quantity
In this example, IndexData corresponds to %MW412 . After execution, all the addresses after
%MW412 are filled with the values from the slave up to the memory word IndexData+Quantity .
In this example, the Quantity value is 47.
42
EIO0000002401 06/2016
Example Description
Matching Read Var Parameters to Twido COMM Macros
The following information shows how to match the parameters of Twido read macros ( C_RDXX ) with the parameters of Read Var :
C_RD1B :
ObjType : 2 (Coils – Mbs 1)
FirstObj : C_RD1B_ADDR_x
Quantity : 1
IndexData: Address of C_RD1B_VAL_x
C_RD1W :
ObjType : 0 (Holding reg. – Mbs 3)
FirstObj : C_RD1W_ADDR_x
Quantity : 1
IndexData: Address of C_RD1W_VAL_x
C_RDNW :
ObjType : 0 (Holding reg. – Mbs 3)
FirstObj : C_RDNW_ADDR_x
Quantity : Parameter 1 of the macro
IndexData: Address and the following words (until IndexData+Quantity ) corresponds to
C_RDNW_VAL_x and the following addresses (depending on the value of parameter1=N)
IndexData does not need to be 4 words after FirstObj as was the case for Twido macros
( C_RD1B_VAL_x was 4 words after C_RD1B_ADDR_x ). This way you have more flexibility to manage the memory.
Read Var Behavior
In the example, every input and output of the function block is connected, but this is not mandatory.
Read Var is also able to operate with just the Execute input connected. However, having a separate bit for each output visually displays the state of the function block.
The following information presents the different states of the Read Var function block with graphics. Together with the timing diagrams, these graphics help you to better understand the function block. In the timing diagrams, each vertical dash corresponds to an execution cycle.
EIO0000002401 06/2016
43
Example Description
Normal Execution of Read Var
Normal functioning: After an execution:
The execution process: Normally, this state is very short and it is normal to not see it. However, if there is a communication interruption, the block will be in this state until the timeout is reached.
44
EIO0000002401 06/2016
Example Description
Timing Diagram 1: Normal functioning. On a rising edge of Execute, the Modbus request starts and the Busy output is set to TRUE. When the exchange is complete (response received) and correct, the Done output is set to TRUE.
Abort Input of Read Var
It is possible to stop a running exchange. To do so, use the Abort input of the function block:
During an execution, setting the Abort input to TRUE stops the process and sets the Aborted output to TRUE. Aborted output is not set to TRUE if the Abort input is set to TRUE outside of an execution. The following timing diagram corresponds to this state.
EIO0000002401 06/2016
45
Example Description
46
Timing Diagram 2: If the Abort input is set to TRUE during the exchange, the exchange stops, the
Busy output is set to FALSE and the Aborted output is set to TRUE. When the Execute input is reset, all output parameters return to their initial state of FALSE.
EIO0000002401 06/2016
Example Description
Error Management with Read Var
If there is a communication interruption, the Error output is set to TRUE at each execution attempt.
The Error output is maintained to TRUE until the Execute input is reset. While the Error output is set to TRUE, it is possible to read the CommError and OperError outputs for diagnostic purposes.
EIO0000002401 06/2016
47
Example Description
Multiple Execution of Read Var
The following timing diagram presents the functioning of multiple Read Var function blocks:
Since every dash corresponds to an execution cycle, you can see that an execution cycle can be lost between each execution of Read Var , so no extra modifications are made in the application.
48
EIO0000002401 06/2016
Example Description
Write Var Function Block
Introduction
This function block replaces the Twido macros C_WR1B , C_WR1W , and C_WRNW .
The figure shows writing a single bit.
With SoMachine Basic, you can use this function to write different type of objects. ObjType is the parameter that manages this:
ObjectTypeMW writes the holding registers (memory words %MW ) of the slave by sending function code 0x10.
ObjectTypeM writes the holding bits (memory bits %M ) of the slave. This parameter needs to be changed to bit (Mbs Fct 1). With this configuration, the function code 0x0F is sent.
The IndexData parameter corresponds to the holding registers of the master. So, even if a bit is written, the value needs to be stored in a memory word. When writing only one bit, the decimal value of the IndexData parameter corresponds to the bit value to be written. The value is stored in the least significant bit.
On initialization, change the value in IndexData according to your application.
Although the EXCH instruction still exists in SoMachine Basic, Write Var is more powerful. Firstly, it is less restrictive than EXCH and conforms to the Modbus specifications by having the maximum
123 words, compared to 114 in Twido. Furthermore, it combines Modbus request and error management in a single block, making the MSG function block obsolete. Also, you save some memory words %MW in your application, as the function block does not need an exchange table.
EIO0000002401 06/2016
49
Example Description
NOTE: Write Var uses the function codes 0x0F for writing bits and 0x10 for writing words, even if Quantity is 1. If your Modbus device does not manage multiple write function codes, you must keep the EXCH instruction generated by the conversion. Furthermore, C_WR1W_ADDRW_x ,
C_WR1W_VALW_x , C_WR1B_ADDRW_x and C_WR1B_VALW_x do not have an equivalent when using the Write Var function block.
Matching Write Var parameters to Twido COMM Macros
The following information presents how to match the parameters of Twido write macros ( C_WRXX ) to the parameters of Write Var in SoMachine Basic:
C_WR1B :
ObjType : 2 (Coils – Mbs 1)
FirstObj : C_WR1B_ADDR_x
Quantity : 1
IndexData: Address of C_WR1B_VAL_x
C_WR1W :
ObjType : 0 (Holding reg. – Mbs 3)
FirstObj : C_WR1W_ADDR_x
Quantity : 1
IndexData: Address of C_WR1W_VAL_x
C_WRNW :
ObjType : 0 (Holding reg. – Mbs 3)
FirstObj : C_WRNW_ADDR_x
Quantity : Parameter 1 of the macro
IndexData: Address and the following memory words (until IndexData+Quantity ) correspond to C_WRNW_VAL_x and the following addresses (depending on the value of parameter1=N)
IndexData does not need to be 4 words after FirstObj as was the case for Twido macros
( C_WR1B_VAL_x was 4 words after C_WR1B_ADDR_x ). This way, you have more flexibility to manage the memory.
Write Var Behavior
In the example, every input and output of the function block is connected. This is not mandatory.
Write Var is also able to function with just the Execute input connected. However, having a separate bit for each output visually shows the state of the function block.
The following information presents the different states of the Write Var function block with graphics. Together with the timing diagrams, these graphics help you to better understand the function block. In the timing diagrams, each vertical dash corresponds to an execution cycle.
50
EIO0000002401 06/2016
Example Description
Normal Execution of Write Var
Normal functioning: After an execution.
The execution process: Normally this state is very short and it is normal to not see it. However, if there is a communication interruption, the block remains in this state until the timeout is reached.
EIO0000002401 06/2016
51
Example Description
Timing Diagram 1: Normal functioning. On a rising edge of Execute, the Modbus request starts and the Busy output is set to TRUE. When the exchange is complete (response received) and correct, the Done output is set to TRUE.
Abort Input of Write Var
It is possible to stop a running exchange. To do so, use the Abort input of the function block.
52
EIO0000002401 06/2016
Example Description
During execution, the Abort input stops the process and sets the Aborted output to TRUE. The
Aborted output is not set to TRUE if the Abort input is set to TRUE outside of an execution. The following timing diagram shows this state.
Timing Diagram 2: If the Abort input is set to TRUE during the exchange, the exchange stops, the
Busy output is set to FALSE and the Aborted output is set to TRUE. When the Execute input is reset, all the output parameters return to the initial state of FALSE.
EIO0000002401 06/2016
53
Example Description
Error Management with Write Var
If there is a communication interruption, the Error output is set to TRUE at each execution attempt.
54
The Error output is maintained at TRUE until the Execute input is reset. While the Error output is set to TRUE, it is possible to read the CommError and OperError fields for diagnostic purposes.
EIO0000002401 06/2016
Example Description
Multiple Execution of Write Var
The following timing diagram presents the functioning of multiple Write Var function blocks.
Each dash corresponds to an execution cycle. An execution cycle can be lost between each execution of Read Var , so no extra modifications are made in the application.
EIO0000002401 06/2016
55
Example Description
56
EIO0000002401 06/2016
دانلود
تبلیغات