📄 adport.pas
字号:
procedure AbortTracing;
procedure StartTracing;
procedure StopTracing;
{DispatchLogging}
procedure InitLogging(const Size : Cardinal);
procedure DumpLog(const FName : ShortString; const InHex : Boolean);
procedure AppendLog(const FName : ShortString; const InHex : Boolean);
procedure ClearLogging;
procedure AbortLogging;
procedure StartLogging;
procedure StopLogging;
public
OverrideLine : Boolean; {True to override line parms}
{Creation/destruction}
constructor Create(AOwner : TComponent); override;
{-Create a TApdComPort component}
destructor Destroy; override;
{-Destroy a TApdComPort component}
{General}
procedure InitPort; dynamic;
{-Physically open the serial port}
procedure DonePort; virtual;
{-Physically close the serial port}
procedure Assign(Source: TPersistent); override;
{-Assign fields from TApdComPort object specified by Source}
procedure ForcePortOpen;
{-Force the port open after it is loaded}
procedure SendBreak(Ticks : Word; Yield : Boolean);
{-Send a line break of ticks duration}
procedure SetBreak(BreakOn : Boolean);
{-Sets or clears line break condition}
{.Z-}
procedure RegisterUser(const H : THandle);
{-Register a TApdComPort user to receive PortOpen/PortClose events}
procedure RegisterUserEx(const H : THandle); {!!.03}
{-Register a TApdComPort user to receive open/closing/close events}
procedure RegisterUserCallback(CallBack : TPortCallback);
{-Register a TApdComPort user to receive callbacks}
procedure RegisterUserCallbackEx(CallBackEx : TPortCallbackEx); {!!.03}
{-Register a TApdComPort user to receive extended callbacks}
procedure DeregisterUser(const H : THandle);
{-Deregister a TApdComPort user from receiving PortOpen/PortClose events}
procedure DeregisterUserCallback(CallBack : TPortCallback);
{-Deregister a TApdComPort user callback}
procedure DeregisterUserCallbackEx(CallBackEx : TPortCallbackEx); {!!.03}
{-Deregister a TApdComPort user callback}
procedure ProcessCommunications; virtual;
{-Call the internal dispatcher}
procedure FlushInBuffer;
{-Discard the contents of the input buffer}
procedure FlushOutBuffer;
{-Discard the contents of the output buffer}
{Trigger managment}
function AddDataTrigger(const Data : ShortString;
const IgnoreCase : Boolean) : Word;
{-Add a data trigger}
function AddTimerTrigger : Word;
{-Add a timer trigger}
function AddStatusTrigger(const SType : Word) : Word;
{-Add a status trigger}
procedure RemoveTrigger(const Handle : Word);
{-Remove a trigger}
procedure RemoveAllTriggers;
{-Remove all triggers}
procedure SetTimerTrigger(const Handle : Word; const Ticks : LongInt;
const Activate : Boolean);
{-Activate or deactivate a timer trigger}
procedure SetStatusTrigger(const Handle : Word; const Value : Word;
const Activate : Boolean);
{-Activate or deactivate a status trigger}
{I/O}
function CharReady : Boolean;
{-Return True if at least one character is in the input buffer}
function PeekChar(const Count : Word) : Char;
{-Return a received character other than the next one}
function GetChar : Char;
{-Return the next received character}
procedure PeekBlock(var Block; const Len : Word);
{-Return a block of data other than the next block}
procedure GetBlock(var Block; const Len : Word);
{-Return the next block of data}
procedure PutChar(const C : Char);
{-Add C to the output buffer}
procedure PutString(const S : String);
{-Add S to the output buffer}
function PutBlock(const Block; const Len : Word) : Integer;
{-Add Block to the output buffer}
{Waits}
function CheckForString(var Index : Byte; C : Char;
const S : String;
IgnoreCase : Boolean) : Boolean;
{-Compare C against a sequence of chars, looking for S}
function WaitForString(const S : String;
const Timeout : LongInt;
const Yield, IgnoreCase : Boolean) : Boolean;
{-Wait for S}
function WaitForMultiString(const S : String; const Timeout : LongInt;
const Yield, IgnoreCase : Boolean;
const SepChar : Char) : Integer;
{-Wait for S, which contains several substrings separated by ^}
procedure PrepareWait;
{-Set EventBusy true to prevent triggers}
property ComNumber : Word
read FComNumber write SetComNumber default adpoDefComNumber;
property CustomDispatcher : TActivationProcedure
read fCustomDispatcher write fCustomDispatcher;
property DeviceLayer : TDeviceLayer
read FDeviceLayer write SetDeviceLayer default adpoDefDeviceLayer;
property ComWindow : THandle
read fComWindow;
property Baud : LongInt
read FBaud write SetBaud default adpoDefBaudRt;
property Parity : TParity
read FParity write SetParity default adpoDefParity;
property PromptForPort : Boolean
read FPromptForPort write FPromptForPort
default adpoDefPromptForPort;
property DataBits : Word
read FDatabits write SetDatabits default adpoDefDatabits;
property StopBits : Word
read FStopbits write SetStopbits default adpoDefStopbits;
{Miscellaneous port properties}
property InSize : Word
read FInSize write SetInSize default adpoDefInSize;
property OutSize : Word
read FOutSize write SetOutSize default adpoDefOutSize;
property Open : Boolean
read FOpen write SetOpen default adpoDefOpen;
property AutoOpen : Boolean
read FAutoOpen write FAutoOpen default adpoDefAutoOpen;
property CommNotificationLevel : Word
read FCommNotificationLevel write SetCommNotificationLevel
default adpoDefCommNotificationLevel;
property TapiMode : TTapiMode
read FTapiMode write FTapiMode default adpoDefTapiMode;
property TapiCid : Word
read FTapiCid write FTapiCid;
property RS485Mode : Boolean
read FRS485Mode write SetRS485Mode default adpoDefRS485Mode;
property BaseAddress : Word
read GetBaseAddress write SetBaseAddress
default adpoDefBaseAddress;
property ThreadBoost : TApThreadBoost
read FThreadBoost write SetThreadBoost;
property MasterTerminal : TWinControl
read FMasterTerminal write FMasterTerminal;
{Modem control/status}
property DTR : Boolean
read FDTR write SetDTR default adpoDefDTR;
property RTS : Boolean
read FRTS write SetRTS default adpoDefRTS;
{Flow control properties}
property HWFlowOptions : THWFlowOptionSet
read FHWFlowOptions write SetHWFlowOptions default [];
property FlowState : TFlowControlState
read GetFlowState;
property SWFlowOptions : TSWFlowOptions
read FSWFlowOptions write SetSWFlowOptions default adpoDefSWFlowOptions;
property XOnChar : Char
read FXonChar write SetXonChar default adpoDefXOnChar;
property XOffChar : Char
read FXOffChar write SetXoffChar default adpoDefXOffChar;
property BufferFull : Word
read FBufferFull write SetBufferFull default adpoDefBufferFull;
property BufferResume : Word
read FBufferResume write SetBufferResume default adpoDefBufferResume;
{Debugging}
property Tracing : TTraceLogState
read FTracing write SetTracing default adpoDefTracing;
property TraceSize : Cardinal
read FTraceSize write SetTraceSize default adpoDefTraceSize;
property TraceName : TPassString
read FTraceName write FTraceName;
property TraceHex : Boolean
read FTraceHex write FTraceHex default adpoDefTraceHex;
property TraceAllHex : Boolean
read FTraceAllHex write FTraceAllHex default adpoDefTraceAllHex;
property Logging : TTraceLogState
read FLogging write SetLogging default adpoDefLogging;
property LogSize : Cardinal
read FLogSize write SetLogSize default adpoDefLogSize;
property LogName : TPassString
read FLogName write FLogName;
property LogHex : Boolean
read FLogHex write FLogHex default adpoDefLogHex;
property LogAllHex : Boolean
read FLogAllHex write FLogAllHex default adpoDefLogAllHex;
{Options}
property UseMSRShadow : Boolean
read FUseMSRShadow write SetUseMSRShadow default adpoDefUseMSRShadow;
property UseEventWord : Boolean
read FUseEventWord write SetUseEventWord default adpoDefUseEventWord;
{Tracing}
procedure AddTraceEntry(const CurEntry, CurCh : Char);
{-Add an entry to the trace buffer}
procedure AddStringToLog(S : string);
{-Add a string to the current LOG file}
{Trigger events}
property TriggerLength : Word
read FTriggerLength write SetTriggerLength default adpoDefTriggerLength;
property OnTrigger : TTriggerEvent
read FOnTrigger write SetOnTrigger;
property OnTriggerAvail : TTriggerAvailEvent
read FOnTriggerAvail write SetOnTriggerAvail;
property OnTriggerData : TTriggerDataEvent
read FOnTriggerData write SetOnTriggerData;
property OnTriggerStatus : TTriggerStatusEvent
read FOnTriggerStatus write SetOnTriggerStatus;
property OnTriggerTimer : TTriggerTimerEvent
read FOnTriggerTimer write SetOnTriggerTimer;
{Port open/close/change events}
property OnPortOpen : TNotifyEvent
read FOnPortOpen write FOnPortOpen;
property OnPortClose : TNotifyEvent
read FOnPortClose write FOnPortClose;
{Status events}
property OnTriggerLineError : TTriggerLineErrorEvent
read FOnTriggerLineError write SetOnTriggerLineError;
property OnTriggerModemStatus : TNotifyEvent
read FOnTriggerModemStatus write SetOnTriggerModemStatus;
property OnTriggerOutbuffFree : TNotifyEvent
read FOnTriggerOutbuffFree write SetOnTriggerOutbuffFree;
property OnTriggerOutbuffUsed : TNotifyEvent
read FOnTriggerOutbuffUsed write SetOnTriggerOutbuffUsed;
property OnTriggerOutSent : TNotifyEvent
read FOnTriggerOutSent write SetOnTriggerOutSent;
{WaitChar event}
property OnWaitChar : TWaitCharEvent
read FOnWaitchar write FOnWaitChar;
{I/O properties}
property Output : String
write PutString;
{TComHandle, read only}
property Dispatcher : TApdBaseDispatcher
read GetDispatcher;
function ValidDispatcher : TApdBaseDispatcher;
{Modem status, read only}
property ModemStatus : Byte
read GetModemStatus;
property DSR : Boolean
read GetDSR;
property CTS : Boolean
read GetCTS;
property RI : Boolean
read GetRI;
property DCD : Boolean
read GetDCD;
property DeltaDSR : Boolean
read GetDeltaDSR;
property DeltaCTS : Boolean
read GetDeltaCTS;
property DeltaRI : Boolean
read GetDeltaRI;
property DeltaDCD : Boolean
read GetDeltaDCD;
{Line errors}
property LineError : Word
read GetLineError;
property LineBreak : Boolean
read GetLineBreak;
{Buffer info, readonly}
property InBuffUsed : Word
read GetInBuffUsed;
property InBuffFree : Word
read GetInBuffFree;
property OutBuffUsed : Word
read GetOutBuffUsed;
property OutBuffFree : Word
read GetOutBuffFree;
end;
{Port component}
TApdComPort = class(TApdCustomComPort)
published
property DeviceLayer;
property ComNumber;
property Baud;
property PromptForPort;
property Parity;
property DataBits;
property StopBits;
property InSize;
property OutSize;
property AutoOpen;
property Open;
property DTR;
property RTS;
property HWFlowOptions;
property SWFlowOptions;
property XOnChar;
property XOffChar;
property BufferFull;
property BufferResume;
property Tracing;
property TraceSize;
property TraceName;
property TraceHex;
property TraceAllHex;
property Logging;
property LogSize;
property LogName;
property LogHex;
property LogAllHex;
property UseMSRShadow;
property UseEventWord;
property CommNotificationLevel;
property TapiMode;
property RS485Mode;
property OnPortClose;
property OnPortOpen;
property OnTrigger;
property OnTriggerAvail;
property OnTriggerData;
property OnTriggerStatus;
property OnTriggerTimer;
property OnTriggerLineError;
property OnTriggerModemStatus;
property OnTriggerOutbuffFree;
property OnTriggerOutbuffUsed;
property OnTriggerOutSent;
property Tag;
end;
function ComName(const ComNumber : Word) : ShortString;
function SearchComPort(const C : TComponent) : TApdCustomComPort;
implementation
const
ComWindowClass = 'awComWindow';
{Main trigger handler}
function ComWindowProc(hWindow : TApdHwnd; Msg, wParam : Word;
lParam : Longint) : Longint;
stdcall; export;
{-Receives all triggers, dispatches to event handlers}
type
lParamCast = record
Data : Word;
Dispatcher : Word;
end;
var
LP : lParamCast absolute lParam;
TrigHandle : Word absolute wParam;
Count : Word absolute wParam;
CP : TApdCustomComPort;
D : Pointer;
begin
case Msg of
APW_CLOSEPENDING, APW_TRIGGERAVAIL, APW_TRIGGERDATA,
APW_TRIGGERSTATUS, APW_TRIGGERTIMER : ;
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -