📄 data.~pas
字号:
iWaring := 1;
end
else
begin
statData.SimpleText := command.GetError;
end;
// main.frmain.Spcomm1.WriteCommData( PChar(strLines),Length(strLines));
except
ShowMessage('打开串口失败,'+ '当前串口名:'+Main.frmain.Spcomm1.CommName+',波特率为:'+IntToStr(Main.frmain.Spcomm1.BaudRate));
end;
finally
command.Free;
end;
end;
procedure TfrmData.dblkcbbAddressClick(Sender: TObject);
begin
if ADOqryAQAC.Active = False then
begin
ADOqryAQAC.Active := True;
end;
end;
procedure TfrmData.DBLookupComboBox2Click(Sender: TObject);
begin
if ADOqryAQAC.Active = False then
begin
ADOqryAQAC.Active := True;
end;
end;
procedure TfrmData.DBLookupComboBox4Click(Sender: TObject);
begin
if ADOqryAQAC.Active = False then
begin
ADOqryAQAC.Active := True;
end;
end;
procedure TfrmData.dblkcbbACAddressClick(Sender: TObject);
begin
if ADOqryID.Active = False then
begin
ADOqryID.Active := True;
end;
end;
procedure TfrmData.DBLookupComboBox1Click(Sender: TObject);
begin
if ADOqryID.Active = False then
begin
ADOqryID.Active := True;
end;
end;
procedure TfrmData.DBLookupComboBox3Click(Sender: TObject);
begin
if ADOqryID.Active = False then
begin
ADOqryID.Active := True;
end;
end;
procedure TfrmData.dblkcbbACAddressMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ADOqryID.Active = False then
begin
ADOqryID.Active := True;
end;
end;
procedure TfrmData.dblkcbbAddressMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ADOqryAQAC.Active = False then
begin
ADOqryAQAC.Active := True;
end;
end;
procedure TfrmData.dblkcbbACAddressExit(Sender: TObject);
begin
with ADOqryAQAC do
begin
Close;
SQL.Clear;
SQL.Add('select * from AC where id=:@iid');
Parameters.ParamByName('@iid').Value := dblkcbbACAddress.Text;
Open;
end;
end;
procedure TfrmData.DBLookupComboBox1Exit(Sender: TObject);
begin
with ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from AC where id=:@iid');
Parameters.ParamByName('@iid').Value := DBLookupComboBox1.Text;
Open;
end;
//DBLookupComboBox2.ReadOnly := False;
// frmData.statData.SimpleText := ADOqryAQAC.Fields.Fields[0].AsString;
// frmData.statData.SimpleText := edt1.Text + ','+ADOqryAQAC.Fields.Fields[1].AsString;
//DBLookupComboBox2.Text := ADOqryAQAC.Parameters.ParamByName('id').Value;
end;
procedure TfrmData.DBLookupComboBox3Exit(Sender: TObject);
begin
with ADOQuery2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from AC where id=:@iid');
Parameters.ParamByName('@iid').Value := DBLookupComboBox3.Text;
Open;
end;
end;
procedure TfrmData.DBLookupComboBox2MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ADOqryAQAC.Active = False then
begin
ADOqryAQAC.Active := True;
end;
end;
procedure TfrmData.DBLookupComboBox4MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ADOqryAQAC.Active = False then
begin
ADOqryAQAC.Active := True;
end;
end;
procedure TfrmData.DBLookupComboBox1MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ADOqryID.Active = False then
begin
ADOqryID.Active := True;
end;
end;
procedure TfrmData.DBLookupComboBox3MouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if ADOqryID.Active = False then
begin
ADOqryID.Active := True;
end;
end;
function CHKSUM(strChk:string):string;
var
i:Integer;
sum,WLen:Word;
strSum,strReturn:string;
begin
sum := 0;
// ShowMessage('需要进行校验的字符串:'+strChk);
for i := 1 to Length(strChk) do
begin
sum := sum + Ord(strChk[i]) ;
// sum := sum + bBuffer[i];
end;
//有可能时取反加一
sum := sum xor $FFFF + 1;
strSum := IntToHex(sum,4);
//ShowMessage('校验CHKSUM:'+strSum);
WLen := Length(strSum);
if WLen = 4 then
strReturn := strSum
else
if WLen = 3 then
strReturn := '0'+ strSum
else
if WLen = 2 then
strReturn := '00'+strSum
else
if WLen = 1 then
strReturn := '000'+strSum
else
if WLen = 0 then
strReturn := '0000';
Result := strReturn;
end;
procedure TfrmData.btn2Click(Sender: TObject);
var
strTest:string;
begin
strTest := '~20016000903401'+' '+' '+' '+' ';
strTest := strTest + '0023'+' '+' '+'00';
strTest := strTest + CHKSUM(strTest) + #13;
ShowMessage('测试要发送的长度为:'+ IntToStr(Length( strTest )) + '______'+strTest);
try
if not main.frmain.Spcomm1.PortOpen then
main.frmain.Spcomm1.StartComm;
main.frmain.Spcomm1.WriteCommData( PChar(strTest),Length(strTest));
iCORP := 1;
// main.frmain.Spcomm1.WriteCommData( PChar(strLines),Length(strLines));
except
ShowMessage('打开串口失败,'+ '当前串口名:'+Main.frmain.Spcomm1.CommName+',波特率为:'+IntToStr(Main.frmain.Spcomm1.BaudRate));
end;
end;
procedure TfrmData.btn3Click(Sender: TObject);
var
strTest:string;
begin
strTest := '~20016000301C01'+' '+' ';
strTest := strTest + '02'+' '+'01'+'01';
strTest := strTest + CHKSUM(strTest) + #13;
ShowMessage('测试要发送的长度为:'+ IntToStr(Length( strTest )) + '______'+strTest);
try
if not main.frmain.Spcomm1.PortOpen then
main.frmain.Spcomm1.StartComm;
main.frmain.Spcomm1.WriteCommData( PChar(strTest),Length(strTest));
iWaring := 1;
// main.frmain.Spcomm1.WriteCommData( PChar(strLines),Length(strLines));
except
ShowMessage('打开串口失败,'+ '当前串口名:'+Main.frmain.Spcomm1.CommName+',波特率为:'+IntToStr(Main.frmain.Spcomm1.BaudRate));
end;
end;
procedure TfrmData.btn4Click(Sender: TObject);
begin
ShowMessage( IntToStr( 2157 div 100));
end;
procedure TfrmData.FormClose(Sender: TObject; var Action: TCloseAction);
begin
iGAP := 99;
iCOOP := 99;
iCORP := 99;
iTest := 99;
iWaring := 99;
if btmr = True then
begin
btmr := False;
frmain.tmrTC.Enabled := True;
end
else
begin
btmr := False;
frmain.tmrTC.Enabled := False;
end;
end;
procedure TfrmData.FormShow(Sender: TObject);
begin
if frmain.tmrTC.Enabled = True then
begin
btmr := True;
frmain.tmrTC.Enabled := False;
// ShowMessage('FormCreate:true');
end
else
begin
btmr := False ;
frmain.tmrTC.Enabled := False;
//ShowMessage('FormCreate:False');
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -