Hello.
At first I could not configure the data exchange with the pulse counter via usb-rs232.
Then I learned about the need to add a new environment variable in Windows (JAVA_TOOL_OPTIONS = -Dfile.encoding=ISO-8859-1)
The pulse counter must accept a string of hexadecimal values. After that he issues an answer.
val AskСoldChannel = ‘\u0000\u0006\u0026\u0017\u0001\u000E\u0001\u0000\u0000\u0000\u0041\u00CF\u002F\u00D6’
sendCommand(Serial_string,AskСoldChannel)
Next, I discard the insignificant part of the answer and leave only the value of the counter.
logInfo(“Demo”,Serial_string.state.toString.substring(PulsarAnswerValueStartAt,PulsarAnswerValueEndAt).bytes.toString)
The counter has a program from the manufacturer. It issues a query string and a response string. Here is the response string from this program:
[0, 0, 0, 0, 40, 68, E9, 40] - HEX
[0, 0, 0, 0, 64, 104, 233, 64] - DEC
But these values are given by this program. In Openhab, everything is different. In the Openhab log file I get the following response:
[0, 0, 0, 0, 64, 104, -23, 64] - DEC
-23??? What??? There must be 233!
-23 DEC = FFFF FFFF FFFF FFE9 in HEX ! In the end we see the desired E9! But why the value is negative?
Then I wrote down the new value in the counter. It is 1234567890
Then I read the counter value using the manufacturer’s program:
[00, 00, 80, B4, 80, 65, D2, 41] HEX
Then I read the value of the counter using serial binding:
[0, 0, -128, -76, -128, 101, -46, 65] DEC
-128? -76? -46?
Hmmmmm… -128 DEC = FFFF FFFF FFFF FF80 in HEX
-76 DEC = FFFF FFFF FFFF FFB4 in HEX
-46 DEC = FFFF FFFF FFFF FFD2 in HEX
What’s happening? Whence negative values? The counter accurately gives the correct values (checked with Arduino).