Low-level C API wrappers
LibSerialPort.Lib
— ModuleThe LibSerialPort.Lib
module provides a low-level Julia wrapper around each of the C function, types and constants exported by the C library libserialport. The wrapper functions very closely follow the C API, but they check for error codes returned and raise these as a Julia ErrorException
.
LibSerialPort.Lib.sp_blocking_write
— Methodfunction sp_blocking_write(port::Port, buffer::Union{Ref{T},Ptr{T}},
n::Integer = 1; timeout_ms::Integer = 0) where T`
Write the sizeof(T)*n
bytes starting from address buffer
to the specified serial port, blocking until complete.
Note that this function only ensures that the accepted bytes have been written to the OS; they may be held in driver or hardware buffers and not yet physically transmitted. To check whether all written bytes have actually been transmitted, use the sp_output_waiting()
function. To wait until all written bytes have actually been transmitted, use the sp_drain()
function.
Wait up to timeout_ms
milliseconds, where zero means to wait indefinitely.
Returns the number of bytes written on success, or raises an ErrorException
. If the number of bytes returned is less than that requested, the timeout was reached before the requested number of bytes was written. If timeout_ms
is zero, the function will always return either the requested number of bytes or raise an ErrorException
. In the event of an error there is no way to determine how many bytes were sent before the error occured.
LibSerialPort.Lib.sp_drain
— Methodsp_drain(port::Port)
sp_drain(SerialPort::Port)
Wait for buffered data to be transmitted.
LibSerialPort.Lib.sp_flush
— Methodsp_flush(port::Port, buffers::SPBuffer)
sp_flush(port::SerialPort, buffers::SPBuffer)
Discard data in the selected serial-port buffer(s).
Supported values for buffers
: SP_BUF_INPUT
, SP_BUF_OUTPUT
, SP_BUF_BOTH
Returns SP_OK
upon success or raises an ErrorException
otherwise.
Not to be confused with Base.flush
, which writes out buffered data rather than discarding it: the underlying libserialport
C library unfortunately uses the verb “flush” differently from its normal meaning for Base.IO
(sp_drain
provides the latter in this library).
LibSerialPort.Lib.sp_input_waiting
— MethodReturns the number of bytes in the input buffer.
LibSerialPort.Lib.sp_nonblocking_write
— Methodsp_nonblocking_write(port::Port, buffer::Union{Ptr{T},Ref{T}},
n::Integer = 1) where T`
Write the up to sizeof(T)*n
bytes starting from address buffer
to the specified serial port, without blocking.
Note that this function only ensures that the accepted bytes have been written to the OS; they may be held in driver or hardware buffers and not yet physically transmitted. To check whether all written bytes have actually been transmitted, use the sp_output_waiting()
function. To wait until all written bytes have actually been transmitted, use the sp_drain()
function.
Returns the number of bytes written on success, or raises an ErrorException
. The number of bytes returned may be any number from zero to the maximum that was requested.
LibSerialPort.Lib.sp_output_waiting
— MethodReturns the number of bytes in the output buffer.