Difference between revisions of "Unit Serial"

From Ultibo.org
Jump to: navigation, search
 
(31 intermediate revisions by the same user not shown)
Line 5: Line 5:
 
----
 
----
  
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
+
'''Ultibo Serial Interface unit'''
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
+
 
 +
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.
 
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.
 
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
+
Reads from and writes to serial devices are buffered so that varying data transfer rates can be accommodated 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.
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.
 
This unit also implements the serial logging device which can be configured via parameters in the GlobalConfig unit or from the command line.
Line 19: Line 19:
 
----
 
----
  
''To be documented''
+
 
 +
<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"|&nbsp;
 +
|-
 +
| <code>SERIAL_LOGGING_DESCRIPTION = 'Serial Logging';</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>SERIAL_RECEIVE_DEPTH_DEFAULT = SIZE_2K;</code>
 +
| Default receive buffer size in bytes
 +
|-
 +
| <code>SERIAL_TRANSMIT_DEPTH_DEFAULT = SIZE_2K;</code>
 +
| Default transmit buffer size in bytes
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>SERIAL_PUSH_TIMEOUT = 50;</code>
 +
| Timeout (Milliseconds) for Push RX/TX (Implementation specific)
 +
|-
 +
|}
 +
</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''' <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%;"|&nbsp;
 +
|-
 +
| <code>SERIAL_TYPE_UART = 1;</code>
 +
| &nbsp;
 +
|-
 +
| <code>SERIAL_TYPE_USB = 2;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>SERIAL_TYPE_MAX = 2;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</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''' <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%;"|&nbsp;
 +
|-
 +
| <code>SERIAL_STATE_CLOSING = 1;</code>
 +
| &nbsp;
 +
|-
 +
| <code>SERIAL_STATE_OPENING = 2;</code>
 +
| &nbsp;
 +
|-
 +
| <code>SERIAL_STATE_OPEN = 3;</code>
 +
| &nbsp;
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>SERIAL_STATE_MAX = 3;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</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''' <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>
 +
| &nbsp;
 +
|-
 +
| <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
 +
|-
 +
| <code>SERIAL_FLAG_PUSH_RX = $00002000;</code>
 +
| Device requires pushed receive (Implementation specific)
 +
|-
 +
| <code>SERIAL_FLAG_PUSH_TX = $00004000;</code>
 +
| Device requires pushed transmit (Implementation specific)
 +
|-
 +
|}
 +
</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''' <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>
 +
| &nbsp;
 +
|-
 +
| <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''' <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>
 +
| &nbsp;
 +
|-
 +
| <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 wait directions''' <code> SERIAL_WAIT_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>SERIAL_WAIT_NONE = 0;</code>
 +
| &nbsp;
 +
|-
 +
| <code>SERIAL_WAIT_RECEIVE = 1;</code>
 +
| Wait for data to be available in the receive buffer
 +
|-
 +
| <code>SERIAL_WAIT_TRANSMIT = 2;</code>
 +
| Wait for space to be available in the transmit buffer
 +
|-
 +
|}
 +
</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 flush flag''' <code> SERIAL_FLUSH_* </code></div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
| <code>SERIAL_FLUSH_NONE = $00000000;</code>
 +
| &nbsp;
 +
|-
 +
| <code>SERIAL_FLUSH_RECEIVE  = $00000001;</code>
 +
| Flush the receive buffer
 +
|-
 +
| <code>SERIAL_FLUSH_TRANSMIT = $00000002;</code>
 +
| Flush the transmit buffer
 +
|-
 +
|}
 +
</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''' <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>
 +
| &nbsp;
 +
|-
 +
