Serial binding is not sending values above 63 in Decimal or 0x3F in HEX

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 :slight_smile:

You will notice some of it is from the DEMO. This will send a hex string containing the value from the slider/fader/dimmer.

My item file contains:

String RS485Bus “RS485Bus [%x]” (All) {serial=“COM8@115200”} //serial binding
Dimmer RS485Bus_Light_91_02 “Ceiling [%d %%]” (Bathroom, Lights) // creates the dimmer

My rules contain:

rule “RS485Bus_Light_91_02”

when

  Item RS485Bus_Light_91_02 received command

then
var Number percent

  	if(RS485Bus_Light_91_02.state instanceof DecimalType) percent = RS485Bus_Light_91_02.state as DecimalType		
	if(receivedCommand==INCREASE) percent = percent + 5
	if(receivedCommand==DECREASE) percent = percent - 5
	if(percent<0)   percent = 0
	if(percent>100) percent = 100
	postUpdate(RS485Bus_Light_91_02, percent);
			
	//Convert 0-100 range into 8bit hexadecimal.
	val Number scale = Math::floor( percent.floatValue * 2.55).intValue
	if(percent==0)
	{sendCommand(RS485Bus,'\u0091\u0002\u0001\u0008\u0000\u0010\u0020\u0002')}
	else if(percent==100)
	{sendCommand(RS485Bus,'\u0091\u0002\u0001\u0008\u00FF\u0010\u0020\u0002')}
	else 
	{sendCommand(RS485Bus,'\u0091\u0002\u0001\u0008'+ String::format("%c", scale) +'\u0010\u0020\u0002')}

end