Sending HEX Values in TCP Binding

Hi all and @kgoderis,

I’m having trouble sending out hex values through the TCP binding. The problem is similar to that seen in this thread via the serial binding:

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

The TCP binding seems to be hardcoded to use ASCII. There is a line in the openhab.cfg for changing this:

tcp:charset=ASCII

But entering ISO-8859-1 or anything else doesn’t seem to do anything based on a cursory glance at the binding source.

// used character set
private static String charset = “ASCII”;

I think this was discussed before:

https://groups.google.com/forum/#!topic/openhab/bX-j9DKvR_A

Is there anything that can be done to address this? Specifically, I send a string:
JVC_Projector.sendCommand(’\u0021\u0089\u0001\u0050\u0057\u0030\u000A’)
and the transmitted variables are: 21 3F 01 50 57 30 0A
So 89 is converted to 3F, which is not correct. Apparently anything over 63 (or 3F) is not translated. Likely secondary to a mismatch in the characterset.

Thanks so much for your time!

1 Like

I need an integration with this (also TCP and HEX). The HEX codes all start with FF (> 63). So I guess I don’t even should try the TCP binding?

I had some luck using transformation maps & escape codes.

I created a new binding so I could send the HEX values directly.

I’ve gotten it to work finally, but with no acceptable transformation.

String JVC_Projector “JVC Projector [%s]” {tcp=">[10.111.15.68:20554:*]"}

I can now send and receive HEX values, and it works great! But there are lots of errors in the logs.

