Hex String to Binary

Hello - I am trying to convert a Hex String to Binary, then sending binary to a device using TCP Request Node. However, the device is not responding correctly. So far, I have the following code. Not really sure what I'm doing. The hex to binary string seems to be working, but I'm not sure about how to convert the binary string to raw binary. Any advice would be appreciated.

Inject string: "57 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 CF 1B 55 AA 00 55 AA 02 00 00 00 00 00 00 55 AA 40 00 00 00 00 01 54 00 00 02 00 00 00 00 00"

Function fnHex2Bin
 	msg.payload = msg.payload.split(" ");
 	var result = "";
 	msg.payload.forEach(str => {
 	 result += (parseInt(str,16).toString(2));  //hex base-16
 	})
 	msg.payload = new Buffer(result);
 return msg

what about this...

Function fnHex2Bin
 	msg.payload = msg.payload.split(" ");
 	var result = [];
 	msg.payload.forEach(str => {
 	 result.push(parseInt(str,16));  //hex base-16
 	})
 	msg.payload = new Buffer(result);
 return msg

Yes! That Worked! I've been trying to sort out this integration for weeks now. Thank you!

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.