Class TCustomPortUART

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TCustomPortUART = class abstract(TCustomDataPort)

Description

Abstract UART (Universal Asynchronous Receiver / Transmitter) communication manager.

Hierarchy

Overview

Fields

Protected FSystemCore: TCustomSystemCore;
Protected internal const InterimSleepTime = 10000 ;
Protected internal const StringBufferSize = 32 ;

Methods

Public constructor Create(const ASystemCore: TCustomSystemCore);
Public function ReadBuffer(const Buffer: Pointer; const BufferSize, Timeout: Cardinal): Cardinal; virtual;
Public function ReadByte(out Value: Byte; const Timeout: Cardinal = 0): Boolean; inline;
Public function ReadString(out Text: StdString; const MaxCharacters: Cardinal = 0; const Timeout: Cardinal = 0): Boolean;
Public function WriteBuffer(const Buffer: Pointer; const BufferSize, Timeout: Cardinal): Cardinal; virtual;
Public function WriteByte(const Value: Byte; const Timeout: Cardinal = 0): Boolean; inline;
Public function WriteBytes(const Values: array of Byte; const Timeout: Cardinal = 0): Boolean;
Public function WriteString(const Text: StdString; const Timeout: Cardinal = 0): Boolean;
Protected function GetBaudRate: Cardinal; virtual; abstract;
Protected function GetBitsPerWord: TBitsPerWord; virtual; abstract;
Protected function GetParity: TParity; virtual; abstract;
Protected function GetStopBits: TStopBits; virtual; abstract;
Public procedure Flush; virtual; abstract;
Protected procedure SetBaudRate(const Value: Cardinal); virtual; abstract;
Protected procedure SetBitsPerWord(const Value: TBitsPerWord); virtual; abstract;
Protected procedure SetParity(const Value: TParity); virtual; abstract;
Protected procedure SetStopBits(const Value: TStopBits); virtual; abstract;

Properties

Public property BaudRate: Cardinal read GetBaudRate write SetBaudRate;
Public property BitsPerWord: TBitsPerWord read GetBitsPerWord write SetBitsPerWord;
Public property Parity: TParity read GetParity write SetParity;
Public property StopBits: TStopBits read GetStopBits write SetStopBits;
Public property SystemCore: TCustomSystemCore read FSystemCore;

Description

Fields

Protected FSystemCore: TCustomSystemCore;

Reference to TCustomSystemCore currently being used by UART port.

Protected internal const InterimSleepTime = 10000 ;

Default sleep time while waiting during transmission between multiple attempts.

Protected internal const StringBufferSize = 32 ;

Default buffer size used when reading and writing strings.

Methods

Public constructor Create(const ASystemCore: TCustomSystemCore);

Creates UART (serial) port instance associated with a specific instace of TCustomSystemCore. Note that ASystemCore parameter is required as it is used for timeout calculations.

Public function ReadBuffer(const Buffer: Pointer; const BufferSize, Timeout: Cardinal): Cardinal; virtual;

Reads data buffer from UART (serial) port.

Parameters
Buffer
Pointer to data buffer where the data will be written to.
BufferSize
Number of bytes to read.
Timeout
Maximum time (in milliseconds) to wait while attempting to read the buffer. If this parameter is set to zero, then the function will block indefinitely, attempting to read until the specified number of bytes have been read.
Returns

Number of bytes that were actually read.

Public function ReadByte(out Value: Byte; const Timeout: Cardinal = 0): Boolean; inline;

Attempts to read a byte from UART (serial) port. Timeout defines maximum time (in milliseconds) to wait while attempting to do so; if this parameter is set to zero, then the function will block indefinitely until the byte has been read. True is returned when the operation was successful and False when the byte could not be read.

Public function ReadString(out Text: StdString; const MaxCharacters: Cardinal = 0; const Timeout: Cardinal = 0): Boolean;

Reads string from UART (serial) port.

Parameters
Text
String that will hold the incoming data.
MaxCharacters
Maximum number of characters to read. Once this number of characters has been read, the function immediately returns, even if there is more data to read. When this parameter is set to zero, then the function will continue to read the data, depending on value of Timeout.
Timeout
Maximum time (in milliseconds) to wait while attempting to read the buffer. If this parameter is set to zero, then the function will read only as much data as fits in readable FIFO buffers (or fail when such buffers are not supported).
Returns

