实时在线云消费机、考勤门禁控制器、网络读卡器服务端C# Socket源码

news/2024/11/30 5:43:25/

 

消费机UDP通讯协议介绍:

设备向服务器发送的指令格式,每个字段用半角逗号(,)分隔。
序号指令名称指令格式指令说明示例
1响应服务器的搜索100,包序列号,终端IP,子网掩码,网关IP,远程电脑主机IP,端口号,终端硬件号响应电脑发出的搜寻局域网内所有终端设备指令000,就是电脑软件用广播式向39190端口发送字符串“000”100,00009,192.168.1.218,255.255.255.0,192.168.1.1,192.168.1.3,39169,1234567890
2开机信息101,包序列号,终端IP,远程电脑主机IP,机号,时间1、设备开机时向电脑发送的开机信息,电脑可以根据这条信息发送相应的开机提示信息。
2、电脑发送002查询设备时间时,也是响应这条信息。
101,00009,192.168.1.1,192.168.1.3,00002,2012-04-20 11:12:13
3普通消费模式下刷卡102,包序列号,终端IP,远程电脑主机IP,机号,卡号当设备消费模式不是定额方式或计次方式时,刷卡后设备向电脑发送此信息。102,00009,192.168.1.1,192.168.1.3,00002,8888888888
4输入消费金额后刷卡、定额模式下刷卡103,包序列号,终端IP,远程电脑主机IP,机号,卡号,消费额,时间,21、设备消费模式为普通模式、快捷键模式时,先按金额后刷卡;
2、设备消费模式为定额方式时刷卡;

3、服务器端此时应用008指令回应消费成功或006指令回应消费失败。
103,00009,192.168.1.1,192.168.1.3,00002, 8888888888,5.50, 2012-04-20 11:12:13,2
5计次刷卡消费104,包序列号,终端IP,远程电脑主机IP,机号,卡号,时间在设备设定为计次消费模式下时,刷卡后直接发送至服务器104,00009,192.168.1.1,192.168.1.3,00002,8888888888,2012-04-20 11:12:13
6记帐信息105,包序列号,终端IP,远程电脑主机IP,机号,卡号,消费额,消费时间,状态(0:金额消费 1:计次),记录地址标识,总记录数电脑没回应的情况下,消费信息将先记账,在网络联通后,向服务器发送105,00009,192.168.1.1,192.168.1.3,00002,8888888888,5.50,2012-04-20 11:12:13,1,12345678,18
7键盘输入106,包序列号,终端IP,远程电脑主机IP,机号,键盘输入信息向服务器发送键盘指令,操作方法是先按设备【Func】进菜单,选【发送数字指令】,输入数字后,按回车发送106,00009,192.168.1.1,192.168.1.3,00002,11
8取餐模式下刷卡108,包序列号,终端IP,远程电脑主机IP,机号,卡号,时间设备设定为取餐模式下时,刷卡后直接发送至服务器108,00009,192.168.1.1,192.168.1.3,00002,8888888888,2012-04-20 11:12:13
9响应服务器发过来的显示指令109,包序列号,终端IP,远程电脑主机IP,机号,接收到的指令响应服务器发来的006、008、009、010、103指令,服务器端可通过此指令终止重发机制
响应电脑112,包序列号,终端IP,远程电脑主机IP,机号,返回值返回值:
0表示成功;
1表示广播式发送成功
2表示接收器和读卡器无线通讯失败
向应服务器查询信息114,包序列号,终端IP,远程电脑主机IP,机号,卡号,查询指令,时间
响应服务器的015指令115,包序列号,终端IP,远程电脑主机IP,机号,返回值
10二维码扫描信息125,包序列号,终端IP,远程电脑主机IP,机号,二维码格式标识,二维码信息(可以包含逗号)125,00004,192.168.1.228,192.168.1.168,00003,0, http://wwww.baidu.com,abc
11输入金额后再扫二维码128,包序列号,终端IP,远程电脑主机IP,机号,口令,消费额,时间,二维码格式标识,二维码信息(可以包含逗号)128,00004,192.168.1.228,192.168.1.168,00003,12345,5.50, 2012-04-20 11:12:13,0, http://wwww.baidu.com,abc
12门禁机刷卡150,包序列号,终端IP,远程电脑主机IP,机号,卡号,读头号,对应的门或继电器号,门磁未关秒数(0门已关),密码类别(0密码无效/1刷卡后按密码/2补签密码/3防迫胁密码/4开门密码),密码(最多10位数字),时间150,00055,192.168.1.228,192.168.1.168,00001,0305912578,0,0,0,0,00000000,2020-01-01 08:18:18
服务器向设备发送的指令,每个字段用半角逗号(,)分隔。
序号指令名称指令格式指令说明示例
1搜寻设备000搜寻局域网内所有终端设备指令,终端会向主机回应100指令000
2确认信息已收到001,包序列号用于告诉终端,信息已收到,不需要重发3次相同信息了。001,00009
3读设备时间002,机号读取终端时间,终端收到这些指令后会回应101指令(请看表1),00000表示任意机号002,00002
4改设备时间003,机号,时间设定终端设备时间,终端收到这些指令后会回应101指令003,00002,2012-04-20 11:12:13
5更改机备IP地址004,终端IP,子网掩码,网关IP,网送MAC,远程电脑主机IP,远程电脑主机MAC,是否自动搜出MAC,端口号,终端硬件号设定指定的终端IP地址等参数。
是否自动搜出MAC取值说明:
1:为自动搜出远程主机MAC
2:为自动搜出网关的MAC
4:为当设备IP在局域网中有冲突时,自动获取可用的IP(也就是开启DHCP功能)
8:允许保存DHCP自动获取的IP
004,192.168.1.228,255.255.255.0,192.168.1.1,AA-BB-CC-DD-EE-FF,255.255.255.255, AA-BB-CC-DD-EE-FF,0,39190,0138215662
6扣款不成功006,机号,卡号,信息,显示延时(秒),蜂鸣器发声(种类见表3),语音(种类见表4)扣款不成功时,服务器向终端发送的显示及声响信息,此信息仅在设备刷卡后显示“正在等待电脑回应..”时有效。006,00002,1234567890,此卡尚未开户\,余额信息不存在,10,0,1
要让设备显示逗号用“\,”表示。
显示换行用“\n”表示。
7扣款成功008,机号,卡号,消费额,信息,显示延时(秒),蜂鸣器发声(种类见表3),语音(种类见表4)扣款成功时,服务器向终端发送的显示及声响信息,此信息仅在设备刷卡后显示“正在等待电脑回应..”时有效。008,00002,1234567890,5.50,姓名  扣费成功\n余额12256.60元\n,10,1,1
要让设备显示逗号用“\,”表示。
显示换行用“\n”表示。
8驱动显示及响声009,机号,信息,显示延时(秒),蜂鸣器发声(种类见表3),语音(种类见表4)服务器发送,用于驱动终端设备显示信息及声响。009,00002,显示信息,10,1,1
要让设备显示逗号用“\,”表示。
显示换行用“\n”表示。
9清除记帐记录011,机号,卡号,消费额,消费时间,记录地址标识清除一条已经上传的记帐记录,使设备继续上传剩余的记账记录011,00002,8888888888,5.50,2012-04-20 11:12:13,12345678
10更改设备的管理员密码012,机号,新密码(必须为6位数字),012-012::012-012(这个固定常量用于防止网络干扰误改)更改设备的管理员密码012,00002,123456,012-012::012-012(这个固定常量用于防止网络干扰误改)
11门禁机开门成功指令050,机号,卡号(号卡为0表示外接按钮),信息,显示延时(秒,为0时不驱动显示,保留门禁机原来的显示不动),蜂鸣器发声(种类见表3),语音(种类见表4),读头号或按钮号,对应的门或继电器号,继电器开关保续时间(20毫秒为一个单位),门磁未关报警秒数开门成功时,电脑向终端发送的显示及声响信息,此信息仅在设备刷卡后显示“正在等待电脑回应..”时有效。050,00002,1234567890,姓名:张三丰 开门成功,20,2,0,0,0,300,0
12门禁机禁止开门提示051,机号,卡号(号卡为0表示外接按钮),信息,显示延时(秒,为0时不驱动显示,保留门禁机原来的显示不动),蜂鸣器发声(种类见表3),语音(种类见表4)开门不成功时,电脑向终端发送的显示及声响信息,此信息仅在设备刷卡后显示“正在等待电脑回应..”时有效。051,00002,1234567890,姓名:张三丰 禁止通行!,20,6,0

