Help with modbus binding and transformation

I don’t know.

You did say you tried
import java.math.BigInteger.
but you keep showing us
import java.lang.Math
are you sure you tried that?

now this code:

import java.math.BigInteger

rule “update reg40017 register”
when
Member of reg40017_Bits received command
then
var register = BigInteger.valueOf(0)
if ( reg40017.state != NULL && reg40017.state != UNDEF) {
register = (reg40017.state as DecimalType).toBigDecimal.toBigInteger
}
switch triggeringItem.name {
case “reg40017_bit_16_0” : {
if (receivedCommand == ON) {
register = register.setBit(0)
} else if (receivedCommand == OFF) {
register = register.clearBit(0)
}
}

and I do not see errors on my log, but bit is not set, and only warnings in the log:
2019-09-22 20:15:07.827 [WARN ] [ernal.handler.ModbusDataThingHandler] - Thing modbus:data:id2:poolpoll:bit_16_2 ‘bit_16_2’: not processing command ON since writeStart is missing and transformation output is not a JSON

Ed

maybe to ad some debug log messages???

because no errors, but when i switch a bit, it’s reads value, and set me back

i use autoupdate=true in items

Yeee.

change it autoupdate to false, and seems start to work, let me check…

Ed

Hello,

yes, now works as expected. And thanks for help. Now I have last question, maybe you also can help me. to open pool I need to set “ON” to bit 2 for 3 seconds, and then after 3 second I need to send OFF. now I am doing this manual. but I assume it’s possible to write in Rule?
variable: “reg40017_bit_16_2”

Ed

Thanks,

works, now I can finish myself everything else. one more time, thanks

Ed

Hello,

can I ask one more question? I have in modbus one register is hour 00…23, and second is minutes 00…59. how i can use it as a datetime those values? and only manage and see time. because if I use date variable, i see full time, but i only want to see time hh:mm. and also this wariable is r/w

ed

That’s fine, for display you need only format the part you want.

DateTime someItem “my label [%1$H:%1$tM]”

1 Like

Hello,

one more question. How it’s possible to read uint8 from 16 bit register???. I have time in uint16, but low 8 bit is hour, and high 8 bit is minutes.

Ed

It’s in the docs


and there is an example

        // Extract high or low byte of the 16-bit register as unsigned 8-bit integer (uint8)
        Thing data input1502lo [ readStart="1502.0", readValueType="uint8" ]
        Thing data input1502hi [ readStart="1502.1", readValueType="uint8" ]

Hello,

thanks for you help. is it possible to see all bits in paper UI like I see them from modbus:
image
because I see them separately…

Edward

I don’t really know what you mean. PaperUI is an administration UI and doesn’t offer many choices about how things get displayed.
If you want to create a custom display, use one of the proper user-oriented UIs; BasicUI with sitemaps, HABpanel, etc.

that’s one i know

Hello,

I assume to change and write I also need to use rule. Maybe you have example for lo/hi byte update rule?

Ed

No specific example for bytes. Principle would be the same as bits - assemble separate Items into one register image, and command that.

Merging two “bytes” into one register wouldn’t need bit manipulation, the new value would be ((hi * 256) + lo))

Hello,

I have time in 64bits. I read value as uint64, and seems Number is a not right item. because I see it correct as a string, but Number is decimal, and I can’t use operations like or/and/>>/<< …

How I can operate with 64bits? or I need to operate with string?

I need to transform 64bits ([secon,dayofweek]:[hour:minute]:[month:day]:[yearhi,yearlo]) to datetime.

Ed

Can’t comment on operations of yours that we cannot see.
If you are talking about ‘and’, and I think bit-shifting? you would probably need to use some fairly exotic Java functions to obtain these for 64 bit integers.

Is your data perhaps encoded as BCD, not binary?

Give some details. This doesn’t sound like datetime in 64 bits. It sounds like 8 bytes of encoded information. We already covered how to extract bytes.

Hello,

Yes, I can read multiple uint16, then extract lo and hi, and then create multiple rules… but Now I have idea, and maybe it’s works.
I can read one single uint64. in this uint64 I can work only as a string, because Number format truncate it. in uint64 I receive a string: “3969090754143982356”

" 3969090754143982356" = 37:15:0B:03:02:0A:13:14‬ = sec, min, hour, dayofweek, day, month, yearlo, yearhi

I found some github function: https://github.com/peterolson/BigInteger.js

my task is from uint64 use javascript and transform to datetime

Ed

That’s interesting, it would be nice to see an example. It’s my understanding that the Number type used in openHAB internally holds numbers as Java BigDecimal types - and that should be expandable to any precision in theory.
Some part of openHAB framework may limit it.

Carry on. The binding provides all the tools to read a collection of bytes, but of course you do not have to use those and could do something different.

You could implement all or part in a JS transform at the channel. I think I’d probably do that in two parts - one JS to get date from two registers, one to get time from the other two.

It’s worth reminding that there is no such thing as 64-bit or even bytes at the Modbus protocol level. Everything is handled as 16-bit registers, and how we choose to use or arrange those is up to us.