On December 17, 2017 at 09:29, Rene Lou said...
Hi pete S
If you need to send hex data, this method will work as well:
socket.write("\x04\x01\x00\x00\x00\x00\xE0\x00");
socket.write("\x04\x00\x00\x00\x00\x00\xE0\x00");
or
var string_1 = "\x04\x01\x00\x00\x00\x00\xE0\x00";
var string_2 = "\x04\x00\x00\x00\x00\x00\xE0\x00";
socket.write(string_1);
socket.write(string_2);
or
var cmd_array = ["\x04\x01\x00\x00\x00\x00\xE0\x00", "\x04\x00\x00\x00\x00\x00\xE0\x00"];
socket.write(cmd_array[0]);
socket.write(cmd_array[1]);
or a combination, eg:
var cmd_array = ["\x01", "\x00"];
var string_header = "\x04";
var end_of_package = "\x00\x00\x00\x00\xE0\x00";
socket.write(string_header + cmd_array[0] + end_of_package);
socket.write(string_header + cmd_array[1] + end_of_package);
Just use \x before the hex and put it between "" since it has to be a string.
Rene
Yep - that's what I thought as well. That works fine for serial, but just doesn't send anything (according to wireshark) on a tcpsocket. Hence, the need to convert it to a string. Oh well, works now.