Home > Mobile >  How to use QT modbus TCP to write a register value
How to use QT modbus TCP to write a register value

Time:05-18

I do the TCP server, to write 01, 40009, I can now use QModbusServer setdata values, but you can't get a message on the client side using the simulator,
 
//if there is no defined modbus serial port, direct return
if (! ModbusDevice)
{
STD: : cout & lt; <"The Modbus communication failure, please check whether the configuration is correct!" return;
}
QString str2="9 c490001020001";
For (int I=0; i <10; I++)
{
Int j=2 * I;
QString str1=str2. Mid (j, 2);
bool ok;
Quint16 hex=str1. ToInt (& amp; Ok, 16);
//qDebug (" % d ", hex);
Ok=modbusDevice - & gt; SetData (QModbusDataUnit: : HoldingRegisters, I, hex);
//STD: : cout & lt;
}

  •  Tags:  
  • Qt
  • Related