hammerspoon2-docs
    Preparing search index...

    Class HSSerialPort

    A serial port, created via hs.serial.createPortNamed() or hs.serial.createPortAtPath(). The port is not open until you call open(). Configure it (baud rate, data bits, etc.) either before or after opening — configuration changes made while open are applied immediately. Received data, and lifecycle events, are delivered via the callback registered with setCallback().

    Index

    Constructors

    Properties

    allowNonStandardBaudRates: boolean

    Whether baudRate may be set to a value outside the standard set. Default is false.

    baudRate: number

    The baud rate, in bits per second. Default is 115200. Setting a non-standard value (i.e. not one of 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, 115200, 230400) is rejected unless allowNonStandardBaudRates is true.

    dataBits: number

    The number of data bits, 5–8. Default is 8.

    dtr: boolean

    The state of the DTR (Data Terminal Ready) control line. Default is false.

    identifier: string

    The unique identifier assigned to this port object.

    isOpen: boolean

    Whether the port is currently open.

    name: string

    The port's name (e.g. "usbserial-1420").

    parity: string

    The parity mode: "none", "odd", or "even". Default is "none".

    path: string

    The port's device path (e.g. "/dev/cu.usbserial-1420").

    rts: boolean

    The state of the RTS (Request To Send) control line. Default is false.

    shouldEchoReceivedData: boolean

    Whether data sent with sendData() is also delivered back to the callback as a "received" event, simulating local echo. Default is false.

    stopBits: number

    The number of stop bits, 1 or 2. Default is 1.

    usesDTRDSRFlowControl: boolean

    Whether to use hardware DTR/DSR flow control. Default is false.

    usesRTSCTSFlowControl: boolean

    Whether to use hardware RTS/CTS flow control. Default is false.

    Methods

    • Closes the port and releases all resources. Called automatically during shutdown.

      Returns void

    • Sends data through the port. The string is transmitted as raw bytes: each character's code point (0–255) becomes one byte on the wire. This lets you round-trip arbitrary binary data — build the string with String.fromCharCode() for non-text payloads.

      Parameters

      • value: string

        The data to send

      Returns HSSerialPort

      self, for chaining

    • Sets the callback invoked for port lifecycle events and received data. The callback receives two arguments: an event type string and a data string.

      Parameters

      • fn: (event: string, data: string) => void

        Called on port events

      Returns HSSerialPort

      self, for chaining