📄 unit1.~pas
字号:
begin
Application.MessageBox('无法找到可用的串口,请释放其他软件对串口的占用再重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
if(CheckBox3.Checked) then
begin
jihao := 0;
end
else
begin
if(Length(Edit18.Text) = 0) then
begin
Application.MessageBox('结束设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit18.SetFocus();
exit;
end;
if(not isrightint(Edit18.Text)) then
begin
Application.MessageBox('结束设备号输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit18.SetFocus();
Edit18.SelectAll();
exit;
end;
jihao := strtoint(Edit18.Text);
end;
comport_handle := PortOpen(commindex.ItemIndex+1);
if(comport_handle = INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('串口无法打开,请选择其他串口重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
CloseBeep(comport_handle,jihao);
PortClose(comport_handle);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
strls:string;
strls1:string;
status:integer;
i:integer;
jhls:pchar;
jihao:integer;
beepforxms:integer;
unbeepforxms:integer;
times:integer;
cardhao:array[0..9] of byte;
cardserial_long:Longword;
begin
if(commindex.Items.Count<1) then
begin
Application.MessageBox('无法找到可用的串口,请释放其他软件对串口的占用再重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
if(Length(Edit6.Text) = 0) then
begin
Application.MessageBox('设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit6.SetFocus();
Edit6.SelectAll();
exit;
end;
if(not isrightint(Edit6.Text)) then
begin
Application.MessageBox('设备号中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit6.SetFocus();
Edit6.SelectAll();
exit;
end;
jihao := strtoint(Edit6.Text);
comport_handle := PortOpen(commindex.ItemIndex+1);
if(comport_handle = INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('串口无法打开,请选择其他串口重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
status := GetCardNoForByte(comport_handle,jihao,@cardhao);
PortClose(comport_handle);
if(status = 0) then
begin//读卡成功
strls1 := '';
for i:=0 to 3 do
begin
strls := '00'+IntToHex(cardhao[i],2);
strls1 := strls1 + RightStr(strls,2) + '-';
end;
strls := '00'+IntToHex(cardhao[4],2);
strls1 := strls1 + RightStr(strls,2);
Edit8.Text := strls1;
cardserial_long := 0;
for i:=1 to 4 do
begin
cardserial_long := cardserial_long * 256;
cardserial_long := cardserial_long + cardhao[i];
end;
strls := '000000000' + IntToStr(cardserial_long);
Edit3.Text := RightStr(strls,10);
strls := '000' + IntToStr(cardhao[2]);
strls1 := RightStr(strls,3) + ',';
strls := '00000' + IntToStr(integer(cardhao[3])*256+integer(cardhao[4]));
Edit5.Text := strls1 + RightStr(strls,5);
exit;
end;
Edit3.Text := '读卡失败';
Edit5.Text := '读卡失败';
Edit8.Text := '读卡失败';
end;
procedure TForm1.Button10Click(Sender: TObject);
var
strls:string;
strls1:string;
status:integer;
i:integer;
jhls:pchar; //键盘字串
jihao:integer;
beepforxms:integer;
unbeepforxms:integer;
times:integer;
cardhao:array[0..9] of byte;
keystring:array[0..20] of char;
cardserial_long:Longword;
begin
if(commindex.Items.Count<1) then
begin
Application.MessageBox('无法找到可用的串口,请释放其他软件对串口的占用再重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
if(Length(Edit6.Text) = 0) then
begin
Application.MessageBox('设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit6.SetFocus();
Edit6.SelectAll();
exit;
end;
if(not isrightint(Edit6.Text)) then
begin
Application.MessageBox('设备号中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit6.SetFocus();
Edit6.SelectAll();
exit;
end;
jihao := strtoint(Edit6.Text);
comport_handle := PortOpen(commindex.ItemIndex+1);
if(comport_handle = INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('串口无法打开,请选择其他串口重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
jhls := keystring;
status := GetKeyInputForString(comport_handle,jihao,jhls);
PortClose(comport_handle);
if(status = 0) then
begin
Edit21.Text := string(jhls);
exit;
end
else if (status = 3) or (status = 4) then
begin
Edit21.Text := '没有键盘输入...';
exit;
end;
//ShowMessage(IntToStr(status));
Edit21.Text := '读键盘码失败';
end;
procedure TForm1.Button11Click(Sender: TObject);
var
strls:string;
strls1:string;
status:integer;
i:integer;
jhls:pchar;
jihao:integer;
beepforxms:integer;
unbeepforxms:integer;
times:integer;
cardhao:array[0..9] of byte;
dispstring:string;
cardserial_long:Longword;
begin
if(commindex.Items.Count<1) then
begin
Application.MessageBox('无法找到可用的串口,请释放其他软件对串口的占用再重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
if(CheckBox1.Checked) then
begin
jihao := 0;
end
else
begin
if(Length(Edit22.Text) = 0) then
begin
Application.MessageBox('设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit22.SetFocus();
exit;
end;
if(not isrightint(Edit22.Text)) then
begin
Application.MessageBox('设备号输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
Edit22.SetFocus();
Edit22.SelectAll();
exit;
end;
jihao := strtoint(Edit22.Text);
end;
if(Length(Edit20.Text) = 0) then
begin
Application.MessageBox('显示字符框为空!', '警告', MB_OK+MB_ICONINFORMATION);
Edit20.SetFocus();
exit;
end;
comport_handle := PortOpen(commindex.ItemIndex+1);
if(comport_handle = INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('串口无法打开,请选择其他串口重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
dispstring := Edit20.Text;
SetDispFull(comport_handle,jihao,pchar(dispstring));
PortClose(comport_handle);
end;
procedure TForm1.btn1Click(Sender: TObject);
var
strls:string;
strls1:string;
status:integer;
i:integer;
jhls:pchar;
jihao:integer;
beepforxms:integer;
unbeepforxms:integer;
times:integer;
cardhao:array[0..9] of byte;
cardserial_long:Longword;
begin
if btn1.Caption = '开始轮询' then
begin
if(commindex.Items.Count<1) then
begin
Application.MessageBox('无法找到可用的串口,请释放其他软件对串口的占用再重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
if(Length(edt_1.Text) = 0) then
begin
Application.MessageBox('启始设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
edt_1.SetFocus();
edt_1.SelectAll();
exit;
end;
if(not isrightint(edt_1.Text)) then
begin
Application.MessageBox('启始设备号输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
edt_1.SetFocus();
edt_1.SelectAll();
exit;
end;
if(Length(edt_2.Text) = 0) then
begin
Application.MessageBox('结束设备号输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
edt_2.SetFocus();
edt_2.SelectAll();
exit;
end;
if(not isrightint(edt_2.Text)) then
begin
Application.MessageBox('结束设备号输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
edt_2.SetFocus();
edt_2.SelectAll();
exit;
end;
if(Length(edt_3.Text) = 0) then
begin
Application.MessageBox('每一轮循环间隔输入框为空!', '警告', MB_OK+MB_ICONINFORMATION);
edt_3.SetFocus();
edt_3.SelectAll();
exit;
end;
if(not isrightint(edt_3.Text)) then
begin
Application.MessageBox('每一轮循环间隔输入框中有非法字符!', '警告', MB_OK+MB_ICONINFORMATION);
edt_3.SetFocus();
edt_3.SelectAll();
exit;
end;
startxbh := StrToInt(edt_1.Text);
endxbh := StrToInt(edt_2.Text);
if(startxbh>endxbh) then
begin
midxbh := endxbh;
endxbh := startxbh;
startxbh := midxbh;
end
else
begin
midxbh := startxbh;
end;
sjjg := StrToInt(edt_3.Text);
zqs := 0;
comport_handle := PortOpen(commindex.ItemIndex+1);
if(comport_handle = INVALID_HANDLE_VALUE) then
begin
Application.MessageBox('串口无法打开,请选择其他串口重试!', '警告', MB_OK+MB_ICONINFORMATION);
exit;
end;
//发送
Delay_ms(8);//如果是使用无源485网卡,这个延时一定要加
lv1.Items.Clear();
edt_4.Text :='0';
//timescount = 0;
edt_1.Enabled := false;
edt_2.Enabled := false;
edt_3.Enabled := false;
Button_updata.Enabled := false;
Button1.Enabled := false;
Button2.Enabled := false;
Button3.Enabled := false;
Button6.Enabled := false;
Button8.Enabled := false;
Button9.Enabled := false;
Button10.Enabled := false;
Button10.Enabled := false;
btn1.Caption := '终止轮询';
timeconitue := true;
thread0 := lsthread.Create(false);
end
else
begin
timeconitue := false;
edt_1.Enabled := true;
edt_2.Enabled := true;
edt_3.Enabled := true;
Button_updata.Enabled := true;
Button1.Enabled := true;
Button2.Enabled := true;
Button3.Enabled := true;
Button6.Enabled := true;
Button8.Enabled := true;
Button9.Enabled := true;
Button10.Enabled := true;
Button10.Enabled := true;
btn1.Enabled := false;
end;
end;
procedure TForm1.myproc();
var
i:Integer;
keystr:array[0..38] of char;
keystr_pchar:pchar;
cardstr:array[0..20] of char;
cardstr_pchar:pchar;
status:integer;
jihao:integer;
cardhao:array[0..9] of byte;
cardserial_long:Longword;
pItem:TListItem;
isadditem1:Boolean;
strls:string;
strls0:string;
strls1:string;
strlsok0:string;
strlsok1:string;
begin
//轮询读卡及键盘
if (midxbh>endxbh) then
begin
midxbh := startxbh;
edt_4.Text := IntToStr(StrToInt(edt_4.Text)+1);
if(sjjg >0) then
begin
Delay_ms(sjjg)
end;
end;
//读函数
status := GetCardNoForByte(comport_handle,midxbh,@cardhao);
if(status = 0) then
begin//读卡成功
pItem := lv1.Items.Add();
pItem.Caption := IntToStr(midxbh);
strls1 := '';
for i:=0 to 3 do
begin
strls := '00'+IntToHex(cardhao[i],2);
strls1 := strls1 + RightStr(strls,2) + '-';
end;
strls := '00'+IntToHex(cardhao[4],2);
strls1 := strls1 + RightStr(strls,2);
pItem.SubItems.Add(strls1);
cardserial_long := 0;
for i:=1 to 4 do
begin
cardserial_long := cardserial_long * 256;
cardserial_long := cardserial_long + cardhao[i];
end;
strls := '000000000' + IntToStr(cardserial_long);
pItem.SubItems.Add(RightStr(strls,10));
strls := '000' + IntToStr(cardhao[2]);
strls1 := RightStr(strls,3) + ',';
strls := '00000' + IntToStr(integer(cardhao[3])*256+integer(cardhao[4]));
pItem.SubItems.Add(strls1 + RightStr(strls,5));
SendMessage(lv1.Handle,WM_KEYDOWN, 35, 0);
exit;
end;
midxbh := midxbh + 1;
if(not timeconitue) then
begin
PortClose(comport_handle); //关闭串口
btn1.Caption := '开始轮询';
btn1.Enabled := true;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -