Difference between revisions of "Unit Serial"
Line 251: | Line 251: | ||
---- | ---- | ||
− | '' | + | |
+ | '''Serial properties''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PSerialProperties = ^TSerialProperties;</code> | ||
+ | |||
+ | <code>TSerialProperties = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>Flags:LongWord;</code> | ||
+ | | Device flags (eg SERIAL_FLAG_DATA_8BIT) | ||
+ | |- | ||
+ | | <code>MinRate:LongWord;</code> | ||
+ | | Minimum supported baud rate (0 for any rate supported) | ||
+ | |- | ||
+ | | <code>MaxRate:LongWord;</code> | ||
+ | | Maximum supported baud rate (0 for any rate supported) | ||
+ | |- | ||
+ | | <code>BaudRate:LongWord;</code> | ||
+ | | Current baud rate setting | ||
+ | |- | ||
+ | | <code>DataBits:LongWord;</code> | ||
+ | | Current data bits setting | ||
+ | |- | ||
+ | | <code>StopBits:LongWord;</code> | ||
+ | | Current stop bits setting | ||
+ | |- | ||
+ | | <code>Parity:LongWord;</code> | ||
+ | | Current parity setting | ||
+ | |- | ||
+ | | <code>FlowControl:LongWord;</code> | ||
+ | | Current flow control setting | ||
+ | |- | ||
+ | | <code>ReceiveDepth:LongWord;</code> | ||
+ | | Current receive depth setting | ||
+ | |- | ||
+ | | <code>TransmitDepth:LongWord;</code> | ||
+ | | Current transmit depth setting | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''Serial buffer''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PSerialBuffer = ^TSerialBuffer;</code> | ||
+ | |||
+ | <code>TSerialBuffer = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | | <code>Wait:TEventHandle;</code> | ||
+ | | Data ready / Buffer free event | ||
+ | |- | ||
+ | | <code>Start:LongWord;</code> | ||
+ | | Index of first byte in buffer | ||
+ | |- | ||
+ | | <code>Count:LongWord;</code> | ||
+ | | Number of bytes in buffer | ||
+ | |- | ||
+ | | <code>Size:LongWord;</code> | ||
+ | | Size of buffer | ||
+ | |- | ||
+ | | <code>Data:Pointer;</code> | ||
+ | | Buffered data | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''Serial enumeration callback''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TSerialEnumerate = function(Serial:PSerialDevice; Data:Pointer):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''Serial notification callback''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TSerialNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''Serial device open''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TSerialDeviceOpen = function(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''Serial device close''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TSerialDeviceClose = function(Serial:PSerialDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''Serial device read''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TSerialDeviceRead = function(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''Serial device write''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TSerialDeviceWrite = function(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''Serial device status''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TSerialDeviceStatus = function(Serial:PSerialDevice):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''Serial device properties''' | ||
+ | |||
+ | {| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;" | ||
+ | |- | ||
+ | | <code>TSerialDeviceProperties = function(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;</code> | ||
+ | | style="width: 40%;"| | ||
+ | |- | ||
+ | |} | ||
+ | |||
+ | '''Serial device''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PSerialDevice = ^TSerialDevice;</code> | ||
+ | |||
+ | <code>TSerialDevice = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|''Device Properties'' | ||
+ | |- | ||
+ | | <code>Device:TDevice;</code> | ||
+ | | The Device entry for this Serial | ||
+ | |- | ||
+ | |colspan="2"|''Serial Properties'' | ||
+ | |- | ||
+ | | <code>SerialId:LongWord;</code> | ||
+ | | Unique Id of this Serial device in the Serial device table | ||
+ | |- | ||
+ | | <code>SerialState:LongWord;</code> | ||
+ | | Serial state (eg SERIAL_STATE_OPEN) | ||
+ | |- | ||
+ | | <code>SerialStatus:LongWord;</code> | ||
+ | | Serial status (eg SERIAL_STATUS_RX_FULL)(May not be real time status depending on the driver) | ||
+ | |- | ||
+ | | <code>DeviceOpen:TSerialDeviceOpen;</code> | ||
+ | | A Device specific DeviceOpen method implementing the standard Serial device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceClose:TSerialDeviceClose;</code> | ||
+ | | A Device specific DeviceClose method implementing the standard Serial device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceRead:TSerialDeviceRead;</code> | ||
+ | | A Device specific DeviceRead method implementing the standard Serial device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceWrite:TSerialDeviceWrite;</code> | ||
+ | | A Device specific DeviceWrite method implementing the standard Serial device interface (Mandatory) | ||
+ | |- | ||
+ | | <code>DeviceStatus:TSerialDeviceStatus;</code> | ||
+ | | A Device specific DeviceStatus method implementing the standard Serial device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | | <code>DeviceProperties:TSerialDeviceProperties;</code> | ||
+ | | A Device specific DeviceProperties method implementing the standard Serial device interface (Or nil if the default method is suitable) | ||
+ | |- | ||
+ | |colspan="2"|''Driver Properties'' | ||
+ | |- | ||
+ | | <code>Lock:TMutexHandle;</code> | ||
+ | | Device lock | ||
+ | |- | ||
+ | | <code>Receive:TSerialBuffer;</code> | ||
+ | | Serial receive buffer | ||
+ | |- | ||
+ | | <code>Transmit:TSerialBuffer;</code> | ||
+ | | Serial transmit buffer | ||
+ | |- | ||
+ | | <code>Properties:TSerialProperties;</code> | ||
+ | | Device properties | ||
+ | |- | ||
+ | |colspan="2"|''Statistics Properties'' | ||
+ | |- | ||
+ | | <code>ReceiveCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ReceiveErrors:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>ReceiveOverruns:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>TransmitCount:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>TransmitErrors:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>TransmitOverruns:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | |colspan="2"|''Internal Properties'' | ||
+ | |- | ||
+ | | <code>Prev:PSerialDevice;</code> | ||
+ | | Previous entry in Serial table | ||
+ | |- | ||
+ | | <code>Next:PSerialDevice;</code> | ||
+ | | Next entry in Serial table | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | |||
+ | '''Serial logging''' | ||
+ | |||
+ | <div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial;"> | ||
+ | <code>PSerialLogging = ^TSerialLogging;</code> | ||
+ | |||
+ | <code>TSerialLogging = record</code> | ||
+ | <div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;"> | ||
+ | {| class="wikitable" style="font-size: 14px; background: white;" | ||
+ | |- | ||
+ | |colspan="2"|''Logging Properties'' | ||
+ | |- | ||
+ | | <code>Logging:TLoggingDevice;</code> | ||
+ | | style="width: 50%;"| | ||
+ | |- | ||
+ | |colspan="2"|''Serial Properties'' | ||
+ | |- | ||
+ | | <code>Serial:PSerialDevice;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>BaudRate:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>DataBits:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>StopBits:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>Parity:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | | <code>FlowControl:LongWord;</code> | ||
+ | | | ||
+ | |- | ||
+ | |} | ||
+ | </div></div> | ||
+ | <br /> | ||
=== Public variables === | === Public variables === |
Revision as of 03:21, 25 January 2017
Return to Unit Reference
Contents
[hide]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_TYPE_*
SERIAL_STATE_*
SERIAL_FLAG_*
SERIAL_READ_*
SERIAL_WRITE_*
SERIAL_STATUS_*
SERIAL_LOG_*
SERIAL_LOGGING_*
Type definitions
Serial properties
Serial buffer
Serial enumeration callback
TSerialEnumerate = function(Serial:PSerialDevice; Data:Pointer):LongWord;
|
Serial notification callback
TSerialNotification = function(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;
|
Serial device open
TSerialDeviceOpen = function(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
|
Serial device close
TSerialDeviceClose = function(Serial:PSerialDevice):LongWord;
|
Serial device read
TSerialDeviceRead = function(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
|
Serial device write
TSerialDeviceWrite = function(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
|
Serial device status
TSerialDeviceStatus = function(Serial:PSerialDevice):LongWord;
|
Serial device properties
TSerialDeviceProperties = function(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;
|
Serial device
Serial logging
Public variables
Serial logging
SERIAL_DEFAULT_LOG_LEVEL:LongWord = SERIAL_LOG_LEVEL_DEBUG;
|
Minimum level for Serial messages. Only messages with level greater than or equal to this will be printed. |
SERIAL_LOG_ENABLED:Boolean;
|
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