obj
UART.swift:71This declaration is gated by at least one @_spi attribute.
let obj: UnsafeMutableRawPointer
This declaration is gated by at least one @_spi attribute.
let obj: UnsafeMutableRawPointer
import SwiftIO
The SwiftIO library allows you to access and control the hardware in an easy way.
final class UART
UART is a two-wire serial communication protocol used to communicate with serial devices. The devices must agree on a common transmisson rate before communication.
@frozen struct UnsafeMutableRawPointer
A raw pointer for accessing and manipulating untyped data.
init(_ idName: Id, baudRate: Int = 115200, parity: Parity = .none, stopBits: StopBits = .oneBit, dataBits: DataBits = .eightBits, readBufferLength: Int = 1024)
Initializes an interface for UART communication.
func checkBufferReceived() -> Int
Returns the number of received data from the serial buffer.
@discardableResult func clearBuffer() -> Result<(), Errno>
Clears all bytes from the buffer to store the incoming data.
func getBaudRate() -> Int
Gets the current baud rate for serial communication.
@discardableResult func read(into buffer: inout [UInt8], count: Int? = nil, timeout: Int? = nil) -> Result<Int, Errno>
Reads a specified amount of bytes from the external device.
@discardableResult func read(into buffer: UnsafeMutableRawBufferPointer, count: Int? = nil, timeout: Int? = nil) -> Result<Int, Errno>
Reads a specified amount of bytes from the external device into the buffer pointer.
@discardableResult func read(into buffer: inout UInt8, timeout: Int? = nil) -> Result<Int, Errno>
Reads a byte from the external device.
@discardableResult func setBaudRate(_ baudRate: Int) -> Result<(), Errno>
Sets the baud rate for communication. It should be set ahead of time to ensure the same baud rate between devices.
@discardableResult func write(_ byte: UInt8) -> Result<(), Errno>
Writes a byte to the external device through the serial connection.
@discardableResult func write(_ string: String, addNullTerminator: Bool = false) -> Result<(), Errno>
Writes a string to the external device through the serial connection.
@discardableResult func write(_ data: UnsafeRawBufferPointer, count: Int? = nil) -> Result<(), Errno>
Writes buffer pointer of the data in the underlying storage to the external device.
@discardableResult func write(_ data: [UInt8], count: Int? = nil) -> Result<(), Errno>
Writes a series of bytes to the external device through the serial connection.
enum DataBits
The length of the data being transmitted.
enum Parity
The parity bit used to verify if data has changed during transmission. It counts the number of logical-high bits and see if it equals an odd or even number.
enum StopBits
One or two stops bits are reserved to end the communication.