How Can We Help?
Read Coil Status 0x (FC=01) in Modbus RTU with HMI
This tutorial concerne only the HMI Modbus Master function FC01. This is a special function for special cases and experts.
Function code Read Coil Status 0x (FC=01) in Modbus of the HMI
By default, the function code Read Coil Status 0x (FC=01) in Modbus of the HMI 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 from register 32 (INT(34/8)*8) with a length of 8 bits (i.e. bits 32 to 40). It will then retrieve bit 34.
Thus, to read bits 33, 34, 35 and 36 from the same screen, it will send a single request (register 32 length 8)
But some equipments do not support this type of reading.
Read only the requested bits, not by bytes
In the picture 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) into their respective directories where the HMI-Tool software is located (C:\Program Files (x86)\HMITool7.0)
- Add this macro in “Init Script”.
#include "MacroInit.h"
void Macro_main(IN *p)
{
MarcoInit
//ToDo
//RemoveHMIError = 0;// For the right "ReadCoilStatus FC=01" : Add files modbus_rtu_master.dll and modbus_rtu_master.so
LocalWord[50100]=1; // Set to 1 to have a "ReadCoilStatus FC=01" which reads by bit and not by byte
}
- Make sure that the symbols (Bit Lamp,..) of the bits you want to read are on a different screen than the startup screen (there must be a change of screen for this to take effect)
- Load the project and test!