Ищу помощи в зависаниях проги.
Прога работает с библиотекой TLazSerial и отправляет в СОМ порт данные по таймеру с интервалом 200 и 1000 мс.
Проблема в том что прога периодически подвисает , иногда часто иногда редко , на разных компах по разному , повесить немного и дальше работает ю
Подскажите почему , что не так и как исправить.
Код
- Код: Выделить всё
uses
Classes, LazSerial, Forms,StdCtrls, ExtCtrls, LazSynaSer,dos;
type
{ TForm1 }
{ TTenesi_Creator }
TTenesi_Creator = class(TForm)
ConBut: TButton;
deviceList: TComboBox;
Label1: TLabel;
Label10: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label9: TLabel;
Tenesi: TLazSerial;
Timer1: TTimer;
Timer2: TTimer;
procedure ConButClick(Sender: TObject);
procedure deviceListDropDown(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
private
public
end;
var
Tenesi_Creator: TTenesi_Creator;
ModeFly:byte;
Bat,Lat,Lon,Alt,AltG,Cog,GPSVSI,Sat,Speed,VSI,Curs:double;
Pitch,Roll:integer;
implementation
{$R *.lfm}
{ TForm1 }
procedure TTenesi_Creator.deviceListDropDown(Sender: TObject);
begin
deviceList.Items.CommaText:=LazSynaSer.GetSerialPortNames;
end;
procedure TTenesi_Creator.FormCreate(Sender: TObject);
begin
end;
procedure TTenesi_Creator.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
If Tenesi.Active then Tenesi.Close;
end;
procedure TTenesi_Creator.Timer1Timer(Sender: TObject);
Var comanda,s:string;
begin
if Bat<21 then Bat:=25.2
else bat:=bat-0.1;
if Curs>360 then Curs:=Curs-360
else Curs:=Curs+1;
Lat:=56.1234567;
Lon:=35.7654321;
if alt>1000 then alt:=-100
else alt:=alt+0.3;
ModeFly:=2;
VSI:=435.67;
str(Pitch:4,s); Label2.Caption:= 'Pit '+s;
str(Roll:4,s); Label9.Caption:= 'Rol '+s;
str(Bat:2:2,s); Label10.Caption:='Bat '+s;
str(Lat:3:7,s); Label6.Caption:= 'Lat '+s;
str(Lon:3:7,s); Label13.Caption:='Lon '+s;
str(AltG:5:2,s); Label5.Caption:= 'AlG '+s;
str(Alt:5:2,s); Label14.Caption:='Alt '+s;
str(Curs:4:2,s); Label15.Caption:='Crs '+s;
str(Speed:4:2,s); Label3.Caption:= 'Spe '+s;
Label16.Caption:='Модель ПК A2';
Label4.Caption:='Fly Mode GPS';
Label1.Caption:='111111111111';
if Tenesi.Active
then
begin
Label1.Caption:='222222222222';
Comanda:='PK_A2,';
comanda:=comanda+'Mode: ';
case ModeFly of
0:comanda:=comanda+' MAN,';
1:comanda:=comanda+' ATT,';
2:comanda:=comanda+' GPS,';
end;
str(Bat:2:2,s); comanda:=comanda+' Bat: '+s+#13#10;
Tenesi.WriteData(Comanda);
str(Lat:2:7,s); comanda:='Lat: '+s+',';
str(Lon:2:7,s); comanda:=comanda+' Lon: '+s+',';
str(AltG:4:2,s); comanda:=comanda+'GPS alt: '+s+',';
str(Cog:3:2,s); comanda:=comanda+'COG: '+s+',';
str(Speed:2:2,s); comanda:=comanda+'Speed: '+s+',';
str(GPSVSI:3:2,s); comanda:=comanda+'GPS VSI: '+s+',';
str(Sat:2:2,s); comanda:=comanda+'Sat: '+s+#13#10;
Tenesi.WriteData(Comanda);
str(Alt:3:2,s); comanda:='Alt: '+s+',';
//str(VSI:3:0,s); comanda:=comanda+'VSI: '+s+',';
str(Curs:3:2,s); comanda:=comanda+' Heading: '+s+#13#10;
Label1.Caption:='333333333333';
Tenesi.WriteData(Comanda);
Label1.Caption:='444444444444';
end;
Label1.Caption:='555555555555';
end;
procedure TTenesi_Creator.Timer2Timer(Sender: TObject);
Var HH,MM,CC,KK:word;
s,Comand:string;
begin
Label1.Caption:='66666666666';
GetTime(HH,MM,CC,KK);
str(HH:2,s);
Comand:='Date/Time: 05.07.19 '+s+':';
str(MM:2,s);Comand:=Comand+s+':';
str(CC:2,s);Comand:=Comand+s+#13#10;
Label1.Caption:='77777777777';
If Tenesi.Active then Tenesi.WriteData(Comand);
Label1.Caption:='88888888888';
end;
//Выполняется по нажатию на кнопку Подключение Устройства 1
procedure TTenesi_Creator.ConButClick(Sender: TObject);
begin
Tenesi.Device := deviceList.Text;
Tenesi.BaudRate:= LazSerial.br115200;
if Not Tenesi.Active then Tenesi.Open
else Tenesi.Close;
if Tenesi.Active
then ConBut.Caption:='Отключить'
Else ConBut.Caption:='Подключить';
end;
end.