Help with binary data - serial binding 3.1

I have a set of rules that worked fine in Openhab 2 running the Serial binding (Openhab V1 binding), but I am having trouble getting it to work with Openhab3 and the new serial binding.

The item Icomcontrol is a string that receives binary data. The old item description appears here:

String Icomcontrol "Icom Control" { serial="COM7,CHARSET(ISO-8859-1),BASE64" }

So, for the Serial binding in Openhab 3, I performed the configuration in the UI. I selected COM7 for the serial port, ensured the baud rate (9600) and parameters (8N1) were the same as for the prior version that was working. I selected ISO-8859-1 in the Charset option for the Thing, and for the Item, I linked Icomcontrol to the Binary Data channel with the default profile selected.

The data coming in have a lot of extra characters attached to them. Namely, my log file is showing:

2021-09-25 22:05:42.879 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:3120b580f4:data triggered PRESSED
2021-09-25 22:05:44.018 [INFO ] [openhab.event.ChannelTriggeredEvent ] - serial:serialBridge:3120b580f4:data triggered PRESSED

The extra information appears to be “data:application/octet-stream;base64”, and the characters do not make sense. They are not the hex-coded bytes I was expecting to receive. My rule does not process them correctly:

rule icomstring
	 Item Icomcontrol received update
	 if (autoant.state == ON) {
	 val char[] hexArray = "0123456789ABCDEF".toCharArray()
	 val byte[] bytes = DatatypeConverter::parseBase64Binary(Icomcontrol.state.toString())
         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)))
	 val outString = new String(hexChars)
	 val icomband = transform("REGEX", ".*(..)00FD.*", outString)
 	 logInfo("rule check values", "command: " + icomband)
	 if (icomband == "01") {
				sendCommand(Antcontrol, "2:2:160\n")
				postUpdate(antband,"160 Meters")
			else if (icomband == "03") {
			sendCommand(Antcontrol, "2:2:80\n")
				postUpdate(antband,"80 Meters")
			else if (icomband == "07") {
			sendCommand(Antcontrol, "2:2:40\n")
				postUpdate(antband,"40 Meters")
			else if (icomband == "10") {
			sendCommand(Antcontrol, "2:2:30\n")
				postUpdate(antband,"30 Meters")
			else if (icomband == "14") {
			sendCommand(Antcontrol, "2:2:20\n")
				postUpdate(antband,"20 Meters")
			else if (icomband == "18") {
			sendCommand(Antcontrol, "2:2:17\n")
				postUpdate(antband,"17 Meters")
			else if (icomband == "21") {
			sendCommand(Antcontrol, "2:2:15\n")
				postUpdate(antband,"15 Meters")
			else if (icomband == "24") {
			sendCommand(Antcontrol, "2:2:12\n")
				postUpdate(antband,"12 Meters")
			else if (icomband == "28" || icomband == "29") {
			sendCommand(Antcontrol, "2:2:10\n")
				postUpdate(antband,"10 Meters")

The rule is looking for the bytes FEFE009800 to then identify BCD elements to extract and then act upon. I suspect I have a simple setting wrong. Can anyone help me with this please?

My platform: Openhab 3.1 on Windows 10.

Many thanks,


Try replacing line:

val byte[] bytes = DatatypeConverter::parseBase64Binary(Icomcontrol.state.toString())


val byte[] bytes = RawType.valueOf(Icomcontrol.state.toString()).getBytes()


Thank you very much for your help. That correction fixed my problem right away!

Many thanks,


1 Like

This suggestion was solve my issue thanks for sharing this is useful.