Modbus Write Task
Write data to Modbus servers with write tasks.
Write tasks are the primary method for sending control commands to a Modbus server from Synnax.
Prerequisites
Before configuring the task, you’ll need to have connected to a Modbus server.
A Short Primer on Tasks
Tasks are the primary method for communicating with devices in Synnax. Tasks can be used for both control and data acquisition purposes. A Modbus Write Task defines a background process that writes data to Holding Registers or Coils on the Modbus server based on values written to Synnax command channels.
A Modbus Write Task can be started, stopped, and re-configured at any time. Synnax permanently stores the configuration of the task, so it’s easy to set up multiple tasks for different purposes.
How Commands Work in Synnax
Commands in Synnax use command channels to signal a task to write values to the device. For example, to set a Holding Register to a specific value, you would write that value to the corresponding command channel.
A command channel for a Holding Register might be
modbus_server_holding_register_100_cmd, where modbus_server is the device
identifier, holding_register is the register type, 100 is the register address, and
_cmd indicates that it’s a command channel.
Command channels also have an associated index channel that stores the timestamps at
which commands were sent. This channel is suffixed with _cmd_time. For the command
channel modbus_server_holding_register_100_cmd, the index channel would be
modbus_server_holding_register_100_cmd_time.
Write tasks process commands from these command channels and send the appropriate Modbus write requests to the device. The task continuously monitors command channels and writes new values as they are received.
Open the Task Configuration Dialog
To create a write task from the command palette, open the Synnax Console and click on
the Search and Command Palette at the top. You can also open this palette with
Ctrl+Shift+P on Windows and Cmd+Shift+P on macOS.
In command mode (enabled when the first character in the input is ”>”), type “Modbus”. You’ll see an option called “Create a Modbus Write Task”. Select this option to open the write task configuration dialog.
Task Configuration Parameters
| Field | Description |
|---|---|
| Name | A name for your write task. |
| Modbus Device | Which Modbus server the task will write to. |
| Data Saving | Data saving defines whether command data will be permanently stored in Synnax. When enabled, Synnax will store a record of all commands sent. When disabled, only the most recent command will be kept in memory. |
Writable Register Types
For write tasks, you can write to two types of Modbus registers:
| Register Type | Description | Data Width |
|---|---|---|
| Coil Output | Write to discrete output Coils. Used for binary control signals like turning devices on/off. | 1 bit (boolean) |
| Holding Register Output | Write to analog output registers. Used for control values like setpoints, speeds, or positions. | 16 bits (configurable data type) |
Input Registers and Discrete Inputs are read-only register types and cannot be used in write tasks. To read from these registers, use a read task.
Data Types for Holding Registers
For Holding Register outputs, you can specify the data type for each channel. Synnax supports the following data types:
| Data Type | Description | Size |
|---|---|---|
int16 | 16-bit signed integer | 1 register (2 bytes) |
uint16 | 16-bit unsigned integer | 1 register (2 bytes) |
int32 | 32-bit signed integer | 2 registers (4 bytes) |
uint32 | 32-bit unsigned integer | 2 registers (4 bytes) |
float32 | 32-bit IEEE 754 floating point | 2 registers (4 bytes) |
Coil Outputs are always boolean values and do not require a data type specification.
For multi-register data types (int32, uint32, float32), make sure the byte and
word ordering matches your server’s configuration. Use the “Swap Bytes” and “Swap
Words” settings in the device connection configuration if needed.
Adding Channels to a Task
To add a channel to a task, click the “Add Channel” button in the task configuration dialog. For each channel, you’ll need to specify:
- Register Type - Select from Coil Output or Holding Register Output
- Address - The Modbus register address (e.g., 0, 100, 40001)
- Data Type - For Holding Registers, select the data type (
int16,uint16,int32,uint32,float32) - Channel Name - A descriptive name for the command channel
You can enable or disable individual channels using the toggle button to the right of each channel. This is useful for temporarily stopping command processing for specific channels without removing them from the task.
Configuring the Task
Once you’ve added all your channels and configured the task parameters, click the “Configure” button to save the task configuration. This will create Synnax command channels for each of your Modbus outputs and prepare the task for execution.
Note that configuring a write task will only create command channels. The task will process commands from these channels and write the values to the Modbus server.
After configuration, you can start and stop the task at any time. The task configuration is permanently stored, so you can easily resume command processing later.
Stopping and Starting Tasks
To stop and start a task, you can open up the Tasks Toolbar on the left-hand side and click play and pause. You can also click the play/pause icon in the bottom of the task configuration window.
Using a Schematic to Control Write Tasks
Once the write task is configured and running, you can use a schematic to send commands to the Modbus server. Simply connect schematic controls (like buttons, sliders, or valves) to the command channels created by your write task.
For example, to control a valve connected to a Coil Output, you would set the valve’s
command field to the command channel of the Coil Output. Clicking the valve in the
schematic would send a command to toggle the Coil state.