# Modbus Server Device – Assigning Tag Associations to Modbus Storage

The Modbus Plugin allows you to assign Tags to specific memory addresses of a Modbus Server device, thereby exposing some portions of the local Modbus Server storage as tags.

To assign a tag to a memory address, double-click on the Modbus Server device in the Project Explorer, or right-click the device and select the Assign Tags of the context menu. Either action will open the Modbus Server Configuration UI tab for that Modbus Server device:

Each row in the Configuration UI represents an association between a Cognex Designer tag and a range of memory addresses of the Modbus Server device. For example, a 16-bit signed integer allocates one memory slot, while a 32-bit signed integer allocates two memory slots that will be associated with the tag. The available settings and controls are described below:

Setting | Description
Endianness | Sets the endianness used in the Modbus Server storage. The available values are the following: System Default (this is the default setting) Little Endian Big Endian Note: The Endianness setting is used only in case of numerical tag types (short, ushort, int, uint, single, double).
Byte Swapping | Sets Byte Swapping used in the Modbus Server storage. The available values are the following: Swap Bytes in 16-bit words Do not swap Bytes in 16-bit words (this is the default setting)
Connection Properties... | Opens the Connection Properties dialog of the Modbus Server device. You can also open this dialog by right-clicking on the device in the Project Explorer, and then selecting the Properties option in the context menu.
Upload / Download | Allows you to upload or download data between the Modbus Server device storage and the specified tag with the applicable buttons: : Uploads the data from the Modbus Server device storage to the tag. This button can be used for value initialization, and is only enabled if there are no validation errors. : Downloads the data from the tag to the Modbus Server device storage. This button can be used for value initialization, and is only enabled if there are no validation errors.
Tag | Specifies the name of the Tag that will be assigned to the specified memory area. An auto-completion list helps you to select the exact tag, and you can select any of the existing tags of the project. The Type of the tag can be selected from a list of types that are interpretable on the Modbus storage. By default, Cognex Designer selects the Type that is probably the "best" according to the selected data format. The available tag types are the following: Boolean Int16 UInt16 Integer UInt32 Long UInt64 Decimal Byte[] String Single Double When the specified tag name does not match any of the existing tags, a button is available to create a new tag with the specified name. Clicking this button opens the Create New Tag for the Association dialog, used to create a new tag for the selected association. Use the Tag Name property to specify the name of the new tag, then use the Type drop-down list to specify the type of the tag.
IO Type | Specifies the type of the Modbus Server storage to which the Tag will be assigned. Possible values are: Coils Discrete Inputs Input Registers Holding Registers (this is the default value)
Starting Address | Sets the starting address of the Modbus Server storage the tag will be assigned to. The value range of this property is 0 – 65534.
Unit Count | Represents the allocated IO units (bits or 16-bit registers) on the selected IO Type of the Modbus Server storage. This property is only editable if the value of the Format property is set to ASCII Text, Byte Array, Short Array, or Bit Array. When editable, the value range of this property is 1 – 65535. If not editable, the property shows the pre-determined value of the selected Format. This is 1 for Single bit and 16-bit data formats, 2 for 32-bit data formats, and 4 for 64-bit data formats.
Bit Offset | Determines which bit of the 16-bit IO unit will be assigned to the Tag. This option is only available if the IO Type property is set to Holding Register or Input Register and the Format property is set to Single Bit. When available, the value range of this property is 0 – 15.
Format | Specifies the data format in the Modbus Server storage, determining the interpretation of the data on the Modbus Server. The available values and their related settings and compatibility scenarios with other settings are the following:
Data Format | Applies Endianness | Applies Byte Swapping | Default Type When Creating New Tag | Acceptable for 1-Bit Size Units? | Acceptable for 16-Bit Size Units?
Single Bit | No | No | Boolean | Yes | Yes
16-bit signed integer (default) | Yes | Yes | Integer | No | Yes
16-bit unsigned integer | Yes | Yes | Integer | No | Yes
32-bit signed integer | Yes | Yes | Integer | No | Yes
32-bit unsigned integer | Yes | Yes | Long | No | Yes
32-bit floating point | Yes | Yes | Double | No | Yes
64-bit floating point | Yes | Yes | Double | No | Yes
ASCII Text | No | Yes | String | No | Yes
Byte Array | No | Yes | Byte[] | No | Yes
Short Array | No | Yes | Int16[] | No | Yes
Bit Array | No | No | Boolean[] | Yes | No
For further data formatting, you can assign the data to a byte array and process it with PLC formatting Task Blocks.
| Adds a new association between a tag and a range of memory addresses of the Modbus Server device. Use the (Remove) button in the column to remove an existing association.

Note:

When you modify the contents of the Configuration UI, it will be validated automatically. The following validation rules are used:

- The same Tag cannot be used for more than one association.
- The associated memory areas must be disjointed.
- The Starting Address must be between 0 – 65534 (inclusive).
- The data Format must be supported by the target IO Type (see the above table).
- The tag Name must match an existing Tag’s name.
- The sum of the address and unit count must not be greater than 65535.
- The Unit count must be between 1 – 65535 (inclusive).

If the contents of the Configuration UI are not valid, the invalid cells are indicated in the dialog in red. If this is the case, the modifications are not applied to the underlying device until you fix the errors. As such, the device always uses the latest valid state.

If a tag is assigned to a memory address, every write operation will be forwarded to this storage. Also, any time the storage is written by a Modbus Client device, the new value will be assigned to the tag.