Translations:Modbus RTU в виде custom protocol/9/en
Материал из WebHMI Wiki
function readRegister (reg, device, unitId)
--- FORMING REQUEST ----------- -- slave address request[1] = unitId; -- function code request[2] = device.xtraFields[1] -- address of register request[3] = GetHiByte(reg.internalAddr) request[4] = GetLoByte(reg.internalAddr) -- count of registers local count = 1 if (reg.dataType == 3) then -- double word count = 2 end request[5] = GetHiByte(count) request[6] = GetLoByte(count) -- CRC local crc = GetCRC(request, 2) local crcLo,crcHi = 0,0 -- will be used below too crcLo = GetLoByte(crc) ; request[7] = crcLo crcHi = GetHiByte(crc) ; request[8] = crcHi