| <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''' <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_WARN = LOG_LEVEL_WARN;</code>
 +
| Serial warning messages
 +
|-
 +
| <code>SERIAL_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR;</code>
 +
| Serial error messages
 +
|-
 +
| <code>SERIAL_LOG_LEVEL_NONE = LOG_LEVEL_NONE;</code>
 +
| No Serial messages
 +
|-
 +
|colspan="2"|&nbsp;
 +
|-
 +
| <code>SERIAL_LOGGING_LINE_END = Chr(13) + Chr(10);</code>
 +
| CR LF
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Type definitions ===
 
=== Type definitions ===
 
----
 
----
  
''To be documented''
+
 
 +
'''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 wait'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSerialDeviceWait = function(Serial:PSerialDevice; Direction,Timeout:LongWord; var Count:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Serial device flush'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSerialDeviceFlush = function(Serial:PSerialDevice;Flags:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Serial device get status'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSerialDeviceGetStatus = function(Serial:PSerialDevice):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Serial device set status'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSerialDeviceSetStatus = function(Serial:PSerialDevice; Status:LongWord):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Serial device get properties'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSerialDeviceGetProperties = function(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
 
 +
'''Serial device set properties'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>TSerialDeviceSetProperties = 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>DeviceWait:TSerialDeviceWait;</code>
 +
| A Device specific DeviceWait method implementing the standard Serial device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceFlush:TSerialDeviceFlush;</code>
 +
| A Device specific DeviceFlush method implementing the standard Serial device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceGetStatus:TSerialDeviceGetStatus;</code>
 +
| A Device specific DeviceGetStatus method implementing the standard Serial device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceSetStatus:TSerialDeviceSetStatus;</code>
 +
| A Device specific DeviceSetStatus method implementing the standard Serial device interface (Optional)
 +
|-
 +
| <code>DeviceGetProperties:TSerialDeviceGetProperties;</code>
 +
| A Device specific DeviceGetProperties method implementing the standard Serial device interface (Or nil if the default method is suitable)
 +
|-
 +
| <code>DeviceSetProperties:TSerialDeviceSetProperties;</code>
 +
| A Device specific DeviceSetProperties 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>
 +
| &nbsp;
 +
|-
 +
| <code>ReceiveErrors:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>ReceiveOverruns:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>TransmitCount:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>TransmitErrors:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>TransmitOverruns:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
|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%;"|&nbsp;
 +
|-
 +
|colspan="2"|''Serial Properties''
 +
|-
 +
| <code>Serial:PSerialDevice;</code>
 +
| &nbsp;
 +
|-
 +
| <code>BaudRate:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>DataBits:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>StopBits:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>Parity:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
| <code>FlowControl:LongWord;</code>
 +
| &nbsp;
 +
|-
 +
|}
 +
</div></div>
 +
<br />
  
 
=== Public variables ===
 
=== Public variables ===
 
----
 
----
  
''To be documented''
+
 
 +
'''Serial logging'''
 +
 
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>SERIAL_DEFAULT_LOG_LEVEL:LongWord = SERIAL_LOG_LEVEL_DEBUG;</code>
 +
| style="width: 40%;"|Minimum level for Serial messages. Only messages with level greater than or equal to this will be printed.
 +
|-
 +
|}
 +
{| class="wikitable" style="font-size: 14px; text-align: left; width: 100%; height: 50px;"
 +
|-
 +
| <code>SERIAL_LOG_ENABLED:Boolean;</code>
 +
| style="width: 40%;"|
 +
|-
 +
|}
 +
<br />
  
 
=== Function declarations ===
 
=== Function declarations ===
Line 43: Line 656:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| None documented
 
|-
 
|-
 
|}
 
|}
Line 54: Line 667:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceOpen(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceOpen(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Open a Serial device ready for sending and receiving</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Serial
| To be documented
+
| The Serial device to open
 +
|-
 +
! 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)
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 66: Line 703:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceClose(Serial:PSerialDevice):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceClose(Serial:PSerialDevice):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Close a Serial device and terminate sending and receiving</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Serial
| To be documented
+
| The Serial device to close
 +
|-
 +
! Note
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 78: Line 718:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceRead(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceRead(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read data from a Serial device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Serial
| To be documented
+
| The Serial device to read from
 +
|-
 +
! Buffer
 +
| Pointer to a buffer to receive the data
 +
|-
 +
! Size
 +
| The size of the buffer
 +
|-
 +
! Flags
 +
| The flags to control reading (eg SERIAL_READ_NON_BLOCK)
 +
|-
 +
! Count
 +
| The number of bytes read on return
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 90: Line 745:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceWrite(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceWrite(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Write data to a Serial device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Serial
| To be documented
+
| The Serial device to write to
 +
|-
 +
! Buffer
 +
| Pointer to a buffer of data to transmit
 +
|-
 +
! Size
 +
| The size of the buffer
 +
|-
 +
! Flags
 +
| The flags to control writing (eg SERIAL_WRITE_NON_BLOCK)
 +
|-
 +
! Count
 +
| The number of bytes written on return
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 101: Line 771:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceStatus(Serial:PSerialDevice):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceWait(Serial:PSerialDevice; Direction,Timeout:LongWord; var Count:LongWord):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Wait for data to be available in the receive or transmit buffers of a Serial device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Serial
| To be documented
+
| The Serial device to wait for
 +
|-
 +
! Direction
 +
| The direction of data to wait for (eg SERIAL_WAIT_RECEIVE)
 +
|-
 +
! Timeout
 +
| The number of milliseconds to wait for data (INFINITE to wait forever)
 +
|-
 +
! Count
 +
| The number of bytes available on return
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 113: Line 795:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceFlush(Serial:PSerialDevice; Flags:LongWord):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Discard the contents of the receive and/or transmit buffers of a Serial device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Serial
| To be documented
+
| The Serial device to flush
 +
|-
 +
! Flags
 +
| The flags to indicate what to flush (eg SERIAL_FLUSH_RECEIVE)
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceStatus(Serial:PSerialDevice):LongWord; inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current line status of a Serial device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Serial
 +
| The Serial device to get the status from
 +
|-
 +
! Return
 +
| A set of flags containing the device status (eg SERIAL_STATUS_RTS)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceGetStatus(Serial:PSerialDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current line status of a Serial device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Serial
 +
| The Serial device to get the status from
 +
|-
 +
! Return
 +
| A set of flags containing the device status (eg SERIAL_STATUS_RTS)
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceSetStatus(Serial:PSerialDevice; Status:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the current line status of a Serial device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Serial
 +
| The Serial device to set the status for
 +
|-
 +
! Status
 +
| The device status flags to be set (eg SERIAL_STATUS_RTS)
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
! Note
 +
| Not all SERIAL_STATUS_* flags can be set, the device may ignore invalid values.
 +
Not all serial devices support set status, returns ERROR_CALL_NOT_IMPLEMENTED if not supported.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord; inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the properties for the specified Serial device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Serial
 +
| The Serial device to get properties from
 +
|-
 +
! Properties
 +
| Pointer to a PSerialProperties structure to fill in
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
! Note
 +
| Replaced by SerialDeviceGetProperties for consistency
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceGetProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the properties for the specified Serial device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Serial
 +
| The Serial device to get properties from
 +
|-
 +
! Properties
 +
| Pointer to a PSerialProperties structure to fill in
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceSetProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Set the properties for the specified Serial device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Serial
 +
| The Serial device to set properties for
 +
|-
 +
! Properties
 +
| Pointer to a PSerialProperties structure to use
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 130: Line 927:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Return'''
+
! Return
 
| Pointer to new Serial entry or nil if Serial could not be created
 
| Pointer to new Serial entry or nil if Serial could not be created
 
|-
 
|-
Line 142: Line 939:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Size'''
+
! Size
 
| Size in bytes to allocate for new Serial (Including the Serial entry)
 
| Size in bytes to allocate for new Serial (Including the Serial entry)
 
|-
 
|-
! '''Return'''
+
! Return
 
| Pointer to new Serial entry or nil if Serial could not be created
 
| Pointer to new Serial entry or nil if Serial could not be created
 
|-
 
|-
Line 157: Line 954:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Serial
| To be documented
+
| The serial device to destroy
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 169: Line 969:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Serial
| To be documented
+
| The serial device to register
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceDeregister(Serial:PSerialDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Deregister a Serial from the Serial table</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Serial
 +
| The serial device to deregister
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 177: Line 995:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceFind(SerialId:LongWord):PSerialDevice;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceFind(SerialId:LongWord):PSerialDevice;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find a serial device by Id in the serial table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! SerialId
| To be documented
+
| The Id number of the serial to find
 +
|-
 +
! Return
 +
| Pointer to serial device entry or nil if not found
 
|-
 
|-
 
|}
 
|}
Line 189: Line 1,010:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceFindByName(const Name:String):PSerialDevice; inline;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceFindByName(const Name:String):PSerialDevice; inline;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find a serial device by name in the serial table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Name
| To be documented
+
| The name of the serial to find (eg Serial0)
 +
|-
 +
! Return
 +
| Pointer to serial device entry or nil if not found
 
|-
 
|-
 
|}
 
|}
Line 201: Line 1,025:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceFindByDescription(const Description:String):PSerialDevice; inline;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceFindByDescription(const Description:String):PSerialDevice; inline;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Find a serial device by description in the serial table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Description
| To be documented
+
| The description of the serial to find (eg BCM2836 PL011 UART)
 +
|-
 +
! Return
 +
| Pointer to serial device entry or nil if not found
 
|-
 
|-
 
|}
 
|}
Line 213: Line 1,040:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceEnumerate(Callback:TSerialEnumerate; Data:Pointer):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceEnumerate(Callback:TSerialEnumerate; Data:Pointer):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Enumerate all serial devices in the serial table</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Callback
| To be documented
+
| The callback function to call for each serial in the table
 +
|-
 +
! Data
 +
| A private data pointer to pass to callback for each serial in the table
 +
|-
 +
! Return
 +
| ERROR_SUCCESS if completed or another error code on failure
 
|-
 
|-
 
|}
 
|}
Line 225: Line 1,058:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceNotification(Serial:PSerialDevice; Callback:TSerialNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceNotification(Serial:PSerialDevice; Callback:TSerialNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Register a notification for serial device changes</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Serial
| To be documented
+
| The serial device to notify changes for (Optional, pass nil for all serial devices)
 +
|-
 +
! Callback
 +
| The function to call when a notification event occurs
 +
|-
 +
! Data
 +
| A private data pointer to pass to callback when a notification event occurs
 +
|-
 +
! Notification
 +
| The events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
 +
|-
 +
! Flags
 +
| The flags to control the notification (eg NOTIFIER_FLAG_WORKER)
 
|-
 
|-
 
|}
 
|}
Line 240: Line 1,085:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingStart(Logging:PLoggingDevice):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingStart(Logging:PLoggingDevice):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of LoggingDeviceStart API for Serial Logging</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| Not intended to be called directly by applications, use LoggingDeviceStart instead.
 
|-
 
|-
 
|}
 
|}
Line 252: Line 1,097:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingStop(Logging:PLoggingDevice):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingStop(Logging:PLoggingDevice):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of LoggingDeviceStop API for Serial Logging</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| Not intended to be called directly by applications, use LoggingDeviceStop instead.
 
|-
 
|-
 
|}
 
|}
Line 264: Line 1,109:
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingOutput(Logging:PLoggingDevice; const Data:String):LongWord;</pre>
 
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingOutput(Logging:PLoggingDevice; const Data:String):LongWord;</pre>
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
+
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of LoggingDeviceOutput API for Serial Logging</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications, use LoggingDeviceOutput instead.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingSetTarget(Logging:PLoggingDevice; const Target:String):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Implementation of LoggingDeviceSetTarget API for Serial Logging</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications, use LoggingDeviceSetTarget instead.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 
 +
'''RTL text IO functions'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SysTextIOReadChar(var ACh:Char; AUserData:Pointer):Boolean;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Handler for platform TextIOReadChar function</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SysTextIOWriteChar(ACh:Char; AUserData:Pointer):Boolean;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Handler for platform TextIOWriteChar function</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SysTextIOWriteBuffer(ABuffer:PChar; ACount:LongInt; AUserData:Pointer):LongInt;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Handler for platform TextIOWriteBuffer function</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| Not intended to be called directly by applications
 
|-
 
|-
 
|}
 
