usb-Serial-port:how to send a message like Pyserial?

I am using a usb-serial with /dev/ttyUSB0, in RaspberryPi, I can send/receive messages as following python code,
#python-start
command = b'\x01\x04\x00\x00\x00\x02\x71\xcb'
with serial.Serial("/dev/ttyUSB0", baudrate=9600, timeout=1.0) as ser:
ser.write(command)
s = ser.read(11)
print(s)
##response example,
b'\x01\x04\x04\x08\xb9\x13\x85\xe4\x92'
###python-end

Now, I want to use Node-red "node-red-node-serialport", failed.
What I am trying,
#nodered function
var b = Buffer.from([1,4,0,0,0,2,113,203]);
msg.payload = b;

I tried "inject" with "buffer" ["0x01","0x04","0x00","0x00","0x00","0x02","0xe4","0x92"].
It doesn't work, why?

Have you tried injecting a buffer of [1,4,0,0,0,2,113,203]

Perhaps you also need to send an end character like LF or CR or ETX?

The end char can be set in the serial node settings.

and which serial node are you using - from the look of your python you should be using the serial request node.

Thank you for your help~,
Hardware: {Raspberry Pi 4 / [usb(ch340)-rs485]}====={sensor:temperature}
Software: {os:"Raspbian GNU/Linux 10 (buster)", [python:3.7.3, pyserial :3.4], Node-RED version: v1.0.3, Node.js version: v10.15.2, Linux 4.19.97-v7l+ arm LE, node-red-node-serialport: 0.10.1}

because I want to request/reply and retrieve the values, so Request-node.

unfortunately, LF,CR,LF/CR,ETX verified, as "https://www.cisco.com/c/en/us/td/docs/ios/12_4/cfg_fund/command/reference/cfnapph.html"

Forgive me on the long post.
And here is my flow,
[{"id":"8cacebbb.7d8c18","type":"inject","z":"2924cfef.17058","name":"","topic":"","payload":"[1,4,0,0,0,2,113,203]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":390,"y":320,"wires":[["6efba883.73d928","29211535.f8deca"]]},{"id":"29211535.f8deca","type":"debug","z":"2924cfef.17058","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":550,"y":240,"wires":},{"id":"6efba883.73d928","type":"serial request","z":"2924cfef.17058","name":"","serial":"fa73b26e.94d4c","x":550,"y":320,"wires":[["29211535.f8deca"]]},{"id":"fa73b26e.94d4c","type":"serial-port","z":"","serialport":"/dev/ttyS0","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"1000","bin":"bin","out":"time","addchar":"","responsetimeout":"10000"}]

Thank you Steve-Mcl, it works as what you said.
Here is change,
var buf = Buffer.from([0x01,0x04,0x00,0x00,0x00,0x02,0x71,0xcb,0xda]);

Thank you all, for your help!

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