Samsung TV with Global Cache IP2SL Hex issues

I’m trying to write a plug in for a Samsung TV using a global Cash IP 2 Serial gateway (GC-100-6). I have been using it with iRule and it works fine. The problem I’m having is the Hex data that is actually being sent is getting changed from what I’m intending to send. I have confirmed the code to be correct via iRule and the global cache iTest tool. I am trying to send \x08\x22\x00\x00\x00\x02\xD4. When I monitor the traffic with wire shark

From the iTest tool (Correct and works):
Data (7 bytes)
Data: 082200000002d4
[Length: 7]

From Home Remote:
Data (8 bytes)
Data: 082200000002c394
[Length: 8]

The last bit is changed from d4 to c3 and 94 is added.

Below is the plug in, It’s still rough, I copied the Runco plug in as a template. Once I get it past proof of concept I will clean it up and share it.

plugin.Name = “SamsungTV_RS_232”;
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 1200000;
plugin.DefaultSettings = {
“Host” : “10.37.250.56”,
“Port” : “4999”,
};

var VERSION = “2021-05-1”;

var socket = new TCPClient();

var mediaCommandMappings = {
“PowerOff” : “\x08\x22\x00\x00\x00\x01\xD5”,
“PowerOn” : “\x08\x22\x00\x00\x00\x02\xD4”
};

var inputSourceMappings = {
“HDMI1” : “\x08\x22\x0a\x00\x05\x00\xc7”,
“Input2” : “\x08\x22\x0A\x00\x05\x01\xC6”,
“Input3” : “\x08\x22\x0A\x00\x05\x02\xC5”,
“TV” : “\x08\x22\x0A\x00\x00\x00\xCC”,
};

//Channell UP :\x08\x22\x03\x00\x01\x00\xD2
//Channel Down: \x08\x22\x03\x00\x02\x00\xD1
// helper function to clear the socket receive buffer

function flushReceiveBuffer() {
if(socket.available) {
socket.receive();
}
}

function onChangeRequest(device, attribute, value) {
console.log(“onChangeRequest called…”);
var cmd;
switch(attribute) {
case “MediaCommand”:
case “InputSource”:

        //var cmd = "";

        if(attribute == "Switch") {
            if(value == "On") {
                cmd = mediaCommandMappings["PowerOn"];
            } else {
                cmd = mediaCommandMappings["PowerOff"];
            }
        } else if(attribute == "MediaCommand") {
            cmd = mediaCommandMappings[value];
        } else if(attribute == "InputSource") {
            cmd = inputSourceMappings[value];
        }

        if(cmd) {
            console.log(plugin.Name + "  sending command: " + " (" + value + ") " + cmd);
            //socket.send(cmd + "\r");
		socket.send(cmd);			
        } else {
            console.log("ERROR: inputsource unsupported command: " + value);
        }
        break;

    case "Switch":

        //var cmd = "";

        if(attribute == "Switch") {
            if(value == "On") {
                cmd = mediaCommandMappings["PowerOn"];
            } else {
                cmd = mediaCommandMappings["PowerOff"];
            }
        } else if(attribute == "MediaCommand") {
            cmd = mediaCommandMappings[value];
        } else if(attribute == "InputSource") {
            cmd = inputSourceMappings[value];
        }

        if(cmd) {
            socket.send(cmd);
            console.log(plugin.Name + "  sending switch command: " + " (" + value + ") " + cmd);
        } else {
            console.log("ERROR: inputsource unsupported command: " + value);
        }
        break;
    default:
        console.log("ERROR: default unsupported attribute type: " + attribute);
        break;
}

}

function onConnect() {
console.log(“onConnect called…”);

var host = plugin.Settings["Host"];
var port = plugin.Settings["Port"];

console.log("  Host: " + host);
console.log("  Port: " + port);

var device = plugin.Devices[plugin.Name];

if(device) {
    console.log("  setting supported media commands...");
    device.SupportedMediaCommands = Object.keys(mediaCommandMappings);
    console.log("  set...");

    console.log("  setting supported input sources...");
    device.SupportedInputSources = Object.keys(inputSourceMappings);
    console.log("  set...");
}

console.log("  connecting...");
socket.connect(host, port);
console.log("  connected");

// get projector status

// projectorGetStatus();
}

function onDisconnect() {
console.log(“onDisconnect called…”);
socket.close();
console.log(" disconnected");
}

function onPoll() {
var device = plugin.Devices[plugin.Name];

if(device && (device.HasSubscribers("InputSource")
                || device.HasSubscribers("Switch")
            )) {

    console.log("polling for projector status...");

    // refresh the projector status
   // projectorGetStatus();
}

}

function onSynchronizeDevices() {
console.log(“onSynchronizeDevices called…”);

var device = new Device();

device.Id = plugin.Name;
device.DisplayName = "Samsung TV";
device.Icon = "TV";
device.Capabilities = [ "MediaControl", "MediaInputSource", "Switch" ];
device.Attributes = [ ];

plugin.Devices[plugin.Name] = device;

console.log("  done syncing");

}

Instead of sending a string, send an array of bytes. Here’s an example that should help.

That did it, Thanks!!!