Delphi 7是一款功能强大的快速应用程序开发工具,它提供了丰富的开发环境和组件库,支持多种操作系统和数据库连接,方便开发者进行高效的程序设计。然而,由于它是一款较旧的开发环境,在使用时需要注意兼容性和安全问题。
- Delphi 7支持自定义消息,通过声明消息标识符和消息记录类型,可以实现消息的发送和处理。
- Delphi 7提供了异常处理结构,使用try...except...finally结构来处理运行时出现的意外情况,确保程序在遇到错误时仍能优雅地执行清理和恢复操作。
- Delphi 7支持多种数据类型,包括基本数据类型(如整数、浮点数、布尔型等)、复合数据类型(如数组、记录和集合)等。
- Delphi 7提供了丰富的运算符和表达式,以及选择结构、循环结构等控制结构,方便开发者进行程序设计。
Delphi 7UI页面设计:
Delphi 7代码如下:
varForm1: TForm1;implementationuses Unit3, Unit2, Unit4, Unit5, Unit6, tcpserver;{$R *.dfm}function isrightint(textls:string):boolean;stdcall;
begintryif(strtoint(textls) =0) thenbeginend;result := True;exceptresult := False;exit;end;
end;
procedure TForm1.Button9Click(Sender: TObject);
varsendbuf:array[0..280] of Byte;i:Integer;
beginForm3:=TForm3.Create(nil);Form3.ShowModal;if(Form3.ModalResult=mrOk) thenbegin//下传//启始机号2字节,结束机号2字节,目标电脑IP地址,sendbuf[0] := $e8;//表示修改目标电脑IP地址 1c//1d 1e 1f 20if Form3.isalljihao thenbeginsendbuf[1] := 0;sendbuf[2] := 0;sendbuf[3] := 255;sendbuf[4] := 255;endelsebegini := StrToInt(Form3.startjihaostr);sendbuf[1] := i mod 256;sendbuf[2] := (i div 256) mod 256;i := StrToInt(Form3.endjihaostr);sendbuf[3] := i mod 256;sendbuf[4] := (i div 256) mod 256;end;//21 22 23 24 25 26 27 28sendbuf[5] := StrToInt(Form3.strremoteip1);sendbuf[6] := StrToInt(Form3.strremoteip2);sendbuf[7] := StrToInt(Form3.strremoteip3);sendbuf[8] := StrToInt(Form3.strremoteip4);sendbuf[9] := sendbuf[5];sendbuf[10] := sendbuf[6];sendbuf[11] := sendbuf[7];sendbuf[12] := sendbuf[8];//29 2a 2b 2c 2d 2e//对方的MAC 29 2a 2b 2c 2d 2esendbuf[13] := StrToInt('$' + Form3.strremotemac1);sendbuf[14] := StrToInt('$' + Form3.strremotemac2);sendbuf[15] := StrToInt('$' + Form3.strremotemac3);sendbuf[16] := StrToInt('$' + Form3.strremotemac4);sendbuf[17] := StrToInt('$' + Form3.strremotemac5);sendbuf[18] := StrToInt('$' + Form3.strremotemac6);//2fif Form3.isautogetremotemac thenbeginsendbuf[19] := 1;endelsebeginsendbuf[19] := 0;end;//30 31 32 33sendbuf[20] := $55;sendbuf[21] := $aa;sendbuf[22] := $66;sendbuf[23] := $99;IdUDPServer1.Binding.SendTo( '255.255.255.255',myport,sendbuf,24); //广播式发送Label6.Caption :='提示:已发送更改目标电脑IP地址信息至读卡器,请稍候搜寻所有读卡器以刷新最新参数!';end;Form3.Free;
end;procedure TForm1.Button3Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit7.Text) = '') thenbeginShowMessage('时间长输入框不能为空');Edit7.Text:='';Edit7.SetFocus;Exit;end;if not isrightint(Edit7.Text) thenbeginShowMessage('时间长输入必须为数字');Edit7.SelectAll;Edit7.SetFocus;Exit;end;if StrToInt(Edit7.Text)>65535 thenbeginShowMessage('时间长输入不能大于65535,为65535是表示久永');Edit7.SelectAll;Edit7.SetFocus;Exit;end;if(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit2.SelectAll;Edit2.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;//开启继电器sendbuf[0] := $78;//命令字:驱动继电器//机号低,机号高,命令字 时间低,时间高strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;case ComboBox3.ItemIndex of1: sendbuf[3] := $e1;2: sendbuf[3] := $e2;3: sendbuf[3] := $e3;4: sendbuf[3] := $e4;5: sendbuf[3] := $e5;6: sendbuf[3] := $e6;7: sendbuf[3] := $e7;8: sendbuf[3] := $e8;else sendbuf[3] := $e0;end;strls:=Edit7.Text;sendbuf[4] := StrToInt(strls) mod 256;sendbuf[5] := (StrToInt(strls) div 256) mod 256;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,6);end;procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;ABinding: TIdSocketHandle);
varlen:Integer;strls:string;strls1:string;i:Integer;j:Integer;m:Integer;keystrlen:Integer;strip:string;listls:TListItem;divnostr:string;sendbuf:array[0..280] of Byte;MyUdpData: array[1..280] of byte;cardhao:Longword;mccount:LongWord;beginAData.Position:= 0;len:=AData.Size;if(len>269) thenbeginlen := 269;end;if(len>0) thenbeginAData.Read(MyUdpData[1],len);if(MyUdpData[1] = $f1) thenbegin//有新读卡器重启//机器序列号divnostr:='';for i := 16 to 19 dobegindivnostr := divnostr + RightStr('00'+IntToStr(MyUdpData[i]),3);if i <> 19 thenbegindivnostr:=divnostr+'-';end;end;for i := 0 to ListView1.Items.Count - 1 dobeginif divnostr = ListView1.Items[i].SubItems.Strings[9] thenbeginListView1.Items.Delete(i);Break;end;end;//len = 19//命令,IP地址 ,掩码 ,对方地址 , 机号,机器序列号//(241, 192, 168, 1, 218, 255, 255, 255, 0, 255, 255, 255, 255, 0, 0, 186, 0, 220, 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16listls:=ListView1.Items.Add;//机号listls.Caption:=RightStr('0000'+IntToStr(MyUdpData[15]*256+MyUdpData[14]),5);//本机IP地址strls:='';for i := 2 to 5 dobeginstrls := strls + RightStr('00'+IntToStr(MyUdpData[i]),3);if i <> 5 thenbeginstrls:=strls+'.';end;end;listls.SubItems.Add(strls);//子网掩码strls:='';for i := 6 to 9 dobeginstrls := strls + RightStr('00'+IntToStr(MyUdpData[i]),3);if i <> 9 thenbeginstrls:=strls+'.';end;end;listls.SubItems.Add(strls);//固定端口号,读卡器内定的,不能再改listls.SubItems.Add('');listls.SubItems.Add('');//参数listls.SubItems.Add('');//网关IPlistls.SubItems.Add('');//网关MAC//远程电脑IP地址strls:='';for i := 10 to 13 dobeginstrls := strls + RightStr('00'+IntToStr(MyUdpData[i]),3);if i <> 13 thenbeginstrls:=strls+'.';end;end;listls.SubItems.Add(strls);listls.SubItems.Add('');//目标主机MAClistls.SubItems.Add('');//自动搜标志//机器序列号 -listls.SubItems.Add(divnostr);//接收时间listls.SubItems.Add(FormatDateTime('hh:mm:ss',Now));endelse if(MyUdpData[1] = $f2) thenbegin//有新读卡器重启//机器序列号divnostr:='';for i := 36 to 39 dobegindivnostr := divnostr + RightStr('00'+IntToStr(MyUdpData[i]),3);if i <> 39 thenbegindivnostr:=divnostr+'-';end;end;for i := 0 to ListView1.Items.Count - 1 dobeginif divnostr = ListView1.Items[i].SubItems.Strings[9] thenbeginListView1.Items.Delete(i);Break;end;end;listls:=ListView1.Items.Add;//机号listls.Caption:=RightStr('0000'+IntToStr(MyUdpData[13]*256+MyUdpData[12]),5);//本机IP地址strls:='';for i := 2 to 5 dobeginstrls := strls + RightStr('00'+IntToStr(MyUdpData[i]),3);if i <> 5 thenbeginstrls:=strls+'.';end;end;listls.SubItems.Add(strls);//子网掩码strls:='';for i := 6 to 9 dobeginstrls := strls + RightStr('00'+IntToStr(MyUdpData[i]),3);if i <> 9 thenbeginstrls:=strls+'.';end;end;listls.SubItems.Add(strls);//端口号strls := RightStr('0000'+IntToStr(MyUdpData[11]*256+MyUdpData[10]),5);listls.SubItems.Add(strls);//参数strls := IntToStr(MyUdpData[35]);listls.SubItems.Add(strls);//网关IPstrls:='';for i := 14 to 17 dobeginstrls := strls + RightStr('00'+IntToStr(MyUdpData[i]),3);if i <> 17 thenbeginstrls:=strls+'.';end;end;listls.SubItems.Add(strls);//网关MACstrls:='';for i := 18 to 23 dobeginstrls := strls + IntToHex(MyUdpData[i],2);if i <> 23 thenbeginstrls:=strls+'-';end;end;listls.SubItems.Add(strls);//远程电脑IP地址strls:='';for i := 24 to 27 dobeginstrls := strls + RightStr('00'+IntToStr(MyUdpData[i]),3);if i <> 27 thenbeginstrls:=strls+'.';end;end;listls.SubItems.Add(strls);//远程电脑MACstrls:='';for i := 28 to 33 dobeginstrls := strls + IntToHex(MyUdpData[i],2);if i <> 33 thenbeginstrls:=strls+'-';end;end;listls.SubItems.Add(strls);//自动搜标志strls := IntToStr(MyUdpData[34]);listls.SubItems.Add(strls);//机器序列号listls.SubItems.Add(divnostr);//接收时间listls.SubItems.Add(FormatDateTime('hh:mm:ss',Now));endelse if (MyUdpData[1] = $c1) or (MyUdpData[1] = $d1) or (MyUdpData[1] = $d4) then //$c1表示IC卡,$d1表示ID卡,$C4,$D4表示接收到韦根信号begin//读卡器IP地址strip := IntToStr(MyUdpData[2]) + '.' + IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]);strls := '接收:读卡器IP地址[';strls := strls + strip;strls := strls + '],机号[';//机号strls := strls + IntToStr(MyUdpData[6] + MyUdpData[7]*256);strls := strls + '],数据包序号[';//数据包序号,每个包都不一样,按递增1变化strls := strls + IntToStr(MyUdpData[8] + MyUdpData[9]*256);strls := strls + '],物理卡号[';//物理卡号//十六进制的//strls := strls + IntToHex(MyUdpData[10],2) + '-' + IntToHex(MyUdpData[11],2) + '-' + IntToHex(MyUdpData[12],2) + '-' + IntToHex(MyUdpData[13],2) + '-' + IntToHex(MyUdpData[14],2);//十进制的if (MyUdpData[1] = $c1) thenbegin//IC卡for i := 0 to 3 dobegincardnumberbuf[i] := MyUdpData[11+i]end;endelsebegin//ID卡for i := 0 to 3 dobegincardnumberbuf[i] := MyUdpData[10+i]end;end;if (MyUdpData[1] = $d4) thenbegin//韦根码cardhao := cardnumberbuf[0] + cardnumberbuf[1]*256;strls1 := RightStr('0000' + IntToStr(cardhao),5);endelsebegincardhao := cardnumberbuf[0] + cardnumberbuf[1]*256 + cardnumberbuf[2]*256*256 + cardnumberbuf[3]*256*256*256;strls1 := RightStr('000000000' + IntToStr(cardhao),10);end;strls := strls + strls1;strls := strls + ']';Memo2.Text := strls;strls := '';for i := 3 downto 0 dobeginstrls := strls + RightStr('00' + IntToHex(cardnumberbuf[i],2),2);end;Edit1.Text := strls;//接收成功要发送确认信息sendbuf[0] := $69;//命令字,表示确认收到信息//IP地址sendbuf[1] := MyUdpData[2];sendbuf[2] := MyUdpData[3];sendbuf[3] := MyUdpData[4];sendbuf[4] := MyUdpData[5];//机号sendbuf[5] := MyUdpData[6];sendbuf[6] := MyUdpData[7];//数据包序号sendbuf[7] := MyUdpData[8];sendbuf[8] := MyUdpData[9];IdUDPServer1.Binding.SendTo(strip,myport,sendbuf,9); //广播式发送endelse if (MyUdpData[1] = $c2) or (MyUdpData[1] = $d2) then //$c2表示IC卡设备的按键信息,$d2表示ID卡设备的按键信息begin//读卡器IP地址strip := IntToStr(MyUdpData[2]) + '.' + IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]);strls := '接收:读卡器IP地址[';strls := strls + strip;strls := strls + '],机号[';//机号strls := strls + IntToStr(MyUdpData[6] + MyUdpData[7]*256);strls := strls + '],数据包序号[';//数据包序号,每个包都不一样,按递增1变化strls := strls + IntToStr(MyUdpData[8] + MyUdpData[9]*256);strls := strls + '],按键信息[';//MyUdpData[10]长度keystrlen := MyUdpData[10];for i := 1 to keystrlen dobeginstrls := strls + chr(MyUdpData[10 + i]);end;strls := strls + ']';Memo2.Text := strls;//接收成功要发送确认信息sendbuf[0] := $69;//命令字,表示确认收到信息//IP地址sendbuf[1] := MyUdpData[2];sendbuf[2] := MyUdpData[3];sendbuf[3] := MyUdpData[4];sendbuf[4] := MyUdpData[5];//机号sendbuf[5] := MyUdpData[6];sendbuf[6] := MyUdpData[7];//数据包序号sendbuf[7] := MyUdpData[8];sendbuf[8] := MyUdpData[9];IdUDPServer1.Binding.SendTo(strip,myport,sendbuf,9); //广播式发送endelse if(MyUdpData[1] = $c3) thenbegin //读卡 10 11 12//读卡器IP地址strip := IntToStr(MyUdpData[2]) + '.' + IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]);strls := '接收:读卡器IP地址[';strls := strls + strip;strls := strls + '],机号[';//机号strls := strls + IntToStr(MyUdpData[6] + MyUdpData[7]*256);strls := strls + '],数据包序号[';//数据包序号,每个包都不一样,按递增1变化strls := strls + IntToStr(MyUdpData[8] + MyUdpData[9]*256);strls := strls + '],总接收扇区数[' + IntToStr(MyUdpData[10]) + ']';Memo2.Text := strls;j := MyUdpData[11] * 48;m := MyUdpData[12] * 48;for i := 0 to 3 dobegincardnumberbuf[i] := MyUdpData[13+i]end;for i := 0 to (m-1) dobeginreadcardbuf[j+i] := MyUdpData[17+i]end;if (MyUdpData[12] + MyUdpData[11]) >= MyUdpData[10] thenbegin//已完全收到所有包strls := '';for i := 3 downto 0 dobeginstrls := strls + RightStr('00' + IntToHex(cardnumberbuf[i],2),2);end;Edit1.Text := strls;m := MyUdpData[10] * 48;strls := '';for i := 0 to (m-1) dobeginstrls := strls + RightStr('00' + IntToHex(readcardbuf[i],2),2);end;Memo1.Text := strls;end;endelse if(MyUdpData[1] = $c5) then//1 2 3 4 5 6 7 8 9 10 11 12 13 14 15begin //指定密码读卡的返回结果 3B C0 A8 01 DA 00 00 01 46 DF 44 C5 08 00 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 19 16//读卡器IP地址strip := IntToStr(MyUdpData[2]) + '.' + IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]);sendbuf[0] := $5a;//命令字:显示发送至双行显示屏的读卡器//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;sendbuf[3] := 1;sendbuf[4] := 20;//显示保留时间,单位为秒,为255时表示永久显示if MyUdpData[14] = 0 thenbeginstrls := '读卡成功! ';endelse if MyUdpData[14] = 12 thenbeginstrls := '旧密码不正确! ';endelsebeginstrls := '错误代码:' + IntToStr(MyUdpData[14]) + ' ';end;for i := 1 to 34 dobeginsendbuf[4+i] := Byte(strls[i]);end;IdUDPServer1.Binding.SendTo(strip,myport,sendbuf,4+1+34); //发送 ,全屏时字符数为34strls := '接收:读卡器IP地址[';strls := strls + strip;strls := strls + '],机号[';//机号strls := strls + IntToStr(MyUdpData[6] + MyUdpData[7]*256);strls := strls + '],共接收到卡号[';strls1 := IntToHex(MyUdpData[12],2) + IntToHex(MyUdpData[11],2) + IntToHex(MyUdpData[10],2) + IntToHex(MyUdpData[9],2);strls := strls + strls1 + ']的';Edit1.Text := strls1;//数据包序号,每个包都不一样,按递增1变化strls := strls + IntToStr(MyUdpData[8]);strls := strls + '个区返回,其中[' + IntToStr(MyUdpData[13]) + ']区返回代码为[';strls := strls + IntToStr(MyUdpData[14]) + ']';if MyUdpData[14] = 0 thenbegin//返回成功,下面提前区数据48个字节strls := strls + ',卡内数据如下';Memo2.Text := strls;strls := '';for i := 0 to 47 dobeginstrls := strls + RightStr('00' + IntToHex(MyUdpData[15+i],2),2);end;Memo1.Text := strls;endelsebeginMemo2.Text := strls;Memo1.Clear;end;endelse if(MyUdpData[1] = $cd) then //响应电脑改密码,写卡指令beginif(MyUdpData[2] = $3a) thenbegin //1 2 3 4 5 6 7 8 9 10 11 12 13 14//修改卡密码 CD 3A C0 A8 01 DA 00 00 01 46 DF 44 C5 08 00//读卡器IP地址strip := IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]) + '.' + IntToStr(MyUdpData[6]);sendbuf[0] := $5a;//命令字:显示发送至双行显示屏的读卡器//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;sendbuf[3] := 1;sendbuf[4] := 20;//显示保留时间,单位为秒,为255时表示永久显示if MyUdpData[15] = 0 thenbeginstrls := '卡密码修改成功! ';endelse if MyUdpData[15] = 12 thenbeginstrls := '旧密码不正确! ';endelsebeginstrls := '错误代码:' + IntToStr(MyUdpData[15]) + ' ';end;for i := 1 to 34 dobeginsendbuf[4+i] := Byte(strls[i]);end;IdUDPServer1.Binding.SendTo(strip,myport,sendbuf,4+1+34); //发送 ,全屏时字符数为34strls := '更改卡第' + IntToStr(MyUdpData[14]) + '区密码:卡号[';//十六进制的strls := strls + IntToHex(MyUdpData[13],2) +IntToHex(MyUdpData[12],2) + IntToHex(MyUdpData[11],2) + IntToHex(MyUdpData[10],2) + '],提示:';if MyUdpData[15] = 0 thenbeginstrls := strls + '成功!';endelse if MyUdpData[15] = 12 thenbeginstrls := strls + '旧密码不正确!';endelsebeginstrls := strls + '错误代码:' + IntToStr(MyUdpData[15]);end;ShowMessage(strls);endelse if(MyUdpData[2] = $3d) thenbegin//指定密码写卡 返回信息//读卡器IP地址strip := IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]) + '.' + IntToStr(MyUdpData[6]);sendbuf[0] := $5a;//命令字:显示发送至双行显示屏的读卡器//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;sendbuf[3] := 1;sendbuf[4] := 20;//显示保留时间,单位为秒,为255时表示永久显示if MyUdpData[15] = 0 thenbeginstrls := '卡密码修改成功! ';endelse if MyUdpData[15] = 12 thenbeginstrls := '旧密码不正确! ';endelsebeginstrls := '错误代码:' + IntToStr(MyUdpData[15]) + ' ';end;for i := 1 to 34 dobeginsendbuf[4+i] := Byte(strls[i]);end;IdUDPServer1.Binding.SendTo(strip,myport,sendbuf,4+1+34); //发送 ,全屏时字符数为34strls := '写数据到卡第' + IntToStr(MyUdpData[14]) + '区:卡号[';//十六进制的strls := strls + IntToHex(MyUdpData[13],2) + IntToHex(MyUdpData[12],2) + IntToHex(MyUdpData[11],2) + IntToHex(MyUdpData[10],2) + '],提示:';if MyUdpData[15] = 0 thenbeginstrls := strls + '成功!';endelse if MyUdpData[15] = 12 thenbeginstrls := strls + '旧密码不正确!';endelsebeginstrls := strls + '错误代码:' + IntToStr(MyUdpData[15]);end;ShowMessage(strls);end;endelse if (MyUdpData[1] = $ce) or (MyUdpData[1] = $de) then //响应电脑查询指令begin//读卡器IP地址strip := IntToStr(MyUdpData[2]) + '.' + IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]);strls := '响应电脑查询指令信息包:读卡器IP地址[';strls := strls + strip;strls := strls + '],机号[';//机号strls := strls + IntToStr(MyUdpData[6] + MyUdpData[7]*256);strls := strls + '],数据包序号[';//数据包序号,每个包都不一样,按递增1变化strls := strls + IntToStr(MyUdpData[8] + MyUdpData[9]*256);//MyUdpData[10]为返回的信息类型,1表示卡物理号if MyUdpData[10] = 0 thenbeginstrls := strls + '],信息为空NULL';Memo2.Text := strls;endelsebeginstrls := strls + '],物理卡号[';//十进制的if MyUdpData[11] > 10 then//物理卡号长度不能大于10个字节beginMyUdpData[11] := 10;end;for i := 1 to MyUdpData[11] dobegincardnumberbuf[i-1] := MyUdpData[11+i]end;cardhao := cardnumberbuf[0] + cardnumberbuf[1]*256 + cardnumberbuf[2]*256*256 + cardnumberbuf[3]*256*256*256;strls1 := RightStr('000000000' + IntToStr(cardhao),10);strls := strls + strls1;strls := strls + ']';Memo2.Text := strls;strls := '';for i := 3 downto 0 dobeginstrls := strls + RightStr('00' + IntToHex(cardnumberbuf[i],2),2);end;Edit1.Text := strls;end;endelse if (MyUdpData[1] = $cf) or (MyUdpData[1] = $df) then //表示卡离开,$cf表示IC卡,$df表示ID卡begin//读卡器IP地址strip := IntToStr(MyUdpData[2]) + '.' + IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]);strls := '卡离开信息包:读卡器IP地址[';strls := strls + strip;strls := strls + '],机号[';//机号strls := strls + IntToStr(MyUdpData[6] + MyUdpData[7]*256);strls := strls + '],数据包序号[';//数据包序号,每个包都不一样,按递增1变化strls := strls + IntToStr(MyUdpData[8] + MyUdpData[9]*256);strls := strls + '],物理卡号[';//MyUdpData[10]为返回的信息类型,1表示卡物理号//十进制的if MyUdpData[11] > 10 then//物理卡号长度不能大于10个字节beginMyUdpData[11] := 10;end;for i := 1 to MyUdpData[11] dobegincardnumberbuf[i-1] := MyUdpData[11+i]end;cardhao := cardnumberbuf[0] + cardnumberbuf[1]*256 + cardnumberbuf[2]*256*256 + cardnumberbuf[3]*256*256*256;strls1 := RightStr('000000000' + IntToStr(cardhao),10);strls := strls + strls1;strls := strls + ']';Memo2.Text := strls;strls := '';for i := 3 downto 0 dobeginstrls := strls + RightStr('00' + IntToHex(cardnumberbuf[i],2),2);end;Edit1.Text := strls;//接收成功要发送确认信息sendbuf[0] := $69;//命令字,表示确认收到信息//IP地址sendbuf[1] := MyUdpData[2];sendbuf[2] := MyUdpData[3];sendbuf[3] := MyUdpData[4];sendbuf[4] := MyUdpData[5];//机号sendbuf[5] := MyUdpData[6];sendbuf[6] := MyUdpData[7];//数据包序号sendbuf[7] := MyUdpData[8];sendbuf[8] := MyUdpData[9];IdUDPServer1.Binding.SendTo(strip,myport,sendbuf,9); //广播式发送endelse if(MyUdpData[1] = $4b) thenbeginLabel2.Caption := '设定成功!';endelse if(MyUdpData[1] = $3c) thenbegin//继续发送写卡信息if((MyUdpData[8] + MyUdpData[9]) >= writecardarealen) thenbegin//读卡器IP地址strip := IntToStr(MyUdpData[2]) + '.' + IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]);Label2.Caption := '写卡成功!';sendbuf[0] := $5a;//命令字:显示发送至双行显示屏的读卡器//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;sendbuf[3] := 1;sendbuf[4] := 20;//显示保留时间,单位为秒,为255时表示永久显示strls := '写卡成功!Write card successfully! ';for i := 1 to 34 dobeginsendbuf[4+i] := Byte(strls[i]);end;IdUDPServer1.Binding.SendTo(strip,myport,sendbuf,4+1+34); //发送 ,全屏时字符数为34endelsebeginsendbuf[0] := $3c;//命令字:写扇区肉容//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;//本次传输的启始指针,以一区数据48个字节为一单位//总区数sendbuf[3] := writecardareapoint;//本次传输区数j := writecardarealen - writecardareapoint;if(j>4) thenbeginj := 4;end;sendbuf[4] := j;sendbuf[5] := cardnumberbuf[0];sendbuf[6] := cardnumberbuf[1];sendbuf[7] := cardnumberbuf[2];sendbuf[8] := cardnumberbuf[3];for i := 0 to (j*48 - 1) dobeginsendbuf[9+i] := writecardbuf[writecardareapoint*48+i];end;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,9+j*48); //发送 ,全屏时字符数为34Label2.Caption := '正在发送......';writecardareapoint := writecardareapoint + sendbuf[4];end;endelse if(MyUdpData[1] = $1d) thenbeginif (MyUdpData[8] = 0) thenbeginShowMessage('1D指令设定成功!');endelsebeginShowMessage('1D指令返回错误代码:' + IntToStr(MyUdpData[8]));end;endelse if (MyUdpData[1] = $F8) then //设备返回时间信息begin//MyUdpData[10]为秒,[11]为分。。时日月周年//读卡器IP地址strip := IntToStr(MyUdpData[2]) + '.' + IntToStr(MyUdpData[3]) + '.' + IntToStr(MyUdpData[4]) + '.' + IntToStr(MyUdpData[5]);Edit19.Text := IntToStr(MyUdpData[16]);Edit20.Text := IntToStr(MyUdpData[14]);Edit21.Text := IntToStr(MyUdpData[13]);Edit23.Text := IntToStr(MyUdpData[12]);Edit24.Text := IntToStr(MyUdpData[11]);Edit25.Text := IntToStr(MyUdpData[10]);//接收成功要发送确认信息sendbuf[0] := $69;//命令字,表示确认收到信息//IP地址sendbuf[1] := MyUdpData[2];sendbuf[2] := MyUdpData[3];sendbuf[3] := MyUdpData[4];sendbuf[4] := MyUdpData[5];//机号sendbuf[5] := MyUdpData[6];sendbuf[6] := MyUdpData[7];//数据包序号sendbuf[7] := MyUdpData[8];sendbuf[8] := MyUdpData[9];IdUDPServer1.Binding.SendTo(strip,39169,sendbuf,9); //广播式发送end;endelsebegin// Adata.ReadBuffer(aUDP,Adata.Size);//这样收包end;end;procedure TForm1.Button8Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit2.SelectAll;Edit2.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;sendbuf[0] := $96;//命令字:驱动蜂鸣器响//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;sendbuf[3] := ComboBox1.ItemIndex;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,4); //发送end;procedure TForm1.Button2Click(Sender: TObject);
beginClose();
end;procedure TForm1.FormShow(Sender: TObject);
beginLabel10.Caption := IdIPWatch1.LocalIP;ListView1.Items.Clear;myport := 39169;IdUDPServer1.DefaultPort:=39169;//39169为读卡器专用端口,是固定的不可更改IdUDPServer1.BroadcastEnabled:=True;tryIdUDPServer1.Active := True;excepton EIdCouldNotBindSocket dobeginshowmessage('读卡器专用UDP协议端口[39169]已被其他程序占用,无法打开,程序将自行退出,请检查后重新打开软件!');Close();end;end;Memo1.Text := '123456789012345612345678901234561234567890123456123456789012345612345678901234561234567890123456';end;procedure TForm1.Button1Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit7.Text) = '') thenbeginShowMessage('时间长输入框不能为空');Edit7.Text:='';Edit7.SetFocus;Exit;end;if not isrightint(Edit7.Text) thenbeginShowMessage('时间长输入必须为数字');Edit7.SelectAll;Edit7.SetFocus;Exit;end;if StrToInt(Edit7.Text)>65535 thenbeginShowMessage('时间长输入不能大于65535,为65535是表示久永');Edit7.SelectAll;Edit7.SetFocus;Exit;end;if(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit2.SelectAll;Edit2.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;//开启继电器sendbuf[0] := $78;//命令字:驱动继电器//机号低,机号高,命令字 时间低,时间高strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;case ComboBox3.ItemIndex of1: sendbuf[3] := $f1;2: sendbuf[3] := $f2;3: sendbuf[3] := $f3;4: sendbuf[3] := $f4;5: sendbuf[3] := $f5;6: sendbuf[3] := $f6;7: sendbuf[3] := $f7;8: sendbuf[3] := $f8;else sendbuf[3] := $f0;end;strls:=Edit7.Text;sendbuf[4] := StrToInt(strls) mod 256;sendbuf[5] := (StrToInt(strls) div 256) mod 256;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,6);end;procedure TForm1.Timer1Timer(Sender: TObject);
var
sendbuf:array[0..280] of Byte;
beginsendbuf[0] := $96;//命令字:驱动蜂鸣器响//机号sendbuf[1] := 0;sendbuf[2] := 0;sendbuf[3] := 0;IdUDPServer1.Binding.SendTo('192.168.1.218',myport,sendbuf,4); //发送
end;procedure TForm1.Button7Click(Sender: TObject);
varsendbuf:array[0..280] of Byte;
beginsendbuf[0] := $a5;//搜寻所有连线的读卡器命令IdUDPServer1.Binding.SendTo('255.255.255.255',myport,sendbuf,1); //广播式发送end;procedure TForm1.Button5Click(Sender: TObject);
varlistls:TListItem;strls:string;sendbuf:array[0..280] of Byte;i:Integer;beginif ListView1.SelCount>0 thenbeginlistls:=ListView1.Selected;if(Trim(listls.SubItems.Strings[4]) <>'') thenbegin//跨网关型读卡器Form2:=TForm2.Create(nil);Form2.strjihao:=listls.Caption;strls:=listls.SubItems.Strings[0];Form2.strmyip1:=MidStr(strls,1,3);Form2.strmyip2:=MidStr(strls,5,3);Form2.strmyip3:=MidStr(strls,9,3);Form2.strmyip4:=MidStr(strls,13,3);strls:=listls.SubItems.Strings[1];Form2.strsubnetmask1:=MidStr(strls,1,3);Form2.strsubnetmask2:=MidStr(strls,5,3);Form2.strsubnetmask3:=MidStr(strls,9,3);Form2.strsubnetmask4:=MidStr(strls,13,3);Form2.LocalIPstr := ComboBox6.Text;//端口号if Trim(listls.SubItems.Strings[3]) = '' thenbeginForm2.strmyport := '39169';endelsebeginForm2.strmyport := listls.SubItems.Strings[2];end;//参数if Trim(listls.SubItems.Strings[3]) = '' thenbegini := $01;endelsebegini := StrToInt(listls.SubItems.Strings[3]);end;if (i mod 2) > 0 then //b0beginForm2.isoncardbeep1 := True;endelsebeginForm2.isoncardbeep1 := False;end;i := i div 2;if (i mod 2) > 0 then //b1beginForm2.isdhcp1 := True;endelsebeginForm2.isdhcp1 := False;end;i := i div 2;if (i mod 2) > 0 then //b2beginForm2.isoutcardsend1 := True;endelsebeginForm2.isoutcardsend1 := False;end;Form2.devcardondelaytype := ((i div 2) mod 8); //b345,b67保留//网关strls:=listls.SubItems.Strings[4];Form2.strgateip1:=MidStr(strls,1,3);Form2.strgateip2:=MidStr(strls,5,3);Form2.strgateip3:=MidStr(strls,9,3);Form2.strgateip4:=MidStr(strls,13,3);//网关macstrls:=listls.SubItems.Strings[5];Form2.strgatemac1:=MidStr(strls,1,2);Form2.strgatemac2:=MidStr(strls,4,2);Form2.strgatemac3:=MidStr(strls,7,2);Form2.strgatemac4:=MidStr(strls,10,2);Form2.strgatemac5:=MidStr(strls,13,2);Form2.strgatemac6:=MidStr(strls,16,2);//目标主机IP地址strls:=listls.SubItems.Strings[6];Form2.strremoteip1:=MidStr(strls,1,3);Form2.strremoteip2:=MidStr(strls,5,3);Form2.strremoteip3:=MidStr(strls,9,3);Form2.strremoteip4:=MidStr(strls,13,3);//目标主机MACstrls:=listls.SubItems.Strings[7];Form2.strremotemac1:=MidStr(strls,1,2);Form2.strremotemac2:=MidStr(strls,4,2);Form2.strremotemac3:=MidStr(strls,7,2);Form2.strremotemac4:=MidStr(strls,10,2);Form2.strremotemac5:=MidStr(strls,13,2);Form2.strremotemac6:=MidStr(strls,16,2);//自动搜标志if Trim(listls.SubItems.Strings[8]) = '' thenbeginForm2.isautogetremotemac1 := True;Form2.isautogetgatemac1 := True;endelsebegini := StrToInt(listls.SubItems.Strings[8]);if(i mod 2) = 1 thenbeginForm2.isautogetremotemac1 := True;endelsebeginForm2.isautogetremotemac1 := False;end;if((i div 2) mod 2) = 1 thenbeginForm2.isautogetgatemac1 := True;endelsebeginForm2.isautogetgatemac1 := False;end;end;//出厂序号Form2.strmydevno:=listls.SubItems.Strings[9];Form2.ShowModal;if(Form2.ModalResult=mrOk) thenbegin//用新指令更改sendbuf[0] := $F9;//IP地址 1d 1e 1f 20sendbuf[1] := StrToInt(Form2.strmyip1);sendbuf[2] := StrToInt(Form2.strmyip2);sendbuf[3] := StrToInt(Form2.strmyip3);sendbuf[4] := StrToInt(Form2.strmyip4);//子网掩码 21 22 23 24sendbuf[5] := StrToInt(Form2.strsubnetmask1);sendbuf[6] := StrToInt(Form2.strsubnetmask2);sendbuf[7] := StrToInt(Form2.strsubnetmask3);sendbuf[8] := StrToInt(Form2.strsubnetmask4);//对方地址 25 26 27 28sendbuf[9] := StrToInt(Form2.strremoteip1);sendbuf[10] := StrToInt(Form2.strremoteip2);sendbuf[11] := StrToInt(Form2.strremoteip3);sendbuf[12] := StrToInt(Form2.strremoteip4);//对方的MAC 29 2a 2b 2c 2d 2esendbuf[13] := StrToInt('$' + Form2.strremotemac1);sendbuf[14] := StrToInt('$' + Form2.strremotemac2);sendbuf[15] := StrToInt('$' + Form2.strremotemac3);sendbuf[16] := StrToInt('$' + Form2.strremotemac4);sendbuf[17] := StrToInt('$' + Form2.strremotemac5);sendbuf[18] := StrToInt('$' + Form2.strremotemac6);//网关地址 2f 30 31 32sendbuf[19] := StrToInt(Form2.strgateip1);sendbuf[20] := StrToInt(Form2.strgateip2);sendbuf[21] := StrToInt(Form2.strgateip3);sendbuf[22] := StrToInt(Form2.strgateip4);//网关MAC 33 34 35 36 37 38sendbuf[23] := StrToInt('$' + Form2.strgatemac1);sendbuf[24] := StrToInt('$' + Form2.strgatemac2);sendbuf[25] := StrToInt('$' + Form2.strgatemac3);sendbuf[26] := StrToInt('$' + Form2.strgatemac4);sendbuf[27] := StrToInt('$' + Form2.strgatemac5);sendbuf[28] := StrToInt('$' + Form2.strgatemac6);//机号 39 3astrls:=Form2.strjihao;sendbuf[29] := StrToInt(strls) mod 256;sendbuf[30] := (StrToInt(strls) div 256) mod 256;//端口 3b 3cstrls:=Form2.strmyport;sendbuf[31] := StrToInt(strls) mod 256;sendbuf[32] := (StrToInt(strls) div 256) mod 256;//机器序列号 3d 3e 3f 40strls:=Form2.strmydevno;sendbuf[33] := StrToInt(MidStr(strls,1,3));sendbuf[34] := StrToInt(MidStr(strls,5,3));sendbuf[35] := StrToInt(MidStr(strls,9,3));sendbuf[36] := StrToInt(MidStr(strls,13,3));if Form2.isoncardbeep1 thenbeginsendbuf[37] := 1;endelsebeginsendbuf[37] := 0;end;if Form2.isautogetremotemac1 thenbegin//自动sendbuf[37] := sendbuf[37] + 2;end;if Form2.isautogetgatemac1 thenbeginsendbuf[37] := sendbuf[37] + 4;end;if Form2.isdhcp1 thenbeginsendbuf[37] := sendbuf[37] + 8;end;if Form2.isoutcardsend1 thenbeginsendbuf[37] := sendbuf[37] + 16;end;sendbuf[37] := sendbuf[37] + Form2.devcardondelaytype * 32;//输入编码,防止误操作 42 43 44 45sendbuf[38] := $55;sendbuf[39] := $aa;sendbuf[40] := $66;sendbuf[41] := $99;IdUDPServer1.Binding.SendTo( '255.255.255.255',myport,sendbuf,42); //广播式发送Label6.Caption :='提示:广播式发送更改信息至读卡器,由于广播式信息在网络中的延迟,读卡器将在0~5秒内响应,请稍候......';end;Form2.Free;endelsebeginForm5:=TForm5.Create(nil);Form5.strjihao:=listls.Caption;strls:=listls.SubItems.Strings[0];Form5.strmyip1:=MidStr(strls,1,3);Form5.strmyip2:=MidStr(strls,5,3);Form5.strmyip3:=MidStr(strls,9,3);Form5.strmyip4:=MidStr(strls,13,3);strls:=listls.SubItems.Strings[1];Form5.strsubnetmask1:=MidStr(strls,1,3);Form5.strsubnetmask2:=MidStr(strls,5,3);Form5.strsubnetmask3:=MidStr(strls,9,3);Form5.strsubnetmask4:=MidStr(strls,13,3);strls:=listls.SubItems.Strings[6];Form5.strremoteip1:=MidStr(strls,1,3);Form5.strremoteip2:=MidStr(strls,5,3);Form5.strremoteip3:=MidStr(strls,9,3);Form5.strremoteip4:=MidStr(strls,13,3);if(Trim(listls.SubItems.Strings[2]) <> '') thenbeginForm5.strmyport:=listls.SubItems.Strings[2];endelsebeginForm5.strmyport:='39169';end;Form5.strmydevno:=listls.SubItems.Strings[9];Form5.ShowModal;if(Form5.ModalResult=mrOk) thenbeginsendbuf[0] := $F0;//表示修改读卡器参数//IP地址sendbuf[1] := StrToInt(Form5.strmyip1);sendbuf[2] := StrToInt(Form5.strmyip2);sendbuf[3] := StrToInt(Form5.strmyip3);sendbuf[4] := StrToInt(Form5.strmyip4);//子网掩码sendbuf[5] := StrToInt(Form5.strsubnetmask1);sendbuf[6] := StrToInt(Form5.strsubnetmask2);sendbuf[7] := StrToInt(Form5.strsubnetmask3);sendbuf[8] := StrToInt(Form5.strsubnetmask4);//对方地址sendbuf[9] := StrToInt(Form5.strremoteip1);sendbuf[10] := StrToInt(Form5.strremoteip2);sendbuf[11] := StrToInt(Form5.strremoteip3);sendbuf[12] := StrToInt(Form5.strremoteip4);//机号strls:=Form5.strjihao;sendbuf[13] := StrToInt(strls) mod 256;sendbuf[14] := (StrToInt(strls) div 256) mod 256;//机器序列号strls:=Form5.strmydevno;sendbuf[15] := StrToInt(MidStr(strls,1,3));sendbuf[16] := StrToInt(MidStr(strls,5,3));sendbuf[17] := StrToInt(MidStr(strls,9,3));sendbuf[18] := StrToInt(MidStr(strls,13,3));if Form5.isoncardbeep1 thenbeginsendbuf[19] := 1;endelsebeginsendbuf[19] := 0;end;IdUDPServer1.Binding.SendTo( '255.255.255.255',myport,sendbuf,20); //广播式发送Label6.Caption :='提示:广播式发送更改信息至读卡器,由于广播式信息在网络中的延迟,读卡器将在0~5秒内响应,请稍候......';end;Form5.Free;end;endelsebeginShowMessage('请先选择需要更改的行');end;
end;procedure TForm1.Button10Click(Sender: TObject);
beginif ListView1.SelCount>0 thenbeginif(Application.MessageBox('是否删除有记录?', '警告', MB_YESNO +MB_ICONINFORMATION) = IDYES) thenbeginListView1.DeleteSelected;end;endelsebeginShowMessage('请先选择需要删除的行');end;
end;procedure TForm1.Button6Click(Sender: TObject);
begin
// if(Application.MessageBox('是否删除所有记录?', '警告', MB_YESNO +MB_ICONINFORMATION) = IDYES) then
// begin
//
//
// end;ListView1.Items.Clear;
end;procedure TForm1.Button4Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit2.SelectAll;Edit2.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;sendbuf[0] := $5a;//命令字:显示发送至双行显示屏的读卡器//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;if(CheckBox2.Checked) thenbegin//可以同时发出声响sendbuf[3] := ComboBox2.ItemIndex;endelsebeginsendbuf[3] := $ff;//不发出声响end;//背光可设为不亮(为兼容以前的客户,特改为以下算法)
// if(sendbuf[3] = $ff) then
// begin
// sendbuf[3] := sendbuf[3] and $7f;//不发出声响时,bit7为0表示背光不亮
// end
// else
// begin
// sendbuf[3] := sendbuf[3] or $80;//发声响时,bit7为1表示背光不亮
// end;sendbuf[4] := 20;//显示保留时间,单位为秒,为255时表示永久显示//显示文字的ASCII码//Edit8strls := Edit8.Text + ' ';for i := 1 to 34 dobeginsendbuf[4+i] := Byte(strls[i]);end;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,4+1+34); //发送 ,全屏时字符数为34end;procedure TForm1.Button11Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit2.SelectAll;Edit2.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;sendbuf[0] := $5a;//显示发送至四行显示屏的读卡器//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;if(CheckBox2.Checked) thenbegin//可以同时发出声响sendbuf[3] := ComboBox2.ItemIndex;endelsebeginsendbuf[3] := $ff;//不发出声响end;sendbuf[4] := 20;//显示保留时间,单位为秒,为255时表示永久显示//显示文字的ASCII码//Edit8strls := Edit8.Text + ' ';for i := 1 to 72 dobeginsendbuf[4+i] := Byte(strls[i]);end;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,4+1+72); //发送 ,全屏时字符数为34end;procedure TForm1.Button15Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;j:Integer;m:Integer;pedit:TEdit;pcheckbox:TCheckBox;pComboBox:TComboBox;beginForm4:=TForm4.Create(nil);Form4.ShowModal;if(Form4.ModalResult=mrOk) thenbeginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit2.SelectAll;Edit2.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;sendbuf[0] := $4b;//命令字:设定读卡的区号及区密码//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;j := 0;i := 3;for m := 1 to 16 dobegincase m of1:beginpedit := Form4.Edit1;pcheckbox := Form4.CheckBox1;pComboBox := Form4.ComboBox1;end;2:beginpedit := Form4.Edit2;pcheckbox := Form4.CheckBox2;pComboBox := Form4.ComboBox2;end;3:beginpedit := Form4.Edit3;pcheckbox := Form4.CheckBox3;pComboBox := Form4.ComboBox3;end;4:beginpedit := Form4.Edit4;pcheckbox := Form4.CheckBox4;pComboBox := Form4.ComboBox4;end;5:beginpedit := Form4.Edit5;pcheckbox := Form4.CheckBox5;pComboBox := Form4.ComboBox5;end;6:beginpedit := Form4.Edit6;pcheckbox := Form4.CheckBox6;pComboBox := Form4.ComboBox6;end;7:beginpedit := Form4.Edit7;pcheckbox := Form4.CheckBox7;pComboBox := Form4.ComboBox7;end;8:beginpedit := Form4.Edit8;pcheckbox := Form4.CheckBox8;pComboBox := Form4.ComboBox8;end;9:beginpedit := Form4.Edit9;pcheckbox := Form4.CheckBox9;pComboBox := Form4.ComboBox9;end;10:beginpedit := Form4.Edit10;pcheckbox := Form4.CheckBox10;pComboBox := Form4.ComboBox10;end;11:beginpedit := Form4.Edit11;pcheckbox := Form4.CheckBox11;pComboBox := Form4.ComboBox11;end;12:beginpedit := Form4.Edit12;pcheckbox := Form4.CheckBox12;pComboBox := Form4.ComboBox12;end;13:beginpedit := Form4.Edit13;pcheckbox := Form4.CheckBox13;pComboBox := Form4.ComboBox13;end;14:beginpedit := Form4.Edit14;pcheckbox := Form4.CheckBox14;pComboBox := Form4.ComboBox14;end;15:beginpedit := Form4.Edit15;pcheckbox := Form4.CheckBox15;pComboBox := Form4.ComboBox15;end;16:beginpedit := Form4.Edit16;pcheckbox := Form4.CheckBox16;pComboBox := Form4.ComboBox16;end;end;if(pcheckbox.Checked) thenbeginInc(j);Inc(i);sendbuf[i] := m-1; //第0区 4if pComboBox.ItemIndex > 0 thenbeginsendbuf[i] := sendbuf[i] or $80;end;Inc(i);sendbuf[i] := StrToInt('$' + midstr(pedit.Text,1,2));Inc(i);sendbuf[i] := StrToInt('$' + midstr(pedit.Text,3,2));Inc(i);sendbuf[i] := StrToInt('$' + midstr(pedit.Text,5,2));Inc(i);sendbuf[i] := StrToInt('$' + midstr(pedit.Text,7,2));Inc(i);sendbuf[i] := StrToInt('$' + midstr(pedit.Text,9,2));Inc(i);sendbuf[i] := StrToInt('$' + midstr(pedit.Text,11,2));end;end;sendbuf[3] := j;//区数量sendbuf[4+j*7] := $55;sendbuf[5+j*7] := $aa;sendbuf[6+j*7] := $66;sendbuf[7+j*7] := $99;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,8+j*7); //发送 ,全屏时字符数为34Label2.Caption := '正在发送......';end;end;procedure TForm1.Button17Click(Sender: TObject);
beginEdit1.Text := '';Memo2.Text := '';Memo1.Text := '';
end;procedure TForm1.Button16Click(Sender: TObject);
//写卡
var strls:string;i:Integer;j:Integer;sendbuf:array[0..280] of Byte;
beginstrls := Edit1.Text;for i := 0 to 3 dobegincardnumberbuf[3 - i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;strls := Memo1.Text;j := Length(strls);j := j div 2;for i := 0 to (j-1) dobeginwritecardbuf[i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;writecardarealen := j div 48;writecardareapoint := 0;if(writecardarealen > 0) thenbegin//至少一个扇区的内容sendbuf[0] := $3c;//命令字:写扇区肉容//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;//本次传输的启始指针,以一区数据48个字节为一单位//总区数sendbuf[3] := writecardareapoint;//本次传输区数j := writecardarealen - writecardareapoint;if(j>4) thenbeginj := 4;end;sendbuf[4] := j;sendbuf[5] := cardnumberbuf[0];sendbuf[6] := cardnumberbuf[1];sendbuf[7] := cardnumberbuf[2];sendbuf[8] := cardnumberbuf[3];for i := 0 to (j*48 - 1) dobeginsendbuf[9+i] := writecardbuf[writecardareapoint*48+i];end;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,9+j*48);Label2.Caption := '正在发送......';writecardareapoint := writecardareapoint + sendbuf[4];end;end;procedure TForm1.Button18Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit1.SelectAll;Edit1.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;sendbuf[0] := $1e;//命令字:设定开机及待机时的文字显示//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;sendbuf[3] := 0;//两行屏为0,四行屏为1//开机文字的ASCII码strls := Edit10.Text + ' ';for i := 1 to 34 dobeginsendbuf[3+i] := Byte(strls[i]);end;//待机文字的ASCII码strls := Edit11.Text + ' ';for i := 1 to 34 dobeginsendbuf[37+i] := Byte(strls[i]);//37+34+1=72end;//固定的后缀sendbuf[72] := $55;sendbuf[73] := $aa;sendbuf[74] := $66;sendbuf[75] := $99;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,76);end;procedure TForm1.Button12Click(Sender: TObject);
varsendbuf:array[0..280] of Byte;
beginsendbuf[0] := $a6;//返回连线读卡器的跨网关参数IdUDPServer1.Binding.SendTo('255.255.255.255',myport,sendbuf,1); //广播式发送end;procedure TForm1.Button13Click(Sender: TObject);
vari:Integer;
begintryi := StrToInt(Edit12.Text);if(i > 65535) thenbeginShowMessage('端口输入错误,必须为不大于65535的数字!');Edit12.SelectAll;Edit12.SetFocus;Exit;end;IdUDPServer1.Free;IdUDPServer1:=TIdUDPServer.Create(self);IdUDPServer1.BroadcastEnabled:=True;IdUDPServer1.DefaultPort:=i;//39169为读卡器专用端口,是固定的不可更改IdUDPServer1.OnUDPRead := IdUDPServer1UDPRead;IdUDPServer1.Active := True;myport := i;ShowMessage('端口修改成功!');excepton EIdCouldNotBindSocket dobeginshowmessage('读卡器专用UDP协议端口['+Edit12.Text+']已被其他程序占用,请尝试其他端口!');Edit12.SelectAll;Edit12.SetFocus;exit;end;on e:Exception do //捕获异常beginShowMessage('端口输入错误,必须为不大于65535的数字!');Edit12.SelectAll;Edit12.SetFocus;end;end;
end;procedure TForm1.Button14Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit2.SelectAll;Edit2.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;sendbuf[0] := $4b;//由于和设定区号密码指令相同,有冲突,仅用于2013前版本的四行只读读卡器//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;if(CheckBox2.Checked) thenbegin//可以同时发出声响sendbuf[3] := ComboBox2.ItemIndex;endelsebeginsendbuf[3] := $ff;//不发出声响end;sendbuf[4] := 20;//显示保留时间,单位为秒,为255时表示永久显示//显示文字的ASCII码//Edit8strls := Edit8.Text + ' ';for i := 1 to 72 dobeginsendbuf[4+i] := Byte(strls[i]);end;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,4+1+72); //发送 ,全屏时字符数为34end;procedure TForm1.Button19Click(Sender: TObject);
varsendbuf:array[0..280] of Byte;i:Integer;
beginForm6:=TForm6.Create(nil);Form6.ShowModal;if(Form6.ModalResult=mrOk) thenbegin//下传//启始机号2字节,结束机号2字节,目标电脑IP地址,sendbuf[0] := $e1;//表示修改目标电脑IP地址if Form6.isalljihao thenbeginsendbuf[1] := 0;sendbuf[2] := 0;sendbuf[3] := 255;sendbuf[4] := 255;endelsebegini := StrToInt(Form6.startjihaostr);sendbuf[1] := i mod 256;sendbuf[2] := (i div 256) mod 256;i := StrToInt(Form6.endjihaostr);sendbuf[3] := i mod 256;sendbuf[4] := (i div 256) mod 256;end;sendbuf[5] := StrToInt(Form6.strremoteip1);sendbuf[6] := StrToInt(Form6.strremoteip2);sendbuf[7] := StrToInt(Form6.strremoteip3);sendbuf[8] := StrToInt(Form6.strremoteip4);sendbuf[9] := sendbuf[5];sendbuf[10] := sendbuf[6];sendbuf[11] := sendbuf[7];sendbuf[12] := sendbuf[8];IdUDPServer1.Binding.SendTo( '255.255.255.255',myport,sendbuf,13); //广播式发送Label6.Caption :='提示:已发送更改目标电脑IP地址信息至读卡器,请稍候搜寻所有读卡器以刷新最新参数!';end;Form6.Free;
end;procedure TForm1.Button20Click(Sender: TObject);
varmydatetime:TDateTime;
beginmydatetime := Now;Edit19.Text := FormatDateTime('YY',mydatetime);Edit20.Text := FormatDateTime('MM',mydatetime);Edit21.Text := FormatDateTime('DD',mydatetime);Edit23.Text := FormatDateTime('hh',mydatetime);Edit24.Text := FormatDateTime('nn',mydatetime);Edit25.Text := FormatDateTime('ss',mydatetime);
end;procedure TForm1.Button21Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit1.SelectAll;Edit1.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;//读取设备时间sendbuf[0] := $d2;//读取设备时间//机号低,机号高,命令字 时间低,时间高strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;strls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,3);//设备返回结果在UDP返回消息中end;procedure TForm1.Button22Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit1.SelectAll;Edit1.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;sendbuf[0] := $c3;//设定设备时间//机号低,机号高,命令字 时间低,时间高strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;sendbuf[3] := StrToInt(Edit25.Text);sendbuf[4] := StrToInt(Edit24.Text);sendbuf[5] := StrToInt(Edit23.Text);sendbuf[6] := StrToInt(Edit21.Text);sendbuf[7] := StrToInt(Edit20.Text);sendbuf[8] := StrToInt(Edit19.Text);sendbuf[9] := 0;for i := 3 to 8 dobeginsendbuf[9] := sendbuf[9] xor sendbuf[i];end;//固定的后缀 75+36+1sendbuf[10] := $55;sendbuf[11] := $aa;sendbuf[12] := $66;sendbuf[13] := $99;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,14);end;procedure TForm1.Button23Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit1.SelectAll;Edit1.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;sendbuf[0] := $1e;//命令字:设定开机及待机时的文字显示//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;sendbuf[3] := 1;//两行屏为0,四行屏为1//开机文字的ASCII码strls := Edit10.Text + ' ';for i := 1 to 72 dobeginsendbuf[3+i] := Byte(strls[i]);end;//待机文字的ASCII码strls := Edit9.Text + ' ';for i := 1 to 36 dobeginsendbuf[75+i] := Byte(strls[i]); //3+72end;//固定的后缀 75+36+1sendbuf[112] := $55;sendbuf[113] := $aa;sendbuf[114] := $66;sendbuf[115] := $99;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,116); //4+34+34+4=76,4+72+36+4=116end;procedure TForm1.Button24Click(Sender: TObject); //远程更改设备管理员密码
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit1.SelectAll;Edit1.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;if(Length(Edit13.Text) < 6) thenbeginShowMessage('密码长度不足6位');Edit13.SetFocus;Exit;end;sendbuf[0] := $0f;//设定设备密码//机号低,机号高,命令字 密码strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;strls := Edit13.Text;sendbuf[3] := StrToInt('$'+midstr(strls,1,2));sendbuf[4] := StrToInt('$'+midstr(strls,3,2));sendbuf[5] := StrToInt('$'+midstr(strls,5,2));sendbuf[6] := 0;for i := 3 to 5 dobeginsendbuf[6] := sendbuf[6] xor sendbuf[i];end;//固定的后缀 75+36+1sendbuf[7] := $55;sendbuf[8] := $aa;sendbuf[9] := $66;sendbuf[10] := $99;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,11);end;
procedure TForm1.Button25Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit2.SelectAll;Edit2.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;sendbuf[0] := $A7;//命令字:重新获取刷卡信息//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,3); //发送
end;procedure TForm1.Button26Click(Sender: TObject);
//修改卡密码
varstrls:string;i:Integer;sendbuf:array[0..280] of Byte;
begin//卡号提取strls := Trim(Edit1.Text);if (Length(strls) < 1) thenbegincardnumberbuf[0] := 0;cardnumberbuf[1] := 0;cardnumberbuf[2] := 0;cardnumberbuf[3] := 0;endelsebeginfor i := 0 to 3 dobegincardnumberbuf[3 - i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;end;//新A密码if(Length(Edit15.Text) < 12) thenbeginShowMessage('新A密码长度不足');Edit15.SetFocus;Exit;end;if(Length(Edit17.Text) < 12) thenbeginShowMessage('新B密码长度不足');Edit17.SetFocus;Exit;end;//3a 机号L 机号H 区数量 卡号 区号 密码验证方式及修改项标志 旧密码 区第三块数据 55 AA 66 99sendbuf[0] := $3a;//修改卡密码//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;//本次操作的区数sendbuf[3] := 1;//仅操作一个区//卡号 不为零表示操作指定卡号的卡sendbuf[4] := cardnumberbuf[0];sendbuf[5] := cardnumberbuf[1];sendbuf[6] := cardnumberbuf[2];sendbuf[7] := cardnumberbuf[3];//区参数----------------------------------------------------------------------------------//区号sendbuf[8] := ComboBox4.ItemIndex;//密码修改项标志,任何情况下都会更改A密码sendbuf[9] := 0;if ComboBox5.ItemIndex > 0 thenbeginsendbuf[9] := sendbuf[9] + 1;//为1以B密码来验证旧密码,为0以A密码来验证旧密码end;if CheckBox3.Checked thenbeginsendbuf[9] := sendbuf[9] + 2;//表示更改该区的访问位end;if CheckBox4.Checked thenbeginsendbuf[9] := sendbuf[9] + 4;//表示更改B密码,不加2表示不更改B密码end;//旧密码strls := Edit14.Text;for i := 0 to 5 dobeginsendbuf[10 + i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;//区第三块数据//新A密码strls := Edit15.Text;for i := 0 to 5 dobeginsendbuf[16 + i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;//访问位strls := Edit16.Text;for i := 0 to 3 dobeginsendbuf[22 + i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;//新B密码strls := Edit17.Text;for i := 0 to 5 dobeginsendbuf[26 + i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;//-----------------------------------------------------------------------------------//抗干扰sendbuf[32] := $55;sendbuf[33] := $AA;sendbuf[34] := $66;sendbuf[35] := $99;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,8+1*24+4);end;procedure TForm1.Button28Click(Sender: TObject);
//指定密码写卡
varstrls:string;i:Integer;j:Integer;sendbuf:array[0..280] of Byte;
begin//卡号提取strls := Trim(Edit1.Text);if (Length(strls) < 1) thenbegincardnumberbuf[0] := 0;cardnumberbuf[1] := 0;cardnumberbuf[2] := 0;cardnumberbuf[3] := 0;endelsebeginfor i := 0 to 3 dobegincardnumberbuf[3 - i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;end;//写卡数据准备strls := Memo1.Text;j := Length(strls);j := j div 2;for i := 0 to (j-1) dobeginwritecardbuf[i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;//3b 机号L 机号H 区数量 卡号 区号 密码验证方式 旧密码sendbuf[0] := $3d;//指定密码写卡//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;//本次操作的区数sendbuf[3] := 1;//仅操作一个区//卡号 不为零表示操作指定卡号的卡sendbuf[4] := cardnumberbuf[0];sendbuf[5] := cardnumberbuf[1];sendbuf[6] := cardnumberbuf[2];sendbuf[7] := cardnumberbuf[3];//区参数----------------------------------------------------------------------------------//区号sendbuf[8] := ComboBox4.ItemIndex;//密码修改项标志,任何情况下都会更改A密码sendbuf[9] := 0;if ComboBox5.ItemIndex > 0 thenbeginsendbuf[9] := sendbuf[9] + 1;//为1以B密码来验证旧密码,为0以A密码来验证旧密码end;//旧密码strls := Edit14.Text;for i := 0 to 5 dobeginsendbuf[10 + i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;//卡数据48个字节for i := 0 to 47 dobeginsendbuf[16 + i] := writecardbuf[i];end;//-----------------------------------------------------------------------------------//抗干扰sendbuf[64] := $55;sendbuf[65] := $AA;sendbuf[66] := $66;sendbuf[67] := $99;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,8+1*56+4);end;procedure TForm1.Button27Click(Sender: TObject);
//指定密码读卡
varstrls:string;i:Integer;sendbuf:array[0..280] of Byte;
begin//卡号提取strls := Trim(Edit1.Text);if (Length(strls) < 1) thenbegincardnumberbuf[0] := 0;cardnumberbuf[1] := 0;cardnumberbuf[2] := 0;cardnumberbuf[3] := 0;endelsebeginfor i := 0 to 3 dobegincardnumberbuf[3 - i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;end;//3b 机号L 机号H 区数量 卡号 区号 密码验证方式 旧密码sendbuf[0] := $3b;//指定密码读卡//机号strls:=Edit2.Text;sendbuf[1] := StrToInt(strls) mod 256;sendbuf[2] := (StrToInt(strls) div 256) mod 256;//本次操作的区数sendbuf[3] := 1;//仅操作一个区//卡号 不为零表示操作指定卡号的卡sendbuf[4] := cardnumberbuf[0];sendbuf[5] := cardnumberbuf[1];sendbuf[6] := cardnumberbuf[2];sendbuf[7] := cardnumberbuf[3];//区参数----------------------------------------------------------------------------------//区号sendbuf[8] := ComboBox4.ItemIndex;//密码修改项标志,任何情况下都会更改A密码sendbuf[9] := 0;if ComboBox5.ItemIndex > 0 thenbeginsendbuf[9] := sendbuf[9] + 1;//为1以B密码来验证旧密码,为0以A密码来验证旧密码end;//旧密码strls := Edit14.Text;for i := 0 to 5 dobeginsendbuf[10 + i] := StrToInt('$' + MidStr(strls,i*2+1,2));end;//-----------------------------------------------------------------------------------if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,8+1*8);end;procedure TForm1.Button29Click(Sender: TObject);
begin//IdTCPServer1.Active := True;//IdTCPServer1.Bindings.Add.IP := '127.0.0.1';//绑定IP//IdTCPServer1.Bindings.Add.Port := 39169;//绑定端口//Formtcp:=Formtcp.Create(nil);Formtcp.ShowModal;end;procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
varrbyte:array[0..4096] of byte;
begin// if (AThread.Terminated) or (not AThread.Connection.Connected) then
// begin
//
// Exit;
// end;
//
// AThread.Connection.ReadBuffer(Head, SizeOf(Head));//这一步出现问题。end;procedure TForm1.FormCreate(Sender: TObject);
varaa:TList;i :Integer;begintrybeginaa :=GetAdapterInfo;for i := 0 to aa.Count - 1 dobeginComboBox6.Items.Add(TAdapterInfo(aa.Items[i]).IPAddress);end;ComboBox6.ItemIndex:= aa.Count - 1;end;exceptbeginshowmessage('本计算机网卡异常,请检查后重启软件!');Close ;end;end;end;procedure TForm1.Button30Click(Sender: TObject);
varstrls:string;sendbuf:array[0..280] of Byte;i,j,k,m:Integer;pedit:TEdit;
beginif(Trim(Edit2.Text) = '') thenbeginShowMessage('机号不能为空');Edit2.Text:='';Edit2.SetFocus;Exit;end;if not isrightint(Edit2.Text) thenbeginShowMessage('机号必须为数字');Edit2.SelectAll;Edit2.SetFocus;Exit;end;if StrToInt(Edit2.Text)>65535 thenbeginShowMessage('机号不能大于65535');Edit1.SelectAll;Edit1.SetFocus;Exit;end;for i := 3 to 6 dobeginpedit := TEdit(FindComponent('Edit' + IntToStr(i)));strls := pedit.Text;if Trim(strls) = '' thenbeginShowMessage('输入不能为空');pedit.Text:='';pedit.SetFocus;Exit;end;if not isrightint(strls) thenbeginShowMessage('输入必须为数字');pedit.SelectAll;pedit.SetFocus;Exit;end;if StrToInt(strls)>255 thenbeginShowMessage('输入不能大于255');pedit.SelectAll;pedit.SetFocus;Exit;end;end;if(Trim(Edit22.Text) = '') thenbeginShowMessage('端口不能为空');Edit22.Text:='';Edit22.SetFocus;Exit;end;if not isrightint(Edit22.Text) thenbeginShowMessage('端口必须为数字');Edit22.SelectAll;Edit22.SetFocus;Exit;end;if StrToInt(Edit22.Text)>65535 thenbeginShowMessage('端口不能大于65535');Edit22.SelectAll;Edit22.SetFocus;Exit;end;if(Trim(Edit26.Text) = '') thenbeginShowMessage('端口不能为空');Edit26.Text:='';Edit26.SetFocus;Exit;end;if not isrightint(Edit26.Text) thenbeginShowMessage('端口必须为数字');Edit26.SelectAll;Edit26.SetFocus;Exit;end;if StrToInt(Edit26.Text)>65535 thenbeginShowMessage('端口不能大于65535');Edit26.SelectAll;Edit26.SetFocus;Exit;end;sendbuf[0] := $1d;//设定设备参数//机号低,机号高,命令字 密码i:=StrToInt(Edit2.Text);sendbuf[1] := i mod 256;sendbuf[2] := (i div 256) mod 256;sendbuf[3] := 7; //长度sendbuf[4] := 92;//设定TCP协议的端口sendbuf[5] := 4; //参数长度//读卡器的TCP端口i:=StrToInt(Edit22.Text);sendbuf[6] := i mod 256;sendbuf[7] := (i div 256) mod 256;//远程服务器的端口i:=StrToInt(Edit26.Text);sendbuf[8] := i mod 256;sendbuf[9] := (i div 256) mod 256;sendbuf[10] := sendbuf[6] xor sendbuf[7] xor sendbuf[8] xor sendbuf[9];//固定的后缀sendbuf[11] := $55;sendbuf[12] := $aa;sendbuf[13] := $66;sendbuf[14] := $99;if not CheckBox1.Checked thenbeginstrls := Edit3.Text + '.' + Edit4.Text + '.' + Edit5.Text + '.' + Edit6.Text;endelsebeginstrls := '255.255.255.255';end;IdUDPServer1.Binding.SendTo(strls,myport,sendbuf,15);
end;procedure TForm1.ComboBox6Change(Sender: TObject);
begintrybeginIdUDPServer1.Active :=False ;IdUDPServer1.BroadcastEnabled:=False;IdUDPServer1.Bindings.Clear;IdUDPServer1.Bindings.Add;IdUDPServer1.Bindings[0].IP := ComboBox6.Text ; //本地IPLabel10.Caption := ComboBox6.Text ;IdUDPServer1.Bindings[0].Port := myport; //本地IPIdUDPServer1.BroadcastEnabled:=true;IdUDPServer1.Active := true; //激活IdUDPServer 控件end;exceptend;
end;end.