coassoftwaresystems / delphi-modbus

Delphi ModbusTCP components
114 stars 61 forks source link

Read and write registers 4x #54

Open ilariaAnd opened 2 years ago

ilariaAnd commented 2 years ago

Hi, I develop with delphi 10.2.
I have to read (and write) registers 4x. I have no problems for the registers of type unsigned INT(16bit) -readHoldingRegister- , but i don't know how to read and write the registers of type unsigned long/float (32bit)

Any suggestions? Thanks. Ilaria

rcervenan commented 2 years ago

Hello, for long type try this (let's say your long variable is starting on address 11)

var Data: array[1..4097] of Word; DataC: DWord; val,pos,cnt: Integer; begin pos := 1; cnt := 51; if mctPLC.ReadHoldingRegisters(pos, cnt, Data) then ... pos := 11; LongRec(DataC).Hi := Data[pos]; LongRec(DataC).Lo := Data[pos+1]; ...