TCP Binding sending hex characters [Solved?]

I spent an evening figuring this out, so I thought I’d share this. I have an older Pioneer Elite Plasma that the documentation gives codes like this for the Power commands:

\x02**PON\x03
\x02**POF\x03

To get it to work I had to change the \x02 to \u0002. In my map file I had:

ON=\u0002**PON\u0003
OFF=\u0002**POF\u0003
2 Likes

Hmmm. Maybe I shouldn’t have marked this solved. My item file looks like

Switch PioneerPower	"Power"	{tcp=">[ON:192.168.50.146:2101:'MAP(kuro.map)'], >[OFF:192.168.50.146:2101:'MAP(kuro.map)']"}

Yes, the TV responds to commands, but the event.logs

2016-08-09 07:20:34.676 [ItemCommandEvent          ] - Item 'PioneerPlasma' received command **PON
2016-08-09 07:20:34.676 [ItemStateChangedEvent     ] - PioneerPlasma changed from NULL to **PON
2016-08-09 07:20:34.801 [ItemCommandEvent          ] - Item 'PioneerPlasma_PWR' received command OFF
2016-08-09 07:20:34.801 [ItemStateChangedEvent     ] - PioneerPlasma_PWR changed from ON to OFF
2016-08-09 07:20:34.801 [ItemCommandEvent          ] - Item 'PioneerPlasma' received command **POF
2016-08-09 07:20:34.801 [ItemStateChangedEvent     ] - PioneerPlasma changed from **PON to **POF
2016-08-09 07:20:35.067 [ItemStateChangedEvent     ] - PioneerPlasma changed from **POF to ERR
2016-08-09 07:20:35.067 [ItemStateChangedEvent     ] - PioneerPlasma changed from ERR to ERR

and openhab.log showed errors like this:

2016-08-09 07:20:35.067 [ERROR] [ing.tcp.protocol.internal.TCPBinding] - transformation throws exception [transformation=null, response=ERR]
java.lang.NullPointerException
	at java.util.regex.Matcher.getTextLength(Matcher.java:1283)[:1.8.0_25]
	at java.util.regex.Matcher.reset(Matcher.java:309)[:1.8.0_25]
	at java.util.regex.Matcher.<init>(Matcher.java:229)[:1.8.0_25]
	at java.util.regex.Pattern.matcher(Pattern.java:1093)[:1.8.0_25]
	at org.openhab.binding.tcp.protocol.internal.TCPBinding.splitTransformationConfig(TCPBinding.java:247)[198:org.openhab.binding.tcp:1.9.0.201607190111]
	at org.openhab.binding.tcp.protocol.internal.TCPBinding.transformResponse(TCPBinding.java:266)[198:org.openhab.binding.tcp:1.9.0.201607190111]
	at org.openhab.binding.tcp.protocol.internal.TCPBinding.parseBuffer(TCPBinding.java:157)[198:org.openhab.binding.tcp:1.9.0.201607190111]
	at org.openhab.binding.tcp.AbstractSocketChannelBinding.parseChanneledBuffer(AbstractSocketChannelBinding.java:1030)[198:org.openhab.binding.tcp:1.9.0.201607190111]
	at org.openhab.binding.tcp.AbstractSocketChannelBinding.execute(AbstractSocketChannelBinding.java:1766)[198:org.openhab.binding.tcp:1.9.0.201607190111]
	at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:157)[189:org.openhab.core.compat1x:2.0.0.201606271614]
	at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173)[189:org.openhab.core.compat1x:2.0.0.201606271614]

So, I set up a new instance of OH 1.8.3, to try it a different way that I read about. (Above was on OH2)

Items:

    /* Pioneer Elite Plasma Master Bedroom */
String PioneerPlasma "[%s]"  { tcp=">[192.168.50.146:2101:'REGEX((.*))']" }
Switch PioneerPlasma_PWR "Power"

Rule:

import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import java.util.regex.Matcher
import java.util.regex.Pattern

rule "PioneerPlasma Power"
when
        Item PioneerPlasma_PWR received command
then
        if(receivedCommand==ON){
                sendCommand(PioneerPlasma, "\u0002**PON\u0003")
        }
        else if(receivedCommand==OFF){
                sendCommand(PioneerPlasma, "\u0002**POF\u0003")
        }
end

The device does not respond to commands. To me, the logs look like the \u0002 and \u0003 are being removed before they are sent to the device.
events.log

