Exemplo n.º 1
0
        void readWork_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            DataReceivedArgs i = new DataReceivedArgs(inPacket);

            if (DataReceivedHandle != null)
            {
                DataReceivedHandle(this, i);
            }
        }
Exemplo n.º 2
0
        void OnDataRecieved(object sender, DataReceivedArgs e)
        {
            //uint t = e.Packet[1];
            //t = t * 256 + e.Packet[2];
            //t = t * 256 + e.Packet[3];
            //t = t * 256 + e.Packet[4];
            //textBox1.Text = textBox1.Text + e.Packet[0] + e.Packet[1] + e.Packet[2] + e.Packet[3] + e.Packet[4] + e.Packet[5] + e.Packet[6] + "\r\n\r\n";

            byte[] rbuf = new byte[100];
            int    i, num;

            //textBox1.Text += Encoding.ASCII.GetString(e.Packet.Length);
            //textBox1.Text += e.Packet.Length.ToString();
            for (i = 0; i < e.Packet.Length; i++)
            {
                rbuf[i] = e.Packet[i];
            }
            //rbuf[i] = (byte)(i + 97);
            //rbuf[0] = 97;
            //e.Packet[0] = 33;
            e.Packet[0] = 32;

            string str = BitConverter.ToString(e.Packet);
            //textBox1.Text  = str;


            //string str_id = e.Packet[51].ToString("D3") + " " +
            //                e.Packet[52].ToString("D3") + " " +
            //                e.Packet[53].ToString("D3") + " " +
            //                e.Packet[54].ToString("D3") + " " +
            //                e.Packet[55].ToString("D3");

            string str_id = e.Packet[51].ToString("X2") + " " +
                            e.Packet[52].ToString("X2") + " " +
                            e.Packet[53].ToString("X2") + " " +
                            e.Packet[54].ToString("X2");

            //e.Packet[55].ToString("X");

            if (e.Packet[1] == 0xBE)        //  写卡回应
            {
                //BaseInfo bf = new BaseInfo();
                cIC_Card_Data ic_data = new cIC_Card_Data();
                ic_data.IC_ID = str_id;
                //ic_data.IC_Fun = "";
                //ic_data.Floor_Data = "";
                //ic_data.IC_FunA = "";
                ////ic_data.Add_ID = "";

                if (tbxIcNum.Text != "")
                {
                    if (!int.TryParse((tbxIcNum.Text), out num))
                    {
                        MessageBox.Show("请输入卡号!");
                    }
                    else
                    {
                        ic_data.ic_num = num;
                    }
                }

                ic_data.持卡人  = tbxName.Text;
                ic_data.电梯ID = tbxCarNum.Text;


                for (i = 0; i < 16; i++)
                {
                    ic_data.Block_8[i]  = e.Packet[3 + i];
                    ic_data.Block_9[i]  = e.Packet[19 + i];
                    ic_data.Block_10[i] = e.Packet[35 + i];
                }

                if (bf.Find_IcData(ic_data) == 1)
                {
                    textBox1.Text += "\r\n access_db have data\r\n!";
                    if (bf.Updata_IcData(ic_data) == 1)
                    {
                        textBox1.Text += "\r\n access_db have up data ok\r\n!";
                    }
                    else
                    {
                        textBox1.Text += "\r\n access_db updata error\r\n!";
                    }
                }
                else
                {
                    if (bf.Add_IcData(ic_data) == 1)
                    {
                        textBox1.Text += "\r\n access_db add data ok\r\n!";
                    }
                    else
                    {
                        textBox1.Text += "\r\n access_db add data error\r\n!";
                    }
                    //bf.Add_IcData(ic_data);
                }

                //if (bf.Add_IcData(ic_data) == 1)
                //{
                //    //MessageBox.Show("add access_db ok!");
                //    textBox1.Text += "add access_db ok!";
                //}
                //else
                //    MessageBox.Show("add access_db error!");
            }
            else if (e.Packet[1] == 0xB5)
            {
                //BaseInfo bf = new BaseInfo();
                cIC_Card_Data ic_data = new cIC_Card_Data();
                ic_data.IC_ID = str_id;
                ic_data.电梯ID  = str_id;
                //ic_data.IC_Fun = "";
                //ic_data.Floor_Data = "";
                //ic_data.IC_FunA = "";
                ////ic_data.Add_ID = "";

                if (tbxIcNum.Text != "")
                {
                    if (!int.TryParse((tbxIcNum.Text), out num))
                    {
                        MessageBox.Show("请输入卡号!");
                    }
                    else
                    {
                        ic_data.ic_num = num;
                    }
                }

                ic_data.持卡人  = tbxName.Text;
                ic_data.电梯ID = tbxCarNum.Text;

                for (i = 0; i < 16; i++)
                {
                    ic_data.Block_8[i]  = e.Packet[3 + i];
                    ic_data.Block_9[i]  = e.Packet[19 + i];
                    ic_data.Block_10[i] = e.Packet[35 + i];
                }

                if (bf.Find_IcData(ic_data) == 1)
                {
                    textBox1.Text += "\r\n access_db have data\r\n!";
                    if (bf.Updata_IcData(ic_data) == 1)
                    {
                        textBox1.Text += "\r\n access_db have up data ok\r\n!";
                    }
                    else
                    {
                        textBox1.Text += "\r\n access_db updata error\r\n!";
                    }
                }
                else
                {
                    bf.Add_IcData(ic_data);
                }
            }
            else if (e.Packet[1] == 0xBC)   //	采集 主板 ID
            {
                //e.Packet[3 + 0];
                FrmMBoardID frm_Mboard = new FrmMBoardID();
                //frm_Mboard.MBoard_ID = e.Packet[3 + 0].ToString("X2");
                //frm_Mboard.MBoard_ID = str.Substring(2,12);

                frm_Mboard.MBoard_ID = BitConverter.ToString(e.Packet, 3, 12);
                frm_Mboard.Show();
            }

            //if ((e.Packet[1] % 2) == 1)
            //    MessageBox.Show("卡号:" + str_id + "\r\n\r\n" +
            //                    "还剩次数:" + (e.Packet[7] + e.Packet[8] * 256).ToString() + "\r\n\r\n" +
            //                    "已刷卡的次数:" + (e.Packet[31] + e.Packet[32] * 256).ToString());
            //else
            //    MessageBox.Show("卡号:" + str_id + "\r\n\r\n" +
            //                    "刷卡无次数限制!" + "\r\n\r\n" +
            //                    "已刷卡的次数:" + (e.Packet[31] + e.Packet[32] * 256).ToString());

            //}
            //else
            //{
            //    MessageBox.Show("卡号:" + str_id );
            //}
            //textBox1.Text += Encoding.ASCII.GetString(e.Packet)+"\r\n";
            //textBox1.Text += e.Packet[1].ToString("X2") + e.Packet[2].ToString("X2");

            //textBox1.Text += Encoding.Unicode.GetString(e.Packet) + "\r\n";
            //textBox1.Text += Encoding.UTF7.GetString(e.Packet) + "\r\n";
            //textBox1.Text += Encoding.UTF8.GetString(e.Packet) + "\r\n";
            //textBox1.Text += Encoding.UTF32.GetString(e.Packet) + "\r\n";
            //textBox1.Text += Encoding.BigEndianUnicode.GetString(e.Packet) + "\r\n";

            //textBox1.Text += Encoding.Default.GetString(e.Packet) + "\r\n";
        }