Topic: DMD0299 MWX - Modbus Network Write |
|
The Modbus Network Write (MWX) instruction is used to write data to a Modbus Server. The Modbus Server (Slave) can be either a Modbus/TCP server which communicates through the on-board Ethernet port, or a Modbus/RTU server which communicates over the on-board serial port, one of the serial POMs for the BRX CPUs, or one of the serial ports on a SERIO module.
This instruction will be using either an Ethernet port or a Serial port, which is a shared resource. The port's ability to concurrently handle multiple instructions is provided through the client device . The client device allows the port to process these concurrent requests without the need for interlocking logic in the ladder program. For example, DirectLOGIC PLCs use the 'Port Busy' SP relay in the ladder program to interlock all of the RX and WX communication requests that use same communication port. That interlocking logic is not required with this instruction because the client device that manages the port provides all of the required interlocking internally.
The MWX instruction uses Modbus/TCP protocol an Ethernet (Modbus/TCP) client device is selected, and uses Modbus/RTU protocol when a Serial (Modbus/RTU) client device is selected.
Note: If a single Do-more CPU will be writing data to multiple Modbus/TCP Servers, the best performance will be had by creating a separate Modbus/TCP Client for each of the Modbus/TCP Servers. Use this link for more information on creating additional Modbus/TCP Client devices. Doing this will minimized the TCP overhead required to manage connections to multiple Modbus/TCP Servers. Any time you use the same Modbus/TCP Client for multiple IP Addresses you will see Info Message M240 similar to the following in the Output Window: |
|
Element References:Note: Use the F9 key or click the 'three dot box' at the right edge of the parameter field to open the Default Element Selection Tool (the Element Picker or the Element Browser) or use the Down-Arrow key (Auto-Complete) on any parameter field to see a complete list of the memory locations that are valid for that parameter of the instruction.
Device selects which of the configured Devices to use to execute the Modbus Write Data request.
Modbus/TCP Addressing : if a Modbus/TCP Client is selected as the Device the following selections that specify the Ethernet network addressing will be enabled. If a Modbus/RTU Client is selected these options will be grayed out.
Unit ID (Slave ID) specifies the unique ID number of the Modbus Server that will receive the data. This can be any constant value between 0 and 255, or any readable numeric location containing a value in that range. If this MWX instruction is configured to use a Modbus/RTU (Serial) Client the Unit ID uniquely identifies the Modbus Server on the serial network, otherwise the Unit ID is unused and should be left at the default value of 255. One notable exception is a Modbus Server that is a Modbus/TCP -to- Modbus/RTU gateway (such as our MB-Gateway). In this instance the Unit ID will uniquely identify the Modbus/RTU Server (Slave) on the serial network side of the gateway.
Note: Unit ID 0 is a special ID number that is the Modbus/RTU broadcast address which is used to send the same Write Request to all of the Modbus/RTU Servers on the serial network.
Function Code selects which of the following Modbus function codes to use:
To Modbus Offset Address - specifies the offset of the Modbus address where the data that is written will be stored in the Modbus server. This can be any constant value in the range of 1 to 65536. This value specifies the ONLY the OFFSET of the location in the Modbus server to write to. For example to write a value to Holding Register 40029 enter only the offset value 29; to write to the Coil at 00017 enter only the offset value 17.
Number of Elements - based on the Function Code selected, this selection specifies how many consecutive elements to write. This selection is disabled for Function Codes 5 & 6.
If Function Code 15 is selected this value specifies how many consecutive coils or discrete outputs to write. This can be any constant from 1 to 1976, or any readable numeric location with a value in that range.
If Function Code 16 is selected this value specifies how many consecutive 16-bit unsigned registers to write. This can be any constant value from 1 to 123, or any readable location with a value in that range. Floating-point (real) and double-word values in a Do-more CPU are 32-bit values which will be written to 2 consecutive 16-bit locations in the Modbus server so the value for the Number of Elements must be multiplied by 2 for these data types to write the correct amount of data.
From Do-more Memory Address or Constant - specifies either a constant value or the beginning address of a range of bits or numeric locations in the CPU where the data to write currently resides. This value must match the type expected by the Function Code. The built-in Modbus memory blocks MC / MI / MIR / MHR should not be used as the location to store data to send by the MWX instruction because these memory locations are reserved for use by the Do-more CPU'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 selects how this instruction will operate. Select from one of the following:
The On Success and On Error parameters specify what action to perform when this instruction completes. You do not have to use the same type of selection for both On Success and On Error.
If the Set Bit selection is used for either On Success or On Error, the specified BIT location will be SET OFF when the instruction is first enabled and will remain OFF until the instruction completes. Once complete, the appropriate Success or Error bit location ON. The specified Bit location is enabled with a SET (Latch) operation meaning that it will remain ON even if the input logic for the instruction goes OFF.
If the JMP to Stage selection is used for either On Success or On Error the target Stage must be in the same Program code-block as this instruction, you cannot specify a target Stage that exists in a different Program code-block. When the operation finishes, the target Stage will be enabled the same way as a standalone Jump to Stage (JMP) instruction would do it. The JMP to Stage option will only be available if this instruction is placed in a Program code-block.
On Success selects which of the following actions to perform if the operation is successful:
On Error selects which of
the following actions to perform if the operation is unsuccessful:
If either the On Success or On Error selections are set to JMP to Stage, Automatically create the SG box for any NEW stage number will be enabled which will automatically create any target stage that does not already exist.
Note: if the Enable selection is Continuous on Power Flow at Interval, the On Success & On Error actions will be processed at the completion of every MWX instruction during the time interval. So it is recommended the you use Set Bit instead of Jump to Stage for this configuration. 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.
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:
|
|
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. For example, If the MWX is writing two Holding Registers from D0, the Do-more Range field will display D0:UW0 - D0:UW1, which means that the first Holding Register value is will come from Word 0 of D0, and the second Holding Register value will come from Word 1 of D0.
In the example above 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:
MWX - Modbus Network Write
Modbus Exception
Response Codes
RX - Do-more Network Read (Do-more PLC <- Do-more PLC)
WX - Do-more Network Write (Do-more PLC -> Do-more PLC)
DLRX - DirectLOGIC Network Read (Do-more PLC <- DirectLOGIC PLC)
DLWX - DirectLOGIC Network Write (Do-more PLC -> DirectLOGIC PLC)
EIPMSG - Send EtherNet/IP Message
PUBLISH - Translate from Do-more
SUBSCRIB - Translate to Do-more
|
|
Example:Description of a Typical Modbus Network Write (MWX) Stage Diagram:This is a stage diagram showing a typical sequence that monitors a 3rd-party Modbus TCP slave and reads up a new recipe whenever it becomes available.
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:This is a ladder program that is equivalent to the above stage diagram. It utilizes both the Modbus Network Read (MRX) and Modbus Network Write (MWX) instructions to monitor a 3rd-party Modbus TCP slave and read up a new recipe whenever it becomes available.
A summary of the master / slave interaction is as follows:
NewRecipeis 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:
|
|