Number of bytes that were actually read.

Public function WriteBuffer(const Buffer: Pointer; const BufferSize, Timeout: Cardinal): Cardinal; virtual;

Writes data buffer to UART (serial) port.

Parameters
Buffer
Pointer to data buffer where the data will be read from.
BufferSize
Number of bytes to write.
Timeout
Maximum time (in milliseconds) to wait while attempting to write the buffer. If this parameter is set to zero, then the function will block indefinitely, attempting to write until the specified number of bytes have been written.
Returns

Number of bytes that were actually written.

Public function WriteByte(const Value: Byte; const Timeout: Cardinal = 0): Boolean; inline;

Attempts to write a byte to UART (serial) port. Timeout defines maximum time (in milliseconds) to wait while attempting to do so; if this parameter is set to zero, then the function will block indefinitely until the byte has been written. True is returned when the operation was successful and False when the byte could not be written.

Public function WriteBytes(const Values: array of Byte; const Timeout: Cardinal = 0): Boolean;

Attempts to write multiple bytes to UART (serial) port. Timeout defines maximum time (in milliseconds) to wait while attempting to do so; if this parameter is set to zero, then the function will block indefinitely, attempting to write until the specified bytes have been written. True is returned when the operation was successful and False when not all bytes could be written.

Public function WriteString(const Text: StdString; const Timeout: Cardinal = 0): Boolean;

Writes string to UART (serial) port.

Parameters
Text
String that should be sent.
Timeout
Maximum time (in milliseconds) to wait while attempting to write the buffer. If this parameter is set to zero, then the function will write only what fits in writable FIFO buffers (or fail when such buffers are not supported).
Returns

Number of bytes that were actually read.

Protected function GetBaudRate: Cardinal; virtual; abstract;

Returns currently set baud rate.

Protected function GetBitsPerWord: TBitsPerWord; virtual; abstract;

Returns current number of bits per word.

Protected function GetParity: TParity; virtual; abstract;

Returns current parity check type.

Protected function GetStopBits: TStopBits; virtual; abstract;

Returns current number of stop bits.

Public procedure Flush; virtual; abstract;

Flushes UART (serial) port read and write FIFO buffers.

Protected procedure SetBaudRate(const Value: Cardinal); virtual; abstract;

Sets new baud rate.

Protected procedure SetBitsPerWord(const Value: TBitsPerWord); virtual; abstract;

Sets new number of bits per word.

Protected procedure SetParity(const Value: TParity); virtual; abstract;

Sets new parity check type.

Protected procedure SetStopBits(const Value: TStopBits); virtual; abstract;

Sets new number of stop bits.

Properties

Public property BaudRate: Cardinal read GetBaudRate write SetBaudRate;

Currently used baud rate in terms of bits per second. Note that to calculate the actual speed of transmission, it is necessary to take into account start and stop bits among other things; for typical situations, the actual transmission speed may be something like BaudRate / 10 bytes per second or less.

Public property BitsPerWord: TBitsPerWord read GetBitsPerWord write SetBitsPerWord;

Number of bits per message (or "word") used in the transmission. Typically this equals to 8 bits, which means one byte is sent at a time. Accepted values usually range between 5 and 8 bits. Lower values, especially when combined with parity checks may result in less and/or easier to detect errors.

Public property Parity: TParity read GetParity write SetParity;

Number of parity (error detection) bits used in the transmission. This means that additional bits will be added to the tail of transmission that indicate whether the number of ones in the message is odd or even; if the received number of bits does not match this hint, the message will be discarded.

Public property StopBits: TStopBits read GetStopBits write SetStopBits;

Number of stop bits used in the transmission. Although normally only one stop bit is necessary, it may be difficult to detect in hardware when transmission channel is noisy; therefore, additional stop bits may help alleviate the problem.

Public property SystemCore: TCustomSystemCore read FSystemCore;

Reference to TCustomSystemCore associated with this UART port instance.


Copyright © 2000 - 2017 Yuriy Kotsarenko. Help files generated by PasDoc.