SerialPort

Description

The SerialPort object represents a serial port (UART) and allows reading and writing data from it.

› Inherits:IoDevice

Properties

baudRate

This property holds the data baud rate for this port.

› Type:BaudRate
› Signal:baudRateChanged()
› Attributes:Writable

dataBits

This property holds the data bits in a frame.

› Type:DataBits
› Signal:dataBitsChanged()
› Attributes:Writable

description

This property holds the description of the serial port, if available.

› Type:String
› Signal:descriptionChanged()
› Attributes:Readonly

error

This property holds the most recently occurred error or SerialPort.NoError if no error occurred. If the same error occurs multiple times this property does not change. Use the errorOccurred() signal to detect multiple occurrences of the same error.

› Type:Error
› Signal:errorChanged()
› Attributes:Readonly

errorString

This property holds the current human readable error string corresponding to the current value in the error property. It may include additional information such as failure reasons or locations.

› Type:String
› Signal:errorStringChanged()
› Attributes:Readonly

manufacturer

This property holds the manufacturer string of the serial port, if available.

› Type:String
› Signal:manufacturerChanged()
› Attributes:Readonly

parity

This property holds the parity checking mode.

› Type:Parity
› Signal:parityChanged()
› Attributes:Writable

portName

This property holds the name of the serial port. The prefix “/dev/” from the system location can be omitted.

› Type:String
› Signal:portNameChanged()
› Attributes:Writable

productIdentifier

This property holds the product identifier of the serial port, if available.

› Type:UnsignedSmallInteger
› Signal:productIdentifierChanged()
› Attributes:Readonly

serialNumber

This property holds the serial number of the serial port, if available.

› Type:String
› Signal:serialNumberChanged()
› Attributes:Readonly

stopBits

This property holds the number of stop bits in a frame.

› Type:StopBits
› Signal:stopBitsChanged()
› Attributes:Writable

usbLocation

This property holds the location of the serial port on the USB bus if the serial port is a virtual USB COM port or similar device.

This property was introduced in InCore 2.0.

› Type:String
› Signal:usbLocationChanged()
› Attributes:Readonly

vendorIdentifier

This property holds the vendor identifier of the serial port, if available.

› Type:UnsignedSmallInteger
› Signal:vendorIdentifierChanged()
› Attributes:Readonly

Methods

builtinRS485PortName()

This method returns the platform-specific name of the builtin RS485 port.

This method was introduced in InCore 2.0.

› Returns:String

Signals

errorOccurred()

This signal is emitted whenever an error has occurred, regardless of whether the error property has changed or not. In contrast to the change notification signal of the error property this signal is also emitted several times if a certain error occurs several times in succession.

Enumerations

BaudRate

This enumeration describes the unit for symbol rate or modulation rate in symbols per second or pulses per second. It is the number of distinct symbol changes (signaling events) made to the transmission medium per second in a digitally modulated signal

Name Value Description
SerialPort.Baud1200 1200 1200 baud.
SerialPort.Baud2400 2400 2400 baud.
SerialPort.Baud4800 4800 4800 baud.
SerialPort.Baud9600 9600 9600 baud.
SerialPort.Baud19200 19200 19200 baud.
SerialPort.Baud38400 38400 38400 baud.
SerialPort.Baud57600 57600 57600 baud.
SerialPort.Baud115200 115200 115200 baud.
SerialPort.Baud230400 230400 230400 baud.
SerialPort.Baud250000 250000 250000 baud.
SerialPort.Baud500000 500000 500000 baud.
SerialPort.Baud1000000 1000000 1000000 baud.

DataBits

This enumeration describes the number of data bits used.

Name Value Description
SerialPort.Data5 5 The number of data bits in each character is 5. It is used for Baudot code. It generally only makes sense with older equipment such as teleprinters.
SerialPort.Data6 6 The number of data bits in each character is 6. It is rarely used.
SerialPort.Data7 7 The number of data bits in each character is 7. It is used for true ASCII. It generally only makes sense with older equipment such as teleprinters.
SerialPort.Data8 8 The number of data bits in each character is 8. It is used for most kinds of data, as this size matches the size of a byte. It is almost universally used in newer applications.

Error

This enumeration describes all errors which can occur in SerialPort objects. The most recently occurred error is stored in the error property.

Name Value Description
SerialPort.NoError 0 No error occurred or was detected.
SerialPort.DeviceNotFoundError 1 An error occurred while attempting to open an non-existing device.
SerialPort.PermissionError 2 An error occurred while attempting to open an already opened device by another process or a user not having enough permission and credentials to open.
SerialPort.OpenError 3 An error occurred while attempting to open an already opened device in this object.
SerialPort.WriteError 7 An I/O error occurred while writing the data.
SerialPort.ReadError 8 An I/O error occurred while reading the data.
SerialPort.ResourceError 9 An I/O error occurred when a resource becomes unavailable, e.g. when the device is unexpectedly removed from the system.
SerialPort.UnsupportedOperationError 10 The requested device operation is not supported or prohibited by the running operating system.
SerialPort.UnknownError 11 Unknown error: an unknown error occurred.
SerialPort.TimeoutError 12 A timeout error occurred.
SerialPort.NotOpenError 13 This error occurs when an operation is executed that can only be successfully performed if the device is open.

Parity

This enumeration describes the parity scheme used.

Name Value Description
SerialPort.NoParity 0 No parity bit it sent. This is the most common parity setting. Error detection is handled by the communication protocol.
SerialPort.EvenParity 2 The number of 1 bits in each character, including the parity bit, is always even.
SerialPort.OddParity 3 The number of 1 bits in each character, including the parity bit, is always odd. It ensures that at least one state transition occurs in each character.
SerialPort.SpaceParity 4 Space parity. The parity bit is sent in the space signal condition. It does not provide error detection information.
SerialPort.MarkParity 5 Mark parity. The parity bit is always set to the mark signal condition (logical 1). It does not provide error detection information.

StopBits

This enumeration describes the number of stop bits used.

Name Value Description
SerialPort.OneStop 1 1 stop bit.
SerialPort.TwoStop 2 2 stop bits.
SerialPort.OneAndHalfStop 3 1.5 stop bits. This is only for the Windows platform.

Example

import InCore.Foundation 2.5
import InCore.IO 2.5

Application {
    SerialPort {
        portName: "ttyUSB0"
        baudRate: SerialPort.Baud9600
        onCompleted: {
            console.log(usbLocation)
            open();
            write("Hello Serial Port!")
        }
        onReadyRead: console.log(readAll())
    }
}