📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ControlCAN, ExtCtrls, DB, ADODB, ComCtrls, OleCtrls,
MSCommLib_TLB, mmsystem, TeEngine, Series, TeeProcs, Chart, SPComm;
type
TForm1 = class(TForm)
Timer1: TTimer;
PageControl1: TPageControl;
TabSheet2: TTabSheet;
Label20: TLabel;
Label21: TLabel;
Panel1: TPanel;
GroupBox4: TGroupBox;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
T_tuoluo_1: TEdit;
T_tuoluo_2: TEdit;
T_tuoluo_3: TEdit;
Panel2: TPanel;
Button4: TButton;
GroupBox6: TGroupBox;
ListBox1: TListBox;
MSComm1: TMSComm;
Edit7: TEdit;
GroupBox10: TGroupBox;
Button7: TButton;
TabSheet3: TTabSheet;
GroupBox7: TGroupBox;
Label25: TLabel;
Label26: TLabel;
Label27: TLabel;
CB_COM_NO: TComboBox;
CB_COM_BPS: TComboBox;
Timer2: TTimer;
Button13: TButton;
procedure Timer1Timer(Sender: TObject);
procedure Timer2Timer(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure MSComm1Comm(Sender: TObject);
procedure Button13Click(Sender: TObject);
private
{ Private declarations }
public
end;
PTListBox = ^TListBox;
var
Form1: TForm1;
var
m_devtype: DWORD;
m_devind: DWORD;
m_cannum, m_cannum1: DWORD;
m_connect, m_connect1: DWORD;
m_threadhandle, m_threadhandle1: integer;
ACC: array[0..4] of DOUBLE; //加表的数据(V)
LUOPAN: array[0..2] of DOUBLE; //电子罗盘数据(度)
PINJIAO: array[0..1] of DOUBLE; //倾角数据(度)
tuoluo: array[0..2] of Longint; //陀螺的数据(V)
outfile: textfile; // mycell:tcell;
database_error: boolean; //数据库操作错误
database_opened: boolean; //数据库打开正常?
SysTime: TsystemTime;
firsttime: TdateTime;
fileopened, isstop, isbegin: boolean;
gv_input, gv_output: olevariant; //串口的接收,发送数据
State, Count: Longword;
HEADER: byte = $80;
RECSIZE: integer = 6;
PacketBody: PByteArray;
rs232_recDATA: array[0..6] of BYTE;
ad_sample, recnum, recnum1: Longword;
htimeid: integer;
datatime, iten: integer;
protimecallback: tfntimecallback;
tempfile1, tempdata: string;
//GPS使用的变量
COM2_NO: integer; //GPS使用的串口数
COM2_BPS: integer; //GPS串口的传输率
new_gps: string; //gps传过来的最终数据
GPGGA_DATA: array[0..11] of string;
GPRMC_DATA: array[0..11] of string;
temp_gps: string; //gps传过来的暂时数据
COM2_INPUT: olevariant;
COM2_OUTPUT: olevariant;
X1, Y1, X2, Y2: Double; //当前map_coordinate
have_gps_data: boolean;
rbuf: array[0..255] of byte;
mscomm2OPEN: BOOLEAN = FALSE;
const
Vref: double = 2.5011;
ALPHA: double = 2664.7;
implementation
{$R *.dfm}
procedure timeproc(utimerid, umessage: uint; dwuser, dw1, dw2: dword) stdcall;
begin
// recnum := recnum + 1;
tempdata:='';
if isbegin and not (isstop) then
begin
try
tempdata := tempdata + ' ' + inttostr(tuoluo[0]);
tempdata := tempdata + ' ' + inttostr(tuoluo[1]);
tempdata := tempdata + ' ' + inttostr(tuoluo[2]);
writeln(outfile, tempdata);
except
end;
end;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
work_time: tsystemtime;
I, J, K, tempnum, tempnum1: integer;
begin
//DateTimeToSystemTime(now, SysTime);
{ panel1.Caption := IntToStr(SysTime.wYear) + '-' + IntToStr(SysTime.wMonth)
+ '-' + IntToStr(SysTime.wDay) + ' ' + IntToStr(SysTime.wHour)
+ ':' + IntToStr(SysTime.wMinute) + ':' + IntToStr(SysTime.wSecond); }
panel1.Caption := datetimetostr(now);
if isbegin then
begin
DateTimeToSystemTime(now - firsttime, work_time);
panel2.Caption := IntToStr(work_time.wHour)
+ ':' + IntToStr(work_time.wMinute) + ':' + IntToStr(work_time.wSecond);
end;
T_tuoluo_1.Text := inttostr(tuoluo[0]);
T_tuoluo_2.Text := inttostr(tuoluo[1]);
T_tuoluo_3.Text := inttostr(tuoluo[2]);
end;
procedure TForm1.Timer2Timer(Sender: TObject);
begin
edit7.Text := formatfloat('##0', recnum);
recnum := 0;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if isbegin then
begin
isbegin := false;
Button4.Caption := '开始';
timekillevent(htimeid);
writeln(outfile, 'End Time: ' + DatetimeToStr(Now));
closefile(outfile);
showmessage('保存文件名:' + tempfile1);
Button13.Enabled := false;
end
else
begin
tempfile1 := Extractfiledir(application.exeName) + '\' + DateToStr(Now) + '.txt';
assignfile(outfile, tempfile1);
rewrite(outfile);
writeln(outfile, 'Start Time: ' + DatetimeToStr(Now));
tempdata := '';
tempdata := tempdata + ' 陀螺0';
tempdata := tempdata + ' 陀螺1';
tempdata := tempdata + ' 陀螺2';
writeln(outfile, tempdata);
tempdata := '';
datatime := 0;
protimecallback := timeproc;
htimeid := timesetevent(10, 0, protimecallback, 1, TIME_PERIODIC);
firsttime := now;
isbegin := true;
Button4.Caption := '结束';
Button13.Enabled := true;
Button13.Caption := '暂停'
end;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
try
if mscomm1.PortOpen then
begin
mscomm1.PortOpen := false;
Button7.Caption := '打开串口';
ListBox1.Items.Add('串口已关闭!' + timetostr(time()));
end
else
begin
mscomm1.CommPort := strtoint(cb_com_no.text); ;
mscomm1.Settings := inttostr(strtoint(cb_com_bps.text)) + ',e,8,1';
mscomm1.RThreshold := 1;
mscomm1.InputLen := 1;
MSComm1.InBufferCount := 0;
mscomm1.InputMode := 1;
mscomm1.PortOpen := true;
ListBox1.Items.Add('串口已打开!' + timetostr(time()));
Button7.Caption := '关闭串口';
end;
except
// mscomm1.PortOpen := false;
showmessage('串口设置错误,请在系统设置中重新设置!');
end;
end;
procedure TForm1.MSComm1Comm(Sender: TObject);
var
temp: byte;
begin
if mscomm1.CommEvent = comEvReceive then
begin
while mscomm1.InBufferCount > 0 do
begin
gv_input := mscomm1.input;
if State = 0 then
begin
//waiting for header field
//if not header, skip char*/
if (gv_input[0] = HEADER) then
begin
State := 1;
Count := 0;
end;
end
//Receiving packet body*/
else
begin
//no data available, return*/
rs232_recDATA[Count] := gv_input[0];
Count := Count + 1;
//One data package*/
if (Count >= RECSIZE) then
begin
State := 0;
temp := ((((rs232_recDATA[0] xor rs232_recDATA[1]) xor rs232_recDATA[2]) xor rs232_recDATA[3]) xor rs232_recDATA[4]);
if rs232_recDATA[5] = temp then
begin
recnum := recnum + 1;
tuoluo[0] := rs232_recDATA[0] + rs232_recDATA[1] * 128 + rs232_recDATA[2] * 128 * 128 + rs232_recDATA[3] * 128 * 128 * 128 +
rs232_recDATA[4] * 128 * 128 * 128 * 128;
{ if ( rs232_recDATA[4] and $08)=8 then
begin
tuoluo[1] := -1 * (($0F - rs232_recDATA[4]) * 128 * 128 * 128 * 128 + ($7F - rs232_recDATA[3]) * 128 * 128 * 128 + ($7F - rs232_recDATA[2]) * 128 * 128
+ ($7F - rs232_recDATA[1]) * 128 + ($7F - rs232_recDATA[0] + 1));
end; }
if isbegin then
begin
tempdata := tempdata + ' ' + inttostr(tuoluo[0]);
datatime := datatime + 1;
if datatime = 10 then
begin
writeln(outfile, tempdata);
tempdata := '';
datatime := 0;
end;
end;
end;
end; //end of checksum*/
end; //end of 1/
end; //end of while
end; //end of comEvReceive:
end;
procedure TForm1.Button13Click(Sender: TObject);
begin
if isstop then
begin
isstop := false;
Button13.Caption := '暂停';
end
else
begin
isstop := true;
Button13.Caption := '继续';
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -