0
Answered

Sending Hex data

Mike Slattery 6 years ago in Bugs and problems updated by Aleksandr Romanov (CTO) 6 years ago 2

I am trying to send embedded hex data and seem to be having issues.Is there another way to do this?


From Main program

Matrix.sendData(camSlot[myCamera], 3, "\x81\x01\x04\x00\x03\xFF");

Matrix Driver


function SendMsg(msg) {
// IR.Log("SendMsg: " + msg);
this.device.Send([msg]);
}


this.sendMsg = SendMsg;

function SendData(slot, baud, data) {

this.sendMsg("/+" + slot + "/" + baud + ":" + data + ".");

}

this.sendData = SendData;


What is received using Hercules Server in hex.

{81}{01}{04}{03}{C3}{BF} 

Missing the \x00 and \xFF get changed to C3 BF 

GOOD, I'M SATISFIED
Satisfaction mark by Mike Slattery 6 years ago
-1

I figured it out. You have to send as hex converted to ASCII and parse through the data.


if (val < 17)
num = 0 + val.toString(16);
else
num = val.toString(16);
Matrix.sendData(camSlot[myCamera], 3, "81 01 04 3F 02 " + num + " FF", 1);

function SendData(slot, baud, data, hex) {
if (hex) {
var partData;
this.sendMsg("/+" + slot + "/" + baud + ":");
for (var ndx = 0; ndx < data.length; ndx = ndx + 3) {
partData = data.substring(ndx, ndx + 2);
// IR.Log("partMSG: " + partData);
this.sendMsg(parseInt(partData, 16));
}
this.sendMsg(".");
}
else
this.sendMsg("/+" + slot + "/" + baud + ":" + data + ".");
}
this.sendData = SendData;