to:SS2000
你看看其他的串口控件,如 CPort 等 就知道了
+'//./' 是指对于设备。
COM1 应为 //./COM1 这就是标准的写法啊。
//相对路径 和 绝对路径 的关系
//当然你用相对路径COM1也可以。不过我习惯用绝对路径
实时性是因为
// Wait for more new data.
if not SetupReadEvent(@overlappedRead,
szInputBuffer, INPUTBUFFERSIZE,
nNumberOfBytesRead) then
goto EndReadThread
{break;}
还有多串口
procedure TReadThread.Execute;
var
szInputBuffer: array[0..INPUTBUFFERSIZE - 1] of Char;
nNumberOfBytesRead: DWORD;
HandlesToWaitFor: array[0..1] of THandle;
dwHandleSignaled: DWORD;
// Needed for overlapped I/O (ReadFile)
overlappedRead: TOverlapped;
label
EndReadThread;
begin
FillChar(overlappedRead, Sizeof(overlappedRead), 0);
// Lets put an event in the Read overlapped structure.
overlappedRead.hEvent := CreateEvent(nil, True, True, nil);
if overlappedRead.hEvent = 0 then
begin
PostHangupCall;
goto EndReadThread
end;
// We will be waiting on these objects.
HandlesToWaitFor[0] := hCloseEvent;
HandlesToWaitFor[1] := overlappedRead.hEvent;
// Setup CommEvent handling.
//改了
// Set the comm mask so we receive error signals.
if not SetCommMask(hCommFile, EV_ERR or EV_RLSD or EV_RING) then
begin
PostHangupCall;
goto EndReadThread
end;
// Start waiting for Read events.
if not SetupReadEvent(@overlappedRead,
szInputBuffer, INPUTBUFFERSIZE,
nNumberOfBytesRead) then
goto EndReadThread;
// Keep looping until we break out.
while True do
begin
// Wait until some event occurs (data to read; error; stopping).
dwHandleSignaled := WaitForMultipleObjects(2, @HandlesToWaitFor,
False, INFINITE);
// Which event occured?
case dwHandleSignaled of
WAIT_OBJECT_0: // Signal to end the thread.
begin
// Time to exit.
goto EndReadThread
end;
WAIT_OBJECT_0 + 1: // CommEvent signaled.
begin
// Get the new data!
if not HandleReadEvent(@overlappedRead,
szInputBuffer,
INPUTBUFFERSIZE,
nNumberOfBytesRead) then
goto EndReadThread;
// Wait for more new data.
if not SetupReadEvent(@overlappedRead,
szInputBuffer, INPUTBUFFERSIZE,
nNumberOfBytesRead) then
goto EndReadThread
{break;}
end;
WAIT_FAILED: // Wait failed. Shouldn't happen.
begin
PostHangupCall;
goto EndReadThread
end
else // This case should never occur.
begin
PostHangupCall;
goto EndReadThread
end
end {case dwHandleSignaled}
end; {while True}
// Time to clean up Read Thread.
EndReadThread:
PurgeComm(hCommFile, PURGE_RXABORT + PURGE_RXCLEAR);
CloseHandle(overlappedRead.hEvent);
end; {TReadThread.Execute}