Lazarus

Programming => General => Topic started by: andromeda on November 27, 2020, 03:33:08 pm

Title: LazSerial wait for incoming data
Post by: andromeda on November 27, 2020, 03:33:08 pm
Hi,
How to implement wait for incoming data with lazserial ?

The com port is connected to interface keyboard, i need to wait until keypressed as kbhit in c language or readkey in pascal.

for example with WaitingData ?

Code: Pascal  [Select][+][-]
  1.  
  2. while (ser.WaitingData = 0) do ;
  3.  

Thanks for your help.
Title: Re: LazSerial wait for incoming data
Post by: jamie on November 27, 2020, 11:27:50 pm
This forum has a nice search feature down on the lower left..

Put in TLazSerial and I bet you will find the answer to your questions
Title: Re: LazSerial wait for incoming data
Post by: Jurassic Pork on November 28, 2020, 01:29:48 am
hello,

for example with WaitingData ?

Code: Pascal  [Select][+][-]
  1. while (ser.WaitingData = 0) do ;
  2.  
your code is a cpu eater.

Are you in a GUI program  ? 
if yes use this :
Code: Pascal  [Select][+][-]
  1. while (ser.WaitingData = 0)  
  2.      do
  3.         begin
  4.           application.processMessages;
  5.           sleep(100);
  6.         end;

Friendly, J.P
Title: Re: LazSerial wait for incoming data
Post by: jamie on November 28, 2020, 01:56:22 am
Well I thought the component already has a thread that runs and I thought there were events already in place?

OnRxData, OnStatus etc.

In anycase, one can post a user message from the Thread to the main thread and you simply implement a message handler.
Title: Re: LazSerial wait for incoming data
Post by: andromeda on November 28, 2020, 08:44:09 pm
is on apply console, not a gui.
TinyPortal © 2005-2018