Modbus TCP
Slave I/O
Modbus TCP is a standard protocol used for many IO device modules. Any IO device capable of using Modbus TCP can have its IO controlled as if it was IO internal to the show controller. For example, Beckhoff IO and Advantech Adam-6000 series IO have product files available. Please contact support if you have a Modbus TCP IO device you would like to control.
The following example demonstrates how to setup a Beckhoff BK9100. 1. Add the IO module to the "Devices" list by clicking the "New" button in the "Devices" window.
-
Enter a name such as "MyBeckhoff".
-
Select the Make, Model and version of the IO.
-
Set the protocol to "Slave IO"
-
Select the controller Ethernet port and enter the IO device's IP address
-
Enter the number of "Inputs" and "Outputs" into the setup fields. The "StartingInput" and "StartingOutput" are typically 0. Set these only if controlling a sub-section of the IO on a particular control module. For example, if you only wanted to watch inputs 3-12 on a module that had 0-12 available.
-
The "InputPollFrequency" can be set to as little as 1 frame. If you have greater than nine devices that are setup to poll inputs, you must decrease the polling to 2 frames or more.
-
The "OutputPollFrequency" is typically set to zero. This does not mean that the outputs will never be polled. They will be polled on startup and after any command is sent to change the output’s status. (ie: after an "On", "Off" or "Toggle" command). If you prefer more constant polling, a recommended value would be 15 frames.
-
-
Click "Finish." Your IO will now show up in the "Inputs" and "Outputs" lists.
-
Go to "Resources" -> "Inputs" and select the device (in this example: "MyBeckhoff") to view the inputs list.
Automatic Read/Write Polling
From Winscript version 6.2.0-b9 and above, the modbus product file supports automatic polling.
The following modbus data types are supported:
- Coils
- Discrete Inputs
- Input Registers
- Holding Registers (16 and 32 bits)
Arrays are supported, but the data on the modbus device must be continuous for each array you add to your script. For example, if an integer array in Winscript is configured to poll holding registers of a modbus device starting at address 0, then the first element of the array corresponds to address 0, the second element corresponds to address 1, and so on.
Integer variables in Winscript use 32 bits by default, but only the least significant 16 bits will be filled from the modbus device. When using the 32-bit Holding Register data type, two adjacent 16-bit holding register values will be concatenated into one 32-bit Winscript integer.
Enabling Automatic Polling
With a script opened in Winscript, navigate to "Resources" at the top of the window, then select "Devices." Select "New" to add a Modbus device, using the Modbus manufacturer and model:
On the next screen, select "modbus_client" as the protocol:
Then, navigate to "Resources" at the top of the Winscript window and select "Device Variables." In the device dropdown, select the name of your modbus device and click "New." Follow the instructions in the variable wizard to make your device variable sync with a PLC tag. You should see new entries in the Device Variables list with modbus info in the "Details" column. See arrReadHoldingRegs and arrWriteHoldingRegs below:
The variables you create in this wizard will automatically sync with the modbus device at the configured addresses. Variables with read access will update in Winscript automatically on the interval specified in the "Poll Every" box. Variables with write access will cause a modbus write command to be sent on the frame in which they are written in Winscript.
Best results have been achieved when using two device variable arrays: one for reading from the PLC and one for writing to the PLC.
NOTE: Many modbus clients exhibit a turnaround time of 10ms or more. If you read and write to the same modbus device within the same frame, you may observe 1-2 frames of jitter at higher frame rates.