The following instructions are for both Modbus RTU (TModBusRTUDriver class) and Modbus TCP (TModBusTCPDriver class). To configure a protocol+tag connections you have to do:

  1. Insert a communication port appropriate for the chosen Modbus protocol:
  2. Insert the chosen protocol component;
  3. Connect the protocol to the port, through the “CommunicationPort” property;
  4. Insert the tags manually or through the “Tag builder” tool
  5. If you insert the tags manually, set the properties as described below;
  6. Connect the tag to the protocol driver through the ProtocolDriver property present in each tag.

Both protocol classes support the following tag classes:

  • TPLCTagNumberplctagnumber
  • TPLCBlockplcblock
  • TPLCStructplcstruct
  • TPLCStringplcstring


To configure a tag to use Modbus, you must configure the following tag properties:

  • PLCStation: Modbus equipment address. For Modbus TCP, this property has its value set to 1, it usually depends on the Modbus Server implementation.
  • MemAddress: Address of the input/output/register that you want to read/write. The addresses start from zero, always. Do not use the address notation 1xxxxx, 2xxxxx, 3xxxxx, 4xxxxx, as it is not supported.
  • MemReadFuntion: Function that will be used to read the tag. See table below.
  • MemWriteFuntion: Function that will be used to write tag values. See table below.

For the MemReadFunction and MemWriteFunction properties the following values are accepted according to the desired memory area:

DESIRED AREA MemReadFunction MemWriteFunction
Digital inputs 2 0
Coils (digital outputs) 1

5 (TPLCTagNumberplctagnumber)

15 (TPLCTagNumberplctagnumber TPLCBlockplcblock TPLCStructplcstruct TPLCStringplcstring)

Registers 3

6 (TPLCTagNumberplctagnumber)

16 (TPLCTagNumberplctagnumber TPLCBlockplcblock TPLCStructplcstruct TPLCStringplcstring)

Analog registers (analog inputs) 4 0
Device status 7 0

You need to know the ModBus functions your device supports.

2 thoughts on “Modbus RTU and TCP

  1. Popescu Dragos Reply

    I need to read digital inputs from an ICPDAS modbus module, M-7054, using standard 02 function “(0x02) Read discrete inputs”.
    The string to send into module is “adr_byte 0x02 start_input (2bytes) count (2bytes) CRC (2bytes)”. The response will be according to the standard.

    Please tell me how do I do this, using PascalScada Tags?
    I’m using 0.7.3 version.

    • Fabio Luis Girardi Post authorReply


      Few steps:

      1) Insert a TSerialPortDriver into your app and set up it with the same serial settings of your device and activate it.
      2) Insert a TModbusRTUDriver and set CommunicationPort Property to point to Serial Port created on the previous step.
      3) Insert a TPLCTagNumber and set:
      3.1) MemAddress to point to your Digital Input (address starts from zero – 0)
      3.2) MemReadFunction to 2 “(0x02) Read discrete inputs”
      3.3) PLCStation to point to your Modbus slave address;
      3.4) Set property ProtocolDriver to point to ModbusDriver created in step 2.
      3.5) Assure that TagType is pttDefault or pttBit;

      4) Put a THMILabel into your app/form and link it with the tag created at step 3.

      5) If everything is set accordingly, you will see the label showing values 0 or 1, depending on the state of your digital input. The digital input can vary depending on your Modbus device.

Leave a Reply

Your email address will not be published. Required fields are marked *