unit RDThread; interface uses Classes, D2xxUnit, user_types, windows, ConstUnit; type TRDThread = class(TThread) private procedure Get_device_message;{ Private declarations } procedure Wait_for_byte; procedure Message_got; protected procedure Execute; override; public message_: message_Array; constructor Create (suspended:boolean); virtual; destructor Destroy; override; end; var message_begin: Boolean; implementation uses MainUnit; { Important: Methods and properties of objects in visual components can only be used in a method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure TRDThread.UpdateCaption; begin Form1.Caption := 'Updated in a thread'; end; } { TRDThread } constructor TRDThread.Create(suspended:boolean); begin inherited Create ( suspended ); self.Priority := tpLower; self.FreeOnTerminate:=true; end; destructor TRDThread.Destroy; begin self.Suspend; inherited; end; procedure TRDThread.Execute; begin Get_device_message;{ Place thread code here } end; procedure TRDThread.Wait_for_byte; begin repeat if not self.Terminated then begin Get_USB_Device_Status; sleep(10); end else exit; //проверяем буфер устройства //в этом месте идет загрузка на 100%. Вопрос в том как справится!!! until FT_Q_Bytes > 0; exit; end; procedure TRDThread.Message_got; begin message_begin := FALSE; Synchronize(MainForm.device.Got_last_message_byte); end; procedure TRDThread.Get_device_message; var read_byte: Integer; first_byte: Integer; last_byte: Integer; m: Integer; message_array_index: Integer; begin message_array_index := 0; //инициализация массива для хранения посылки for m := 0 to length( message_ ) - 1 do message_[ m ] := 0; while not self.Terminated do begin Wait_for_byte; if self.Terminated then exit; Synchronize(MainForm.device.Got_first_message_byte); Read_USB_Device_Buffer( 24064 ); //читаем буфер устройства first_byte := FT_In_Buffer[ 0 ]; //читаем первое число last_byte := FT_In_Buffer[ 24001 ]; if ( first_byte = 240 ) then //$F0 начало посылки begin message_begin := TRUE;//посылка пошла //Выводим сообщение о получении данных //прогресс бар измерения в 0 end; if message_begin then begin //запоминаем число из посылки message_[ message_array_index ] := read_byte; inc( message_array_index ); end; if ( read_byte = 255 ) then begin //посылка закончилась Message_got; message_array_index := 0; for m := 0 to length( message_ ) - 1 do message_[ m ] := 0; end; end; end; end.