clearBuffer
Clears all bytes from the buffer to store the incoming data.
@discardableResult func clearBuffer() -> Result<(), Errno>
Returns
Whether the configuration succeeds. If not, it returns the specific error.
Clears all bytes from the buffer to store the incoming data.
@discardableResult func clearBuffer() -> Result<(), Errno>
Whether the configuration succeeds. If not, it returns the specific error.
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 enum Result<Success, Failure> where Failure : Error, Success : ~Copyable
A value that represents either a success or a failure, including an associated value in each case.
struct Errno
The Errno struct lists all the possible errors.
@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.
func getBaudRate() -> Int
Gets the current baud rate for serial communication.
func checkBufferReceived() -> Int
Returns the number of received data from the serial buffer.
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.
init(_ idName: Id, baudRate: Int = 115200, parity: Parity = .none, stopBits: StopBits = .oneBit, dataBits: DataBits = .eightBits, readBufferLength: Int = 1024)
Initializes an interface for UART communication.
let obj: UnsafeMutableRawPointer
@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 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.