Class HostPort

extends Port implements Reader
Extends the functionality of the UART Port on platforms that support configurable RS232 devices. It allows setting and reading control lines.

Class summary


constructor device/string --baud-rate/int --data-bits/int= --stop-bits/StopBits= --parity/int=
See super class constructor.

Constructors

constructor device/string --baud-rate/int --data-bits/int=8 --stop-bits/StopBits=Port.STOP-BITS-1 --parity/int=Port.PARITY-DISABLED
See super class constructor.

Methods

The current baud rate.

baud-rate= new-rate/int -> none
Sets the baud rate to the given new-rate.
The receiver should be ready to read and write data at the specified baud rate.
Some platforms only support a fixed set of baud rates. For example, on Linux only the following baud rates are supported: 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, 460800, 576000, 921600, 1152000, 1500000, 2000000, 2500000, 3000000, 3500000, 4000000.
On macOS the baud rate can be set to arbitrary values.

close -> none
Closes this UART port and releases all associated resources.

Number of encountered errors.
Typically, this number is incremented if received data wasn't processed in time, and the UART hardware has lost data.

flush -> none
Flushes the output buffer, waiting until all written data has been transmitted.
Often, one can just use the --wait flag of the write function instead.
Deprecated. Use out instead.

operator == other/any -> bool
Whether this object is equal to the other.
By default, identical is used for equality.
Inheritance
Classes overwrite this operator to get an equality specific to their needs. Equality operators often compare the type and field contents. For example:

class Pin:
  number/int

  constructor .number:

  operator == other:
    if other is not Pin: return false
    return number == other.number
A class doesn't have to follow the above format, but it must keep the operator in sync with any hash-code method. That is, if a class has a hash-code member, then the equality and hash-code must agree. If two instances are equal (a == b), then their hash codes must also be equal (a.hash-code == b.hash-code).

Reads data from the port.
This method blocks until data is available.
Returns null if closed.
Deprecated. Use in instead.

Read the value of the given control flag. flag must be one of the CONTROL_ constants.
Returns the state of the flag

Read the value of all the control flags. Each bit in the returned value corresponds to the bit position indicated
by the CONTROL_ constants.

set-control-flag flag/int state/bool -> none
Sets the state of a control flag. flag must be one of the CONTROL_ constants.

set-control-flags flags/int -> none
Sets all control flags to the specified value. Each bit in the flags corresponds to one of the CONTROL_ constants.

Stringifies this object.
Inheritance
Objects that need a human-friendly string representation should overwrite this method. The default string is based on the internal class-ID.

Waits for a break signal to be received.
A break signal is a continuous low signal on the RX pin for a duration of at least one byte.
Not supported on all platforms.

write data/Data from/int=0 to/int=data.byte-size --break-length/any=0 --wait/any=false -> int
Writes data to the Port.
If break-length is greater than 0, an additional break signal is added after the data is written. The duration of the break signal is bit-duration * break-length, where bit-duration is the duration it takes to write one bit at the current baud rate.
If not all bytes could be written without blocking, this will be indicated by the return value. In this case the break is not written even if requested. The easiest way to handle this by using the writer.Writer class. Alternatively, something like the following could be used.

for position := 0; position < data.byte-size; null:
  position += my-uart.write (data.byte-slice position data.byte-size)
If wait is true, the method blocks until all bytes that were written have been emitted to the physical pins. This is equivalent to calling flush. Otherwise, returns as soon as the data is buffered.
Returns the number of bytes written.
Deprecated. Use out instead.