2015-11-17 05:25:09.034 [ERROR] [t.protocol.internal.TCPBinding] - transformation throws exception [transformation=, response=??PW]
java.lang.IllegalArgumentException: given transformation function '
’ does not follow the expected pattern ‘()’
at org.openhab.binding.tcp.protocol.internal.TCPBinding.splitTransformationConfig(TCPBinding.java:238) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.transformResponse(TCPBinding.java:253) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.internalReceiveChanneledCommand(TCPBinding.java:72) [bundlefile:na]
at org.openhab.binding.tcp.AbstractSocketChannelBinding.internalReceiveCommand(AbstractSocketChannelBinding.java:892) [bundlefile:na]
at org.openhab.core.binding.AbstractBinding.receiveCommand(AbstractBinding.java:96) [org.openhab.core_1.8.0.201511070241.jar:na]
at org.openhab.core.events.AbstractEventSubscriber.handleEvent(AbstractEventSubscriber.java:42) [org.openhab.core_1.8.0.201511070241.jar:na]
at org.eclipse.equinox.internal.event.EventHandlerWrapper.handleEvent(EventHandlerWrapper.java:197) [org.eclipse.equinox.event_1.2.200.v20120522-2049.jar:na]
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:197) [org.eclipse.equinox.event_1.2.200.v20120522-2049.jar:na]
at org.eclipse.equinox.internal.event.EventHandlerTracker.dispatchEvent(EventHandlerTracker.java:1) [org.eclipse.equinox.event_1.2.200.v20120522-2049.jar:na]
at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) [org.eclipse.osgi_3.8.2.v20130124-134944.jar:na]
at org.eclipse.osgi.framework.eventmgr.ListenerQueue.dispatchEventSynchronous(ListenerQueue.java:148) [org.eclipse.osgi_3.8.2.v20130124-134944.jar:na]
at org.eclipse.equinox.internal.event.EventAdminImpl.dispatchEvent(EventAdminImpl.java:135) [org.eclipse.equinox.event_1.2.200.v20120522-2049.jar:na]
at org.eclipse.equinox.internal.event.EventAdminImpl.sendEvent(EventAdminImpl.java:78) [org.eclipse.equinox.event_1.2.200.v20120522-2049.jar:na]
at org.eclipse.equinox.internal.event.EventComponent.sendEvent(EventComponent.java:39) [org.eclipse.equinox.event_1.2.200.v20120522-2049.jar:na]
at org.openhab.core.internal.events.EventPublisherImpl.sendCommand(EventPublisherImpl.java:56) [org.openhab.core_1.8.0.201511070241.jar:na]
at org.openhab.model.script.actions.BusEvent.sendCommand(BusEvent.java:84) [org.openhab.model.script_1.8.0.201511070241.jar:na]
at org.openhab.model.script.actions.BusEvent.sendCommand(BusEvent.java:51) [org.openhab.model.script_1.8.0.201511070241.jar:na]
at sun.reflect.GeneratedMethodAccessor223.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:729) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._featureCallOperation(XbaseInterpreter.java:713) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) [org.eclipse.xtext.util_2.3.0.v201206120633.jar:na]
at org.openhab.model.script.interpreter.ScriptInterpreter.internalFeatureCallDispatch(ScriptInterpreter.java:69) [org.openhab.model.script_1.8.0.201511070241.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateMemberFeatureCall(XbaseInterpreter.java:549) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at sun.reflect.GeneratedMethodAccessor57.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) [org.eclipse.xtext.util_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._evaluateBlockExpression(XbaseInterpreter.java:321) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source) ~[na:na]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0]
at org.eclipse.xtext.util.PolymorphicDispatcher.invoke(PolymorphicDispatcher.java:291) [org.eclipse.xtext.util_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:218) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:204) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.ClosureInvocationHandler.doInvoke(ClosureInvocationHandler.java:46) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at org.eclipse.xtext.xbase.interpreter.impl.AbstractClosureInvocationHandler.invoke(AbstractClosureInvocationHandler.java:28) [org.eclipse.xtext.xbase_2.3.0.v201206120633.jar:na]
at com.sun.proxy.$Proxy79.apply(Unknown Source) [na:na]
at org.openhab.model.script.internal.actions.TimerExecutionJob.execute(TimerExecutionJob.java:44) [org.openhab.model.script_1.8.0.201511070241.jar:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-all-2.1.7.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-all-2.1.7.jar:na]
2015-11-17 05:25:09.522 [ERROR] [t.protocol.internal.TCPBinding] - transformation throws exception [transformation=null, response=?PW@?PW0]
java.lang.NullPointerException: null
at java.util.regex.Matcher.getTextLength(Matcher.java:1283) ~[na:1.8.0]
at java.util.regex.Matcher.reset(Matcher.java:309) ~[na:1.8.0]
at java.util.regex.Matcher.(Matcher.java:229) ~[na:1.8.0]
at java.util.regex.Pattern.matcher(Pattern.java:1093) ~[na:1.8.0]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.splitTransformationConfig(TCPBinding.java:235) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.transformResponse(TCPBinding.java:253) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.parseBuffer(TCPBinding.java:149) [bundlefile:na]
at org.openhab.binding.tcp.AbstractSocketChannelBinding.parseChanneledBuffer(AbstractSocketChannelBinding.java:999) [bundlefile:na]
at org.openhab.binding.tcp.AbstractSocketChannelBinding.execute(AbstractSocketChannelBinding.java:1680) [bundlefile:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.8.0.201511070241.jar:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.8.0.201511070241.jar:na]
2015-11-17 05:25:09.524 [ERROR] [t.protocol.internal.TCPBinding] - transformation throws exception [transformation=, response=?PW@?PW0]
java.lang.IllegalArgumentException: given transformation function '
’ does not follow the expected pattern ‘()’
at org.openhab.binding.tcp.protocol.internal.TCPBinding.splitTransformationConfig(TCPBinding.java:238) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.transformResponse(TCPBinding.java:253) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.parseBuffer(TCPBinding.java:149) [bundlefile:na]
at org.openhab.binding.tcp.AbstractSocketChannelBinding.parseChanneledBuffer(AbstractSocketChannelBinding.java:999) [bundlefile:na]
at org.openhab.binding.tcp.AbstractSocketChannelBinding.execute(AbstractSocketChannelBinding.java:1680) [bundlefile:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.8.0.201511070241.jar:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.8.0.201511070241.jar:na]
2015-11-17 05:25:09.673 [INFO ] [org.openhab.model.script.JVC: ] - ?PW@?PW0
2015-11-17 05:26:14.663 [ERROR] [t.protocol.internal.TCPBinding] - transformation throws exception [transformation=null, response=PJ_OK]
java.lang.NullPointerException: null
at java.util.regex.Matcher.getTextLength(Matcher.java:1283) ~[na:1.8.0]
at java.util.regex.Matcher.reset(Matcher.java:309) ~[na:1.8.0]
at java.util.regex.Matcher.(Matcher.java:229) ~[na:1.8.0]
at java.util.regex.Pattern.matcher(Pattern.java:1093) ~[na:1.8.0]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.splitTransformationConfig(TCPBinding.java:235) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.transformResponse(TCPBinding.java:253) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.parseBuffer(TCPBinding.java:149) [bundlefile:na]
at org.openhab.binding.tcp.AbstractSocketChannelBinding.parseChanneledBuffer(AbstractSocketChannelBinding.java:999) [bundlefile:na]
at org.openhab.binding.tcp.AbstractSocketChannelBinding.execute(AbstractSocketChannelBinding.java:1680) [bundlefile:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.8.0.201511070241.jar:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.8.0.201511070241.jar:na]
2015-11-17 05:26:14.666 [ERROR] [t.protocol.internal.TCPBinding] - transformation throws exception [transformation=, response=PJ_OK]
java.lang.IllegalArgumentException: given transformation function '
’ does not follow the expected pattern ‘()’
at org.openhab.binding.tcp.protocol.internal.TCPBinding.splitTransformationConfig(TCPBinding.java:238) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.transformResponse(TCPBinding.java:253) [bundlefile:na]
at org.openhab.binding.tcp.protocol.internal.TCPBinding.parseBuffer(TCPBinding.java:149) [bundlefile:na]
at org.openhab.binding.tcp.AbstractSocketChannelBinding.parseChanneledBuffer(AbstractSocketChannelBinding.java:999) [bundlefile:na]
at org.openhab.binding.tcp.AbstractSocketChannelBinding.execute(AbstractSocketChannelBinding.java:1680) [bundlefile:na]
at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.8.0.201511070241.jar:na]
at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.8.0.201511070241.jar:na]

Any ideas around how to structure the item?

{tcp=">[10.111.15.68:20554:*]"}

…Doesn’t seem to work and throws this exception…

java.lang.IllegalArgumentException: given transformation function ‘*’ does not follow the expected pattern ‘()’

A. conf/services/tcp.cfg
#ISO-8859 valid range: 0-255, i.e. any valid short int
charset=ISO-8859-1

B. conf/transform/getValue.js

(function(str) {
    var re = "";
    for (var i = 0, len = str.length; i < len - 1; i++) {
        re += str[i].charCodeAt(0).toString(16);
    }
    return re;
})(input)

C. conf/items/demo.items
String Item_Name “HEX Str” (gC) {tcp="<[127.0.0.1:*:‘JS(getValue.js)’]"}