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

**URL:** <https://discourse.nodered.org/t/usb-serial-port-how-to-send-a-message-like-pyserial/25794>\
**Category:** General\
**Created:** [30 April 2020 05:53 UTC](https://discourse.nodered.org/t/usb-serial-port-how-to-send-a-message-like-pyserial/25794 "2020-04-30T05:53:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![canoe](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@canoe](https://discourse.nodered.org/u/canoe)\
**Post date:** [30 April 2020 05:53 UTC](https://discourse.nodered.org/t/usb-serial-port-how-to-send-a-message-like-pyserial/25794/1 "2020-04-30T05:53:20Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [30 April 2020 08:34 UTC](https://discourse.nodered.org/t/usb-serial-port-how-to-send-a-message-like-pyserial/25794/2 "2020-04-30T08:34:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [30 April 2020 09:38 UTC](https://discourse.nodered.org/t/usb-serial-port-how-to-send-a-message-like-pyserial/25794/3 "2020-04-30T09:38:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![canoe](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@canoe](https://discourse.nodered.org/u/canoe)\
**Post date:** [30 April 2020 15:59 UTC](https://discourse.nodered.org/t/usb-serial-port-how-to-send-a-message-like-pyserial/25794/4 "2020-04-30T15:59:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![canoe](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@canoe](https://discourse.nodered.org/u/canoe)\
**Post date:** [30 April 2020 16:33 UTC](https://discourse.nodered.org/t/usb-serial-port-how-to-send-a-message-like-pyserial/25794/5 "2020-04-30T16:33:04Z")

</div>

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](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"}]

---

<div class="post-metadata">

**Author:** ![canoe](https://avatars.discourse-cdn.com/v4/letter/c/848f3c/32.png) [@canoe](https://discourse.nodered.org/u/canoe)\
**Post date:** [30 April 2020 19:41 UTC](https://discourse.nodered.org/t/usb-serial-port-how-to-send-a-message-like-pyserial/25794/6 "2020-04-30T19:41:20Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 May 2020 19:41 UTC](https://discourse.nodered.org/t/usb-serial-port-how-to-send-a-message-like-pyserial/25794/7 "2020-05-14T19:41:21Z")

</div>

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