# RS-232/485 (WIP)

RS-232 and RS-485 are both serial communication protocols used for data transfer between devices. RS-232 is commonly employed for short-distance communication, typically under 50 feet, and supports point-to-point connections at lower speeds. Conversely, RS-485 is designed for longer distances, up to 4000 feet, and supports multi-point configurations with higher data rates. The key differences include their physical wiring setups, signal voltage levels, and maximum distance capabilities.

RS-232 is often found in older computer serial ports, connections to modems, and in certain industrial applications where simple point-to-point communication is sufficient. For example, connecting a computer to a printer or a microcontroller to a GPS module.

RS-485 is widely used in industrial automation systems, such as connecting PLCs (Programmable Logic Controllers) to various sensors and actuators. It is also common in building management systems (BMS), where multiple devices like HVAC systems, lighting controls, and other peripherals need to communicate over long distances in a multi-drop network configuration.

## Functions

### create

Instantiates a serial connection to a specific port.

In the options box, insert as an object the necessary parameters.

<table><thead><tr><th width="133">Parameter</th><th width="93">Type</th><th width="109">Default</th><th>Description</th></tr></thead><tbody><tr><td>path</td><td>String</td><td></td><td>The system path of the serial port you want to open. For example, <code>/dev/tty.XXX</code> on Mac/Linux, or <code>COM1</code> on Windows</td></tr><tr><td>baudRate</td><td>Integer</td><td><code>9600</code></td><td>The baud rate of the port to be opened. This should match one of the commonly available baud rates, such as <code>110</code>, <code>300</code>, <code>1200</code>, <code>2400</code>, <code>4800</code>, <code>9600</code>, <code>14400</code>, <code>19200</code>, <code>38400</code>, <code>57600</code> or <code>115200</code>. Custom rates are supported as a best effort per platform. The device connected to the serial port is not guaranteed to support the requested baud rate, even if the port itself supports that baud rate.</td></tr><tr><td>dataBits</td><td>Integer</td><td><code>8</code></td><td>Must be one of these: <code>5</code>, <code>6</code>, <code>7</code>, or <code>8</code></td></tr><tr><td>lock</td><td>Boolean</td><td><code>true</code></td><td>Prevent other processes from opening the port. Windows does not currently support <code>false</code>.</td></tr><tr><td>stopBits</td><td>Number</td><td><code>1</code></td><td>Must be <code>1</code>, <code>1.5</code> or <code>2</code></td></tr><tr><td>parity</td><td>String</td><td><code>'none'</code></td><td>Must be one of these: <code>'none'</code>, <code>'even'</code>, <code>'mark'</code>, <code>'odd'</code>, <code>'space'</code></td></tr><tr><td>rtscts</td><td>Boolean</td><td>false</td><td>Flow control Setting.</td></tr><tr><td>xon</td><td>Boolean</td><td>false</td><td>Flow control Setting.</td></tr><tr><td>xoff</td><td>Boolean</td><td>false</td><td>Flow control Setting.</td></tr><tr><td>xany</td><td>Boolean</td><td>false</td><td>Flow control Setting.</td></tr><tr><td>hupcl</td><td>Boolean</td><td>true</td><td>Drop DTR on close.</td></tr></tbody></table>

### list

Lists all serial ports found on the system.

### open

Opens the connection of the given serial port.

### isOpen

### getBinding

### changeBaudRate

Changes the baud rate for an open port. Parameter `baudRate` can be set as 110, 300, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 57600, or 115200.

### write

Writes data to the given serial port and waits until all output data is transmitted to the serial port. Use the input box for `data` to insert the data you want to write. You can also use `suffix` to always add specific information at the end of the data you want to write.

{% hint style="info" %}
If you need to transport a carriage return use `<CR>`, for linefeed use `<LF>` and for both together use `<CRLF>`.
{% endhint %}

### read

Read data from a port.

### close

Closes an open connection. If there are in-progress writes when the port is closed the writes will error.

### onError

Reports about any errors

### onData

Listens to data events

<table><thead><tr><th width="157">Parameter</th><th width="98">Type</th><th width="92">Default</th><th>Description</th></tr></thead><tbody><tr><td>name</td><td>String</td><td></td><td>Name of the handler</td></tr><tr><td>handler</td><td>Function</td><td></td><td>Function to run as the handler</td></tr><tr><td>parserOptions</td><td>Object</td><td></td><td>Object that contains the following parser options.</td></tr><tr><td><p>parserOptions.</p><p>delimiter</p></td><td>String</td><td><code>'\n'</code></td><td>Emits data after the delimiter is hit.</td></tr><tr><td><p>parserOptions.</p><p>timeout</p></td><td>Integer</td><td></td><td>Timeout in ms after which data is emitted</td></tr><tr><td><p>parserOptions.</p><p>byteLength</p></td><td>Integer</td><td></td><td>Number of bytes that must have been received until data is emitted.</td></tr></tbody></table>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.heisenware.com/~/changes/Q625pQNc0nXqVGPtyjAY/building-apps/integration/protocol-connectors/rs-232-485-wip.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