2016-08-09 16:40:50 - PioneerPlasma_PWR received command ON
2016-08-09 16:40:50 - PioneerPlasma received command **PON
2016-08-09 16:40:50 - PioneerPlasma state updated to **PON
2016-08-09 16:40:50 - PioneerPlasma state updated to ERR
2016-08-09 16:40:53 - PioneerPlasma_PWR received command OFF
2016-08-09 16:40:53 - PioneerPlasma received command **POF
2016-08-09 16:40:53 - PioneerPlasma state updated to **POF
2016-08-09 16:40:53 - PioneerPlasma state updated to ERR

And openhab.log

16:40:50.077 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'PioneerPlasma Power'
16:40:50.092 [DEBUG] [i.s.RegExTransformationService:42   ] - about to transform '**PON' by the function '(.*)'
16:40:50.093 [DEBUG] [t.protocol.internal.TCPBinding:267  ] - transformed response is '**PON'
16:40:50.225 [DEBUG] [t.AbstractSocketChannelBinding:1717 ] - Picked WriteBufferElement [Channel=Channel [item=PioneerPlasma, command=2, direction=OUT, remote=/192.168.50.146:2101, buffer=, isBlocking=false, isReconnecting=false, channel=/192.168.50.6:61416::/192.168.50.146:2101, host=192.168.50.146, port=2101], buffer=**PON
, isblocking=false] from the queue
16:40:50.226 [DEBUG] [t.AbstractSocketChannelBinding:1727 ] - Sending **PON
 for the outbound channel /192.168.50.6:61416->/192.168.50.146:2101
16:40:50.400 [DEBUG] [o.o.i.r.i.b.GeneralBroadcaster:46   ] - broadcaster 'org.openhab.io.rest.internal.broadcaster.GeneralBroadcaster$1@4268d32a' is empty
16:40:50.477 [DEBUG] [i.s.RegExTransformationService:42   ] - about to transform 'ERR' by the function '(.*)'
16:40:50.478 [DEBUG] [t.protocol.internal.TCPBinding:267  ] - transformed response is 'ERR'
16:40:50.520 [DEBUG] [.r.i.resources.SitemapResource:146  ] - Received HTTP GET request at 'sitemaps/denontest/0002' for media type 'null'.
16:40:50.546 [DEBUG] [.r.i.resources.SitemapResource:146  ] - Received HTTP GET request at 'sitemaps/denontest/0002' for media type 'null'.
16:40:53.127 [DEBUG] [o.i.r.i.resources.ItemResource:205  ] - Received HTTP POST request at 'items/PioneerPlasma_PWR' with value 'OFF'.
16:40:53.129 [DEBUG] [m.r.internal.engine.RuleEngine:305  ] - Executing rule 'PioneerPlasma Power'
16:40:53.133 [DEBUG] [i.s.RegExTransformationService:42   ] - about to transform '**POF' by the function '(.*)'
16:40:53.134 [DEBUG] [t.protocol.internal.TCPBinding:267  ] - transformed response is '**POF'
16:40:53.234 [DEBUG] [t.AbstractSocketChannelBinding:1717 ] - Picked WriteBufferElement [Channel=Channel [item=PioneerPlasma, command=2, direction=OUT, remote=/192.168.50.146:2101, buffer=, isBlocking=false, isReconnecting=false, channel=/192.168.50.6:61416::/192.168.50.146:2101, host=192.168.50.146, port=2101], buffer=**POF
, isblocking=false] from the queue
16:40:53.235 [DEBUG] [t.AbstractSocketChannelBinding:1727 ] - Sending **POF
 for the outbound channel /192.168.50.6:61416->/192.168.50.146:2101
16:40:53.439 [DEBUG] [o.o.i.r.i.b.GeneralBroadcaster:46   ] - broadcaster 'org.openhab.io.rest.internal.broadcaster.GeneralBroadcaster$1@4268d32a' is empty
16:40:53.486 [DEBUG] [i.s.RegExTransformationService:42   ] - about to transform 'ERR' by the function '(.*)'
16:40:53.488 [DEBUG] [t.protocol.internal.TCPBinding:267  ] - transformed response is 'ERR'
16:40:53.498 [DEBUG] [.r.i.resources.SitemapResource:146  ] - Received HTTP GET request at 'sitemaps/denontest/0002' for media type 'null'.
16:40:53.520 [DEBUG] [.r.i.resources.SitemapResource:146  ] - Received HTTP GET request at 'sitemaps/denontest/0002' for media type 'null'.

I think the problem has to do with how the STX (0x02) and ETX (0x03) commands are handled. It looks to me that when I send using method 2, using a rule, that these are not getting sent to the plasma, but using method 1, with a map, they are getting sent.

BTW, the device has serial control, but I am using the tcp binding and an IP to serial device (digi port server).