Difference between revisions of "Unit Serial"
Line 19: | Line 19: | ||
---- | ---- | ||
− | '' | + | |
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Serial specific constants''' <code> SERIAL_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SERIAL_NAME_PREFIX = 'Serial';</code> | ||
+ | | Name prefix for Serial Devices | ||
+ | |- | ||
+ | |colspan="2"| | ||
+ | |- | ||
+ | | <code>SERIAL_RECEIVE_DEPTH_DEFAULT = SIZE_2K;</code> | ||
+ | | Default receive buffer size in bytes | ||
+ | |- | ||
+ | | <code>SERIAL_TRANSMIT_</code> | ||
+ | | Default transmit buffer size in bytes | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Serial device type constants''' <code> SERIAL_TYPE_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SERIAL_TYPE_NONE = 0;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | | <code>SERIAL_TYPE_UART = 1;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>SERIAL_TYPE_USB = 2;</code> | ||
+ | | | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Serial device state constants''' <code> SERIAL_STATE_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SERIAL_STATE_CLOSED = 0;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | | <code>SERIAL_STATE_CLOSING = 1;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>SERIAL_STATE_OPENING = 2;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>SERIAL_STATE_OPEN = 3;</code> | ||
+ | | | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Serial device flag constants''' <code> SERIAL_FLAG_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_NONE = $00000000;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_DATA_8BIT = $00000001;</code> | ||
+ | | Device supports 8 data bits | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_DATA_7BIT = $00000002;</code> | ||
+ | | Device supports 7 data bits | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_DATA_6BIT = $00000004;</code> | ||
+ | | Device supports 6 data bits | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_DATA_5BIT = $00000008;</code> | ||
+ | | Device supports 5 data bits | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_STOP_1BIT = $00000010;</code> | ||
+ | | Device supports 1 stop bit | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_STOP_2BIT = $00000020;</code> | ||
+ | | Device supports 2 stop bits | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_STOP_1BIT5 = $00000040;</code> | ||
+ | | Device supports 1.5 stop bits | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_PARITY_ODD = $00000080;</code> | ||
+ | | Device supports odd parity | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_PARITY_EVEN = $00000100;</code> | ||
+ | | Device supports even parity | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_PARITY_MARK = $00000200;</code> | ||
+ | | Device supports mark parity | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_PARITY_SPACE = $00000400;</code> | ||
+ | | Device supports space parity | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_FLOW_RTS_CTS = $00000800;</code> | ||
+ | | Device supports RTS/CTS flow control | ||
+ | |- | ||
+ | | <code>SERIAL_FLAG_FLOW_DSR_DTR = $00001000;</code> | ||
+ | | Device supports DSR/DTR flow control | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Serial read flag constants''' <code> SERIAL_READ_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SERIAL_READ_NONE = $00000000;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>SERIAL_READ_NON_BLOCK = $00000001;</code> | ||
+ | | Do not block when reading, if the buffer is empty return immediately | ||
+ | |- | ||
+ | | <code>SERIAL_READ_PEEK_BUFFER = $00000002;</code> | ||
+ | | Return the number of bytes available in the receive buffer without reading them | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Serial write flag constants''' <code> SERIAL_WRITE_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SERIAL_WRITE_NONE = $00000000;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>SERIAL_WRITE_NON_BLOCK = $00000001;</code> | ||
+ | | Do not block when writing, if the buffer is full return immediately | ||
+ | |- | ||
+ | | <code>SERIAL_WRITE_PEEK_BUFFER = $00000002;</code> | ||
+ | | Return the number of bytes free in the transmit buffer without writing anything | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Serial status flag constants''' <code> SERIAL_STATUS_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_NONE = $00000000;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_RTS = $00000001;</code> | ||
+ | | RTS (Request to Send) is set (If applicable) | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_CTS = $00000002;</code> | ||
+ | | CTS (Clear to Send) is set (If applicable) | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_DSR = $00000004;</code> | ||
+ | | DSR (Data Set Ready) is set (If applicable) | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_DTR = $00000008;</code> | ||
+ | | DTR (Data Terminal Ready) is set (If applicable) | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_RX_FULL = $00000010;</code> | ||
+ | | Receive buffer is full | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_RX_EMPTY = $00000020;</code> | ||
+ | | Receive buffer is empty | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_TX_FULL = $00000040;</code> | ||
+ | | Transmit buffer is full | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_TX_EMPTY = $00000080;</code> | ||
+ | | Transmit buffer is empty | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_BUSY = $00000100;</code> | ||
+ | | Device is busy | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_BREAK_ERROR = $00000200;</code> | ||
+ | | Break error reported | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_PARITY_ERROR = $00000400;</code> | ||
+ | | Parity error reported | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_FRAMING_ERROR = $00000800;</code> | ||
+ | | Framing error reported | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_OVERRUN_ERROR = $00001000;</code> | ||
+ | | Overrun error reported | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_DCD = $00002000;</code> | ||
+ | | DCD (Data Carrier Detect) is set (If applicable) | ||
+ | |- | ||
+ | | <code>SERIAL_STATUS_RI = $00004000;</code> | ||
+ | | RI (Ring Indicator) is set (If applicable) | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 20px; padding-bottom: 15px;"> | ||
+ | <div style="font-size: 14px; padding-left: 12px;">'''Serial logging constants''' <code> SERIAL_LOG_* </code></div> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>SERIAL_LOG_LEVEL_DEBUG = LOG_LEVEL_DEBUG;</code> | ||
+ | | Serial debugging messages | ||
+ | |- | ||
+ | | <code>SERIAL_LOG_LEVEL_INFO = LOG_LEVEL_INFO;</code> | ||
+ | | Serial informational messages, such as a device being attached or detached | ||
+ | |- | ||
+ | | <code>SERIAL_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;</code> | ||
+ | | Serial error messages | ||
+ | |- | ||
+ | | <code>SERIAL_LOG_LEVEL_NONE = LOG_LEVEL_NONE;</code> | ||
+ | | No Serial messages | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Type definitions === | === Type definitions === |
Revision as of 03:17, 29 November 2016
Return to Unit Reference
Contents
[hide]Description
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_TYPE_*
SERIAL_STATE_*
SERIAL_FLAG_*
SERIAL_READ_*
SERIAL_WRITE_*
SERIAL_STATUS_*
SERIAL_LOG_*
Type definitions
To be documented
Public variables
To be documented
Function declarations
Initialization functions
Serial functions
function SerialDeviceOpen(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
function SerialDeviceRead(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function SerialDeviceWrite(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
function SerialDeviceProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;
function SerialDeviceCreateEx(Size:LongWord):PSerialDevice;
function SerialDeviceDestroy(Serial:PSerialDevice):LongWord;
function SerialDeviceRegister(Serial:PSerialDevice):LongWord;
function SerialDeviceDeregister(Serial:PSerialDevice):LongWord;
function SerialDeviceFindByName(const Name:String):PSerialDevice; inline;
function SerialDeviceFindByDescription(const Description:String):PSerialDevice; inline;
function SerialDeviceEnumerate(Callback:TSerialEnumerate; Data:Pointer):LongWord;
function SerialDeviceNotification(Serial:PSerialDevice; Callback:TSerialNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Serial logging functions
function SerialLoggingStart(Logging:PLoggingDevice):LongWord;
function SerialLoggingOutput(Logging:PLoggingDevice; const Data:String):LongWord;
RTL serial functions
function SysSerialOpen(BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
function SysSerialClose:LongWord;
function SysSerialRead(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
function SysSerialWrite(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Serial helper functions
function SerialDeviceGetDefault:PSerialDevice; inline;
function SerialDeviceSetDefault(Serial:PSerialDevice):LongWord;
function SerialDeviceCheck(Serial:PSerialDevice):PSerialDevice;
function SerialBufferReadStart(Buffer:PSerialBuffer; var Available:LongWord):Pointer;
function SerialBufferReadComplete(Buffer:PSerialBuffer; Removed:LongWord):Boolean;
function SerialBufferWriteStart(Buffer:PSerialBuffer; var Available:LongWord):Pointer;
function SerialBufferWriteComplete(Buffer:PSerialBuffer; Added:LongWord):Boolean;
procedure SerialLog(Level:LongWord; Serial:PSerialDevice; const AText:String);
procedure SerialLogInfo(Serial:PSerialDevice; const AText:String); inline;
procedure SerialLogError(Serial:PSerialDevice; const AText:String); inline;
procedure SerialLogDebug(Serial:PSerialDevice; const AText:String); inline;
Serial logging helper functions
function SerialLoggingDeviceAdd(Serial:PSerialDevice):LongWord;
function SerialLoggingDeviceRemove(Serial:PSerialDevice):LongWord;
function SerialLoggingDeviceParameters(Serial:PSerialDevice; const Parameters:String; var BaudRate,Parity,DataBits,StopBits:LongWord):LongWord;
function SerialLoggingFirstWord(var Value:String;const Delimiter:String):String;
function SerialLoggingDeviceEnum(Serial:PSerialDevice; Data:Pointer):LongWord;
function SerialLoggingDeviceNotify(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;
Return to Unit Reference