[APP][Pro] Modbus

@RonnyW Yes, writing is actually working now! Many thanks!

Two observations:

  • One has to provide the size of 2 when writing, otherwise a Modbus error occurs. I was under the impression that size is ignored for anything but string, but this obviously isn’t the case here.
  • When writing in test mode, the bytes returned are not in the order that they are actually written, e.g. when writing -2500 in test mode with INT32-LE (16-bit Word LE) the bytes FF FF F6 3C are returned instead of F6 3C FF FF.

And one more thing: I don’t think that INT32-LE (16-bit Word LE) is a good term here:

  • The individual registers itself are in Big Endian, not Little Endian.
  • I wouldn’t use LE for the ordering of the registers, as this might be confusing. Maybe something like “INT32 (reverse register order)” might be more intuitive?

The write card has no size input field. You can only select the type and the amount ob bytes is defined internally.

I found the bug. The app first swaps the bytes and writes then. It must be in other order :slight_smile:
So the FF FF F6 3C are written. I wonder why you got the correct value reading again?
I’ll provide a fix for that.

It’s LE, but only based on 16bit/2byte pairs instead of single bytes.
Example (BE):
11 22 33 44 55 66 77 88
88 77 66 55 44 33 22 11
77 88 55 66 33 44 11 22

You see, it’s LE over all, but some Modbus manufacturer are reading the 16bit registers as single 16bit element these elements are placed in LE order. Only for 32bit it looks as just the registers are switched.

New test version 0.7.2:

  • Fixed (U)INT-LE 16bit for write register flow card

@CaptainVoni FYI

Sorry, I meant to write “One has to provide the size of 2 when reading”. When I provide the type INT32, why should it need the size?

I’m a little afraid that this fix will break it here, but I’ll try. :wink:

This :point_up_2: exactly. It’s now broken again. It displays now the bytes in the correct order when using “test mode”, but writing is completely screwed up. If I want to write -1000 (FF FF FC 18, which should be written as FC 18 FF FF if “INT32-LE (16-bit Word LE)” is used), I now have to write -65470465 (FC 18 FF FF).

Reading still works!

Actually I found out that my charger uses Modbus ascii and I can comunicate with the charger wireless via the Elfin-11 from my laptop. But as far as i can see, this app only support Modbus RTU, so need to ask @RonnyW if he could implement support for ascii (just sending a RAW message as a string). :blush:

Strange. That would mean the device exports registers as LE, but writes as BE and internally converts to LE :thinking:

The app is writing now in the same way how the registers are read.
So I think I will keep it as it is for now. But in your case, writing as INT32 should work, too, because it’s using the unswapped bytes.

Perhaps @Edwin_Biemond has used such 16bit LE values for writing in his app?

1 Like

New test version 0.7.3:

  • Fixed type based size in read register flow card.

@CaptainVoni Size is fixed now. It’s only needed for dynmaic size values like String and Byte.

1 Like

Correct. For reading I now have to use “INT32-LE (16-bit Word LE)” with size 2 (size 1 returns an error), and for writing I have to use INT32. Very strange.

Fixed it - now reading also works without size. Thanks!

Is the “Elfin” a LAN/TCP dongle and supports Modbus TCP?
Then you can use this app. Try to read a register with type STRING. I’m curious to see if this works

Thats correct, the Elfin device just passes the information it gets over wifi over to the modbus device and passes the reply back.
Not sure what I should use as the adress and size. The message Looks like this !0 01 and The reply is >0 01 v6.0. More info regarding the commands is here: https://www.hjemmeautomasjon.no/applications/core/interface/file/attachment.php?id=5817

The app (and used NodeJS module) only supports Modbus TCP, not ASCII.

I can’t access the URL.
Can you configure the dongle to use ModbusTCP on LAN and ASCII on serial side?

Ronny - I see you updated Modbus recently. The flowcards I set up previously now have a Mode entry - Test or Live.
Do I need to go and set all these to live?
Screenshot 2024-04-10 at 5.07.35 PM

No, not needed to change this. “Live” is default - see flow card hint (question mark). The test mode is to check the resulting bytes that would be written based on type conversion.

I have used the IP and Port 502 to connect homey to my device but it will not connect. Homey write connect EALREADY and my IPs. If I use a modbus Software to check homey it seems that homey is not reachable as if the port is blocked. Do I have to do somenting in the settings in homey?

you inserted the IP/port of your Modbus device?
And this device is configured to use Modbus/TCP?

You can’t reach Homey on this port. Homey connects to the target device and uses a random
outgoing port.
Perhaps the target device doesn’t disconnect. You cna try to restart the app in Homey and try again.


Thanks for your effort with this very long awaited app Ronny! Great!

I’m using the app for Modbus TCP and it works very well!

But I’m also trying to connect to units using Modbus RTU, with a 8-bit protocol. (For this I’m using a TCP/RTU converter.)

I manage to read data but cannot write.
My guess is that I need a possibility to read/write using Int8/Uint8-formats as well.
Would it be possible to implement this as well? :pray:

Thanks in advance!

BR, Fredrik

Modbus TCP uses 16bit registers.
Are you sure, your device uses 8bit registers? What values are you trying to write? Also 8bit or 16bit (2x8bit like writing a 32bit INT into 2 registers on Modbus TCP)?
I think a TCP/RTU converter should convert the 16bit TCP register in 2 8bit values. But I don’t know any RTU details.

What data type are you using to read an 8bit register? One of the little endian types to get filled the first of the two bytes?