消费机介绍:

         账户金额等所有持卡人信息存在电脑服务器上,在线刷卡消费时设备将IC卡的物理卡号和消费金额传到服务器,服务器脑处理保存后将消费结果返发到消费机上显示,内置高灵敏扫码模组,扫码信息即时上传到服务器,脱网时支持白名单记账消费。

IC实时联网刷卡扫码一体云消费机售饭机食堂打卡机微信支付宝4G网-淘宝网 (taobao.com) 

实时门禁控制板: 

       考勤门禁控制板可外接刷卡读头、扫描枪、人脸识别器,将读取到的ID号即时发送到服务器,由服务器的软件判断后再返回开门信号或反馈信息。脱网时由控制板内的白名单控制刷卡是否可通行。

门禁板详细介绍:实时TCP网络双门双向门禁控制板大型小区网络开关可编程二次开发-淘宝网 (taobao.com) 

服务器端C#源程序 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.Collections;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
using System.Management;namespace UdpPostReaderDemoCSharp
{public partial class Form1 : Form{Form3 f3;Form5 f5;Form6 f6;int PortNumber;public string localIp;string machinnos;Boolean  ready = false ;  //线程运行标志Socket ListenerSock;      //SocketThread ListenerThre;      //端口侦听线程IPEndPoint RemoteIPoint;  //这里指向发送数据包的目的Ip及端口,EndPoint是IPEndPoint的基类,IPEndPoint可以强转为EndPoint。EndPoint ep = (EndPoint)iep,主要目的是IPEndPoint可以自己写入IP地址和端口string BeepCode;string VoiceCode;public string sendcode;   //批量下传注册号的指针、缓冲、重发标志public bool SendCount;public int SendAgain;public int SendPoin;public int SendPoinMax;public string[] SendBufStr=new string[7950];delegate void Update1(string text1,string text2);   //线程内更新UI委拖[DllImport("Iphlpapi.dll")]private static extern int SendARP(Int32 dest, Int32 host, ref   Int64 mac, ref   Int32 length);[DllImport("Ws2_32.dll")]private static extern Int32 inet_addr(string ip);public Form1(){InitializeComponent();}public static Int64 GetMACByIP(string ip)   //通过IP获取MAC{Int32 ldest = inet_addr(ip);   //目的地的ip     try{Int64 macinfo = new Int64();Int32 len = 6;int res = SendARP(ldest, 0, ref   macinfo, ref   len);return macinfo;}catch (Exception err){Console.WriteLine("Error:{0}", err.Message);}return 0;}public static bool checkmac(string macstr)   //检查MAC是否合法{try{string[] dataArray = macstr.Split(new char[2] { '-', '-' });for (int i = 0; i < 6; i++){byte macb = Convert.ToByte(Convert.ToInt32(dataArray[i], 16));}return true;}catch{return false;}}public static bool checkDateTime(string indt)  //检查日期时间字符串是否合法{try{DateTime userqsj = Convert.ToDateTime(indt);return true;}catch{return false;}}public static string getcuptwaystr(string inputip)   // 获取网关{ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");//获得本机ip、掩码、网关ManagementObjectCollection nics = mc.GetInstances();foreach (ManagementObject nic in nics){if (Convert.ToBoolean(nic["ipEnabled"]) == true){if ((nic["IPAddress"] as String[])[0] == inputip){string ComputerMaskStr = (nic["IPSubnet"] as String[])[0];string ComputerGatewayStr = (nic["DefaultIPGateway"] as String[])[0];return ComputerGatewayStr;}}}return "";}public static string GetSTCMAC(string inputstr)  //STC系列MAC获取方式{string tempmac="00000000"+Convert.ToInt64(inputstr).ToString("X2");string stcmac = "16-88";for (int i = 1; i <= 4; i++){string str1 = tempmac.Remove(0, tempmac.Length - 2);tempmac = tempmac.Substring(0, tempmac.Length - 2); stcmac = stcmac + "-" + str1;}return stcmac;}public static string GetCHMAC(string inputstr)   //CH系列MAC获取方式{string stcmac = "";if (inputstr.Length >= 16){for (int i = 0; i <= 5; i++){stcmac = stcmac + inputstr.Substring(4 + i * 2, 2);if (i < 5) { stcmac = stcmac + "-"; }}}return stcmac;}public static string DEC_To_Bin(byte indata)      //10进制转8位二进制{string DTB = "00000000" + Convert.ToString(indata, 2);DTB = DTB.Substring(DTB.Length - 8);return DTB;}public static byte BintoDec(string indata){byte outbyte = (byte)Convert.ToInt32(indata, 2);return outbyte;}private void EditUi(string text1, string Msg)     //解析显示接收到的数据包,并对设备进行回应{if (ListBox1.Items.Count > 50) { ListBox1.Items.Clear();}ListBox1.Items.Add(text1 + Msg);ListBox1.SelectedIndex = ListBox1.Items.Count - 1;string DevRecFramesStr;string DevBufferIpAddrStr;string DevBufferMachinStr;string DevBufferCardidStr;string DevBufferDatetimeStr;string DevBufferUseMoneryStr;string DevBufferUseTimeStr;string DevBufferMaskStr;string DevBufferGatewayStr;string DevBufferRemoteAddrStr;string DevBufferPort;string DevBufferNumberDecStr;string DevBufferGatewayStrMAC;string DevBufferRemoteAddrMACStr;string DevBufferMACSearchStr;string DevBufferSerialNumStr;string DevBufferStaryStr;string DevBufferRecordAddStr;string DevBufferAllNoStr;string DevBufferInputKeyStr;string DevBufferCommandStr;string DevBufferFunctionStr1;string DevBufferFunctionStr2;string DevBufferQrcodeInfStr;string DevBufferReaderStr;string DevBufferDoorNoStr;string DevBufferDelayStr;string DevBufferPasswPropStr;string DevBufferPassWStr;string DevBufferStateStr;string DevBufferRandomCode;string DevBufferScanStr;string MACSTC;string MACCH;string iswifi;string wifidhcp;string Sendinf;int poi;ListViewItem plist;string[] dataArray = Msg.Split(new char[2] { ',', ',' });switch (dataArray[0]){case "100":  //发送搜索指令后,在线设备的返回信息if (dataArray.Length <=8)    //2018年前的设备{DevBufferIpAddrStr = dataArray[1];DevBufferMaskStr = dataArray[2];DevBufferGatewayStr = dataArray[3];DevBufferRemoteAddrStr = dataArray[4];DevBufferPort = dataArray[5];DevBufferNumberDecStr = dataArray[6];poi = machinnos.IndexOf(DevBufferNumberDecStr);if (poi < 0){MACSTC = GetSTCMAC(DevBufferNumberDecStr);machinnos = machinnos + DevBufferNumberDecStr;plist = ListView1.Items.Add(DevBufferIpAddrStr);plist.SubItems.Add(DevBufferMaskStr);plist.SubItems.Add(DevBufferGatewayStr);plist.SubItems.Add("");plist.SubItems.Add(DevBufferRemoteAddrStr);plist.SubItems.Add("");plist.SubItems.Add("");plist.SubItems.Add(DevBufferPort);plist.SubItems.Add(DevBufferNumberDecStr);plist.SubItems.Add("否");plist.SubItems.Add(MACSTC);}}if (dataArray.Length  >= 9)    //2018年以后的设备{DevBufferIpAddrStr = dataArray[1];DevBufferMaskStr= dataArray[2];DevBufferGatewayStr = dataArray[3];DevBufferGatewayStrMAC = dataArray[4];DevBufferRemoteAddrStr = dataArray[5];DevBufferRemoteAddrMACStr = dataArray[6];DevBufferMACSearchStr = dataArray[7];DevBufferPort = dataArray[8];DevBufferNumberDecStr = dataArray[9];MACSTC = GetSTCMAC(DevBufferNumberDecStr);if ((DEC_To_Bin(Convert.ToByte(DevBufferMACSearchStr))).Substring(0, 1) == "1") { iswifi = "WiFi";} else{ iswifi = "有线"; }if ((DEC_To_Bin(Convert.ToByte(DevBufferMACSearchStr))).Substring(5, 1) == "1") { wifidhcp = "DHCP"; }else{ wifidhcp = "静态ip";}if (dataArray.Length >= 10){DevBufferSerialNumStr = dataArray[10];MACCH = GetCHMAC(DevBufferSerialNumStr);}else{DevBufferSerialNumStr = "";MACCH = "";}poi = machinnos.IndexOf(DevBufferNumberDecStr);if( poi < 0){machinnos = machinnos + DevBufferNumberDecStr;plist = ListView1.Items.Add(DevBufferIpAddrStr);plist.SubItems.Add(DevBufferMaskStr);plist.SubItems.Add(DevBufferGatewayStr);plist.SubItems.Add(DevBufferGatewayStrMAC);plist.SubItems.Add(DevBufferRemoteAddrStr);plist.SubItems.Add(DevBufferRemoteAddrMACStr);plist.SubItems.Add(DevBufferMACSearchStr);plist.SubItems.Add(DevBufferPort);plist.SubItems.Add(DevBufferNumberDecStr);plist.SubItems.Add("是");plist.SubItems.Add(MACSTC);plist.SubItems.Add(DevBufferSerialNumStr);plist.SubItems.Add(iswifi);plist.SubItems.Add(wifidhcp);plist.SubItems.Add(MACCH);}}break;case "101":             //接收到 1、终端开机时向电脑发送的开机信息,         2、电脑发送002查询设备时间所返回的信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferDatetimeStr = dataArray[5];       //日期时间*/if (dataArray.Length  > 6){               //2018年以后的设备有唯一硬件序号*/DevBufferSerialNumStr = dataArray[6];}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次string SystemTimeStr = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");if( DevBufferDatetimeStr.Substring(0, 16) != SystemTimeStr.Substring(0, 16) )  //判断设备时间是否正确,不正确就更正时间{Response("003," + DevBufferMachinStr+","+SystemTimeStr);//更新设备时钟}TextBox3.Text = DevBufferDatetimeStr;break;case "102":DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCardidStr = dataArray[5];         //十位物理卡号if (dataArray.Length > 6){                            //2018年以后的设备有唯一硬件序号*/DevBufferSerialNumStr = dataArray[6];}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次//此处加入业务对数据库的查、增、删、减操作Response("009," + DevBufferMachinStr + "," + "{卡号:}" + DevBufferCardidStr + "\\n" + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString()  + "," + BeepCode + "," + VoiceCode);  //回应显示文字、蜂鸣响声、语音。break;case "103":                                    //按消费金额后刷卡 向电脑发送此信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCardidStr = dataArray[5];         //十位物理卡号DevBufferUseMoneryStr =  dataArray[6];     //消费额DevBufferUseTimeStr = dataArray[7] ;       //消费时间if (dataArray.Length > 8){                                          //2018年以后的设备有唯一硬件序号*/DevBufferSerialNumStr = dataArray[8];}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次//此处加入业务对数据库的查、增、删、减操作//008指令返回本次消费成功并播消费金额,006指令返回其他提示信息,正式系统开发时要有重发机制*switch(VoiceCode){case "1":           //提示消费成功并显示消费金额Sendinf = "008," + DevBufferMachinStr + "," + DevBufferCardidStr + "," + DevBufferUseMoneryStr + "," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString()  + "," + BeepCode + "," + VoiceCode;break;default:            //其它提示Sendinf = "006," + DevBufferMachinStr + "," + DevBufferCardidStr + "," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString () + "," + BeepCode + "," + VoiceCode;break;}Response(Sendinf);break;case "104":                                    //计次模式下刷卡 向电脑发送此信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCardidStr = dataArray[5];         //十位物理卡号DevBufferUseTimeStr = dataArray[6];       //消费时间if (dataArray.Length > 7){                                          //2018年以后的设备有唯一硬件序号*/DevBufferSerialNumStr = dataArray[7];}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次//此处加入业务对数据库的查、增、删、减操作//008指令返回本次消费成功并播消费金额,006指令返回其他提示信息,正式系统开发时要有重发机制*switch (VoiceCode){case "1":           //提示消费成功并显示消费金额Sendinf = "008," + DevBufferMachinStr + "," + DevBufferCardidStr + ",0," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode;break;default:            //其它提示Sendinf = "006," + DevBufferMachinStr + "," + DevBufferCardidStr + "," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode;break;}Response(Sendinf);break;case "105":                                    //接收到 脱网记账消费记录,消费机开启记账功能,有脱机记账消费记录网络恢复正常自动向电脑发送此信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCardidStr = dataArray[5];         //十位物理卡号DevBufferUseMoneryStr = dataArray[6];      //消费额DevBufferUseTimeStr = dataArray[7];        //消费时间DevBufferStaryStr = dataArray[8];          //消费方式  0扣费 1计次*/DevBufferRecordAddStr = dataArray[9];      //记录地址标识*/DevBufferAllNoStr = dataArray[10];          //总计录数*/if (dataArray.Length > 11){                                          //2018年以后的设备有唯一硬件序号*/DevBufferSerialNumStr = dataArray[11];}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次if (!checkDateTime(DevBufferUseTimeStr)) { DevBufferUseTimeStr = "9999-99-99 99:99:99"; } //如果接收到非法的消费时间,将消费时间改为"9999-99-99 99:99:99"才能清除。//此处加入业务对数据库的查、增、删、减操作if (CheckBox3.Checked)  //清除设备内当前这条已上传的记录,驱动设备继续上传剩下的记录{Sendinf = "011," + DevBufferMachinStr + "," + DevBufferCardidStr + "," + DevBufferUseMoneryStr + "," + DevBufferUseTimeStr + "," + DevBufferRecordAddStr;Response(Sendinf);}break;case "106":                                    //接收到设备的按键信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferInputKeyStr = dataArray[5];       //十位物理卡号if (dataArray.Length > 6){                                           //2018年以后的设备有唯一硬件序号*/DevBufferSerialNumStr = dataArray[6];}Response("001," + DevRecFramesStr);         //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次//此处加入业务对数据库的查、增、删、减操作break;case "108":                                    //接收到设备在取餐模式内的的刷卡信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCardidStr = dataArray[5];         //十位物理卡号if (dataArray.Length > 6){                                          //2018年以后的设备有唯一硬件序号*/DevBufferSerialNumStr = dataArray[6];}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次//此处加入业务对数据库的查、增、删、减操作//008指令返回本次消费成功并播消费金额,006指令返回其他提示信息,正式系统开发时要有重发机制*switch (VoiceCode){case "1":           //提示消费成功并显示消费金额Sendinf = "008," + DevBufferMachinStr + "," + DevBufferCardidStr + ",0," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode;break;default:            //其它提示Sendinf = "006," + DevBufferMachinStr + "," + DevBufferCardidStr + "," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode;break;}Response(Sendinf);break;case "109":                                    //设备收到电脑发送的显示声音指令 后 反发的确认指令,可根据这个返回来判断设备有没有收到电脑发出的指令,如没有收到电脑可再次发送DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCommandStr = dataArray[5];        //指令号//此处根据接收到的设备信息,表明设备已接收到发送的信息,取消该设备的重发机制break;case "115":                                    //传送注册卡号到顺序区的反馈 DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferFunctionStr1 = dataArray[5];      //反馈标识Timer2.Enabled = false;  //超时提示清除if (sendcode == "015")   //只传一帧数据{if (DevBufferFunctionStr1 == "0" || DevBufferFunctionStr1 == "1"){f3.TextBox2.Text = "卡号为:" + f3.TextBox1.Text + "的注册卡传送到IP地址为:" + DevBufferIpAddrStr + " 设备的顺序区成功!";}else { f3.TextBox2.Text = "卡号为:" + f3.TextBox1.Text + "的注册卡传送到IP地址为:" + DevBufferIpAddrStr + " 设备的顺序区失败!"; }}else{if (DevBufferFunctionStr1 == "0" || DevBufferFunctionStr1 == "1" || DevBufferFunctionStr1 == "2" || DevBufferFunctionStr1 == "3"){SendPoin++;               //发送指针加1SendAgain = 0;            //重发次数清0f3.Pb1.Value++;}else{SendAgain++;              //重发次数+1if (SendAgain == 3) { SendCount = false; } //重发次数超过3次,退出}if (SendPoin <= SendPoinMax && SendCount){Timer2.Enabled = true;Sendinf = SendBufStr[SendPoin];Response(Sendinf);    //继续发送}else{f3.Button8.Text = "将注册卡号传送到设备的顺序区";f3.Button9.Enabled = true;if (SendPoin >= SendPoinMax){f3.TextBox2.Text = "注册卡号已成功地传送到IP地址为:" + DevBufferIpAddrStr + " 设备的顺序区!";f3.Refresh();}else{f3.TextBox2.Text = "传送注册卡号到IP地址为:" + DevBufferIpAddrStr + " 设备时中途退出!请重新传送!";}}}break;case "116":                                    //传送注册卡号到随机区的反馈 DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferFunctionStr1 = dataArray[5];      //反馈标识Timer2.Enabled = false;  //超时提示清除if (sendcode == "016"){if (DevBufferFunctionStr1 == "0" || DevBufferFunctionStr1 == "1"){f3.TextBox2.Text = "卡号为:" + f3.TextBox1.Text + "的注册卡传送到IP地址为:" + DevBufferIpAddrStr + " 设备的随机区成功!";}else { f3.TextBox2.Text = "卡号为:" + f3.TextBox1.Text + "的注册卡传送到IP地址为:" + DevBufferIpAddrStr + " 设备的随机区失败!"; }}else{if (DevBufferFunctionStr1 == "0" || DevBufferFunctionStr1 == "1" || DevBufferFunctionStr1 == "2" || DevBufferFunctionStr1 == "3"){SendPoin++;           //发送指针加1SendAgain = 0;        //重发次数清0f3.Pb1.Value++;}else{SendAgain++;         //重发次数+1if (SendAgain == 3) { SendCount = false; }   //重发次数超过3次,退出}if (SendPoin <= SendPoinMax && SendCount){Timer2.Enabled = true;Sendinf = SendBufStr[SendPoin];Response(Sendinf);}else{f3.Button9.Text = "将注册卡号传送到设备的随机区";f3.Button8.Enabled = true;if (SendPoin >= SendPoinMax){f3.TextBox2.Text = "注册卡号已成功地传送到IP地址为:" + DevBufferIpAddrStr + " 设备的随机区!";}else{f3.TextBox2.Text = "传送注册卡号到IP地址为:" + DevBufferIpAddrStr + " 设备时中途退出!请重新传送!";}}}break;case "117":                                    //删除设备内指定注册卡号的反馈 DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferFunctionStr1 = dataArray[5];      //反馈标识if (DevBufferFunctionStr1 == "0"){f3.TextBox2.Text = "删除IP地址为:" + DevBufferIpAddrStr + " 设备内卡号为:" + f3.TextBox1.Text + " 的注册卡成功!";}else { f3.TextBox2.Text = "删除IP地址为:" + DevBufferIpAddrStr + " 设备内卡号为:" + f3.TextBox1.Text + " 的注册卡失败!"; }break;case "118":                                    //清除顺序区注册号的反馈 DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferFunctionStr1 = dataArray[5];      //反馈标识if (DevBufferFunctionStr1 == "0"){f3.TextBox2.Text = "清除IP地址为:" + DevBufferIpAddrStr + " 设备内顺序区的注册卡成功!";}else { f3.TextBox2.Text = "清除IP地址为:" + DevBufferIpAddrStr + " 设备内顺序区的注册卡失败!"; }break;case "119":                                    //清除随机区注册号的反馈 DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferFunctionStr1 = dataArray[5];      //反馈标识if (DevBufferFunctionStr1 == "0"){f3.TextBox2.Text = "清除IP地址为:" + DevBufferIpAddrStr + " 设备内随机区的注册卡成功!";}else { f3.TextBox2.Text = "清除IP地址为:" + DevBufferIpAddrStr + " 设备内随机区的注册卡失败!"; }break;case "120":                                    //查询指定的注册卡号是否存在的反馈DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferFunctionStr1 = dataArray[5];      //反馈标识if (DevBufferFunctionStr1 == "0"){f3.TextBox2.Text = "IP地址为:" + DevBufferIpAddrStr + " 设备内存在卡号为:" + f3.TextBox1.Text + " 的注册卡!";}else { f3.TextBox2.Text = "IP地址为:" + DevBufferIpAddrStr + " 设备内不存在卡号为:" + f3.TextBox1.Text + " 的注册卡!"; }break;case "121":                                    //读设备内注册卡总数的反馈DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferFunctionStr1 = dataArray[5];      //反馈标识1DevBufferFunctionStr2 = dataArray[6];      //反馈标识2f3.TextBox2.Text = "IP地址为:" + DevBufferIpAddrStr + " 设备,顺序区内的注册卡数为:" + DevBufferFunctionStr1 + ",随机区内的注册卡数为:" + DevBufferFunctionStr2;break;case "125":                                    //接收到直接扫码信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCommandStr= dataArray[5];         //二维码格式标识DevBufferQrcodeInfStr = "";DevBufferSerialNumStr = "";if (dataArray.Length > 6){                                          //防止二维码信息中有分隔符,int i = 6;while (i < dataArray.Length-1){DevBufferQrcodeInfStr = DevBufferQrcodeInfStr + dataArray[i];i++;}DevBufferSerialNumStr = dataArray[dataArray.Length - 1];}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次Sendinf = "009," + DevBufferMachinStr + ",扫码信息:" + DevBufferQrcodeInfStr + "\\n,"+ NumericUpDown2.Value.ToString()+",1,0";Response(Sendinf);break;case "126":                                    //返回无按键实时考勤门禁机  写参数指令反馈DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferFunctionStr1 = dataArray[5];      //返回值if (sendcode == "026008"){switch (DevBufferFunctionStr1){case "0":f5.ListBox1.Items.Add("IP地址为:" + DevBufferIpAddrStr + "的设备,WIFI热点参数传送成功!30秒后可查询WIFI连接状态。");break;case "1":f5.ListBox1.Items.Add("IP地址为:" + DevBufferIpAddrStr + "的设备,广播式发送成功!");break;case "2":f5.ListBox1.Items.Add("IP地址为:" + DevBufferIpAddrStr + "的设备,无线通讯失败!");break;case "4":f5.ListBox1.Items.Add("IP地址为:" + DevBufferIpAddrStr + "的设备,参数设置指令的数据错误!");break;case "5":f5.ListBox1.Items.Add("IP地址为:" + DevBufferIpAddrStr + "的设备,必须按主板上的RST键3秒,将密码清空后才能再更改通讯密码!");break;}}break;case "127":                                    //返回无按键实时考勤门禁机  读参数指令反馈DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferFunctionStr1 = dataArray[5];      //返回值switch (DevBufferFunctionStr1){case "0":for (int i = 6; i < dataArray.Length; i++){infparsing(dataArray[i]);}break;case "1":f5.ListBox1.Items.Add("不能以广播式发送!");break;case "2":f5.ListBox1.Items.Add("无线通讯失败!");break;default:if (DevBufferFunctionStr1.Substring(0, 2) == "8="){DevBufferFunctionStr1 = DevBufferFunctionStr1.Substring(2, DevBufferFunctionStr1.Length  - 2);string[] wifiinf = DevBufferFunctionStr1.Split(new char[2] { '&', '&' });for(int i=0;i<wifiinf.Length;i++ ){switch (i){case 0:f5.ListBox1.Items.Add("WIFI热点名称    :" + wifiinf[i]);break;case 1:switch (wifiinf[i]){case "0":f5.ListBox1.Items.Add("数据传送方式    :网线和WIFI都有效时,刷卡数据以网线发送");break;case "1":f5.ListBox1.Items.Add("数据传送方式    :网线和WIFI都有效时, 刷卡数据以WIFI发送");break;case "2":f5.ListBox1.Items.Add("数据传送方式    :网线和WIFI同时发送刷卡数据");break;case "3":f5.ListBox1.Items.Add("数据传送方式    :刷卡数据只以网络发送");break;case "4":f5.ListBox1.Items.Add("数据传送方式    :刷卡数据只以WIFI发送");break;}                                            break;case 2:if(wifiinf[i] == "1") { f5.ListBox1.Items.Add("WIFI的IP获取方式:DHCP自动获取") ;}else{f5.ListBox1.Items.Add("WIFI的IP获取方式:绑定静态ip" );}break;case 3:f5.ListBox1.Items.Add("WIFI的IP地址    :"+ wifiinf[i]);break;case 4:f5.ListBox1.Items.Add("WIFI的掩码      :" + wifiinf[i]);break;case 5:f5.ListBox1.Items.Add("WIFI的MAC       :" + wifiinf[i]);break;case 6:f5.ListBox1.Items.Add("WIFI的网关      :" + wifiinf[i]);break;case 7:f5.ListBox1.Items.Add("WIFI网关MAC     :" + wifiinf[i]);break;case 8:f5.ListBox1.Items.Add("设备的WIFI名称  :" + wifiinf[i]);break;case 9:if (wifiinf[i] == "1"){f5.ListBox1.Items.Add("设备WIFI连接状态:连接失败");}else { f5.ListBox1.Items.Add("设备WIFI连接状态:连接成功"); }break;}}}break;}break;case "128":                                    //接收到消费金额及扫码信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCardidStr = dataArray[5];         //口令DevBufferUseMoneryStr =  dataArray[6];     //消费额DevBufferUseTimeStr = dataArray[7] ;       //消费时间DevBufferQrcodeInfStr = "";DevBufferSerialNumStr = "";if (dataArray.Length > 9){                                          //防止二维码信息中有分隔符,int i = 9;while (i < dataArray.Length - 1){DevBufferQrcodeInfStr = DevBufferQrcodeInfStr + dataArray[i];i++;}DevBufferSerialNumStr = dataArray[dataArray.Length - 1];}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次//此处加入业务对数据库的查、增、删、减操作Sendinf = "008," + DevBufferMachinStr + "," + DevBufferCardidStr + "," + DevBufferUseMoneryStr + ",正在进行扫码支付..{请不要按动键盘!\\n}," + NumericUpDown2.Value.ToString() + ",0,1";Response(Sendinf);break;case "150":                                    //接收到实时考勤门禁机刷卡数据DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCardidStr = dataArray[5];         //十位物理卡号DevBufferReaderStr= dataArray[6];          //读头号DevBufferDoorNoStr = dataArray[7];         //门或继电器号*/DevBufferDelayStr = dataArray[8];          //门磁未关秒数,0表示已关*/DevBufferPasswPropStr = dataArray[9];      //密码属性(0密码无效,1刷卡后按密码,2补签密码,3开门密码,4防迫胁密码)*/DevBufferPassWStr = dataArray[10];         //密码(最多8位数字)*/DevBufferUseTimeStr = dataArray[11];       //刷卡时间                        if(dataArray.Length > 12){DevBufferSerialNumStr = dataArray[12];  //2018年以后的设备有唯一硬件序号}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次//此处加入业务对数据库的查、增、删、减操作//用050指令返回开门成功,051指令返回开门失败,正式系统开发时要有重发机制switch(  VoiceCode){case "0":case "1":case "2":case "3":case "4":case "5":case "6":case "7":case "8":case "9":case "10":case "11":case "12":case "13":case "14":case "15":  //提示警告不开门Sendinf = "051," + DevBufferMachinStr + "," + DevBufferCardidStr + "," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode;   break;default :   //显示并开门Sendinf = "050," + DevBufferMachinStr + "," + DevBufferCardidStr + "," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode + "," + DevBufferReaderStr + "," + DevBufferDoorNoStr + "," + NumericUpDown1.Value.ToString() + "," + NumericUpDown2.Value.ToString(); break;}Response(Sendinf);break;case "151":                                    //接收到实时考勤门禁机按钮开门申请信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferInputKeyStr = dataArray[5];       //按钮号DevBufferReaderStr = dataArray[6];         //对应的门或继电器号DevBufferDelayStr = dataArray[7];          //门磁未关秒数(0门已关)DevBufferUseTimeStr = dataArray[8];        //按键时间                        if (dataArray.Length > 9){DevBufferSerialNumStr = dataArray[9];  //2018年以后的设备有唯一硬件序号}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次//此处加入业务对数据库的查、增、删、减操作//用050指令返回开门成功,051指令返回开门失败,正式系统开发时要有重发机制switch (VoiceCode){case "0":case "1":case "2":case "3":case "4":case "5":case "6":case "7":case "8":case "9":case "10":case "11":case "12":case "13":case "14":case "15":  //提示警告不开门Sendinf = "051," + DevBufferMachinStr + "," + DevBufferInputKeyStr + "," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode;break;default:   //显示并开门Sendinf = "050," + DevBufferMachinStr + "," + DevBufferInputKeyStr + "," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode + "," + DevBufferReaderStr + "," +  NumericUpDown1.Value.ToString() + "," + NumericUpDown2.Value.ToString();break;}Response(Sendinf);break;case "152":                                    //接收到实时考勤门禁机门磁报警信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferInputKeyStr = dataArray[5];       //门磁号DevBufferReaderStr = dataArray[6];         //对应的门或继电器号DevBufferDelayStr = dataArray[7];          //门磁未关秒数(0门已关)DevBufferUseTimeStr = dataArray[8];        //设备时间                        if (dataArray.Length > 9){DevBufferSerialNumStr = dataArray[9];  //2018年以后的设备有唯一硬件序号}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次break;case "153":                                    //接收到实时考勤门禁机查询设备状态的053指令反馈DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferInputKeyStr = dataArray[5];       //门及继电器号DevBufferReaderStr = dataArray[6];         //继电器状态DevBufferDelayStr = dataArray[7];          //门磁未关秒数(0门已关)DevBufferStateStr = dataArray[8];          //门磁报警状态                        if (dataArray.Length > 9){DevBufferSerialNumStr = dataArray[9];  //2018年以后的设备有唯一硬件序号}Response("001," + DevRecFramesStr);       //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次f6.TextBox3.Text = "继电器号:" + DevBufferInputKeyStr + ",继电器状态:" + DevBufferReaderStr + ",门磁未关秒数:" + DevBufferDelayStr + ",门磁报警状态:" + DevBufferStateStr;break;case "154":                                    //接收到实时考勤门禁机卡离开感应区DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCardidStr = dataArray[5];         //十位物理卡号DevBufferSerialNumStr = dataArray[6];      //设备有唯一硬件序号break;case "155":                                    //接收到实时考勤门禁机脱网记录DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferCardidStr = dataArray[5];         //十位物理卡号DevBufferReaderStr = dataArray[6];         //读头号DevBufferDoorNoStr = dataArray[7];         //门或继电器号*/DevBufferPasswPropStr = dataArray[8];      //密码属性(0密码无效,1刷卡后按密码,2补签密码,3开门密码,4防迫胁密码)*/DevBufferUseTimeStr = dataArray[9];        //刷卡时间    DevBufferStaryStr = dataArray[10];         //消费方式  0扣费 1计次*/DevBufferRecordAddStr = dataArray[11];     //记录地址标识*/DevBufferAllNoStr = dataArray[12];         //总计录数*/DevBufferSerialNumStr = "";if (dataArray.Length > 12){DevBufferSerialNumStr = dataArray[13];  //2018年以后的设备有唯一硬件序号}Response("001," + DevRecFramesStr);         //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次if (!checkDateTime(DevBufferUseTimeStr)) { DevBufferUseTimeStr = "9999-99-99 99:99:99"; } //如果接收到非法的消费时间,将消费时间改为"9999-99-99 99:99:99"才能清除。//此处加入这里对脱网记录进行处理,对数据库的查、增、删、减操作if (CheckBox3.Checked)  //清除设备内当前这条已上传的记录,驱动设备继续上传剩下的记录{Sendinf = "055," + DevBufferMachinStr + "," + DevBufferCardidStr + ","  + DevBufferUseTimeStr + "," + DevBufferRecordAddStr;Response(Sendinf);}break;case "158":                                    //接收到实时考勤门禁机远程开门058指令的反馈DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferStaryStr = dataArray[5];          //0开门成功,1开门密码认证失败,2开门密码认证失败超过6次,需等待一段时间后再能再次接收058指令(防暴力破解),3 不允许此时间段开门DevBufferRandomCode = dataArray[6];        //动态随机码(8位十六进制)switch (DevBufferStaryStr){case "0":f6.TextBox3.Text = "IP:" + DevBufferIpAddrStr + " 开门成功";f6.TextBox2.Text = DevBufferRandomCode;break;case "1":f6.TextBox3.Text = "IP:" + DevBufferIpAddrStr + " 开门密码认证失败!";f6.TextBox2.Text = DevBufferRandomCode;break;case "2":f6.TextBox3.Text = "IP:" + DevBufferIpAddrStr + " 开门密码认证失败超过6次,需等待一段时间后再能再次接收058指令(防暴力破解)";f6.TextBox2.Text = DevBufferRandomCode;break;case "3":f6.TextBox3.Text = "IP:" + DevBufferIpAddrStr + " 不允许此时间段开门";f6.TextBox2.Text = DevBufferRandomCode;break;}break;case "159":                                    //接收到实时考勤门禁机心跳信息DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferQrcodeInfStr = dataArray[5];      //信息类型DevBufferFunctionStr1 = dataArray[6];      //继电器状态(bit0为第1门bit1为第2门)DevBufferFunctionStr2 = dataArray[7];      //消防输入状态DevBufferRandomCode = dataArray[8];        //&动态随机码(8位十六进制)DevBufferDatetimeStr = dataArray[9];       //日期时间DevBufferSerialNumStr = dataArray[10];     //设备硬件号try{f6.TextBox2.Text = DevBufferRandomCode;}catch { }break;case "170":                                    //接收门禁外接双USB扫描枪模块DevRecFramesStr = dataArray[1];            //包序列号DevBufferIpAddrStr = dataArray[2];         //终端IPDevBufferRemoteAddrStr = dataArray[3];     //远程电脑指机IPDevBufferMachinStr = dataArray[4];         //机号DevBufferScanStr = dataArray[5];           //扫码信息DevBufferReaderStr= dataArray[6];          //对应门的扫描枪号DevBufferDoorNoStr = dataArray[7];         //门或继电器号*/DevBufferDelayStr = dataArray[8];          //门磁未关秒数,0表示已关*/DevBufferUseTimeStr = dataArray[9];        //扫码时间                        DevBufferSerialNumStr = dataArray[10];     //设备有唯一硬件序号Response("001," + DevRecFramesStr);         //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次switch(  VoiceCode){case "0":case "1":case "2":case "3":case "4":case "5":case "6":case "7":case "8":case "9":case "10":case "11":case "12":case "13":case "14":case "15":  //提示警告不开门Sendinf = "051," + DevBufferMachinStr + "," + DevBufferReaderStr + "," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode;   break;default :   //显示并开门Sendinf = "050," + DevBufferMachinStr + ",0," + TextBox5.Text.Trim() + "," + NumericUpDown2.Value.ToString() + "," + BeepCode + "," + VoiceCode + "," + DevBufferReaderStr + "," + DevBufferDoorNoStr + "," + NumericUpDown1.Value.ToString() + "," + NumericUpDown2.Value.ToString(); break;}Response(Sendinf);break;case "198":                                    //接收到消费取消指令DevRecFramesStr = dataArray[1];            //包序列号DevBufferRecordAddStr = dataArray[2];      //消费流水号Response("001," + DevRecFramesStr);        //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次break;case "199":                                    //消费金额发起指令DevRecFramesStr = dataArray[1];            //包序列号DevBufferRecordAddStr = dataArray[2];      //消费流水号DevBufferMachinStr = dataArray[3];         //机号DevBufferUseMoneryStr = dataArray[4];      //消费额Response("001," + DevRecFramesStr);        //向设备回应001+包序列号,表示已收到信息,否则设备会连续发三次//这里执行对消费机发送消费结果的显示及声音//消费结果成功0,失败1                                       余额,卡号Sendinf = "099," + DevRecFramesStr + "," + DevBufferRecordAddStr + ",0," + DevBufferMachinStr + "," + DevBufferUseMoneryStr + ",888.8,1234567890";Response(Sendinf);break;}}private void Form1_Load(object sender, EventArgs e){ComboBox2.SelectedIndex = 0;ComboBox3.SelectedIndex = 1;ComboBox4.SelectedIndex = 16;ComboBox5.SelectedIndex = 1;ready = false;GetIp();StartListener();}private void GetIp(){ArrayList AllIp = new ArrayList();string name = Dns.GetHostName();IPAddress[] ipadrlist = Dns.GetHostAddresses(name);foreach (IPAddress ipa in ipadrlist){if (ipa.AddressFamily == AddressFamily.InterNetwork)localIp = ipa.ToString();if (checkip(localIp)){AllIp.Add(localIp);ComboBox1.Items.Add(localIp);}}if (ComboBox1.Items.Count > 0){ComboBox1.SelectedIndex = 0;localIp = ComboBox1.Text; }else {MessageBox.Show("未能查找到本台电脑安装的网卡,暂不能启动本软件。", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);System.Environment.Exit(0);              //这是最彻底的退出方式,不管什么线程都被强制退出,把程序结束的很干净。}}public static bool checkip(string ipstr)   //判断IP是否合法{IPAddress ip;if (IPAddress.TryParse(ipstr, out ip)){ return true; }else { return false; }}private void StartListener(){IPEndPoint LocalPoint;PortNumber = Convert.ToInt32(TextBox6.Text) ;while (!ready){try{LocalPoint = new IPEndPoint(IPAddress.Parse(localIp), PortNumber);ListenerSock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);ListenerSock.Bind(LocalPoint);ListenerThre = new Thread(new ThreadStart(ThrListener));ListenerThre.Start();ready = true;}catch {ListenerSock.Close();ready = false;MessageBox.Show("有其它应用程序占用了 " + PortNumber.ToString() + " ,请检查并关闭此应用后再打开本程序", "警告", MessageBoxButtons.OK, MessageBoxIcon.Error);System.Environment.Exit(0);                      //这是最彻底的退出方式,不管什么线程都被强制退出,把程序结束的很干净。}}}public  void ThrListener(){while (ready){try{EndPoint RemotePoint = new IPEndPoint(System.Net.IPAddress.Any, 0);byte[] bytes = new byte[1024];int NumGet = ListenerSock.ReceiveFrom(bytes, ref RemotePoint);string Msg = Encoding.GetEncoding(936).GetString(bytes, 0, NumGet);//string Msg = Encoding.UTF8.GetString(bytes, 0, NumGet);             //读wifi参数时,要用utf8编码string dispstr = DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss") + (" FromIP:" + Convert.ToString(RemotePoint) + "          ").Substring(0, 30) + "Data:";RemoteIPoint =(IPEndPoint)RemotePoint;                      //获取数据包来源IP及端口,原路回应this.BeginInvoke(new Update1(EditUi), dispstr, Msg);        //显示接收到的数据包,并根据情况回应设备            }catch(Exception ex ){this.BeginInvoke(new Update1(EditUi), DateTime.Now.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss")+" ",ex.Message  );}}}


http://www.ppmy.cn/news/522939.html

相关文章

名企加速撤离中国 中国制造的出路或与互联网联合

中研网讯&#xff1a; 之前的时间里&#xff0c;中国制造事中国走向世界的名片&#xff0c;一度成为中国经济发展引擎巨擘。而如今&#xff0c;中的制造成本不再&#xff0c;一些东南亚国家抢占中国成本优势地位&#xff1b;另一方面&#xff0c;原本在华生产的外资高端制造业回…

七个质量的故事|优思学院

1. 降落伞的故事 第二次世界大战中期&#xff0c;美国生产的降落伞的安全性能不够&#xff0c;虽然在厂商的努力下&#xff0c;合格率已经提升到99.9&#xff05;&#xff0c;但还差一点点。军方要求产品的合格率必须达到100&#xff05;。可是厂商不以为然&#xff0c;他们强…

ESPRIT 2019初学到走心机编程视频教程

ESPRIT 2019初学到五轴走心机编程视频教程 链接&#xff1a;https://pan.baidu.com/s/1hOq2b-yLXAcJcqDPl0r4yw?pwd8rsn 提取码&#xff1a;8rsn ├┈01.ESPRIT2019 软件基础讲解 ├┈02.ESPRIT2019 软件界面设置讲解 ├┈03.ESPRIT2019 无边界几何讲解 ├┈04.ESPRIT2019 …

七夕节送男朋友什么礼物?2022七夕礼物推荐

七夕送男朋友什么礼物合适&#xff0c;七夕是我们国家的情人节&#xff0c;是为了纪念神话中牛郎和织女的完美爱情而设立的。那么在这么个重要的日子&#xff0c;作为女方应该给心爱的男朋友送些什么礼物合适呢&#xff1f;下面小编为您简单介绍了七夕节适合送给男朋友的礼物清…

C#控制条码打印机 纸张大小,间距,绘制内容(所有条码打印机通用)

其他条码知识 请访问&#xff1a;http://www.ybtiaoma.com ,本文仅供参考&#xff0c;请勿转载&#xff0c;谢谢using System; using System.Drawing; using System.Drawing.Printing; using System.Runtime.InteropServices; using System.Windows.Forms;/*2014-3-1* 测试打印…

windows下找不到模块ImportError: DLL load failed while importing cv2: 找不到指定的模块。(解决方案)

windows下一定要手动安装,否则安装的包不合适也是找不到的,一定是-win_amd64.whl ImportError: DLL load failed while importing cv2: 找不到指定的模块。(解决方案) 方法一 1.从清华镜像官网下载opencv-python和opencv-contrib-python安装包,网址为 清华镜像opencv-pyt…

PC市场怎样走出寒冬?

PC市场怎样走出寒冬&#xff1f; 一、2022年下半年至今&#xff0c;全球三大PC巨头累计全球裁员数已经超过万人&#xff0c;对互联网开发行业有哪些影响吗&#xff1f;二、PC市场寒冬的主要原因是什么&#xff1f;三、PC市场的未来将走向何处&#xff1f; 市场调研机构Canalys数…

20220518 十堂课教会管理者打胜仗———管理者如何快速上手,带领团队打胜仗?

十堂课教会管理者打胜仗———管理者如何快速上手&#xff0c;带领团队打胜仗&#xff1f; 企业经常碰到的难题没有训练过的管理者&#xff0c;不知道自己不知道管理者“愚昧之巅”上的典型表现管理是工程技师常胜管理者的能力冰山模型能持续带团队打胜仗的“卓越管理者”“带团…