I am trying to send a packet of HEX codes out the serial port, but every time I try to send the packet every number is correct so long as it is below 0x3F or 63 in decimal. I am using a Null modem cable to view the sent serial data in a terminal program. Very new at OpenHAB so any help would be great.
As mentioned all the values are sent correctly except the \u0091 which shows up as 0x3F. Any values over 63 decimal value simply shows up in my terminal as 0x3F.
If I use this command
sendCommand(RS485Bus,“z”)
I then get the correct value of 0x7A, so is the serial binding limited to ASCI characters only?
I would also like to send the value of a slider and using the following line
sendCommand(RS485Bus,percent)
But this only sends the ASCI, so is there a way to convert the value of a variable to HEX?
I’m starting to think this is a bug as there is no errors reported in the logs to indicate an error, so I’ll add the following information. If you can let me know if my method is wrong or if this is a bug and how to report it that would be great.
OpenHAB 1.7 is running on windows 7 64bit, not tested under any other OS and I am running the latest Java release.
sendCommand(RS485Bus,’‘’+’\u0002\u0001\u0008\u0010\u0020\u0002’)
This works and all numbers are sent correctly in HEX as I send any hex bytes above 0x3F as an ASCII char.
sendCommand(RS485Bus,’\u0091’)
Will not send correctly and shows up as 0x3F
sendCommand(RS485Bus,’\u0097’)
Will not send correctly and shows up as 0x3F
sendCommand(RS485Bus,’\u0009’)
sends correctly and shows up as 0x09
The logs just reports “… received command ?” as the character ? equals 0x3F, or 63 in decimal.
The solution was to add an environment variable to change the default charset. I will be getting a Raspberry to run this on so its also good to know the same fix will work on that too…
Thanks to a post by John Malawic after 2 days of googling…
On win7 add to environ variables JAVA_TOOL_OPTIONS = -Dfile.encoding=ISO-8859-1
On raspberry I select en_US ISO-8859-1 and it’s ok also.
Do not know if it’s the best solution.
Better solution can be that serial binding provide a configurable charset in openhab.cfg?
File: SerialDevice.java
Like -> outputStream.write(msg.getBytes()); to outputStream.write(msg.getBytes(MyCharSet));
In case anyone else wants to send raw HEX via the serial binding, here is how I finally got it to work after adding the environment variable mentioned in my last reply. If you know of a better way please let me know
You will notice some of it is from the DEMO. This will send a hex string containing the value from the slider/fader/dimmer.
Hi @matt1, I’m glad I found this. I’m having a similar issue sending hex to a JVC projector. Everything works great except the higher numbers.
\u0021\u0089\u0001\u0050\u0057\u0031\u000A
comes across as
21 3F 01 50 57 31
I tried setting the raspberry characterset with en_US ISO-8859-1 from raspi-config but that didn’t seem to do the trick. Any other ideas? Did you get this to work with a raspberry pi?
No have not tried it yet. I have a brand new raspberry pi 2 sitting on my desk with raspbian loaded from img and have not powered it on yet. Will try in a weeks time as I am flat out building my house and installing cat6 at the moment.
Create an environment variable called JAVA_TOOL_OPTIONS
Then make it contain this string -Dfile.encoding=ISO-8859-1
If running on a raspberry pi you would need to google how to set the default character set for JAVA. Still have not done this myself on the PI so if someone does it then please post in this thread to say what needs to be done.
Also be aware this may break something else if another binding needs a different charset.