周六日

  花了一个周六日,用C#重新写了原来VB上的门禁与读写器上位软件。

  C#是强数据类型的,而VB是弱数据类型,以致于我抄VB的程序时不断的Convert。显然这不好,但现在至少保证能运行,以后再维护重构吧,呵呵。

  还有一点,VB里面的integer是16位的整型 = C#里的short

 1        /// <summary>
 2         /// 在线开门
 3         /// </summary>
 4         /// <param name="strDevno"></param>
 5         /// <param name="strCom_IP"></param>
 6         /// <param name="intConnType"></param>
 7         /// <param name="strDoorNo"></param>
 8         /// <returns></returns>
 9         static public bool openDoorOnline(string strDevno, string strCom_IP, string strDoorNo )
10         {
11             int iCheckNum = 0;
12             int i = 0;
13             int icdev = 1;
14             int iGetResult = 1;
15             bool bUdpResult  = false ;
16             byte[] CommandData = new byte[23];
17             byte[] Gdata = new byte[50];
18             string[] strIP;
19 
20 
21             if (strCom_IP.Length > 6)
22                 strIP = strCom_IP.ToString().Split('.');
23             else
24                 strIP = "0.0.0.0".Split('.');
25 
26             CommandData[0] = 126;
27             CommandData[1] = byte.Parse(strIP[0]);
28             CommandData[2] = byte.Parse(strIP[1]);
29             CommandData[3] = byte.Parse(strIP[2]);
30             CommandData[4] = byte.Parse(strIP[3]);
31             CommandData[5] = Convert.ToByte(int.Parse(strDevno) % 256);
32             CommandData[6] = Convert.ToByte(int.Parse(strDevno) / 256);
33             CommandData[7] = 157;
34             CommandData[8] = 4;
35             CommandData[9] = 0;
36             CommandData[10] = byte.Parse(strDoorNo);
37             for (i = 11; i <= 13; i++)
38             {
39                 CommandData[i] = 0;
40             }
41             for (i = 5; i <= 13; i++)
42             {
43                 iCheckNum = iCheckNum + CommandData[i];
44             }
45             iCheckNum = iCheckNum % 65536;
46             CommandData[14] = Convert.ToByte(iCheckNum % 256);
47             CommandData[15] = Convert.ToByte(iCheckNum / 256);
48 
49             if (strCom_IP.Length < 6)
50             {
51                 icdev = com_init(strCom_IP, 38400);
52                 if (icdev > 0)
53                 {
54                     iGetResult = getDataUIM(icdev, 16, CommandData, 16, Gdata, 1000);
55                 }
56                 else
57                 {
58                     iGetResult = 1;
59                 }
60                 com_exit(icdev);
61 
62                 return Convert.ToBoolean(iGetResult);
63             }
64             else
65             {
66                 bUdpResult = UdpComData(16, CommandData, 16, Gdata, strCom_IP, 60000, 1000);
67                 return bUdpResult;
68             }
69 
70         }
posted @ 2012-08-27 12:43  秋官  阅读(269)  评论(0编辑  收藏  举报