Node rosepetal-serial-out
Writes to a serial port. The node does not open the port: it publishes the data on NATS and the engine writes the bytes to the device. It has one input and no output, and appears under the network category of the palette.
Properties
| Field | Description |
|---|---|
| Name | Optional label. Without it the node shows the name of the configuration node, or its port when the configuration node has no name |
| Serial Port | The rosepetal-serial-config node that describes the port (required) |
Input
| Property | Type | Description |
|---|---|---|
msg.payload | Buffer, string, number, array or object | The data to write |
msg.baudrate | number | Optional. Asks the engine to change the baud rate of the port |
msg.timeout | number | Optional. Copied to the meta.timeout field of the write message. The engine in engine/ does not use it |
A message can carry msg.payload, msg.baudrate or both. A message with neither is ignored.
Payload
msg.payload | Bytes written |
|---|---|
| Buffer | The buffer as it is |
| Array | One byte per element of the array |
| Number | The number as decimal text: 42 is written as the characters 42 |
| Object | The object as JSON text |
| String, boolean | The value as text |
The character of Add character to output messages, if the configuration node has one, is appended to every payload, Buffers included: see Output. A payload that is empty after that step is not sent.
Each write is one NATS message on the out subject (rosepetal.serial.out with the default root), a JSON envelope with the data in base64. Besides the payload, only msg._msgid and msg.timeout go into the envelope, in its meta field; msg.meta and the other properties of the message are not forwarded.
Baud rate
msg.baudrate publishes a baudrate message on the control subject, and the engine opens the port again at the new rate. A value that is not a number is reported as an error and no change is requested; the payload of the same message is still written.
The change is not stored in the configuration node, which sends its own settings to the engine again every 30 seconds: the engine in engine/ then opens the port again at the configured baud rate. For a lasting change, set the baud rate in the configuration node.
Example
A device that takes ASCII commands ended by CR LF: set Add character to output messages to \r\n on the configuration node and send
{ "payload": "STATUS?" }The engine writes the 9 bytes STATUS?\r\n. To send a binary frame, build a Buffer in a function node:
msg.payload = Buffer.from([0x02, 0x52, 0x03]); // STX, "R", ETX
return msg;The added character is appended to Buffers as well, so leave the field empty on a configuration node used for binary frames.
Errors
When the write cannot be published, for example because the NATS server cannot be reached, the node reports the error with the message, so a Catch node receives it. The node gets no confirmation from the engine that the bytes reached the device: follow the state of the port in the status.
Status
The status shows the NATS connection first and, once it is connected, the state of the port that the engine reports.
| Status | Meaning |
|---|---|
nats connecting (yellow ring) | Connecting to the NATS server |
nats reconnecting (yellow ring) | The connection to the NATS server was lost and the client is reconnecting |
nats error (red ring) | The NATS server could not be reached, or the client reported an error |
nats disconnected (red ring) | There is no connection to the NATS server |
serial pending (yellow ring) | Connected to NATS; the engine has not reported the state of the port yet |
serial connecting (yellow ring) | The engine is opening the port |
serial connected (green dot) | The engine has the port open |
serial reconnecting (yellow ring) | The engine failed to open the port, or lost it, and waits to try again |
serial error (red ring) | The engine reported an error of the port |
serial closed (red ring) | The port is closed |
serial heartbeat lost (red ring) | The engine has not reported the state of the port for 15 seconds |
Notes
- When the node starts and when it stops it publishes a
node-statusmessage (onlineoroffline) on the control subject. The engine inengine/takes no action on it. - The subjects and payloads are described in NATS channels.