How Can We Help?

Print

Reading the status of coil 0x (FC=01) in Modbus RTU with HMI

 

This tutorial only covers the Modbus master function of the FC01 HMI. This is a special function for special cases and experts.

Function code Read Coil Status 0x (FC=01) in the HMI Modbus

By default, function code Read Coil Status 0x (FC=01) in the HMI Modbus reads the bit register in bytes.
This means that to read the bit in register 34, the HMI will send a “Read Coil Status FC01” request to read register 32 (INT(34/8)*8) with a length of 8 bits (i.e. bits 32 to 40). It then retrieves bit 34.

So, to read bits 33, 34, 35 and 36 of the same screen, it will send a single request (register 32 length 8)

However, some devices do not support this type of reading.

Read only the bits requested, not by bytes

In the image on the right, we can see that we are reading register 34 from the coil for length 1 only.

  • Copy these 2 files (modbus_rtu_master.dll and modbus_rtu_master.so) in their respective directories where the HMI-Tool software is located (C:\NProgram Files (x86)\NHMITool7.0)
  • Add this macro to “Init Script”.
    • #include "MacroInit.h"
      void Macro_main(IN *p)
      {
      MarcoInit
      //ToDo
      //RemoveHMIError = 0;// For the correct "ReadCoilStatus FC=01": Add the files modbus_rtu_master.dll and modbus_rtu_master.so
      LocalWord[50100]=1; // Set to 1 to have a "ReadCoilStatus FC=01" that reads by bit and not by byte
      }
  • Make sure that the symbols (Bit Lamp,…) for the bits you want to read are on a different screen to the start-up screen (there must be a screen change for this to take effect)
  • Load the project and test it!