|}
Line 283: Line 1,179:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| None documented
 
|-
 
|-
 
|}
 
|}
Line 295: Line 1,191:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''BaudRate'''
+
! BaudRate
| Baud rate for the connection (eg 9600, 57600, 115200 etc
+
| Baud rate for the connection (eg 9600, 57600, 115200 etc)
 
|-
 
|-
! '''DataBits'''
+
! DataBits
 
| Size of the data (eg SERIAL_DATA_8BIT)
 
| Size of the data (eg SERIAL_DATA_8BIT)
 
|-
 
|-
! '''StopBits'''
+
! StopBits
 
| Number of stop bits (eg SERIAL_STOP_1BIT)
 
| Number of stop bits (eg SERIAL_STOP_1BIT)
 
|-
 
|-
! '''Parity'''
+
! Parity
 
| Parity type for the data (eg SERIAL_PARITY_NONE)
 
| Parity type for the data (eg SERIAL_PARITY_NONE)
 
|-
 
|-
! '''FlowControl'''
+
! FlowControl
 
| Flow control for the connection (eg SERIAL_FLOW_NONE)
 
| Flow control for the connection (eg SERIAL_FLOW_NONE)
 
|-
 
|-
! '''ReceiveDepth'''
+
! ReceiveDepth
 
| Size of the receive buffer (0 = Default size)
 
| Size of the receive buffer (0 = Default size)
 
|-
 
|-
! '''TransmitDepth'''
+
! TransmitDepth
 
| Size of the transmit buffer (0 = Default size)
 
| Size of the transmit buffer (0 = Default size)
 
|-
 
|-
Line 325: Line 1,221:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SysSerialRead(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Read data from the default Serial device</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Buffer
 +
| Pointer to a buffer to receive the data
 +
|-
 +
! Size
 +
| The size of the buffer
 +
|-
 +
! Count
 +
| The number of bytes read on return
 
|-
 
|-
 
|}
 
|}
Line 337: Line 1,251:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Buffer'''
+
! Buffer
 
