Help with rs232

Hi,

can someone please help me with rs232 communication?

Have a scale that has an RS232 interface.
Unfortunately I have no idea how I can accomplish the commands I send and receive values.

[{"id":"f0190195.7939f8","type":"serial in","z":"5b6e97cb.a67bf8","name":"","serial":"d606e68c.2e18b","x":140,"y":400,"wires":[["9a100448.11dc5"]]},{"id":"9a100448.11dc5","type":"debug","z":"5b6e97cb.a67bf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":400,"y":400,"wires":[]},{"id":"b7af98bb.68b3d","type":"serial out","z":"5b6e97cb.a67bf8","name":"test","serial":"d606e68c.2e18b","x":610,"y":400,"wires":[]},{"id":"df93de13.b2485","type":"inject","z":"5b6e97cb.a67bf8","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":540,"wires":[["74b1d48d.bc7c04"]]},{"id":"74b1d48d.bc7c04","type":"function","z":"5b6e97cb.a67bf8","name":"","func":"msg.payload = new Buffer\n([0x02+A+0x03]);\nreturn msg;\n\n","outputs":1,"noerr":0,"x":370,"y":560,"wires":[["8d036d47.a8cc2"]]},{"id":"8d036d47.a8cc2","type":"debug","z":"5b6e97cb.a67bf8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":620,"y":620,"wires":[]},{"id":"d606e68c.2e18b","type":"serial-port","z":"","serialport":"/dev/ttyAMA0","serialbaud":"2400","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"","bin":"bin","out":"char","addchar":"false","responsetimeout":""}]

these are the commands:

5: Command mode, output on request

Request gross weight Command: HEX (02) + “A“ + “HEX (03), Answer: GW: 0023.45 (kg)

Request net weight Command HEX (02) + “B“ + “HEX (03): Answer: NW: 0013.45 (kg)

Request tare weight Command HEX (02) + “C“ + “HEX (03): Answer: TW: 0010.00 (kg)

Trigger zero position Command HEX (02) + “D“ + “HEX (03): Answer: D
Trigger tare function Command HEX (02) + “E“ + “HEX (03): Answer: E

Pleas Pleas.
THX
Mike

Hi that protocol has to be the simplest I've ever seen.

Try this to get you started...

Inject > function > serial request > debug

In the function node do this...

msg.payload = String.fromCharCode(2) + 'A' + String.fromCharCode(3);
return msg;

See what you get back.

Thank you,

come back now:
string wert

And how can I output the value as real from the string,
for example -0065.0 or 00120.0.

Thank you so much

You can use the javascript split() method to split it into two parts at the ':' giving an array of two elements then use the function parseFloat to convert the second part to a number. So in a function node

msg.payload = parseFloat(msg.payload.split(":")[1])
return msg

Hi,

thank you again.
That is exactly what I was looking for.

Would you also have an idea how I can read this sensor:

Example:PC sends command, query the current working mode:
AA B4 02 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 AB
Sensor with ID A160 response:
AA C5 02 00 00 00 A1 60 03 AB
Show the sensorisin report active mode.
AA C5 02 00 01 00 A1 60 04 AB     
Show the sensorisin report query mode.
PC sends command, setthe sensor with ID A160 toreport query mode:
AA B4 02 01 01 00 00 00 00 00 00 00 00 00 00 A1 60 05 AB
Sensor with ID A160 response:
AA C5 02 01 01 00 A1 60 05 AB   
Show the sensorisset toreport query mode

this is an SD011 which I only want to query if necessary.
and then wants to put it back to sleep mode.

sorry, rs232 is completely new territory for me. Thank you so much

Same as before however the protocol is more complex than STX A ETX

you will have to format an array of bytes (a buffer) to the format specified by the documentation

Best way to approach this is forget about the serial side and develop a flow that outputs a buffer containing AA B4 02 00 00 00 00 00 00 00 00 00 00 00 00 FF FF 00 AB (or in human terms 170, 180, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 171)

once you can reproduce that, then you can send it to the serial node.

Once you reliably get a response, i can show you how to easily extract the information you need.

Hello.

I would like to get the value of pm 10.0 from this string:

SPS30 sensor probing successful
FW: 2.2 HW: 7, SHDLC: 2.0
SPS30 Serial: 0805DD8776DA6E38
measurements started
error reading measurement
measured values:
	1.43 pm1.0
	3.41 pm2.5
	4.95 pm4.0
	5.25 pm10.0
	4.97 nc0.5
	9.06 nc1.0
	11.28 nc2.5
	11.72 nc4.5
	11.79 nc10.0
	0.68 typical particle size

measured values:
	1.43 pm1.0
	6.88 pm2.5
	11.22 pm4.0
	12.09 pm10.0
	0.00 nc0.5
	4.85 nc1.0
	11.06 nc2.5
	12.31 nc4.5
	12.48 nc10.0
	1.63 typical particle size


measured values:
	2.32 pm1.0
	2.45 pm2.5
	2.45 pm4.0
	2.45 pm1...

.

I am currently using this.

msg.payload = parseFloat(msg.payload.split("measured values:")[1])
return msg;

but that only gives me the value of the first line after "measured values:"
how to get to pm10.0

thx

You're gonna have to do multiple splits and loop through the resulting arrays to get values separated.

Start by splitting on newline \n then loop through splitting on space character then check the 2nd element until you find pm10.0 - your value will be in the 1st element.

Alternatively, use a regular expression to extract it.

Where are you getting that from? If you have control over the format then change it to a json string, it will make life much easier. If you don't have control over it can you get it as a sequence of single line messages instead? If so then use a Change nodes to select just the pm10.0 lines and then it will be very easy.

@Colin I had assumed since the thread was a continuation by the OP that it was related to the sds011 protocol from an earlier post.

@mike1976 is this a different serial device? Do you have control over what it outputs? If so, Colin's suggestion is the best way to handle this.

sorry.

posted it in the wrong forum.
It has nothing to do with rs232.

It is a SPS30 sensor from Sensirion.
https://www.sensirion.com/de/umweltsensoren/feinstaubsensoren-pm25/

I read this from UART:

So, since I'm actually very awkward with handling scripts.
I read the whole thing in node-red per exec:
/home/pi/release/sps30-uart-3.1.0/./sps30_example_usage

and if the sensor goes into sleep mode after 1 minute, stop
I read this again with:
killall sps30_example_u
and then I get the values in msg.paylod

yes, i can already imagine that this is certainly not the most beautiful variant, but i was glad when i managed to get at least the first values.

[{"id":"c21ca0ed.e51008","type":"inject","z":"2ce51737.375af","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":220,"y":120,"wires":[["d8d58063.f0d748","42071adb.36c6e4"]]},{"id":"d8d58063.f0d748","type":"exec","z":"2ce51737.375af","command":"/home/pi/release/sps30-uart-3.1.0/./sps30_example_usage","addpay":false,"append":"","useSpawn":"false","timer":"75","oldrc":false,"name":"","x":610,"y":140,"wires":[["ac8fd890.d4a3f8","1c76854.df4bdfb","36d9d39c.fe8c74"],[],[]]},{"id":"ac8fd890.d4a3f8","type":"debug","z":"2ce51737.375af","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":80,"wires":[]},{"id":"65fab7e.29cfdc8","type":"debug","z":"2ce51737.375af","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":630,"y":400,"wires":[]},{"id":"1c76854.df4bdfb","type":"function","z":"2ce51737.375af","name":"","func":"msg.payload = parseFloat(msg.payload.split(\"measured values:\")[3])\nreturn msg;\n","outputs":1,"noerr":0,"x":270,"y":400,"wires":[["65fab7e.29cfdc8"]]},{"id":"36d9d39c.fe8c74","type":"function","z":"2ce51737.375af","name":"","func":"msg.payload = parseFloat(msg.payload.split(\"measured values:pm\")[1])\nreturn msg;\n","outputs":1,"noerr":0,"x":300,"y":460,"wires":[["9b372457.00c728"]]},{"id":"9b372457.00c728","type":"debug","z":"2ce51737.375af","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":460,"wires":[]},{"id":"5ef1f0da.870b38","type":"inject","z":"2ce51737.375af","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":620,"wires":[[]]},{"id":"de31ff05.172898","type":"exec","z":"2ce51737.375af","command":"killall sps30_example_u","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":670,"y":640,"wires":[["ccf89be6.16045"],[],[]]},{"id":"ccf89be6.16045","type":"debug","z":"2ce51737.375af","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1000,"y":620,"wires":[]},{"id":"42071adb.36c6e4","type":"delay","z":"2ce51737.375af","name":"","pauseType":"delay","timeout":"76","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":450,"y":560,"wires":[["de31ff05.172898"]]}]

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