Topic: DMD0298 MRX - Modbus Network Read |
|
|
|
The Modbus Network Read (MRX) instruction is used to read data from a Modbus Server. It uses Modbus/TCP protocol to read data over the onboard Ethernet port, or Modbus/RTU protocol to read data over the onboard serial port or a port on a SERIO module.
Note: If the same Do-more Designer project will be using Modbus Read (MRX) instructions to read data from multiple Modbus/TCP Servers, the best performance will be had by creating a separate Modbus/TCP Client device for each of the Modbus/TCP Servers. For more information on creating Modbus/TCP Client devices see the Device Configuration help topic.
Except for broadcast messages, when the MRX instruction sends a query
to a server it expects a normal response. One of four possible events
can occur from the query:
|
|
Element References:Note: Use the F9 key (Element Browser) or Down-Arrow key (Auto-Complete) at any time to see a complete list of the memory locations that are valid in the current field of the instruction.
Device - designates which of the configured Devices
to read the data from. Before this instruction can select a Device, that
Device must be configured to accept data from an external source. Part
of the configuration for a device is assigning a name to the device. It
is that name which will show up in the Device selection drop-down menu.
For more information on configuring devices go to the Device
Configuration Section under System Configuration.
Modbus/TCP Addressing
Unit ID - (also known as the Slave ID) designates the Unit ID of the Modbus Server to read the data from. This can be any constant value between 1 and 255.
If this Modbus Network Read (MRX) instruction is configured to use a serial device, the Unit ID uniquely identifies the Modbus Server on the serial network.
If this Modbus Network Read (MRX) instruction
is configured to use an Ethernet Device, the Unit ID is unused.
Function Code - designates the Modbus function code to use. The following function codes are available in the drop-down menu:
From Modbus Offset Address - designates the offset of the Modbus address where you want to read the data from. This can be any constant value in the range of 1 to 65536. Note: this field only specifies the offset for the location to begin reading, for example to read the value in Holding Register 40029 enter only the offset value 29, to read the status of the Discrete Input 10017, enter only the offset value 17.
Number of Elements - designates the number of elements of the selected type to read.
If Function Code 1 or 2 is selected this selection defines how many coils or inputs to read. This can be any constant value in the range of 1 to 2008, or any readable numeric location.
If Function Code 3 or 4 is selected this selection defines how many registers (16-bit words) to read. This can be any constant value in the range of 1 to 125, or any readable location.
If Function Code 7 is selected this selection will be grayed out because the value is fixed at 1 (16-bit words) to read.
To Do-more Memory Address - designates the beginning address of the destination data in the controller. This value must match the type specified in the Function Code as follows:
If Function Code 1 or 2 is selected the Do-more Memory Address value can be any writable bit location except for struct fields.
If Function Code 3 or 4 is selected the Do-more Memory Address value can be any writable numeric location except for struct fields.
If Function Code 7 is selected the Do-more Memory Address value can be any writable numeric location except for struct fields.
Note:
in most cases, the built-in Modbus memory blocks MC / MI / MIR / MHR should
not be used as the location to store data received by the MRX instruction
because these memory locations are reserved for use by the Do-more's
Modbus Server (Slave) function. Refer to the Modbus
Memory Blocks diagram in the Memory Configuration section of the System
Configuration for more information. Enable
- designates how this instruction is enabled. Select from one of the following:
On Success - designates one of the following two options if the Modbus Network Read operation is successful:
On Error - designates one of the following two options if the Modbus Network Read operation is unsuccessful:
Exception Response - enable this optional selection and enter a memory location to store the Modbus Exception Response for this instruction. This can be any writable numeric location.
|
|
|
|
Status Display:The red triangle in the upper left corner of the status display indicates this is a Fully Asynchronous instruction.
Because Modbus protocol always works with Unsigned Word (16-bit) data,
this instruction will display the range specified in the To Do-more
Memory Address field in an additional field - called Do-more
Range - with the appropriate cast operators any time the entered element
is NOT an Unsigned Word type.
In the example to the right the specified range is N0 - N19, the N range contains Signed Word values, so the :U cast operator is added to the display in the Do-more Range field as N0:U - N19:U.
For more information on casting, refer to the help topic on Casting.
|
|
|
|
See Also:
|
|
|
|
Example 1 of 2:Description of a Typical Modbus Network Read (MRX) Stage Diagram:
Initially the NewRec (New Recipe) stage monitors a bit from the slave. When this bit comes ON, RecipeRdy (Recipe Ready) causes the transition to the RDRec stage.
The RDRec (Read Recipe) reads the new recipe from the slave. When this completes, RecipeRD (Recipe Read) causes the transition to the RSTRec stage.
The RSTRec (Reset Recipe) writes a bit to the slave to inform it the recipe has been read successfully. When this write is complete, RecipeRST (Recipe Reset) causes a transition to the RSTMon stage.
The RSTMon (Reset Monitor) stage monitors a bit from the slave to confirm the slave heard the reset. When this bit comes ON, MonRST (Monitor Reset) causes a transition back to the NewRec stage to repeat the process and wait for the next new recipe.
|
|
|
|
Description of a Typical Modbus Network Read (MRX) Stage Ladder:
A summary of the master/slave interaction is as follows:
NewRecipe is the initial stage. The MRX instruction is set to execute "Continuous at Interval 0.100s" to read a particular Modbus Input from the slave. This is the bit the slave will set when a new recipe has been stored and is ready for the Do-more PLC to read it up. The MRX reads this bit and stores it in RecipeReady bit. Upon the successful completion of each read the ReadSuccess1 bit will come ON. When there has been a successful read and the RecipeReady bit is ON, Rung 3 resets the RecipeReady bit back OFF (in preparation for the next cycle) and transitions to the ReadRecipe stage. If any one of these reads fails, the MRX instruction will transition to the ErrorStage where the error can be assessed (e.g. evaluation of the Exception Response, Exception1 value).
The ReadRecipe stage executes the MRX instruction once to read up the new recipe from Modbus Input Registers 1-16 and stores them in Do-more memory range RecipeVar1-RecipeVar16. Upon a successful read, the MRX transitions to the ResetRecipe stage. If the read failed, the MRX instruction will transition to the ErrorStage where the error can be assessed (e.g. evaluation of the Exception Response, Exception2 value).
The ResetRecipe stage executes the MWX instruction once to write to a single Modbus Coil to inform the slave the new recipe has been read up successfully. Upon a successful read, the MWX transitions to the ResetMonitor stage. If the write failed, the MWX instruction will transition to the ErrorStage where the error can be assessed (e.g. evaluation of the Exception Response, Exception3 value).
The ResetMonitor stage monitors a feedback bit from the slave that the slave should use to inform the Do-more PLC that it "heard" the recipe read was successful and that the slave can now make preparations for the next recipe. The MRX reads this bit (Modbus Input 2) and stores it in MonitorReset bit. Upon the successful completion of each read the ReadSuccess2 bit will come ON. When there has been a successful read and the MonitorReset bit is ON, Rung 10 resets the MonitorReset bit back OFF (in preparation for the next cycle) and transitions back to the initial NextRecipe stage. If any one of these reads fails, the MRX instruction will transition to the ErrorStage where the error can be assessed (e.g. evaluation of the Exception Response, Exception4 value).
The ErrorStage should have code in it (not shown here) that evaluates the various errors that can occur in this example. |
|
|
|
Example 2 of 2: |
|
|
|
|