| Pointer to a buffer of data to transmit
 
| Pointer to a buffer of data to transmit
 
|-
 
|-
! '''Size'''
+
! Size
 
| The size of the buffer
 
| The size of the buffer
 
|-
 
|-
! '''Count'''
+
! Count
 
| The number of bytes written on return
 
| The number of bytes written on return
 
|-
 
|-
Line 353: Line 1,267:
  
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
<pre style="border: 0; padding-bottom:0px;">function SerialGetCount:LongWord; inline;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function SerialGetCount:LongWord;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current Serial count</div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current Serial count</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| None documented
 
|-
 
|-
 
|}
 
|}
Line 365: Line 1,279:
 
<br />
 
<br />
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceGetDefault:PSerialDevice; inline;</pre>
+
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceGetDefault:PSerialDevice;</pre>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current default Serial device</div>
 
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Get the current default Serial device</div>
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| None documented
 
|-
 
|-
 
|}
 
|}
Line 382: Line 1,296:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| None documented
 
|-
 
|-
 
|}
 
|}
Line 394: Line 1,308:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialTypeToString(SerialType:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert a Serial type value to a string</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialStateToString(SerialState:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Convert a Serial state value to a string</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceRedirectInput(Serial:PSerialDevice):Boolean;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Redirect standard input to the serial device specified by Serial</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Serial
 +
| The serial device to redirect input to (or nil to stop redirection)
 +
|-
 +
! Return
 +
| True if completed successfully or False if an error occurred
 +
|-
 +
! Note
 +
| Redirects the input of the text file Input which also redirects the input of Read, ReadLn and the standard C library.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDeviceRedirectOutput(Serial:PSerialDevice):Boolean;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Redirect standard output to the serial device specified by Serial</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Serial
 +
| The serial device to redirect output to (or nil to stop redirection)
 +
|-
 +
! Return
 +
| True if completed successfully or False if an error occurred
 +
|-
 +
! Note
 +
| Redirects the output of the text files Output, ErrOutput, StdOut and StdErr which also redirects the output of Write, WriteLn and the standard C library.
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialBufferReadStart(Buffer:PSerialBuffer; var Available:LongWord):Pointer;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Return a pointer to the next read from the buffer and the number of bytes that can be read</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Caller must hold the lock on the serial device which owns the buffer
 
|-
 
|-
 
|}
 
|}
Line 406: Line 1,392:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| Caller must hold the lock on the serial device which owns the buffer
 
| Caller must hold the lock on the serial device which owns the buffer
 
|-
 
|-
Line 418: Line 1,404:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| Caller must hold the lock on the serial device which owns the buffer
 
| Caller must hold the lock on the serial device which owns the buffer
 
|-
 
|-
Line 430: Line 1,416:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
 
| Caller must hold the lock on the serial device which owns the buffer
 
