1

enter image description hereI have a HLK-DIO16 device supporting modbus over tcp.

In the user manual I see an example to read Simultaneously 16 digital input

the string is:

0x01030026000165c1

01 device address 03 function code 0026 register initial address 0001 register number 65c1 crc

Using java code with jlibmodus library the method would be

int[] registerValues = m.readHoldingRegisters(slaveId, offset, quantity);

which parameters value for the 3 variables to reproduce the string 0x01030026000165c1

?

Giuseppe
  • 125
  • 2
  • 14
  • which version of jlibmodbus is that? – Erich Kitzmueller Jul 19 '19 at 13:32
  • in this other manual drive.google.com/file/d/… they said that modbus is only over RS interface.. for TCP HEX instruction protocol.. the "hilink" assistance drive me crazy.. I asked them a way to control the device remotely by wifi and they send me modbus specification.. So I need the hex protocol specification? do you think I will sent hex by tcp socket? – Giuseppe Jul 22 '19 at 16:28

1 Answers1

0

EDIT: the answer below applies only to Modbus RTU over serial for the particular device of the question, which does not seem to support Modbus TCP (it does have support for a different HEX protocol over TCP port 8080 though).

This is how to translate these different naming conventions:

slaveId = Device Address (01 in your case)

offset = Initial Register (from where you start reading), 0x0026 in your example above, which is 38 decimal.

quantity= Number of registers to read (that should be 0001 if you want to read 1 register, which will include 16 DIs as bits)

The function code 0x03 and CRC will be added by the library when you call readHoldingRegisters so you don't have to worry about them.

So you can do:

int[] registerValues = m.readHoldingRegisters(1, 38, 1);

And you should get those 16 bits in your registerValues variable. For instance, if you get:

registerValues=255

It would mean all your inputs are set high (to 1).

Marcos G.
  • 3,371
  • 2
  • 8
  • 16
  • thank you Marcos. I tried it but I got "ModbusIOException: 6 bytes expected, but 0 received." the connection was fine (isConnected() return true) – Giuseppe Jul 19 '19 at 11:37
  • Strange... I could not get a hold on a manual for your device. If you have a copy to share I can take a look. Sometimes the isConnected only means you have correctly created the client instance. Can you ping the device and make sure port 502 is open? – Marcos G. Jul 19 '19 at 11:42
  • the port configured is 8080 (using the default 502 the connection give a socket exception because wrong port) the manual is https://drive.google.com/file/d/1DrobylPN8ieLZpM8GIsed_zolV7RxX6M/view?usp=sharing – Giuseppe Jul 19 '19 at 11:51
  • I see the mistake now, the address should be an HEX number not an INT as I wrote. Can you try changing 26 to 38 (0x26=38 decimal)? The slaveID and quantity should be in HEX too, but those would be the same... – Marcos G. Jul 19 '19 at 12:27
  • it can't works also converting in hex. I tried a for loop over offset trying values from 1 to 100.. but nothing It's very strange.. – Giuseppe Jul 19 '19 at 12:59
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/196713/discussion-between-giuseppe-and-marcos-g). – Giuseppe Jul 19 '19 at 13:38