Some Modbus issues with ADAM6250

I thought I know how to handle Modbus devices but it seems that there are still quite a lot to learn.

I bought Advantech ADAM 6250 device for pulse counting purposes and I’m now testing it. I have connected a simple potential free switch to one DI. By toggling this switch I can see that the pulse counter is working by using Modbus Master software. Also when using Advantech’s Adam/Apax software I can see pulses generated. My problem now is that I can’t reset this counter. With the Adam/Apax software it works so the setup of ADAM6250 device is OK.

According to the manual the Modbus commands are:

Code (Hex) Name Usage
01 Read Coil Status Read Discrete Output Bit
02 Read Input Status Read Discrete Input Bit
03 Read Holding Registers Read 16-bit register. Used to read integer or
floating point process data.04 Read Input Registers
05 Force Single Coil Write data to force coil ON/OFF
06 Preset Single Register Write data in 16-bit integer format
08 Loopback Diagnosis Diagnostic testing of the communication port
0F Force Multiple Coils Write multiple data to force coil ON/OFF
10 Preset Multiple Registers Write multiple data in 16-bit integer format

Manual says that counter values are in MB registers:

Address (4X) Channel Description Attribute
40001 – 40002 0 Read
40003 – 40004 1 Read
40005 – 40006 2 Read
40007 – 40008 3 Read
40009 – 40010 4 Read
40011 – 40012 5 Read
40013 – 40014 6 Read
40015 – 40016 7 Read

Reading of channel 0 (with MB Master software) works; in fact I need to read MB regs 0 and 1.

And finally according to the manual clearing of the counters:

Address (0X) Channel Description Attribute
00041 0 Write
00042 1 Write
00043 2 Write
00044 3 Write
00045 4 Write
00046 5 Write
00047 6 Write
00048 7 Write

If I have understood the manual correctly I need to write “1” in order to clear the counter. So I have tried to write “1” to MB reg 41 both with function code 05 and 06 . I am using both MB Poll and MB master softwares and in both cases I get a message saying “Write succeeded” but when reading MB regs 0-1 the counter hasn’t been cleared. Any ideas? I’m pretty sure that rossko57 has a solution to this problem.

Nope, unfamiliar with this device. :pensive:

Strongly advise persisting with this to find out what works, before trying to configure openHAB. It’s much easier to experiment.

That would suggest manual is using “register numbers”, and for software that uses “register address” (like openHAB) you would ‘subtract one’ for same address.

FC05 is for single-bit coils, might work as a switch.It does have a counterpart FC15 (0F hex) for multiple registers.

FC06 is for writing 16-bit registers. It does have a counterpart FC16 (10 hex) for multiple registers.

A few devices insist on using FC15 / FC16 even for one-register writes. They usually throw an error if you try the wrong thing though.

Thanks anyway. I agree that I need to get this working with MB Master/MB Poll before trying to configure OH. I have made some progress with the device when configuring one DI channel as a latch. I can clear the latch status (in MB regs 57-64) and I can also get the date/time stamp for the latch channel in OH. I will eventually connect a rheed relay in my mail box to this latch channel. So I don’t quite understand why resetting the counter regs doesn’t seem to work. I have now contacted tech support at Advantech so let’s see if they have any ideas.

rossko57 I have made some progress with the ADAM device when using Modbus Poll software. The ADAM6250 manual is somewhat misleading because I thought that I should write “1” when clearing the counter. I discovered that I need to write “ON” with function code 05. “ON” corresponds to FF 00. In addition, there is again an offset so the MB reg for channel 0 is 40 instead of 41.

Now I’m somewhat confused how to handle this in OH. Obviously I need to create an Item for MB reg 40, e.g. Adam_reg40. Is this a string or what? Then I need to create a Modbus Data Thing, e.g. Adam_reg40_write and link Adam_reg40 to it but what is the Write Value Type, individual bit? In a rule what is the command, is it something like:

 Adam_reg40.sendCommand(255 00)

or is it:

Adam_reg40.sendCommand(FF 00)

Replying to myself. I realized that the Item should be a number and that FF 00 corresponds to 65280 (=255*2^8+0) so I need to write this to MB reg 40. Now the counter is cleared.

I still have one issue. I have now on/off switch but is there a simple way to create a simple button and when pressing it, my script runs and clears the counter?

You’re overthinking all this. Modbus FC05 is used with “coil” type binary registers. It’s routine to treat such registers as ‘switches’. It’s part of Modbus protocol to write “on” using FF00, the binding does this for you.

Just create a Switch type openHAB Item and link it to the switch channel of your Modbus data Thing. Command the Item ON.

Whether you need to arrange to set the Item back OFF again all depends on how your device works. If you’re read-polling the coil and it sets itself ‘off’ again, that will get reflected in your linked Item. If you’re not reading it back, obviously that will not happen.

Yes, you are quite right. Your solution is really nice and much simpler than mine. Many thanks again for your help.