# Serial Ports

The package `core.io` contains classes to access serial ports, both physical and virtual, on the local machine.

## Serial Ports

The class `core.io.SerialPort` represents a serial port. There are two ways to create `core.io.SerialPort` objects. Either by retrieving a list by calling the `core.Array<core.io.SerialPort> serialPorts()` function and picking one, or by passing a system-specific identifier to the constructor of `core.io.SerialPort` (i.e. `COMX` on Windows, or `/dev/ttySX` on Linux).

The `core.io.SerialPort` class has the following members in addition to `==` and `hash`:

- `core.Maybe<core.io.SerialStream> open(core.io.SerialOptions options)`

  Open the serial port. Provide configuration options.

- `core.Str name()`

  Get the name of the port.

As mentioned previously, the following function can be used to enumerate all serial ports on the system:

- `core.Array<core.io.SerialPort> serialPorts()`

  Find available serial ports.

## Serial Streams

The `open` method of `core.io.SerialPort` returns a `core.io.SerialStream` object that represents an open serial port. The `core.io.SerialOptions` class is used to represent options of the serial connection. It has the following members:

- `init(core.io.SerialOptions other)`

  Copy constructor.

- `init()`

  Create default options (9600 baud, no parity, 1 stop bit).

- `init(core.Nat baudrate)`

  Create default options with custom baud rate, no parity, 1 stop bit.

- `init(core.Nat baudrate, core.Nat byteSize, core.io.SerialParity parity, core.io.SerialStopBits stopBits)`

  Create with all options.

- `core.Nat baudrate`

  Baudrate.

- `core.Nat byteSize`

  Bits per byte.

- `core.io.SerialParity parity`

  Parity.

- `core.io.SerialStopBits stopBits`

  Stop bits.

The `core.io.SerialStream` has the following members:

- `core.io.SerialIStream input()`

  Get the input stream.

- `core.io.SerialOStream output()`

  Get the output stream.

- `void close()`

  Close the stream. Also closes the input/output streams.

- `core.io.SerialOptions options()`

  Get options.

- `void options(core.io.SerialOptions options)`

  Set options.