Difference between revisions of "Unit Serial"
Line 4: | Line 4: | ||
=== Description === | === Description === | ||
---- | ---- | ||
+ | |||
+ | '''Ultibo Serial interface unit''' | ||
Serial devices represent a communication device that can be both read and written and has a set of common properties and capabilities. The underlying device may be an actual UART or it may be | Serial devices represent a communication device that can be both read and written and has a set of common properties and capabilities. The underlying device may be an actual UART or it may be |
Revision as of 05:13, 19 December 2016
Return to Unit Reference
Description
Ultibo Serial interface unit
Serial devices represent a communication device that can be both read and written and has a set of common properties and capabilities. The underlying device may be an actual UART or it may be some other form of device such as a USB to Serial converter. As long as the device can implement the common capabilities then it can be accessed as a serial device without regard to the actual implementation.
Each serial device returns a set of properties that describe the capabilities of the device and includes a set of flags that indicate what features are supported.
Reads from and writes to serial devices are buffered so that varying data transfer rates can be accomodated and both reads and writes allow for non blocking so that a caller can avoid waiting for received data to be available or the device to be ready to transmit.
This unit also implements the serial logging device which can be configured via parameters in the GlobalConfig unit or from the command line.
Constants
SERIAL_*
SERIAL_NAME_PREFIX = 'Serial';
|
Name prefix for Serial Devices |
SERIAL_RECEIVE_DEPTH_DEFAULT = SIZE_2K;
|
Default receive buffer size in bytes |
SERIAL_TRANSMIT_
|
Default transmit buffer size in bytes |
SERIAL_TYPE_*
SERIAL_TYPE_NONE = 0;
|
|
SERIAL_TYPE_UART = 1;
|
|
SERIAL_TYPE_USB = 2;
|
SERIAL_STATE_*
SERIAL_STATE_CLOSED = 0;
|
|
SERIAL_STATE_CLOSING = 1;
|
|
SERIAL_STATE_OPENING = 2;
|
|
SERIAL_STATE_OPEN = 3;
|
SERIAL_FLAG_*
SERIAL_FLAG_NONE = $00000000;
|
|
SERIAL_FLAG_DATA_8BIT = $00000001;
|
Device supports 8 data bits |
SERIAL_FLAG_DATA_7BIT = $00000002;
|
Device supports 7 data bits |
SERIAL_FLAG_DATA_6BIT = $00000004;
|
Device supports 6 data bits |
SERIAL_FLAG_DATA_5BIT = $00000008;
|
Device supports 5 data bits |
SERIAL_FLAG_STOP_1BIT = $00000010;
|
Device supports 1 stop bit |
SERIAL_FLAG_STOP_2BIT = $00000020;
|
Device supports 2 stop bits |
SERIAL_FLAG_STOP_1BIT5 = $00000040;
|
Device supports 1.5 stop bits |
SERIAL_FLAG_PARITY_ODD = $00000080;
|
Device supports odd parity |
SERIAL_FLAG_PARITY_EVEN = $00000100;
|
Device supports even parity |
SERIAL_FLAG_PARITY_MARK = $00000200;
|
Device supports mark parity |
SERIAL_FLAG_PARITY_SPACE = $00000400;
|
Device supports space parity |
SERIAL_FLAG_FLOW_RTS_CTS = $00000800;
|
Device supports RTS/CTS flow control |
SERIAL_FLAG_FLOW_DSR_DTR = $00001000;
|
Device supports DSR/DTR flow control |
SERIAL_READ_*
SERIAL_READ_NONE = $00000000;
|
|
SERIAL_READ_NON_BLOCK = $00000001;
|
Do not block when reading, if the buffer is empty return immediately |
SERIAL_READ_PEEK_BUFFER = $00000002;
|
Return the number of bytes available in the receive buffer without reading them |
SERIAL_WRITE_*
SERIAL_WRITE_NONE = $00000000;
|
|
SERIAL_WRITE_NON_BLOCK = $00000001;
|
Do not block when writing, if the buffer is full return immediately |
SERIAL_WRITE_PEEK_BUFFER = $00000002;
|
Return the number of bytes free in the transmit buffer without writing anything |
SERIAL_STATUS_*
SERIAL_STATUS_NONE = $00000000;
|
|
SERIAL_STATUS_RTS = $00000001;
|
RTS (Request to Send) is set (If applicable) |
SERIAL_STATUS_CTS = $00000002;
|
CTS (Clear to Send) is set (If applicable) |
SERIAL_STATUS_DSR = $00000004;
|
DSR (Data Set Ready) is set (If applicable) |
SERIAL_STATUS_DTR = $00000008;
|
DTR (Data Terminal Ready) is set (If applicable) |
SERIAL_STATUS_RX_FULL = $00000010;
|
Receive buffer is full |
SERIAL_STATUS_RX_EMPTY = $00000020;
|
Receive buffer is empty |
SERIAL_STATUS_TX_FULL = $00000040;
|
Transmit buffer is full |
SERIAL_STATUS_TX_EMPTY = $00000080;
|
Transmit buffer is empty |
SERIAL_STATUS_BUSY = $00000100;
|
Device is busy |
SERIAL_STATUS_BREAK_ERROR = $00000200;
|
Break error reported |
SERIAL_STATUS_PARITY_ERROR = $00000400;
|
Parity error reported |
SERIAL_STATUS_FRAMING_ERROR = $00000800;
|
Framing error reported |
SERIAL_STATUS_OVERRUN_ERROR = $00001000;
|
Overrun error reported |
SERIAL_STATUS_DCD = $00002000;
|
DCD (Data Carrier Detect) is set (If applicable) |
SERIAL_STATUS_RI = $00004000;
|
RI (Ring Indicator) is set (If applicable) |
SERIAL_LOG_*
SERIAL_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;
|
Serial debugging messages |
SERIAL_LOG_LEVEL_INFO = LOG_LEVEL_INFO;
|
Serial informational messages, such as a device being attached or detached |
SERIAL_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;
|
Serial error messages |
SERIAL_LOG_LEVEL_NONE = LOG_LEVEL_NONE;
|
No Serial messages |
Type definitions
To be documented
Public variables
To be documented
Function declarations
Initialization functions
procedure SerialInit;
Note | None documented |
---|
Serial functions
function SerialDeviceOpen(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
Note | None documented |
---|
function SerialDeviceClose(Serial:PSerialDevice):LongWord;
Note | None documented |
---|
function SerialDeviceRead(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Note | None documented |
---|
function SerialDeviceWrite(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Note | None documented |
---|
function SerialDeviceStatus(Serial:PSerialDevice):LongWord;
Note | None documented |
---|
function SerialDeviceProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;
Note | None documented |
---|
function SerialDeviceCreate:PSerialDevice;
Return | Pointer to new Serial entry or nil if Serial could not be created |
---|
function SerialDeviceCreateEx(Size:LongWord):PSerialDevice;
Size | Size in bytes to allocate for new Serial (Including the Serial entry) |
---|---|
Return | Pointer to new Serial entry or nil if Serial could not be created |
function SerialDeviceDestroy(Serial:PSerialDevice):LongWord;
Note | None documented |
---|
function SerialDeviceRegister(Serial:PSerialDevice):LongWord;
Note | None documented |
---|
function SerialDeviceDeregister(Serial:PSerialDevice):LongWord;
Note | None documented |
---|
function SerialDeviceFind(SerialId:LongWord):PSerialDevice;
Note | None documented |
---|
function SerialDeviceFindByName(const Name:String):PSerialDevice; inline;
Note | None documented |
---|
function SerialDeviceFindByDescription(const Description:String):PSerialDevice; inline;
Note | None documented |
---|
function SerialDeviceEnumerate(Callback:TSerialEnumerate; Data:Pointer):LongWord;
Note | None documented |
---|
function SerialDeviceNotification(Serial:PSerialDevice; Callback:TSerialNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Note | None documented |
---|
Serial logging functions
function SerialLoggingStart(Logging:PLoggingDevice):LongWord;
Note | None documented |
---|
function SerialLoggingStop(Logging:PLoggingDevice):LongWord;
Note | None documented |
---|
function SerialLoggingOutput(Logging:PLoggingDevice; const Data:String):LongWord;
Note | None documented |
---|
RTL serial functions
function SysSerialAvailable:Boolean;
Note | None documented |
---|
function SysSerialOpen(BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
BaudRate | Baud rate for the connection (eg 9600, 57600, 115200 etc |
---|---|
DataBits | Size of the data (eg SERIAL_DATA_8BIT) |
StopBits | Number of stop bits (eg SERIAL_STOP_1BIT) |
Parity | Parity type for the data (eg SERIAL_PARITY_NONE) |
FlowControl | Flow control for the connection (eg SERIAL_FLOW_NONE) |
ReceiveDepth | Size of the receive buffer (0 = Default size) |
TransmitDepth | Size of the transmit buffer (0 = Default size) |
function SysSerialClose:LongWord;
Note | None documented |
---|
function SysSerialRead(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Buffer | Pointer to a buffer to receive the data |
---|---|
Size | The size of the buffer |
Count | The number of bytes read on return |
function SysSerialWrite(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Buffer | Pointer to a buffer of data to transmit |
---|---|
Size | The size of the buffer |
Count | The number of bytes written on return |
Serial helper functions
function SerialGetCount:LongWord; inline;
Note | None documented |
---|
function SerialDeviceGetDefault:PSerialDevice; inline;
Note | None documented |
---|
function SerialDeviceSetDefault(Serial:PSerialDevice):LongWord;
Note | None documented |
---|
function SerialDeviceCheck(Serial:PSerialDevice):PSerialDevice;
Note | None documented |
---|
function SerialBufferReadStart(Buffer:PSerialBuffer; var Available:LongWord):Pointer;
Note | Caller must hold the lock on the serial device which owns the buffer |
---|
function SerialBufferReadComplete(Buffer:PSerialBuffer; Removed:LongWord):Boolean;
Note | Caller must hold the lock on the serial device which owns the buffer |
---|
function SerialBufferWriteStart(Buffer:PSerialBuffer; var Available:LongWord):Pointer;
Note | Caller must hold the lock on the serial device which owns the buffer |
---|
function SerialBufferWriteComplete(Buffer:PSerialBuffer; Added:LongWord):Boolean;
Note | Caller must hold the lock on the serial device which owns the buffer |
---|
procedure SerialLog(Level:LongWord; Serial:PSerialDevice; const AText:String);
Note | None documented |
---|
procedure SerialLogInfo(Serial:PSerialDevice; const AText:String); inline;
Note | None documented |
---|
procedure SerialLogError(Serial:PSerialDevice; const AText:String); inline;
Note | None documented |
---|
procedure SerialLogDebug(Serial:PSerialDevice; const AText:String); inline;
Note | None documented |
---|
function SerialParityToString(Parity:LongWord):String;
Note | None documented |
---|
function SerialFlowControlToString(Flow:LongWord):String;
Note | None documented |
---|
Serial logging helper functions
function SerialLoggingDeviceAdd(Serial:PSerialDevice):LongWord;
Note | None documented |
---|
function SerialLoggingDeviceRemove(Serial:PSerialDevice):LongWord;
Note | None documented |
---|
function SerialLoggingDeviceParameters(Serial:PSerialDevice; const Parameters:String; var BaudRate,Parity,DataBits,StopBits:LongWord):LongWord;
Note | The parameters must be in the form 'BaudRate,Parity,DataBits,StopBits' (eg '115200,N,8,1') |
---|
function SerialLoggingFirstWord(var Value:String;const Delimiter:String):String;
Note | None documented |
---|
function SerialLoggingDeviceEnum(Serial:PSerialDevice; Data:Pointer):LongWord;
Note | None documented |
---|
function SerialLoggingDeviceNotify(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;
Note | None documented |
---|
Return to Unit Reference