How to send this HEX command to my device using Node-red

Hello all, I want to send hex commands to my device using Node red. I'm new to node red and JavaScript, what is the way to send this command in the proper way. I want to write it in a function. The device is connected via serial port and on rs232 interface. The things that I have tried:

var buf = Buffer.from([0xaa,0x3f,0x00,0x00,0xf0,0x11]).toString;
msg.payload = buf;
return msg;

2-

var buf = Buffer.from([0xaa,0x3f,0x00,0x00,0xf0,0x11]);
msg.payload = buf;
return msg;

3-

var buf = Buffer.from(['aa','3f','00','00','f0','11']);
msg.payload = buf;
return msg;

And some more ways, like without using a function. In most cases I'm getting no response. I'm pretty sure of the physical connections, since using a different software which is UART Assistant and over the same port with same settings, the device is responding to the same command that I send.
The timestamp node is connected to a function having the code mentioned in option 2, and then this function is connected to a 'serial in' node with these settings that are suitable to communicate with my device: the serial port is COM 1, the baud rate is 38400, data bits 8, parity none, stop bits 1. Then this node is connected to a debug node to check the output. Note that with the same settings I was able to communicate with the device via ASCII commands, now I'm obliged to control via HEX commands; I'm pretty sure that the connections are right.
Note that the output when I inject is an error: "TypeError: The List[1]" argument must be an instance of Buffer or Unit8Array. Received type is string (' ')"
Via the UART Assistant, I'm sending also over COM1 with the exact same settings, the HEX code in this format: aa3f0000f011 and it is working.

Welcome!

I don't know if this will help as I haven't used it (yet), but it does appear to do what you need. Checksum I think you will need to calculate yourself.

node-red-contrib-buffer-parser

Without having your physical setup, we wouldn't be able to test.

Thank you @mudwalker for the reply.
Can you please explain more, I did not get your idea.

The node might help convert some of your commands to numbers and then you can extract the relevant bits. The problem I have always found with these interfaces is that they can be 'touchy'.

Can you give an idea of what it is you are sending to? People in here might have tried and succeeded before.

I'm sending these commands to a robot arm that is designed by a Chinese company. I will try using the node you suggested and reply with the result.

Any link to a manual?
Any flow you can post?
What version of NR and npm are you using?

If it works with the UART, it suggests that the format you are sending is incorrect.
Can you see what the UART is sending?
Do you have a Debug node that you can monitor at/close to the output?

The more information you give, the more help it might be possible to give.

Yes the image posted above is from the manual and the form the UART Assistant is sending the command is like this: AA 3F 00 00 F0 11
The Node-RED's version is 3.0.2 and the node.js version's 16.18.1
And yes I'm attaching a debug node to monitor the output. The output is mostly empty and the serial node will timeout after 10s of no response.

You are sending lower case from NR, UART appears to send upper case. However, I am completely guessing because I am having to interpret your descriptions etc. Nothing solid to work on.

The problem is that I have tried sending in so many different ways, capital letters, small letters, strings, with 0x prefix and without, .... All lead to an empty response after the timeout. :stuck_out_tongue:

They seem to highlight 4 bytes

var buf = Buffer.from([0xaa,0x3f,0x00,0xf011]); /* 170, 63, 0, 17 */
msg.payload = buf;
return msg;

:man_shrugging:

Still same issue. I actually tried this too

The values in the array must by bytes. 0xf011 will get truncated.

is the correct way to format this assuming there are no Endian issues.

If endianness is an issue, then you can use the buffer maker to generate your data.

1 Like
var buf = Buffer.from([0xaa,0x3f,0x00,0xf011]); /* 170, 63, 0, 17 */
msg.payload = buf;
return msg;

Actually this format alone when sent, leads to an error: "TypeError: The List[1]" argument must be an instance of Buffer or Unit8Array. Received type is string (' ')"

Does this mean you have had SOME responses?

If yes, then I would suggest you restart the Node-RED instance and the end device to clear any buffered issues.

No no responses, either timeout or error.

Where do you see this error?

I assume the debug panel? Which node generates this error? (highlight the error with your mouse & the responsible node should be shown)

Yes the error is seen from the debug. The responsible node is the serial in node

Can you please explain this topic more? And how can I use the buffer maker?

can you show us

  1. what is coming out of function 4
  2. what settings the keyto serial node has set (and its config)

Read the built in help

Try the built in demos (CTRL-I to open the import dialog)