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.
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.
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.
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.
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 (' ')"