# Have writing to a usb to RS-485 adapter working but how do I read back the response?

**URL:** <https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319>\
**Category:** General\
**Created:** [1 July 2020 15:31 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319 "2020-07-01T15:31:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeffreys](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jeffreys](https://discourse.nodered.org/u/jeffreys)\
**Post date:** [1 July 2020 15:31 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/1 "2020-07-01T15:31:23Z")

</div>

In Labview, Im used to basically drawing a line from the write to the input node of the USB read. There is not an input node on the USB read to control the flow. How do you read the response from the packet I sent?

Here is my code:

```auto
[{"id":"9a21f667.8fc0c8","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"3b8d164f.baeb12","type":"serial out","z":"9a21f667.8fc0c8","name":"","serial":"6316eb55.80e3a4","x":690,"y":360,"wires":[]},{"id":"fd418c64.ca7508","type":"inject","z":"9a21f667.8fc0c8","name":"Set to EOL","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x08\",\"0x41\",\"0x1E\",\"0x90\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x82\",\"0x03\",\"0x45\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":440,"y":360,"wires":[["3b8d164f.baeb12"]]},{"id":"475ce64b.f69e5","type":"inject","z":"9a21f667.8fc0c8","name":"Set Normal","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x08\",\"0x41\",\"0x1E\",\"0x17\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x83\",\"0x03\",\"0xC3\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":430,"y":400,"wires":[["3b8d164f.baeb12"]]},{"id":"4a6c0228.8aa92c","type":"inject","z":"9a21f667.8fc0c8","name":"MainBoard-Relay1Off","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x22\",\"0x20\",\"0x12\",\"0x00\",\"0x5A\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x03\",\"0x4A\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":500,"wires":[["3b8d164f.baeb12"]]},{"id":"9e59f466.668f48","type":"inject","z":"9a21f667.8fc0c8","name":"MainBoard-Relay2On","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x22\",\"0x20\",\"0x12\",\"0x00\",\"0x5A\",\"0x00\",\"0x00\",\"0x00\",\"0x01\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x03\",\"0x4B\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":540,"wires":[["3b8d164f.baeb12"]]},{"id":"438754f0.729e24","type":"inject","z":"9a21f667.8fc0c8","name":"MainBoard-Relay1On","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x22\",\"0x20\",\"0x12\",\"0x00\",\"0x5A\",\"0x00\",\"0x01\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x03\",\"0x4B\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":460,"wires":[["3b8d164f.baeb12"]]},{"id":"8850d8be.bc3f88","type":"inject","z":"9a21f667.8fc0c8","name":"fake mqtt Set to end of line mode","topic":"","payload":"0201 0141 4000 0841 1E90 0000 0000 8203 45","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":580,"wires":[["b54fa00f.5ecc9"]]},{"id":"b54fa00f.5ecc9","type":"function","z":"9a21f667.8fc0c8","name":"Hex string to Hex buffer","func":"msg.oldPayload = msg.payload; //save it for later debugging\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\nmsg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":600,"wires":[["3b8d164f.baeb12"]]},{"id":"e47641e4.d18d38","type":"inject","z":"9a21f667.8fc0c8","name":"fake mqtt MainBoard-Relay1On","topic":"","payload":"0201 0141 4000 2220 1200 5A00 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0003 4B","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":620,"wires":[["b54fa00f.5ecc9"]]},{"id":"484dec1a.a6fd5c","type":"serial in","z":"9a21f667.8fc0c8","name":"","serial":"6316eb55.80e3a4","x":870,"y":360,"wires":[["57476dc8.786784"]]},{"id":"57476dc8.786784","type":"debug","z":"9a21f667.8fc0c8","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"payload","targetType":"msg","x":1050,"y":360,"wires":[]},{"id":"6316eb55.80e3a4","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

```

---

<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:** [1 July 2020 15:32 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/2 "2020-07-01T15:32:40Z")

</div>

Did you not see my response on your other thread?

---

<div class="post-metadata">

**Author:** ![jeffreys](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jeffreys](https://discourse.nodered.org/u/jeffreys)\
**Post date:** [1 July 2020 15:50 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/4 "2020-07-01T15:50:51Z")

</div>

Our circuit board responds to the command and turns a relay on so I know from running the labview that it gets the command and sends a response. In Node Red the relay is turning on so I know our part is working correctly to write. In labview you set the bits back to read after you write and then just read next in your program flow.  
I dont get any response. I dont get anything in the debug or console.

---

<div class="post-metadata">

**Author:** ![jeffreys](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jeffreys](https://discourse.nodered.org/u/jeffreys)\
**Post date:** [1 July 2020 17:56 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/5 "2020-07-01T17:56:10Z")

</div>

Trying the serial request gave me a time out error. Somehow i need to tell i the number of bits to read. I think that is what is timing out. Not sure how to do that yet tho...

```auto
[{"id":"f042e293.4bd948","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"be2f3e94.08e27","type":"serial out","z":"f042e293.4bd948","name":"","serial":"6316eb55.80e3a4","x":690,"y":280,"wires":[]},{"id":"2d54136f.d45514","type":"inject","z":"f042e293.4bd948","name":"Set to EOL","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x08\",\"0x41\",\"0x1E\",\"0x90\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x82\",\"0x03\",\"0x45\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":440,"y":280,"wires":[["be2f3e94.08e27"]]},{"id":"b9937022.701d4","type":"inject","z":"f042e293.4bd948","name":"Set Normal","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x08\",\"0x41\",\"0x1E\",\"0x17\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x83\",\"0x03\",\"0xC3\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":430,"y":320,"wires":[["be2f3e94.08e27"]]},{"id":"43164026.d98908","type":"inject","z":"f042e293.4bd948","name":"MainBoard-Relay1Off","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x22\",\"0x20\",\"0x12\",\"0x00\",\"0x5A\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x03\",\"0x4A\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":420,"wires":[["be2f3e94.08e27"]]},{"id":"9f0a0b28.d830b","type":"inject","z":"f042e293.4bd948","name":"MainBoard-Relay2On","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x22\",\"0x20\",\"0x12\",\"0x00\",\"0x5A\",\"0x00\",\"0x00\",\"0x00\",\"0x01\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x03\",\"0x4B\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":460,"wires":[["be2f3e94.08e27"]]},{"id":"47cfc409.596604","type":"inject","z":"f042e293.4bd948","name":"MainBoard-Relay1On","topic":"","payload":"[\"0x02\",\"0x01\",\"0x01\",\"0x41\",\"0x40\",\"0x00\",\"0x22\",\"0x20\",\"0x12\",\"0x00\",\"0x5A\",\"0x00\",\"0x01\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x00\",\"0x03\",\"0x4B\"]","payloadType":"bin","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":400,"y":380,"wires":[["52f778b2.1c696"]]},{"id":"13c53829.be0b88","type":"inject","z":"f042e293.4bd948","name":"fake mqtt Set to end of line mode","topic":"","payload":"0201 0141 4000 0841 1E90 0000 0000 8203 45","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":500,"wires":[["d12565c9.4d6cf8"]]},{"id":"d12565c9.4d6cf8","type":"function","z":"f042e293.4bd948","name":"Hex string to Hex buffer","func":"msg.oldPayload = msg.payload; //save it for later debugging\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\nmsg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":520,"wires":[["be2f3e94.08e27"]]},{"id":"c8b308cb.efb1b","type":"inject","z":"f042e293.4bd948","name":"fake mqtt MainBoard-Relay1On","topic":"","payload":"0201 0141 4000 2220 1200 5A00 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0003 4B","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":540,"wires":[["d12565c9.4d6cf8"]]},{"id":"52f778b2.1c696","type":"serial request","z":"f042e293.4bd948","name":"","serial":"6316eb55.80e3a4","x":690,"y":360,"wires":[["c03cb9b3.b9d49"]]},{"id":"c03cb9b3.b9d49","type":"debug","z":"f042e293.4bd948","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":870,"y":360,"wires":[]},{"id":"6316eb55.80e3a4","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

```

---

<div class="post-metadata">

**Author:** ![jeffreys](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jeffreys](https://discourse.nodered.org/u/jeffreys)\
**Post date:** [1 July 2020 18:32 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/6 "2020-07-01T18:32:15Z")

</div>

[https://discourse.nodered.org/t/ascii-convert-control-character/26140](https://discourse.nodered.org/t/ascii-convert-control-character/26140)

I think this is close. Somehow I need to read what has been sent back and calculate a crc and then set that for the end of the incoming message... ( kind of like how they were using /r to return )....

---

<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:** [1 July 2020 19:12 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/7 "2020-07-01T19:12:23Z")

</div>

Hey something else i wrote 🙂

The value at the end of your strings and buffer examples look to be simple 8bit XOR BCC of everything proceeding it.

#### BCC calculation...

```auto
[{"id":"51480b90.640c84","type":"inject","z":"40758d1c.696554","name":"fake mqtt Set to end of line mode","topic":"","payload":"0201 0141 4000 0841 1E90 0000 0000 8203 45","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":390,"y":520,"wires":[["471f1a31.2f05d4"]]},{"id":"471f1a31.2f05d4","type":"function","z":"40758d1c.696554","name":"Hex string to Hex buffer","func":"msg.oldPayload = msg.payload; //save it for later debugging\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\nmsg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nreturn msg;","outputs":1,"noerr":0,"x":670,"y":540,"wires":[["4d1f98ce.f22738"]]},{"id":"5ed8a091.c09b8","type":"inject","z":"40758d1c.696554","name":"fake mqtt MainBoard-Relay1On","topic":"","payload":"0201 0141 4000 2220 1200 5A00 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0003 4B","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":390,"y":560,"wires":[["471f1a31.2f05d4"]]},{"id":"4d1f98ce.f22738","type":"function","z":"40758d1c.696554","name":"BCC Calc","func":"msg.last = msg.payload[msg.payload.length-1]; //capture last element\nvar data = msg.payload.slice(0,-1); //lose last element\n\nlet cs = 0;//the checksum\nfor (let i = data.length - 1; i >= 0; i--) {\n cs ^= data[i]; //XOR\n}\n\nmsg.checksum = cs;\n\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":540,"wires":[["d188f30b.31816"]]},{"id":"d188f30b.31816","type":"debug","z":"40758d1c.696554","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":1010,"y":540,"wires":[]}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/c/3c768d200f527c7e8365977af428cdcea73e9360.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/2/d22ff2c21fc52ea226999f351c7bdbe7c103bc71.png)

It takes your fake COMM strings, strips the last HEX value off off and re-calculates the BCC (look in `msg.checksum` - you will see it matches your two samples which I put into `msg.last` for convenience)

* * *

#### moving forward...

I suspect you need to use the Serial Request node, send a correctly formatted buffer & then you'll get a response.

---

<div class="post-metadata">

**Author:** ![jeffreys](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jeffreys](https://discourse.nodered.org/u/jeffreys)\
**Post date:** [1 July 2020 20:08 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/8 "2020-07-01T20:08:07Z")

</div>

Still get the buffer error thing when added the usb part to your code. Somehow we need to read and then use the read stuff to calcualte the checksum and set that as the end of the time out. Setting how many to read would work also but not sure how to do that

```auto
[{"id":"e016160.58e2068","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8e2e41da.6793f8","type":"inject","z":"e016160.58e2068","name":"fake mqtt Set to end of line mode","topic":"","payload":"0201 0141 4000 0841 1E90 0000 0000 8203 45","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":260,"wires":[["ff792e63.ecf2e8"]]},{"id":"ff792e63.ecf2e8","type":"function","z":"e016160.58e2068","name":"Hex string to Hex buffer","func":"msg.oldPayload = msg.payload; //save it for later debugging\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\nmsg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":280,"wires":[["5bcbd601.5aa87"]]},{"id":"88411c82.9f73d","type":"inject","z":"e016160.58e2068","name":"fake mqtt MainBoard-Relay1On","topic":"","payload":"0201 0141 4000 2220 1200 5A00 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0003 4B","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":300,"wires":[["ff792e63.ecf2e8"]]},{"id":"5bcbd601.5aa87","type":"function","z":"e016160.58e2068","name":"BCC Calc","func":"msg.last = msg.payload[msg.payload.length-1]; //capture last element\nvar data = msg.payload.slice(0,-1); //lose last element\n\nlet cs = 0;//the checksum\nfor (let i = data.length - 1; i >= 0; i--) {\n cs ^= data[i]; //XOR\n}\n\nmsg.checksum = cs;\n\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":280,"wires":[["51d5acde.ada794"]]},{"id":"51d5acde.ada794","type":"serial request","z":"e016160.58e2068","name":"","serial":"6316eb55.80e3a4","x":870,"y":280,"wires":[["b7e52a33.9cb5b"]]},{"id":"b7e52a33.9cb5b","type":"debug","z":"e016160.58e2068","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":1030,"y":280,"wires":[]},{"id":"6316eb55.80e3a4","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

```

---

<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:** [1 July 2020 20:13 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/9 "2020-07-01T20:13:32Z")

</div>

What is it you are communicating with? Is there a documented protocol? And documented comm settings?

---

<div class="post-metadata">

**Author:** ![jeffreys](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jeffreys](https://discourse.nodered.org/u/jeffreys)\
**Post date:** [1 July 2020 20:39 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/10 "2020-07-01T20:39:35Z")

</div>

Its a dumb proprietary wattmaster usb-link 2, usb to 485 converter. There isn't any documentation but we use the expected bit read back to read it in labview. You are the man at this by the way. Thank you for help.

I have this working now. it says ok and im getting something back but the return buffer should of been 0241 4001 4000 0841 1E90 0000 0000 8203 45.

 ![Screenshot from 2020-07-01 16-38-46](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f92605d4a80845fcd4563e65556bcf38e765067e.png)

```auto
[{"id":"e016160.58e2068","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"8e2e41da.6793f8","type":"inject","z":"e016160.58e2068","name":"fake mqtt Set to end of line mode","topic":"","payload":"0201 0141 4000 0841 1E90 0000 0000 8203 45","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":260,"wires":[["ff792e63.ecf2e8"]]},{"id":"ff792e63.ecf2e8","type":"function","z":"e016160.58e2068","name":"Hex string to Hex buffer","func":"msg.oldPayload = msg.payload; //save it for later debugging\nvar noSpaces = msg.payload.replace(/ /g, '');// remove spaces\nmsg.payload = Buffer.from(noSpaces, \"hex\"); //convert to buffer\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":280,"wires":[["5bcbd601.5aa87"]]},{"id":"88411c82.9f73d","type":"inject","z":"e016160.58e2068","name":"fake mqtt MainBoard-Relay1On","topic":"","payload":"0201 0141 4000 2220 1200 5A00 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0003 4B","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":300,"wires":[["ff792e63.ecf2e8"]]},{"id":"5bcbd601.5aa87","type":"function","z":"e016160.58e2068","name":"BCC Calc","func":"msg.last = msg.payload[msg.payload.length-1]; //capture last element\nvar data = msg.payload.slice(0,-1); //lose last element\n\nlet cs = 0;//the checksum\nfor (let i = data.length - 1; i >= 0; i--) {\n cs ^= data[i]; //XOR\n}\n\nmsg.checksum = cs;\n\nreturn msg;","outputs":1,"noerr":0,"x":700,"y":280,"wires":[["51d5acde.ada794"]]},{"id":"51d5acde.ada794","type":"serial request","z":"e016160.58e2068","name":"","serial":"6316eb55.80e3a4","x":870,"y":280,"wires":[["b7e52a33.9cb5b"]]},{"id":"b7e52a33.9cb5b","type":"debug","z":"e016160.58e2068","name":"","active":false,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":1030,"y":280,"wires":[]},{"id":"759e889.7a5c978","type":"serial in","z":"e016160.58e2068","name":"","serial":"6316eb55.80e3a4","x":850,"y":440,"wires":[["c2018e1b.f4a5f"]]},{"id":"c2018e1b.f4a5f","type":"debug","z":"e016160.58e2068","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","targetType":"full","x":1050,"y":440,"wires":[]},{"id":"6316eb55.80e3a4","type":"serial-port","z":"","serialport":"/dev/ttyUSB0","serialbaud":"115200","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"","bin":"false","out":"char","addchar":"","responsetimeout":"10000"}]

```

---

<div class="post-metadata">

**Author:** ![jeffreys](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jeffreys](https://discourse.nodered.org/u/jeffreys)\
**Post date:** [1 July 2020 20:46 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/11 "2020-07-01T20:46:38Z")

</div>

Actually I think all we need to do is take those payloads and turn them into a hex buffer and see if it matches. It's close. There are 9 payload debug outputs and i count 10 bytes. I have to read the buffer to say see what relay outputs are on and then set the bit in the byte for the one I want to turn on and than write it back. I think we are close

---

<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:** [1 July 2020 21:49 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/12 "2020-07-01T21:49:35Z")

</div>

Which debug is giving you replies? suspect it's the top one attached to the serial request & the 2nd serial in node isn't required.

And now you are getting data back, can you do the following?...

> [@Help with creating a buffer of hex bytes from a string of hex words](https://discourse.nodered.org/t/help-with-creating-a-buffer-of-hex-bytes-from-a-string-of-hex-words/29259/12):
>
> 1. Set the debug to show complete msg
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/5/9548bfb49b72f6066167303b9dd351b88bc6e145.png)
> 
> 1. Copy the data response you get and paste it (as code) into a reply  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/1/11ee7aff0f46002f47c988afa0cb520cd721e606.png)
> 2. Tell me what each part _should_ be (e.g. first 4 digits are temperature and should be 31.5 etc)

---

<div class="post-metadata">

**Author:** ![jeffreys](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jeffreys](https://discourse.nodered.org/u/jeffreys)\
**Post date:** [1 July 2020 22:05 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/13 "2020-07-01T22:05:16Z")

</div>

Its on complete message. Its like it is returning each byte read in a new payload. So the first one is

```auto
{"payload":"A","port":"/dev/ttyUSB0","_msgid":"c001b66b.a96578"}

```

Second is

```auto
{"payload":"@","port":"/dev/ttyUSB0","_msgid":"8630c990.484ac8"}

```

Is A = to 02 in hex and @ = 41 in hex? The string we should be getting back is 0241 4001 4000 0841 1E90 0000 0000 8203 45

---

<div class="post-metadata">

**Author:** ![jeffreys](https://avatars.discourse-cdn.com/v4/letter/j/96bed5/32.png) [@jeffreys](https://discourse.nodered.org/u/jeffreys)\
**Post date:** [1 July 2020 22:06 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/14 "2020-07-01T22:06:49Z")

</div>

![Screenshot from 2020-07-01 18-05-43](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/f/1f7ebb389cc1db7ac3190cf80e42ec4e255cb729.png) ![Screenshot from 2020-07-01 18-05-57](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/4/047b7fc91472abf386a72ccaa6e8d11b39116c6b.png)

Here are all the values of the payloads returned.

---

<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:** [1 July 2020 22:21 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/15 "2020-07-01T22:21:23Z")

</div>

Try setting the serial config node to split on 0x03 & return a buffer

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/7/d7868398258a3299caba4aafdf3820864dad70a3.png)

See if that give a more sensible response

EDIT...  
And send a copy of the results once more & a description of what you believe the reply means (same as I asked before please)

---

<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:** [15 July 2020 22:21 UTC](https://discourse.nodered.org/t/have-writing-to-a-usb-to-rs-485-adapter-working-but-how-do-i-read-back-the-response/29319/16 "2020-07-15T22:21:32Z")

</div>

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