Topic: DMD0299 MWX - Modbus Network Write |
|
|
|
The Modbus Network Write (MWX) instruction is used to write data to a Modbus Server. It uses Modbus/TCP protocol to write data over the onboard Ethernet port, or Modbus/RTU protocol to write data over the onboard serial port or a port on an SERIO or SERIO-4 module.
The red triangle in the upper left corner of the status display indicates this is a Fully Asynchronous instruction.
Note: If the same Do-more Designer project will be using Modbus Write (MWX) instructions to write data to 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 devices see the Device Configuration help topic.
Except for broadcast messages, when the MWX 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 that
will receive the data. This can be any constant value between 0 and 255.
If this Modbus Network Write (MWX) instruction is configured to use a serial device, the Unit ID uniquely identifies the Modbus Server on the serial network.
If this Modbus Network Write instruction
(MWX) 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:
To Modbus Offset Address - designates the offset of the Modbus address where you want to write the data. 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 write a value to Holding Register 40029 enter only the offset value 29, to write to the status of Coil 00017, enter only the offset value 17.
Number of Elements - designates the number of elements of the selected type to write.
If Function Code 5 or 15 is selected this selection defines how many coils to write. This can be any constant value in the range of 1 to 1976, or any readable bit location.
If Function Code 6 or 16 is selected this selection defines how many registers (16-bit words) to write. This can be any constant value in the range of 1 to 123, or any readable numeric location.
From Do-more Memory Address or Constant - designates one of the following two options:
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 Write operation
is successful:
On Error - designates one of
the following two options if the Modbus Network Write 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 From 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:Description of a Typical Modbus Network Write (MWX) 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 Write (MWX) 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: |
|
|
|
|