---
title: BSSerialPort
slug: develop/bsserialport
docTags: 
createdAt: 2025-03-11T07:07:17.199Z
---

For more information about available methods, refer to the [roSerialPort](docId:25Ega25ABzfTXgITvvmmS) entry.

If possible, use @brightsign/serialport with the Node Package [serialport](https://serialport.io/) instead of BSSerialPort. A basic reference implementation can be found in [this GitHub repository](https://github.com/brightsign/bs-node-serialport).

## Object Creation

`BSSerialPort(in unsigned long port);`

## Methods

- `SetBaudRate(in unsigned long baudRate) raises(DOMException)` void&#x20;
- `SetDataBits(in unsigned long dataBits) raises(DOMException)` void&#x20;
- `SetStopBits(in unsigned long stopBits) raises(DOMException)` void&#x20;
- `SetParity(in DOMString parity) raises(DOMException)` void&#x20;
- `SetEcho(in boolean flag)` boolean
- `SetInverted(in boolean flag)` boolean
- `SetFlowControl(in boolean flag)`
- `SetGenerateByteEvent(in boolean flag) raises(DOMException)` void&#x20;
- `SetGenerateLineEvent(in boolean flag) raises(DOMException)` void&#x20;
- `SetLineEnding(in DOMString eol) raises(DOMException)` void
- `SendByte(in unsigned long byte)` boolean
- `SendBytes(in ArrayBuffer data)` boolean
- `SendBytes(in ArrayBufferView data)` boolean
- `SendBytes(in DOMString data)` boolean
- `SendBreak(in long duration_ms)` boolean
- `Flush() raises(DOMException)` void
- `Close()`void:  Shuts down the instance, preventing it from further consuming resources. If this method is not called, garbage collection determines when the instance will be destroyed.

## Events

The following events are available via the *BSSerialPort* object. Each event can receive a SerialPortEvent event.

- `onserialbyte`
- `onserialline`

### SerialPortEvent – Attributes

For the onserialbyte event:

- `sbyte` unsigned long readonly  &#x20;

For the onserialline event:

- `sdata` DOMString readonly

## Example

```text
function serialOut()
{
    console.log("*** serialOut **");

    // '2' is the first externally connected USB  port on Cheetah
    var serial_out = new BSSerialPort(2);

    serial_out.SetBaudRate(115200);
    serial_out.SetDataBits(8);
    serial_out.SetStopBits(1);
    serial_out.SetParity("none");
    serial_out.SetEcho(true);

    serial_out.SetGenerateByteEvent(true);
    serial_out.SetGenerateLineEvent(true);

    serial_out.onserialbyte = function(e){
        console.log('### onserialbyte: ' + e.sbyte);
    }

    serial_out.onserialline = function(e){
        console.log('### onserialline: ' + e.sdata);
    }

    serial_out.SendByte(89);
    serial_out.SendByte(90);
    serial_out.SendByte(91);

    serial_out.SendBytes('Hello World!');
    serial_out.SendBytes(String.fromCharCode(64, 27, 66, 67))
}
```