| Caller must hold the lock on the serial device which owns the buffer
 
|-
 
|-
Line 442: Line 1,428:
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
{| class="wikitable" style="font-size: 14px; background: white;"
 
|-
 
|-
! '''Note'''
+
! Note
| To be documented
+
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure SerialLogInfo(Serial:PSerialDevice; const AText:String); inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure SerialLogWarn(Serial:PSerialDevice; const AText:String); inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure SerialLogError(Serial:PSerialDevice; const AText:String); inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">procedure SerialLogDebug(Serial:PSerialDevice; const AText:String); inline;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialDataBitsToString(Parity:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialStopBitsToString(Parity:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialParityToString(Parity:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialFlowControlToString(Flow:LongWord):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
 
 +
'''Serial logging helper functions'''
 +
 
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingDeviceAdd(Serial:PSerialDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Add a new serial logging device on receipt of a device register notification</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingDeviceRemove(Serial:PSerialDevice):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Remove a serial logging device on receipt of a device deregister notification</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingDeviceParameters(Serial:PSerialDevice; const Parameters:String; var BaudRate,Parity,DataBits,StopBits:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Break down the serial parameters value into component parts of baud rate, parity, data bits and stop bits</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| The parameters must be in the form 'BaudRate,Parity,DataBits,StopBits' (eg '115200,N,8,1')
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingFirstWord(var Value:String;const Delimiter:String):String;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' To be documented</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| None documented
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingDeviceEnum(Serial:PSerialDevice; Data:Pointer):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Enumeration callback for serial logging initialization</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications
 +
|-
 +
|}
 +
</div></div>
 +
<br />
 +
<div class="toccolours mw-collapsible mw-collapsed" style="border: 1; font-family: arial; padding-top: 0px; padding-bottom: 15px;">
 +
<pre style="border: 0; padding-bottom:0px;">function SerialLoggingDeviceNotify(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;</pre>
 +
<div style="font-size: 14px; padding-left: 12px;">'''Description:''' Notification callback for serial logging device creation or remove</div>
 +
<div class="mw-collapsible-content" style="text-align: left; padding-left: 5px;">
 +
{| class="wikitable" style="font-size: 14px; background: white;"
 +
|-
 +
! Note
 +
| Not intended to be called directly by applications
 
|-
 
|-
 
|}
 
|}

Latest revision as of 03:35, 15 December 2022

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 accommodated 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 specific constants SERIAL_*
SERIAL_NAME_PREFIX = 'Serial'; Name prefix for Serial Devices
 
SERIAL_LOGGING_DESCRIPTION = 'Serial Logging';  
 
SERIAL_RECEIVE_DEPTH_DEFAULT = SIZE_2K; Default receive buffer size in bytes
SERIAL_TRANSMIT_DEPTH_DEFAULT = SIZE_2K; Default transmit buffer size in bytes
 
SERIAL_PUSH_TIMEOUT = 50; Timeout (Milliseconds) for Push RX/TX (Implementation specific)


Serial device type SERIAL_TYPE_*
SERIAL_TYPE_NONE = 0;  
SERIAL_TYPE_UART = 1;  
SERIAL_TYPE_USB = 2;  
 
SERIAL_TYPE_MAX = 2;  


Serial device state SERIAL_STATE_*
SERIAL_STATE_CLOSED = 0;  
SERIAL_STATE_CLOSING = 1;  
SERIAL_STATE_OPENING = 2;  
SERIAL_STATE_OPEN = 3;  
 
SERIAL_STATE_MAX = 3;  


Serial device flag 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_FLAG_PUSH_RX = $00002000; Device requires pushed receive (Implementation specific)
SERIAL_FLAG_PUSH_TX = $00004000; Device requires pushed transmit (Implementation specific)


Serial read flag 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 flag 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 wait directions SERIAL_WAIT_*
SERIAL_WAIT_NONE = 0;  
SERIAL_WAIT_RECEIVE = 1; Wait for data to be available in the receive buffer
SERIAL_WAIT_TRANSMIT = 2; Wait for space to be available in the transmit buffer


Serial flush flag SERIAL_FLUSH_*
SERIAL_FLUSH_NONE = $00000000;  
SERIAL_FLUSH_RECEIVE = $00000001; Flush the receive buffer
SERIAL_FLUSH_TRANSMIT = $00000002; Flush the transmit buffer


Serial status flag 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 logging 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_WARN = LOG_LEVEL_WARN; Serial warning messages
SERIAL_LOG_LEVEL_ERROR = LOG_LEVEL_ERROR; Serial error messages
SERIAL_LOG_LEVEL_NONE = LOG_LEVEL_NONE; No Serial messages
 
SERIAL_LOGGING_LINE_END = Chr(13) + Chr(10); CR LF


Type definitions



Serial properties

PSerialProperties = ^TSerialProperties;

TSerialProperties = record

Flags:LongWord; Device flags (eg SERIAL_FLAG_DATA_8BIT)
MinRate:LongWord; Minimum supported baud rate (0 for any rate supported)
MaxRate:LongWord; Maximum supported baud rate (0 for any rate supported)
BaudRate:LongWord; Current baud rate setting
DataBits:LongWord; Current data bits setting
StopBits:LongWord; Current stop bits setting
Parity:LongWord; Current parity setting
FlowControl:LongWord; Current flow control setting
ReceiveDepth:LongWord; Current receive depth setting
TransmitDepth:LongWord; Current transmit depth setting

Serial buffer

PSerialBuffer = ^TSerialBuffer;

TSerialBuffer = record

Wait:TEventHandle; Data ready/Buffer free event
Start:LongWord; Index of first byte in buffer
Count:LongWord; Number of bytes in buffer
Size:LongWord; Size of buffer
Data:Pointer; Buffered data

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 wait

TSerialDeviceWait = function(Serial:PSerialDevice; Direction,Timeout:LongWord; var Count:LongWord):LongWord;

Serial device flush

TSerialDeviceFlush = function(Serial:PSerialDevice;Flags:LongWord):LongWord;

Serial device get status

TSerialDeviceGetStatus = function(Serial:PSerialDevice):LongWord;

Serial device set status

TSerialDeviceSetStatus = function(Serial:PSerialDevice; Status:LongWord):LongWord;

Serial device get properties

TSerialDeviceGetProperties = function(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;

Serial device set properties

TSerialDeviceSetProperties = function(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;

Serial device

PSerialDevice = ^TSerialDevice;

TSerialDevice = record

Device Properties
Device:TDevice; The Device entry for this Serial
Serial Properties
SerialId:LongWord; Unique Id of this Serial device in the Serial device table
SerialState:LongWord; Serial state (eg SERIAL_STATE_OPEN)
SerialStatus:LongWord; Serial status (eg SERIAL_STATUS_RX_FULL)(May not be real time status depending on the driver)
DeviceOpen:TSerialDeviceOpen; A Device specific DeviceOpen method implementing the standard Serial device interface (Mandatory)
DeviceClose:TSerialDeviceClose; A Device specific DeviceClose method implementing the standard Serial device interface (Mandatory)
DeviceRead:TSerialDeviceRead; A Device specific DeviceRead method implementing the standard Serial device interface (Mandatory)
DeviceWrite:TSerialDeviceWrite; A Device specific DeviceWrite method implementing the standard Serial device interface (Mandatory)
DeviceWait:TSerialDeviceWait; A Device specific DeviceWait method implementing the standard Serial device interface (Or nil if the default method is suitable)
DeviceFlush:TSerialDeviceFlush; A Device specific DeviceFlush method implementing the standard Serial device interface (Or nil if the default method is suitable)
DeviceGetStatus:TSerialDeviceGetStatus; A Device specific DeviceGetStatus method implementing the standard Serial device interface (Or nil if the default method is suitable)
DeviceSetStatus:TSerialDeviceSetStatus; A Device specific DeviceSetStatus method implementing the standard Serial device interface (Optional)
DeviceGetProperties:TSerialDeviceGetProperties; A Device specific DeviceGetProperties method implementing the standard Serial device interface (Or nil if the default method is suitable)
DeviceSetProperties:TSerialDeviceSetProperties; A Device specific DeviceSetProperties method implementing the standard Serial device interface (Or nil if the default method is suitable)
Driver Properties
Lock:TMutexHandle; Device lock
Receive:TSerialBuffer; Serial receive buffer
Transmit:TSerialBuffer; Serial transmit buffer
Properties:TSerialProperties; Device properties
Statistics Properties
ReceiveCount:LongWord;  
ReceiveErrors:LongWord;  
ReceiveOverruns:LongWord;  
TransmitCount:LongWord;  
TransmitErrors:LongWord;  
TransmitOverruns:LongWord;  
Internal Properties
Prev:PSerialDevice; Previous entry in Serial table
Next:PSerialDevice; Next entry in Serial table

Serial logging

PSerialLogging = ^TSerialLogging;

TSerialLogging = record

Logging Properties
Logging:TLoggingDevice;  
Serial Properties
Serial:PSerialDevice;  
BaudRate:LongWord;  
DataBits:LongWord;  
StopBits:LongWord;  
Parity:LongWord;  
FlowControl:LongWord;  


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

procedure SerialInit;
Description: Initialize the Serial unit and Serial device table
Note None documented


Serial functions

function SerialDeviceOpen(Serial:PSerialDevice; BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
Description: Open a Serial device ready for sending and receiving
Serial The Serial device to open
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)
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceClose(Serial:PSerialDevice):LongWord;
Description: Close a Serial device and terminate sending and receiving
Serial The Serial device to close
Note ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceRead(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Read data from a Serial device
Serial The Serial device to read from
Buffer Pointer to a buffer to receive the data
Size The size of the buffer
Flags The flags to control reading (eg SERIAL_READ_NON_BLOCK)
Count The number of bytes read on return
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceWrite(Serial:PSerialDevice; Buffer:Pointer; Size,Flags:LongWord; var Count:LongWord):LongWord;
Description: Write data to a Serial device
Serial The Serial device to write to
Buffer Pointer to a buffer of data to transmit
Size The size of the buffer
Flags The flags to control writing (eg SERIAL_WRITE_NON_BLOCK)
Count The number of bytes written on return
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceWait(Serial:PSerialDevice; Direction,Timeout:LongWord; var Count:LongWord):LongWord;
Description: Wait for data to be available in the receive or transmit buffers of a Serial device
Serial The Serial device to wait for
Direction The direction of data to wait for (eg SERIAL_WAIT_RECEIVE)
Timeout The number of milliseconds to wait for data (INFINITE to wait forever)
Count The number of bytes available on return
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceFlush(Serial:PSerialDevice; Flags:LongWord):LongWord;
Description: Discard the contents of the receive and/or transmit buffers of a Serial device
Serial The Serial device to flush
Flags The flags to indicate what to flush (eg SERIAL_FLUSH_RECEIVE)
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceStatus(Serial:PSerialDevice):LongWord; inline;
Description: Get the current line status of a Serial device
Serial The Serial device to get the status from
Return A set of flags containing the device status (eg SERIAL_STATUS_RTS)


function SerialDeviceGetStatus(Serial:PSerialDevice):LongWord;
Description: Get the current line status of a Serial device
Serial The Serial device to get the status from
Return A set of flags containing the device status (eg SERIAL_STATUS_RTS)


function SerialDeviceSetStatus(Serial:PSerialDevice; Status:LongWord):LongWord;
Description: Set the current line status of a Serial device
Serial The Serial device to set the status for
Status The device status flags to be set (eg SERIAL_STATUS_RTS)
Return ERROR_SUCCESS if completed or another error code on failure
Note Not all SERIAL_STATUS_* flags can be set, the device may ignore invalid values.

Not all serial devices support set status, returns ERROR_CALL_NOT_IMPLEMENTED if not supported.


function SerialDeviceProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord; inline;
Description: Get the properties for the specified Serial device
Serial The Serial device to get properties from
Properties Pointer to a PSerialProperties structure to fill in
Return ERROR_SUCCESS if completed or another error code on failure
Note Replaced by SerialDeviceGetProperties for consistency


function SerialDeviceGetProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;
Description: Get the properties for the specified Serial device
Serial The Serial device to get properties from
Properties Pointer to a PSerialProperties structure to fill in
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceSetProperties(Serial:PSerialDevice; Properties:PSerialProperties):LongWord;
Description: Set the properties for the specified Serial device
Serial The Serial device to set properties for
Properties Pointer to a PSerialProperties structure to use
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceCreate:PSerialDevice;
Description: Create a new Serial entry
Return Pointer to new Serial entry or nil if Serial could not be created


function SerialDeviceCreateEx(Size:LongWord):PSerialDevice;
Description: Create a new Serial entry
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;
Description: Destroy an existing Serial entry
Serial The serial device to destroy
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceRegister(Serial:PSerialDevice):LongWord;
Description: Register a new Serial in the Serial table
Serial The serial device to register
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceDeregister(Serial:PSerialDevice):LongWord;
Description: Deregister a Serial from the Serial table
Serial The serial device to deregister
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceFind(SerialId:LongWord):PSerialDevice;
Description: Find a serial device by Id in the serial table
SerialId The Id number of the serial to find
Return Pointer to serial device entry or nil if not found


function SerialDeviceFindByName(const Name:String):PSerialDevice; inline;
Description: Find a serial device by name in the serial table
Name The name of the serial to find (eg Serial0)
Return Pointer to serial device entry or nil if not found


function SerialDeviceFindByDescription(const Description:String):PSerialDevice; inline;
Description: Find a serial device by description in the serial table
Description The description of the serial to find (eg BCM2836 PL011 UART)
Return Pointer to serial device entry or nil if not found


function SerialDeviceEnumerate(Callback:TSerialEnumerate; Data:Pointer):LongWord;
Description: Enumerate all serial devices in the serial table
Callback The callback function to call for each serial in the table
Data A private data pointer to pass to callback for each serial in the table
Return ERROR_SUCCESS if completed or another error code on failure


function SerialDeviceNotification(Serial:PSerialDevice; Callback:TSerialNotification; Data:Pointer; Notification,Flags:LongWord):LongWord;
Description: Register a notification for serial device changes
Serial The serial device to notify changes for (Optional, pass nil for all serial devices)
Callback The function to call when a notification event occurs
Data A private data pointer to pass to callback when a notification event occurs
Notification The events to register for notification of (eg DEVICE_NOTIFICATION_REGISTER)
Flags The flags to control the notification (eg NOTIFIER_FLAG_WORKER)


Serial logging functions

function SerialLoggingStart(Logging:PLoggingDevice):LongWord;
Description: Implementation of LoggingDeviceStart API for Serial Logging
Note Not intended to be called directly by applications, use LoggingDeviceStart instead.


function SerialLoggingStop(Logging:PLoggingDevice):LongWord;
Description: Implementation of LoggingDeviceStop API for Serial Logging
Note Not intended to be called directly by applications, use LoggingDeviceStop instead.


function SerialLoggingOutput(Logging:PLoggingDevice; const Data:String):LongWord;
Description: Implementation of LoggingDeviceOutput API for Serial Logging
Note Not intended to be called directly by applications, use LoggingDeviceOutput instead.


function SerialLoggingSetTarget(Logging:PLoggingDevice; const Target:String):LongWord;
Description: Implementation of LoggingDeviceSetTarget API for Serial Logging
Note Not intended to be called directly by applications, use LoggingDeviceSetTarget instead.


RTL text IO functions

function SysTextIOReadChar(var ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for platform TextIOReadChar function
Note Not intended to be called directly by applications


function SysTextIOWriteChar(ACh:Char; AUserData:Pointer):Boolean;
Description: Handler for platform TextIOWriteChar function
Note Not intended to be called directly by applications


function SysTextIOWriteBuffer(ABuffer:PChar; ACount:LongInt; AUserData:Pointer):LongInt;
Description: Handler for platform TextIOWriteBuffer function
Note Not intended to be called directly by applications


RTL serial functions

function SysSerialAvailable:Boolean;
Description: Check if a Serial device is available
Note None documented


function SysSerialOpen(BaudRate,DataBits,StopBits,Parity,FlowControl,ReceiveDepth,TransmitDepth:LongWord):LongWord;
Description: Open the default Serial device ready for sending and receiving
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;
Description: Close the default Serial device and terminate sending and receiving
Note None documented


function SysSerialRead(Buffer:Pointer; Size:LongWord; var Count:LongWord):LongWord;
Description: Read data from the default Serial device
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;
Description: Write data to the default Serial device
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;
Description: Get the current Serial count
Note None documented


function SerialDeviceGetDefault:PSerialDevice;
Description: Get the current default Serial device
Note None documented


function SerialDeviceSetDefault(Serial:PSerialDevice):LongWord;
Description: Set the current default Serial device
Note None documented


function SerialDeviceCheck(Serial:PSerialDevice):PSerialDevice;
Description: Check if the supplied Serial is in the Serial table
Note None documented


function SerialTypeToString(SerialType:LongWord):String;
Description: Convert a Serial type value to a string
Note None documented


function SerialStateToString(SerialState:LongWord):String;
Description: Convert a Serial state value to a string
Note None documented


function SerialDeviceRedirectInput(Serial:PSerialDevice):Boolean;
Description: Redirect standard input to the serial device specified by Serial
Serial The serial device to redirect input to (or nil to stop redirection)
Return True if completed successfully or False if an error occurred
Note Redirects the input of the text file Input which also redirects the input of Read, ReadLn and the standard C library.


function SerialDeviceRedirectOutput(Serial:PSerialDevice):Boolean;
Description: Redirect standard output to the serial device specified by Serial
Serial The serial device to redirect output to (or nil to stop redirection)
Return True if completed successfully or False if an error occurred
Note Redirects the output of the text files Output, ErrOutput, StdOut and StdErr which also redirects the output of Write, WriteLn and the standard C library.


function SerialBufferReadStart(Buffer:PSerialBuffer; var Available:LongWord):Pointer;
Description: Return a pointer to the next read from the buffer and the number of bytes that can be read
Note Caller must hold the lock on the serial device which owns the buffer


function SerialBufferReadComplete(Buffer:PSerialBuffer; Removed:LongWord):Boolean;
Description: Update the buffer to reflect the number of bytes removed when reading
Note Caller must hold the lock on the serial device which owns the buffer


function SerialBufferWriteStart(Buffer:PSerialBuffer; var Available:LongWord):Pointer;
Description: Return a pointer to the next write to the buffer and the number of bytes that can be written
Note Caller must hold the lock on the serial device which owns the buffer


function SerialBufferWriteComplete(Buffer:PSerialBuffer; Added:LongWord):Boolean;
Description: Update the buffer to reflect the number of bytes added when writing
Note Caller must hold the lock on the serial device which owns the buffer


procedure SerialLog(Level:LongWord; Serial:PSerialDevice; const AText:String);
Description: To be documented
Note None documented


procedure SerialLogInfo(Serial:PSerialDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure SerialLogWarn(Serial:PSerialDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure SerialLogError(Serial:PSerialDevice; const AText:String); inline;
Description: To be documented
Note None documented


procedure SerialLogDebug(Serial:PSerialDevice; const AText:String); inline;
Description: To be documented
Note None documented


function SerialDataBitsToString(Parity:LongWord):String;
Description: To be documented
Note None documented


function SerialStopBitsToString(Parity:LongWord):String;
Description: To be documented
Note None documented


function SerialParityToString(Parity:LongWord):String;
Description: To be documented
Note None documented


function SerialFlowControlToString(Flow:LongWord):String;
Description: To be documented
Note None documented


Serial logging helper functions

function SerialLoggingDeviceAdd(Serial:PSerialDevice):LongWord;
Description: Add a new serial logging device on receipt of a device register notification
Note None documented


function SerialLoggingDeviceRemove(Serial:PSerialDevice):LongWord;
Description: Remove a serial logging device on receipt of a device deregister notification
Note None documented


function SerialLoggingDeviceParameters(Serial:PSerialDevice; const Parameters:String; var BaudRate,Parity,DataBits,StopBits:LongWord):LongWord;
Description: Break down the serial parameters value into component parts of baud rate, parity, data bits and stop bits
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;
Description: To be documented
Note None documented


function SerialLoggingDeviceEnum(Serial:PSerialDevice; Data:Pointer):LongWord;
Description: Enumeration callback for serial logging initialization
Note Not intended to be called directly by applications


function SerialLoggingDeviceNotify(Device:PDevice; Data:Pointer; Notification:LongWord):LongWord;
Description: Notification callback for serial logging device creation or remove
Note Not intended to be called directly by applications


Return to Unit Reference