⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spcomm.pas

📁 其中包含XPMenu控件和SPComm控件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
end;

procedure TComm.SetDsrSensitivity( b : Boolean );
begin
     if b = FDsrSensitivity then
        Exit;

     FDsrSensitivity := b;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetTxContinueOnXoff( b : Boolean );
begin
     if b = FTxContinueOnXoff then
        Exit;

     FTxContinueOnXoff := b;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetUseRWThread(const Value: Boolean);
begin
  FUseRWThread := Value;

  if hCommFile = 0 then Exit;
  if Value then
    CreateAndStartRWThread
  else
  begin
    // Close the threads.
    CloseRWThread;
  end;
end;

procedure TComm.SetOutx_XonXoffFlow( b : Boolean );
begin
     if b = FOutx_XonXoffFlow then
        Exit;

     FOutx_XonXoffFlow := b;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetInx_XonXoffFlow( b : Boolean );
begin
     if b = FInx_XonXoffFlow then
        Exit;

     FInx_XonXoffFlow := b;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetReplaceWhenParityError( b : Boolean );
begin
     if b = FReplaceWhenParityError then
        Exit;

     FReplaceWhenParityError := b;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetIgnoreNullChar( b : Boolean );
begin
     if b = FIgnoreNullChar then
        Exit;

     FIgnoreNullChar := b;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetRtsControl( c : TRtsControl );
begin
     if c = FRtsControl then
        Exit;

     FRtsControl := c;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetXonLimit( Limit : WORD );
begin
     if Limit = FXonLimit then
        Exit;

     FXonLimit := Limit;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetXoffLimit( Limit : WORD );
begin
     if Limit = FXoffLimit then
        Exit;

     FXoffLimit := Limit;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetByteSize( Size : TByteSize );
begin
     if Size = FByteSize then
        Exit;

     FByteSize := Size;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetParity( p : TParity );
begin
     if p = FParity then
        Exit;

     FParity := p;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetStopBits( Bits : TStopBits );
begin
     if Bits = FStopBits then
        Exit;

     FStopBits := Bits;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetXonChar( c : AnsiChar );
begin
     if c = FXonChar then
        Exit;

     FXonChar := c;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetXoffChar( c : AnsiChar );
begin
     if c = FXoffChar then
        Exit;

     FXoffChar := c;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetReplacedChar( c : AnsiChar );
begin
     if c = FReplacedChar then
        Exit;

     FReplacedChar := c;

     if hCommFile <> 0 then
        _SetCommState
end;

procedure TComm.SetReadIntervalTimeout( v : DWORD );
begin
     if v = FReadIntervalTimeout then
        Exit;

     FReadIntervalTimeout := v;

     if hCommFile <> 0 then
        _SetCommTimeout
end;

procedure TComm.SetReadTotalTimeoutMultiplier( v : DWORD );
begin
     if v = FReadTotalTimeoutMultiplier then
        Exit;

     FReadTotalTimeoutMultiplier := v;

     if hCommFile <> 0 then
        _SetCommTimeout
end;

procedure TComm.SetReadTotalTimeoutConstant( v : DWORD );
begin
     if v = FReadTotalTimeoutConstant then
        Exit;

     FReadTotalTimeoutConstant := v;

     if hCommFile <> 0 then
        _SetCommTimeout
end;

procedure TComm.SetWriteTotalTimeoutMultiplier( v : DWORD );
begin
     if v = FWriteTotalTimeoutMultiplier then
        Exit;

     FWriteTotalTimeoutMultiplier := v;

     if hCommFile <> 0 then
        _SetCommTimeout
end;

procedure TComm.SetWriteTotalTimeoutConstant( v : DWORD );
begin
     if v = FWriteTotalTimeoutConstant then
        Exit;

     FWriteTotalTimeoutConstant := v;

     if hCommFile <> 0 then
        _SetCommTimeout
end;

(******************************************************************************)
//  READ THREAD
(******************************************************************************)

//
//  PROCEDURE: TReadThread.Execute
//
//  PURPOSE: This is the starting point for the Read Thread.
//
//  PARAMETERS:
//    None.
//
//  RETURN VALUE:
//    None.
//
//  COMMENTS:
//
//    The Read Thread uses overlapped ReadFile and sends any data
//    read from the comm port to the Comm32Window.  This is
//    eventually done through a PostMessage so that the Read Thread
//    is never away from the comm port very long.  This also provides
//    natural desynchronization between the Read thread and the UI.
//
//    If the CloseEvent object is signaled, the Read Thread exits.
//
//        Separating the Read and Write threads is natural for a application
//    where there is no need for synchronization between
//    reading and writing.  However, if there is such a need (for example,
//    most file transfer algorithms synchronize the reading and writing),
//    then it would make a lot more sense to have a single thread to handle
//    both reading and writing.
//
//
procedure TReadThread.Execute;
var
   szInputBuffer: array[0..INPUTBUFFERSIZE-1] of Char;
   nNumberOfBytesRead:    DWORD;

   HandlesToWaitFor:      array[0..2] of THandle;
   dwHandleSignaled:      DWORD;

   fdwEvtMask:                    DWORD;

   // Needed for overlapped I/O (ReadFile)
   overlappedRead:                TOverlapped;

   // Needed for overlapped Comm Event handling.
   overlappedCommEvent:   TOverlapped;
label
  EndReadThread;
begin
     FillChar( overlappedRead, Sizeof(overlappedRead), 0 );
     FillChar( overlappedCommEvent, Sizeof(overlappedCommEvent), 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;

     // And an event for the CommEvent overlapped structure.
     overlappedCommEvent.hEvent := CreateEvent( nil, True, True, nil);
     if overlappedCommEvent.hEvent = 0 then
     begin
          PostHangupCall();
          goto EndReadThread
     end;

     // We will be waiting on these objects.
     HandlesToWaitFor[0] := hCloseEvent;
     HandlesToWaitFor[1] := overlappedCommEvent.hEvent;
     HandlesToWaitFor[2] := 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 CommEvents (Errors)
     if not SetupCommEvent( @overlappedCommEvent,  fdwEvtMask ) then
        goto EndReadThread;

     // 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(3, @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
                    // Handle the CommEvent.
                    if not HandleCommEvent( @overlappedCommEvent, fdwEvtMask, TRUE ) then
                       goto EndReadThread;

                    // Start waiting for the next CommEvent.
                    if not SetupCommEvent( @overlappedCommEvent, fdwEvtMask ) then
                       goto EndReadThread
                    {break;??}
               end;

               WAIT_OBJECT_0 + 2: // Read Event signaled.
               begin
                    // Get the new data!
                    if not HandleReadEvent( @overlappedRead,
                                            szInputBuffer,
                                            INP

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -