Dzień dobry czy ktoś z Was miał podobny problem, tzn chce za pomoca holding registers przekazywać dane po TCP/IP ( STEROWNIK - OPENHAB) . W sterowniku dla danego rejestru np 40001 : 1bit to ON , 2 bit to OFF i tu nie ma problemu. Czy ktoś może pomóc jak po stronie OPENHAB ugryźć ten problem aby zmieniać stany bitów za pomocą zwykłego switch'a
pozdrawiam
i z góry dziękuję za wskazówki czy ewentualne rozwiązanie problemu
OK jeszcze nikt mi nie pomógł 🤣 ale dam Coś od siebie 😀 . Aby czytać/pisać poszczególne bity rejestrów w mapie modbus należy jak poniżej:
dom.items
Number reg40001 "reg40001 register [%d]" { channel="modbus:data:id2:poolpoll:reg40001:number"}
Group reg40001_Bits
Switch reg40001_bit_1_2 "Open Pool [%s]" (reg40001_Bits) {channel="modbus:data:id2:poolpoll:bit_1_2:switch"}
Bridge modbus:tcp:id2 [ host="192.168.1.130" , port=502, id=1 , timeBetweenTransactionsMillis=100 ]
{
Bridge poller poolpoll [ start=1, length=10, refresh=1000, type="holding" ]
{
Thing data reg40001 [ readStart="1", readValueType="uint16", writeStart="1", writeValueType="uint16", writeType="holding", writeMultipleEvenWithSingleRegisterOrCoil = "true" ]
Thing data bit_1_2 [ readStart="1.2", readValueType="bit"]
}
}
//import java.lang.Math // we need this for testBit
import java.math.BigInteger // we need this for testBit
rule "update reg40001 register"
when
Member of reg40001_Bits received command
then
var BigInteger register = 0 // we need BigInteger type to use testBit
if ( reg40001.state != NULL && reg40001.state != UNDEF) { // avoid using invalid register image
register = (reg40001.state as DecimalType).toBigDecimal.toBigInteger // use existing image
}
switch triggeringItem.name { // act on switched Item name to change only one bit
case "reg40001_bit_1_0" : {
if (receivedCommand == ON) {
register = register.setBit(0)
} else if (receivedCommand == OFF) { // by testing both, we will ignore REFRESH commands
register = register.clearBit(0)
}
}
case "reg40001_bit_1_1" : {
if (receivedCommand == ON) {
register = register.setBit(1)
} else if (receivedCommand == OFF) {
register = register.clearBit(1)
}
}
case "reg40001_bit_1_2" : {
if (receivedCommand == ON) {
register = register.setBit(2)
} else if (receivedCommand == OFF) {
register = register.clearBit(2)
}
}
}
// at last, write to Modbus
reg40001.sendCommand(register)
end
sitemap dom label="dom"
{Frame{
Group item=reg40001_Bits
}
}