Skip to content

Event "OnReciveData" is not triggered in the thread #10

Description

@sergey-zheleztsov

Hello, MHumm!
If an instance of TCommPortDriver is created in a separate thread, the data arrival event in the port buffer is not triggered, apparently due to the fact that the window function is used for verification. For normal operation, I had to add a system message processing cycle to the Execute procedure

procedure TMeterThread.Execute;
...
Cprt := TCommPortDriver.Create( nil );
Cprt.BaudRate := br9600;
Cprt.StopBits := sb1BITS;
Cprt.Parity := ptNONE;
Cprt.DataBits := db8BITS;
Cprt.PollingDelay := 50;
Cprt.PacketSize := -1; 
Cprt.Port := TPortNumber( PrtNm.Substring( 3 ).ToInteger );   // Number in the "\\.\COMn"
Cprt.OnReceiveData := CPRxChar;   // <- OnReceiveData - does not work in TMeterThread :((
Cprt.OnError := CommPortError;
...
// But if you add the lines below, the OnReceiveData event starts
case MsgWaitForMultipleObjectsEx( 0, nil^, 50, QS_ALLINPUT, 0 ) of
      WAIT_OBJECT_0:
        begin
          while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
          begin
            if Msg.message = WM_QUIT then
              Exit;
            TranslateMessage(Msg);
            DispatchMessage(Msg);
          end;
        end;
      WAIT_FAILED:
        Break;
    end;
...
end;   // of Execute

Is there any way to take this into account in a future release?

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions