Recent

Author Topic: How can i increase timer speed.  (Read 9451 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: How can i increase timer speed.
« Reply #15 on: August 27, 2015, 05:16:26 pm »
I use endless while loop. If i don't use  Application.ProcessMessages  application will be block and user don't do anything. Therefore i have to use that.

This is not correct for threads. Better read some thread tutorials.

balazsszekely

  • Guest
Re: How can i increase timer speed.
« Reply #16 on: August 27, 2015, 05:27:51 pm »
Quote
@aidv
Synchronize(@myProcedure);

I don't want to start the discussion all over again, but synchronize is not good either, especially in this particular case, where a lot of data is involved. Synchronize will update the UI, but until the update is done, it blocks the woker thread. There are better ways, for more details please read this: http://forum.lazarus.freepascal.org/index.php/topic,29339.0.html

mse

  • Sr. Member
  • ****
  • Posts: 286
Re: How can i increase timer speed.
« Reply #17 on: August 27, 2015, 05:40:53 pm »
MSEgui has "tsercommchannel" component where the port data will be received in a separate thread with a data buffer and an "onresponse" event. IIRC there are similar components for Delphi/Lazarus, I don't remember the name(s).

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: How can i increase timer speed.
« Reply #18 on: August 27, 2015, 06:12:39 pm »
hello ,

may be you can use a buffer ( stream ) with the rxData serial event, treat more  than one data  frame at one time.

Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: How can i increase timer speed.
« Reply #19 on: August 27, 2015, 06:33:58 pm »
If i don't use  Application.ProcessMessages  application will be block and user don't do anything.

I guess you called procedure TMyThread.Execute directly. Instead, you can create the thread in a suspended state (passing True to its Create procedure). Provide any needed information in properties, and finally call Start (which will call Execute in a separate thread).

This way you will have two threads, the main GUI thread, and the this newly created thread.

As for using Synchronize or not, read the thread posted by GetMem.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 1228
Re: How can i increase timer speed.
« Reply #20 on: August 27, 2015, 11:30:54 pm »
Sorry but i don't understand something :

Quote
I read serial data that 115200 baudrate, and I must read 2K data in a second.
i must read 2000 data and each data has long 10 bytes = 20000 bytes

115200 bauds = 14400 bytes per second 
 how your device can send 20000 bytes in one second at 115200 bauds ? 
« Last Edit: August 27, 2015, 11:34:06 pm by Jurassic Pork »
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

boreas

  • New Member
  • *
  • Posts: 33
Re: How can i increase timer speed.
« Reply #21 on: August 28, 2015, 09:19:30 am »
Sorry but i don't understand something :

Quote
I read serial data that 115200 baudrate, and I must read 2K data in a second.
i must read 2000 data and each data has long 10 bytes = 20000 bytes

115200 bauds = 14400 bytes per second 
 how your device can send 20000 bytes in one second at 115200 bauds ?
You right. I update baud rate 230400  ::)

u2o

  • Jr. Member
  • **
  • Posts: 72
  • No message
Re: How can i increase timer speed.
« Reply #22 on: August 29, 2015, 09:56:55 am »
Hi All!

Boreas, you need create Threaded procedures...

Please think like as an example: a File Searcher.
When you press the search button , the program searches for files/folders, and shows in what folder is looking for, and the results are being added to the list. But the main screen of the application will never hang up, it works smoothly and even one can cancel the search (already in progress) to start a new search.

For it, you need get the current state (in the main form or in a main threaded procedure) of your running Threaded Procedures to interact with the data...  After it (eg. data received), you can send to another threaded procedure the order to send the data to the printer/panel/monitor to show the results. Thus, the time it takes the data received or send, as well as to display, everything is detached from the main thread runs in separate threads... (and really fast, because that procedures/functions not need refresh the main interface, you refresh it when you need).

This achieves no delays, but beware .... When you work with time limits, may be found to the problem of obtaining data that take longer than you think at some point, so you should consider that if the data was not received and processed in the estimated time, you must report adequately at the printer/panel/monitor.

Please, download the attached demo and see the procedure class procedure TThreadControl.Thread_DoMyWork; on line 214 of the file unitthreadcontrol.pas ...

You will see
Code: [Select]
    while True do begin                         // while you don't call TThreadControl.Stop();
      Sleep(250);
      if bStopFlag then break;
    end;

If you write that loop (with Sleep) on the main form (by pressing a button), you will see that the interface will hangs... With threads, that doesn't happen.

In the attached demo, you will see
  • How to start the thread
  • How to send data before starting the thread, to perform 3 different actions (in the same thread)
  • How to stop the thread
  • How to get data from the thread: If it is running or not, the time running and in what point (of the thread) it is currently.

I apologize in advance, because the code refers to Threads is a bit complex to understand, but this is what you need...

{Apologies if I translated something wrong ... I speak spanish}

// Updated 7z attachement
« Last Edit: August 29, 2015, 10:39:21 am by u2o »

 

TinyPortal © 2005-2018