Send command to serial port and receive a answer

yes you are right.
then I need to read two defined binary bytes and convert to binary (numbers).

Is somewhere a list of commands which I can use in DSL rule?

It’s worth highlighting that when in a DSL rule you do something like
myString.get(7)
it is actually a Java operation. The variable object myString will be a Java string object, and the .get() method is a standard method of that Java object type.

So no “list of DSL commands” would include xxx.get() - it’s not DSL, it’s something that comes with the Java object that the DSL is using.

The bottom line is that I’ve found no useful guide to DSL features, apart from finding examples and experimenting. However, identifying if you are looking for a method of a Java object opens up the whole web of Java guides.

2 Likes

to read a exact bytes from data received on the serial port
this instruction will read all bytes into array named bytes ? :
val byte[] bytes = RawType.valueOf(SerialBridge_BinaryData.state.toString()).getBytes()
so then I only need read exact bytes ?:

val byteone = new byte (bytes.get(7))
val bytetwo = new byte (bytes.get(8))

but there is a error :
Cannot instantiate the primitive type byte;

still searching for easiest way how to extraxt 16temperature values

ok after a lot of tests and errors I make this code :

val char[] hexArray = "0123456789ABCDEF".toCharArray()
val byte[] bytes = RawType.valueOf(SerialBridge_BinaryData.state.toString()).getBytes()
val char[] hexChars = newCharArrayOfSize(bytes.length() * 2)
	 for (var j = 0; j < bytes.length(); j++) {
	 var int v = bytes.get(j).bitwiseAnd(0xFF)
	 hexChars.set(j * 2, hexArray.get(v >>> 4))
	 hexChars.set(j * 2 + 1, hexArray.get(v.bitwiseAnd(0x0F)))
   }
logInfo("Debug",hexChars.toString)
 
    var Number header1
    var Number header2
    var Number header3
    var Number header4
    header1 = bytes.get(0)
  header2 = bytes.get(4)
  header3 = bytes.get(5)
  header4 = bytes.get(6)
  logInfo("Debug", header1.toString)
  logInfo("Debug", header2.toString)
  logInfo("Debug", header3.toString)
  logInfo("Debug", header4.toString)

and output:

now I’m trying understand how it’s linked together - HEX and DEC number
Also not sure what’s difference between var and val definition

ok I changed part of my code to this:

    header1 = bytes.get(0)
  header2 = bytes.get(1)
  header3 = bytes.get(2)
  header4 = bytes.get(6)

and output is :

so clear for me is that F,F is -1
next F,F is -1
next 1,0 is 16 (10H is 16DEC)
and 1,F is 31 (1FH is 31DEC

but why F,F is -1 and not 255?

You need to investigate “two’s complement” binary numbers. It’s a long-standing computer to method to represent negative numbers in a byte or binary word - there is no minus sign available in 0/1 coding .

so, in bytes
00000001 (hex 01) represents a decimal number 1
00001111 (hex 0F) represents a decimal number 15
we can go up to 127 that way, but here comes the magic.
we’ll use that topmost bit to represent “minus”
11111111 (hex FF) means decimal -1
You can think of it that if we start from zero
00000000
and take away 1 - which is what -1 means - we get
11111111
because there are no overflow or carry bits, we’ve only got 8 bits.
Then
11111110 (hex FE) means -2, etc.

Bottom line is, if you ask to print the numeric value of a byte with hex FE, it will print -2
The bit pattern is always 11111110, we’re only talking about what meaning we give to it.

And also not sure what’s difference between var and val definition

A val is like a constant, you cannot change it later.

but datas are changing. It’s array and I’m writing data into

Looks like while other programming languages define signed ( -N … 0 … +(N-1) and unsigned ( 0 … N ) data types java only has signed data types: Java Data Types

Every time you run this rule, this val creates a new variable called bytes. You can’t change that variable later on in the rule, but you don’t need to.
Wben the rule has finished, bytes is thrown away.
Next time you run this rule, this val creates a new variable called bytes

Thank you. It’s more clear fór me.
Is it possible in UI create a object with more parameters? I want create object with parameters like: real temperature, requested temperature, type of unit, mode, calculation constat and etc,

Which UI? What do you mean by “object”, are you still talking about rules or Things, or are we on to GUI widgets for display and control now? If widget, start a new thread for new topics for best response.

My idea for better orientation was to make under openhab a group “radiator_room1” and under this group I will add items like so on the end I have :
radiator_room1.real_temp (and it’s number)
radiator_room1.req_temp (number)
radiator_room1.used (boolean)
radiator_room1.tem_constant (number)
… etc
Don’t know if it’s possible

It’s one of the purposes of Groups.

My problem is that I can’t find any button create group.
I found that I can add item into parrent group, but searching how to create

edit: forgot please. I found. Under item I must select type Group

A Group is just a specialized Item.

if I will read a exact byte prof the serial port :

val byte[] bytes = RawType.valueOf(SerialBridge_BinaryData.state.toString()).getBytes()
var Number header1
header1 = bytes.get(0)

how to convert header1 to binary ? I want also read only some bits, because some configuration informations are only in some bits

header1 is binary. What do you want to do with it?

Use bitwise AND that you’ve already seen in some examples.

Good. thanks. Right Now for me a modbus Is working, also USB/rs485. Ebus communication is in development - making USB/ebus adapter.
Thanks a lot for great support and for patience with me.

1 Like