예제 #1
0
        public bool UpdateDevice(byte[] pBuf)
        {
            InteractionData tx = new InteractionData();

            tx.buff[0] = 0x03;
            tx.buff[1] = 0x55;  //主机-->设备
            InteractionData rx = DeviceInteraction(tx);

            if (rx == null || rx.CheckDataList() == false)
            {
                return(false);
            }
            HexID[0] = rx.buff[0x10];
            HexID[1] = rx.buff[0x11];
            HexID[2] = rx.buff[0x12];
            HexID[3] = rx.buff[0x13];

            tx = new InteractionData();
            rx = DeviceInteraction(tx);
            if (rx == null || rx.CheckDataList() == false)
            {
                return(false);
            }
            HexVer[0] = rx.buff[0x10];
            HexVer[1] = rx.buff[0x11];
            return(true);
        }
예제 #2
0
        public HIDResult CANInfoDataStep(int step, out InteractionData rx)
        {
            InteractionData tx = new InteractionData();

            tx.buff[0] = 0x14;
            tx.buff[1] = 0x55;  //主机-->设备
            tx.buff[4] = 0x20;
            for (int i = 0; i < 0x10; i++)
            {
                tx.buff[i + 0x10] = CANInfo_AT[step, i];
            }
            rx = DeviceInteraction(tx);
            if (rx == null)
            {
                return(HIDResult.USBError);
            }
            else if (rx.CheckDataList() == false)
            {
                return(HIDResult.RxError);
            }
            else if (rx.buff[1] == 0x00)
            {
                return(HIDResult.OK);
            }
            else
            {
                return(HIDResult.CANErr);
            }
        }
예제 #3
0
        public HIDResult CANEeprom2Step(int step, out InteractionData rx, out int rxCount)
        {
            InteractionData tx = new InteractionData();

            tx.buff[0] = 0x14;
            tx.buff[1] = 0x55;  //主机-->设备
            tx.buff[4] = 0x20;
            for (int i = 0; i < 0x10; i++)
            {
                tx.buff[i + 0x10] = CANEeprom_b[step % 3, i];
            }
            rxCount = CANEeprom_b[step % 3, 0x0f];
            if (0x01 == (step % 3))
            {
                tx.buff[0x0A + 0x10] = CANEeprom_Cmd00[step / 3];
            }
            rx = DeviceInteraction(tx);
            if (rx == null)
            {
                return(HIDResult.USBError);
            }
            else if (rx.CheckDataList() == false)
            {
                return(HIDResult.RxError);
            }
            else if (rx.buff[1] == 0x00)
            {
                return(HIDResult.OK);
            }
            else
            {
                return(HIDResult.CANErr);
            }
        }
예제 #4
0
        //public byte[] SwVer=new byte[2]{0x20,0x01};
        public bool CheckDevice()
        {
            InteractionData tx = new InteractionData();

            tx.buff[0] = 0x03;
            tx.buff[1] = 0x55;  //主机-->设备
            InteractionData rx = DeviceInteraction(tx);

            if (rx == null || rx.CheckDataList() == false)
            {
                return(false);
            }
            HexID[0] = rx.buff[0x10];
            HexID[1] = rx.buff[0x11];
            HexID[2] = rx.buff[0x12];
            HexID[3] = rx.buff[0x13];
//             if (HexID[0] != 0x01)
//                 return false;
//             if (HexID[0] != 0x04 || HexID[1] != 0x45 || HexID[2] != 0x61 || HexID[3] != 0x67)
//                 return false;
            tx = new InteractionData();
            rx = DeviceInteraction(tx);
            if (rx == null || rx.CheckDataList() == false)
            {
                return(false);
            }
            HexVer[0] = rx.buff[0x10];
            HexVer[1] = rx.buff[0x11];
            return(true);
        }
예제 #5
0
        public HIDResult EZSReadDataStep(int step, EZSMode mode, out InteractionData rx)
        {
            InteractionData tx = new InteractionData();

            tx.buff[0]    = 0x0D;
            tx.buff[1]    = 0x55; //主机-->设备
            tx.buff[0x0A] = 0x02; //cnt
            tx.buff[0x0B] = 0x6F;
//             if (mode == EZSMode.NEC)
//             {
//                 tx.buff[0x0C] = DTnec[step];
//             }
//             else if (mode == EZSMode.MOT)
//             {
//                 tx.buff[0x0C] = DTmot[step];
//             }
            tx.buff[0x0C] = (byte)step;
            byte tmp_cmd = tx.buff[0x0C];


            rx = DeviceInteraction(tx);
            if (rx == null)
            {
                return(HIDResult.USBError);
            }
            else if (rx.CheckDataList() == false)
            {
                return(HIDResult.RxError);
            }
            else if (rx.buff[0x01] == 0x01)
            {
                return(HIDResult.ReadEZSError1);
            }
            else if (rx.buff[0x01] == 0x02)
            {
                return(HIDResult.ReadEZSError2);
            }
            else if (rx.buff[0x0B] != 0x70)
            {
                return(HIDResult.ReadEZSError3);
            }
//             else if (rx.buff[0x0C] != tmp_cmd)
//             {
//                 return HIDResult.ReadEZSError4;
//             }
            else if (rx.buff[1] == 0x00)
            {
                return(HIDResult.OK);
            }
            else
            {
                return(HIDResult.ReadEZSError5);
            }
        }
예제 #6
0
 public InteractionData DeviceInteraction(InteractionData tx, int n)
 {
     try
     {
         //int rxCount = HIDStream.Read(InputReport, 0, m_nInputReportLength);
         if (HIDProcCallback != null)
         {
             HIDProcCallback(-2);
         }
         HIDStream.Write(tx.GetDataList(), 0, m_nOutputReportLength);
         byte[]       InputReport = new byte[m_nInputReportLength];
         IAsyncResult ia          = HIDStream.BeginRead(InputReport, 0, m_nInputReportLength, null, null);
         for (int s = 0; s < n; s++)
         {
             if (ia.AsyncWaitHandle.WaitOne(500, false))
             {
                 if (HIDProcCallback != null)
                 {
                     HIDProcCallback(-1);
                 }
                 InteractionData rx = new InteractionData(InputReport);
                 return(rx);
             }
             else
             {
                 if (HIDProcCallback != null)
                 {
                     HIDProcCallback(s + 1);
                 }
             }
         }
         if (HIDProcCallback != null)
         {
             HIDProcCallback(-1);
         }
         HIDStream.Close();
         HIDStream.Dispose();
         HIDStream = null;
         m_hHandle = CreateFile(hidPath, GENERIC_READ | GENERIC_WRITE, 0, IntPtr.Zero, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, IntPtr.Zero);
         HIDStream = new FileStream(m_hHandle, FileAccess.Read | FileAccess.Write, m_nInputReportLength, true);
         return(null);
     }
     catch (IOException ex)
     {
         // The device was removed!
         throw new HIDDeviceException(ex.Message + ":Device was removed");
     }
 }
예제 #7
0
        public HIDResult CANWrite4Step(int step, out InteractionData rx)
        {
            InteractionData tx = new InteractionData();

            tx.buff[0] = 0x14;
            tx.buff[1] = 0x55;  //主机-->设备
            tx.buff[4] = 0x20;
            for (int i = 0; i < 0x10; i++)
            {
                tx.buff[i + 0x10] = CANwr_d[step % 2, i];
            }
            if (step % 2 == 1)
            {
                for (int i = 0; i < 0x08; i++)
                {
                    tx.buff[i + 0x13] = DTwr[0x08 * DTwrIndex + i];//DATAwr[k][i];
                }
                tx.buff[0x12] = (byte)DTwrIndex;
                DTwrIndex++;
            }
            rx = DeviceInteraction(tx);
            if (rx == null)
            {
                return(HIDResult.USBError);
            }
            else if (rx.CheckDataList() == false)
            {
                return(HIDResult.RxError);
            }
            else if (rx.buff[1] == 0x00)
            {
                return(HIDResult.OK);
            }
            else if (rx.buff[1] == 0x03)
            {
                return(HIDResult.CANWriteWait);
            }
            else
            {
                return(HIDResult.CANErr);
            }
        }
예제 #8
0
        public bool Check_mima()
        {
            InteractionData tx = new InteractionData();

            tx.buff[0] = 0x03;
            tx.buff[1] = 0x55;  //主机-->设备
            InteractionData rx = DeviceInteraction(tx);

            if (rx == null || rx.CheckDataList() == false)
            {
                return(false);
            }
            KEY[0] = 0x02;
            KEY[1] = 0x58;
            KEY[2] = 0xBE;
            KEY[3] = 0x24;
//             KEY[4] = 0x8A;
//             KEY[5] = 0x95;
//             KEY[6] = 0x60;
//             KEY[7] = 0x3D;

            KEY[4] = (byte)(HexID[0] - 0x77);
            KEY[5] = (byte)(HexID[1] - 0x55);
            KEY[6] = (byte)(HexID[2] - 0x33);
            KEY[7] = (byte)(HexID[3] - 0x11);

            HOP[0] = rx.buff[0x14];
            HOP[1] = rx.buff[0x15];
            HOP[2] = rx.buff[0x16];
            HOP[3] = rx.buff[0x17];

            DECRYPT();
            if ((HOP[0x02] == rx.buff[0x18]) && (HOP[3] == rx.buff[0x19]))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #9
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Attention!\r\n After performing the procedure of reading the password key becomes disabled! Need to overwrite it! Continue?", "Waring", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
            {
                return;
            }
            textBox4.Text = "";
            textBox3.Text = "";
            textBox2.Text = "";
            textBox1.Text = "";
            WFGlobal.WaitMS(5);
            button1.Enabled      = false;
            button2.Enabled      = false;
            progressBar1.Visible = true;
            progressBar1.Value   = 0;
            if (HIDDevice.TheHIDDevice.Check_mima() == false)
            {
                MessageBox.Show("Authorization information error!!", "Error");
                progressBar1.Visible = false;
                button1.Enabled      = true;
                button2.Enabled      = true;
                return;
            }
            progressBar1.Value = 33;
            WFGlobal.WaitMS(5);
            toolStripStatusLabel2.Text = "读取中......";
            PSWrd = false;
            InteractionData tx = new InteractionData();

            tx.buff[0] = 0x0c;
            tx.buff[1] = 0x55;  //主机-->设备
            InteractionData rx = HIDDevice.TheHIDDevice.DeviceInteraction(tx);

            if (rx == null)
            {
                toolStripStatusLabel2.Text      = "USB Error!!";
                toolStripStatusLabel2.ForeColor = System.Drawing.Color.Red;
            }
            else if (rx.CheckDataList() == false)
            {
                toolStripStatusLabel2.Text      = "Reciece Error!!";
                toolStripStatusLabel2.ForeColor = System.Drawing.Color.Red;
            }
            else if (rx.buff[1] == 0x03)
            {
                toolStripStatusLabel2.Text      = "Get PSW Error 3 !!";
                toolStripStatusLabel2.ForeColor = System.Drawing.Color.Red;
            }
            else if (rx.buff[1] != 0x00)
            {
                toolStripStatusLabel2.Text      = "Get PSW Error 1 !!";
                toolStripStatusLabel2.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                progressBar1.Value = 66;
                WFGlobal.WaitMS(5);
                tx         = new InteractionData();
                tx.buff[0] = 0x01;
                tx.buff[1] = 0xaa;      //主机<--设备
                tx.buff[4] = 0x20;
                rx         = HIDDevice.TheHIDDevice.DeviceInteraction(tx);
                if (rx == null)
                {
                    toolStripStatusLabel2.Text      = "USB Error!!";
                    toolStripStatusLabel2.ForeColor = System.Drawing.Color.Red;
                }
                else if (rx.CheckDataList() == false)
                {
                    toolStripStatusLabel2.Text      = "Reciece Error!!";
                    toolStripStatusLabel2.ForeColor = System.Drawing.Color.Red;
                }
                else if (rx.buff[1] != 0x01)
                {
                    toolStripStatusLabel2.Text      = "Get PSW Error 2 !!";
                    toolStripStatusLabel2.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    toolStripStatusLabel2.Text = "读取成功!!";

                    toolStripStatusLabel2.ForeColor = System.Drawing.Color.Green;
                    byte[] BufPassWord = new byte[0x18];
                    for (int i = 0; i < 0x18; i++)
                    {
                        BufPassWord[i] = rx.buff[i + 0x10];
                    }
                    for (int i = 0; i < 0x18; i++)
                    {
                        PSWpub[i] = BufPassWord[i];
                    }
                    //
                    //PSW
                    PSWpub[0x00] = BufPassWord[0x07];
                    PSWpub[0x01] = BufPassWord[0x0F];
                    PSWpub[0x02] = BufPassWord[0x00];
                    PSWpub[0x03] = BufPassWord[0x01];
                    PSWpub[0x04] = BufPassWord[0x02];
                    PSWpub[0x05] = BufPassWord[0x03];
                    PSWpub[0x06] = BufPassWord[0x04];
                    PSWpub[0x07] = BufPassWord[0x05];
                    PSWpub[0x08] = BufPassWord[0x06];
                    //SSID
                    PSWpub[0x09] = BufPassWord[0x0B];
                    PSWpub[0x0A] = BufPassWord[0x0C];
                    PSWpub[0x0B] = BufPassWord[0x0D];
                    PSWpub[0x0C] = BufPassWord[0x0E];
                    //HASH
                    PSWpub[0x0D] = BufPassWord[0x0A];
                    PSWpub[0x0E] = BufPassWord[0x09];
                    PSWpub[0x0F] = BufPassWord[0x08];
                    PSWpub[0x10] = BufPassWord[0x17];
                    PSWpub[0x11] = BufPassWord[0x16];
                    PSWpub[0x12] = BufPassWord[0x15];
                    PSWpub[0x13] = BufPassWord[0x14];
                    PSWpub[0x14] = BufPassWord[0x13];
                    //OTHERS
                    PSWpub[0x15] = BufPassWord[0x12];
                    PSWpub[0x16] = BufPassWord[0x11];
                    PSWpub[0x17] = BufPassWord[0x10];

                    textBox4.Text      = WFNetLib.Strings.StringsFunction.byteToHexStr(PSWpub, 0x0d, 8, " "); //HASH
                    textBox3.Text      = WFNetLib.Strings.StringsFunction.byteToHexStr(PSWpub, 0x01, 8, " "); //PSD
                    textBox1.Text      = WFNetLib.Strings.StringsFunction.byteToHexStr(PSWpub, 0x09, 4, " "); //serial
                    textBox2.Text      = (BufPassWord[0x0B] & 0x07).ToString();                               //key
                    PSWrd              = true;
                    progressBar1.Value = 100;
                    MessageBox.Show("Read PSW OK!!");
                }
            }
            progressBar1.Visible = false;
            button1.Enabled      = true;
            button2.Enabled      = true;
        }
예제 #10
0
        private void btnProgram_Click(object sender, EventArgs e)
        {
            if (HIDDevice.TheHIDDevice == null)
            {
                MessageBox.Show("请连接设备");
                return;
            }     
            if (LoadBuf==null)
            {
                toolStripButton1_Click(null, null);
                return;
            }
            try
            {
                this.Enabled = false;                
                toolStripStatusLabel6.Text = "烧写中......";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Green;
                WFGlobal.WaitMS(5);
                if (HIDDevice.TheHIDDevice.Check_mima() == false)
                {
                    MessageBox.Show("Authorization information error!!", "Error");
                    return;
                }
                progressBar1.Visible = true;
                progressBar1.Value = 0;
                InteractionData tx = new InteractionData();
                InteractionData rx;
                tx.buff[0] = 0x01;
                tx.buff[1] = 0x55;	//主机-->设备
                //             tx.buff[8] = HIDDevice.SwVer[1];//L
                //             tx.buff[9] = HIDDevice.SwVer[0];//H
                int k = 0;
                byte Length = 0xA0;
                byte tmpLeng;
                while (Length != 0x00)
                {
                    if (Length >= 0x30)
                    {
                        tmpLeng = 0x30;
                        tx.buff[4] = 0x30;//本次传送数据的长度;
                        Length -= 0x30;
                    }
                    else
                    {
                        tmpLeng = Length;
                        tx.buff[4] = Length;//本次传送数据的长度;
                        Length = 0x00;
                    }

                    for (int i = 0; i < tmpLeng; i++)
                    {
                        tx.buff[i + 0x10] = LoadBuf[k++];
                    }
                    rx = HIDDevice.TheHIDDevice.DeviceInteraction(tx);
                    if (rx == null)
                    {
                        toolStripStatusLabel6.Text = "USB Error!!";
                        toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
                        return;
                    }
                    else if (rx.CheckDataList() == false)
                    {
                        toolStripStatusLabel6.Text = "Reciece Error!!";
                        toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
                        return;
                    }
                    else
                    {
                        tx.buff[5] += tmpLeng;
                        progressBar1.Value += 20;
                        WFGlobal.WaitMS(5);
                    }

                }
                tx = new InteractionData();
                if (radioButton1.Checked)
                    tx.buff[0] = 0x06;
//                 else if (radioButton2.Checked)
//                     tx.buff[0] = 0x07;
                else if (radioButton3.Checked)
                    tx.buff[0] = 0x11;
                else
                {
                    toolStripStatusLabel6.Text = "No Options!!";
                    toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
                    return;
                }
                tx.buff[1] = 0x55;	//主机-->设备
                //             tx.buff[8] = HIDDevice.SwVer[1];//L
                //             tx.buff[9] = HIDDevice.SwVer[0];//H
                rx = HIDDevice.TheHIDDevice.DeviceInteraction(tx);
                if (rx == null)
                {
                    toolStripStatusLabel6.Text = "USB Error!!";
                    toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
                }
                else if (rx.CheckDataList() == false)
                {
                    toolStripStatusLabel6.Text = "Reciece Error!!";
                    toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
                }
                else if (rx.buff[1] != 0)
                {
                    toolStripStatusLabel6.Text = "烧写错误!!";
                    toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
                    progressBar1.Value = 100;
                    MessageBox.Show("Program Error!!");
                }
                else
                {
                    toolStripStatusLabel6.Text = "烧写成功!!";
                    toolStripStatusLabel6.ForeColor = System.Drawing.Color.Green;
                    progressBar1.Value = 100;
                    MessageBox.Show("烧写成功!!");
                }
            }
            finally
            {
                progressBar1.Visible = false;
                this.Enabled = true;  
            }
        }
예제 #11
0
        void Renew()
        {
            if (HIDDevice.TheHIDDevice == null)
            {
                MessageBox.Show("请连接设备");
                return;
            }
            if (MessageBox.Show("是否要擦除?", "注意", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                return;
            this.Enabled = false;
            progressBar1.Visible = true;
            progressBar1.Value = 0;            
            if (HIDDevice.TheHIDDevice.Check_mima() == false)
            {
                MessageBox.Show("Authorization information error!!", "Error");
                this.Enabled = true;
                progressBar1.Visible = false;
                return;
            }
            progressBar1.Value = 50;
            toolStripStatusLabel6.Text = "擦除中......";
            toolStripStatusLabel6.ForeColor = System.Drawing.Color.Green;
            WFGlobal.WaitMS(5); 
            InteractionData tx = new InteractionData();
            if (radioButton1.Checked)
                tx.buff[0] = 0x0A;
//             else if (radioButton2.Checked)
//                 tx.buff[0] = 0x0B;
            else if (radioButton3.Checked)
                tx.buff[0] = 0x12;
            else
            {
                toolStripStatusLabel6.Text = "No Options!!";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
                return;
            }
            tx.buff[1] = 0x55;	//主机-->设备
//             tx.buff[8] = HIDDevice.SwVer[1];//L
//             tx.buff[9] = HIDDevice.SwVer[0];//H
            InteractionData rx = HIDDevice.TheHIDDevice.DeviceInteraction(tx);
            if (rx == null)
            {
                toolStripStatusLabel6.Text = "USB Error!!";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
            }
            else if (rx.CheckDataList() == false)
            {
                toolStripStatusLabel6.Text = "Reciece Error!!";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
            }
            else if (rx.buff[1] != 0)
            {
                toolStripStatusLabel6.Text = "擦除错误!!";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                toolStripStatusLabel6.Text = "擦除成功";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Green;
                progressBar1.Value = 100;
                MessageBox.Show("擦除成功!!");
            }
            this.Enabled = true;
            progressBar1.Visible = false;
        }
예제 #12
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            if (HIDDevice.TheHIDDevice == null)
            {
                MessageBox.Show("请连接设备");
                return;
            }
            textBox4.Text = "";
            textBox5.Text = "";
            textBox6.Text = "";
            textBox7.Text = "";
            textBox9.Text = "";
            textBox10.Text = "";
            textBox11.Text = "";
            if (HIDDevice.TheHIDDevice.Check_mima() == false)
            {
                MessageBox.Show("Authorization information error!!","Error");
                return;
            }
            toolStripStatusLabel6.Text = "读取中......";
            toolStripStatusLabel6.ForeColor = System.Drawing.Color.Green;
            WFGlobal.WaitMS(5);
            InteractionData tx = new InteractionData();
            if (radioButton1.Checked)
                tx.buff[0] = 0x08;
//             else if (radioButton2.Checked)
//                 tx.buff[0] = 0x09;
            else if (radioButton3.Checked)
                tx.buff[0] = 0x10;
            else
            {
                toolStripStatusLabel6.Text = "No Options!!";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
                return;
            }
            tx.buff[1] = 0x55;	//主机-->设备
//             tx.buff[8] = HIDDevice.SwVer[1];//L
//             tx.buff[9] = HIDDevice.SwVer[0];//H
            InteractionData rx = HIDDevice.TheHIDDevice.DeviceInteraction(tx);
            if (rx == null)
            {
                toolStripStatusLabel6.Text = "USB Error!!";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
            }
            else if (rx.CheckDataList() == false)
            {
                toolStripStatusLabel6.Text = "Reciece Error!!";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
            }
            else if (rx.buff[1] != 0)
            {
                toolStripStatusLabel6.Text = "读取错误!!";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                toolStripStatusLabel6.Text = "读取成功";
                toolStripStatusLabel6.ForeColor = System.Drawing.Color.Green;
                if (0x55 == rx.buff[0x10])
                {
                    textBox4.Text = (rx.buff[0x15] & 0x07).ToString();//key
                    //rx.buff[0x15] = (byte)(rx.buff[0x15] & 0xF8);
                    textBox5.Text = WFNetLib.Strings.StringsFunction.byteToHexStr(rx.buff, 0x15, 4, " ");//serial                    
                    byte[] CvtIn = new byte[3];
                    CvtIn[0] = rx.buff[0x14];//0x2F;
                    CvtIn[1] = rx.buff[0x13];//0x1F;
                    CvtIn[2] = rx.buff[0x12];//0x7F;
                    textBox11.Text = WFNetLib.Strings.StringsFunction.byteToHexStr(CvtIn, " ");//counts    
                    int lift = rx.buff[0x14] * 32 * 128 + rx.buff[0x13] * 128 + rx.buff[0x12];
                    textBox7.Text = lift.ToString();
                }
                else
                {
                    textBox5.Text = "";
                    textBox4.Text = "";
                    textBox11.Text = "";
                }
                if (0x55 == rx.buff[0x20])
                {
                    textBox6.Text = WFNetLib.Strings.StringsFunction.byteToHexStr(rx.buff, 0x25, 2, " ");//Status
                    textBox10.Text = rx.buff[0x23].ToString("X2");//Ver.Soft
                    textBox9.Text = WFNetLib.Strings.StringsFunction.byteToHexStr(rx.buff, 0x33, 6, " ");//Remark
                }
                else
                {
                    textBox6.Text = "";
                    textBox10.Text = "";
                    textBox9.Text = "";
                }
            }
        }
예제 #13
0
 public InteractionData DeviceInteraction(InteractionData tx)
 {
     return(DeviceInteraction(tx, 80));
 }
예제 #14
0
        void UpdateDevice(byte[] pBuf)
        {
            if (pBuf.Length != 0x7010)
            {
                if (bMessge)
                {
                    MessageBox.Show("The file for device update is error len!!");
                }
                toolStripStatusLabel3.Text = "The file for device update is error len!!";
                return;
            }
            if (pBuf[0x7000] != HIDDevice.TheHIDDevice.HexID[0] ||
                pBuf[0x7001] != HIDDevice.TheHIDDevice.HexID[1] ||
                pBuf[0x7002] != HIDDevice.TheHIDDevice.HexID[2] ||
                pBuf[0x7003] != HIDDevice.TheHIDDevice.HexID[3])
            {
                if (bMessge)
                {
                    MessageBox.Show("The file does not match with the device!!");
                }
                toolStripStatusLabel3.Text = "The file does not match with the device!!";
                return;
            }
            ushort oldVer = BytesOP.MakeShort(HIDDevice.TheHIDDevice.HexVer[0], HIDDevice.TheHIDDevice.HexVer[1]);
            ushort newVer = BytesOP.MakeShort(pBuf[0x7004], pBuf[0x7005]);

            if (newVer < oldVer)
            {
                if (bMessge)
                {
                    MessageBox.Show("File version below equipment version!!!!!");
                }
                toolStripStatusLabel3.Text = "File version below equipment version!!!!!";
                return;
            }
            //ushort crc = Verify.GetVerify_CRC16(pBuf, 0x700e);yte
            byte[] pDtOut = new byte[2];
            byte   temp, N, Carry;

            pDtOut[0] = 0x00;           //CRC_HI
            pDtOut[1] = 0x00;           //CRC_LO
            for (int i = 0; i < 0x700E; i++)
            {
                temp = pBuf[i];
                for (int j = 0; j < 8; j++)
                {
                    N         = (byte)(0x80 & temp);
                    pDtOut[0] = (byte)(pDtOut[0] ^ N);
                    if ((pDtOut[0] & 0x80) == 0x80)
                    {
                        pDtOut[0] = (byte)(pDtOut[0] ^ 0x08);
                        pDtOut[1] = (byte)(pDtOut[1] ^ 0x10);
                        Carry     = 0x80;
                    }
                    else
                    {
                        Carry = 0x00;
                    }
                    pDtOut[0] = (byte)(pDtOut[0] << 1);
                    if ((pDtOut[1] & 0x80) == 0x80)
                    {
                        pDtOut[0] = (byte)(pDtOut[0] | 0x01);
                    }
                    else
                    {
                        pDtOut[0] = (byte)(pDtOut[0] & 0xFE);
                    }

                    pDtOut[1] = (byte)(pDtOut[1] << 1);
                    if ((Carry & 0x80) == 0x80)
                    {
                        pDtOut[1] = (byte)(pDtOut[1] | 0x01);
                    }
                    else
                    {
                        pDtOut[1] = (byte)(pDtOut[1] & 0xFE);
                    }
                    temp = (byte)(temp << 1);
                }
            }
            ushort crc     = BytesOP.MakeShort(pDtOut[0], pDtOut[1]);
            ushort filecrc = BytesOP.MakeShort(pBuf[0x700e], pBuf[0x700f]);

            if (crc != filecrc)
            {
                if (bMessge)
                {
                    MessageBox.Show("Calibration error file!!!!!");
                }
                toolStripStatusLabel3.Text = "Calibration error file!!!!!";
                return;
            }
            if (HIDDevice.TheHIDDevice.Check_mima() == false)
            {
//                 if (bMessge)
//                 {
//                     MessageBox.Show("Authorization information error!!", "Error");
//                 }
//                 toolStripStatusLabel3.Text = "Authorization information error!!";
//                 return;
            }
            if (bMessge)
            {
                MessageBox.Show("Device will begin to upgrade!!", "Waring", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            this.Enabled         = false;
            progressBar1.Visible = true;
            progressBar1.Value   = 0;
            try
            {
                toolStripStatusLabel3.Text = "Device Updating......";
                WFGlobal.WaitMS(20);
                int             k      = 0;
                int             Length = 0x7000;//
                InteractionData tx     = new InteractionData();
                tx.buff[0] = 0x01;
                tx.buff[1] = 0x55;      //主机-->设备
                tx.buff[4] = 0x20;      //本次传送数据的长度;
                byte            JL = 0;
                InteractionData rx;
                byte            Ads_U = 0x00;
                byte            Ads_H = 0x10;//0x60
                byte            Ads_L = 0x00;
                while (Length != 0x00)
                {
                    Length -= 0x20;
                    if (JL == 0)
                    {
                        tx.buff[5] = 0x00;      //操作的地址,L,送数据时仅用一个地址字节
                    }
                    else
                    {
                        tx.buff[5] = 0x20;      //操作的地址,L,送数据时仅用一个地址字节
                    }

                    for (int i = 0; i < 0x20; i++)
                    {
                        tx.buff[i + 0x10] = pBuf[k++];
                    }
                    rx = HIDDevice.TheHIDDevice.DeviceInteraction(tx);
                    if (rx == null)
                    {
                        toolStripStatusLabel3.Text = "USB Error!!";
                        MessageBox.Show("USB Error!!");
                        return;
                    }
                    else if (rx.CheckDataList() == false)
                    {
                        toolStripStatusLabel3.Text = "USB Reciece Error!!";
                        MessageBox.Show("USB Reciece Error!!");
                        return;
                    }
                    //每传送两串数据,发一次写命令,设备把数据写入内部FLASH
                    JL++;
                    if (2 == JL)
                    {
                        JL = 0;
                        //--data cal
                        InteractionData tx1 = new InteractionData();
                        tx1.buff[0] = 0x02;
                        rx          = HIDDevice.TheHIDDevice.DeviceInteraction(tx1);
                        if (rx == null)
                        {
                            toolStripStatusLabel3.Text = "USB Error!!";
                            MessageBox.Show("USB Error!!");
                            return;
                        }
                        else if (rx.CheckDataList() == false)
                        {
                            toolStripStatusLabel3.Text = "Reciece Error!!";
                            MessageBox.Show("USB Reciece Error!!");
                            return;
                        }
                        //--
                        tx1.buff[0] = 0x05;
                        tx1.buff[1] = 0x55;     //主机-->设备
                        tx1.buff[5] = Ads_L;
                        tx1.buff[6] = Ads_H;
                        tx1.buff[7] = Ads_U;
                        rx          = HIDDevice.TheHIDDevice.DeviceInteraction(tx1);
                        if (rx == null)
                        {
                            toolStripStatusLabel3.Text = "USB Error!!";
                            MessageBox.Show("USB Error!!");
                            return;
                        }
                        else if (rx.CheckDataList() == false)
                        {
                            toolStripStatusLabel3.Text = "Reciece Error!!";
                            MessageBox.Show("USB Reciece Error!!");
                            return;
                        }
                        Ads_L += 0x40;
                        if (0x00 == Ads_L)
                        {
                            Ads_H++;
                        }
                    }
                    progressBar1.Value = (0x7000 - Length) * 98 / 0x7000;
                    WFGlobal.WaitMS(10);
                }
                tx         = new InteractionData();
                tx.buff[0] = 0x0f;
                rx         = HIDDevice.TheHIDDevice.DeviceInteraction(tx);
                if (rx == null)
                {
                    toolStripStatusLabel3.Text = "USB Error!!";
                    MessageBox.Show("USB Error!!");
                    return;
                }
                else if (rx.CheckDataList() == false)
                {
                    toolStripStatusLabel3.Text = "Reciece Error!!";
                    MessageBox.Show("USB Reciece Error!!");
                    return;
                }
                if (HIDDevice.TheHIDDevice.CheckDevice())
                {
                    progressBar1.Value         = 100;
                    toolStripStatusLabel3.Text = "Device Update Finish";
                    WFGlobal.WaitMS(100);
                    svd.SetVerifyData_BINUpdateTime(DateTime.Now);
                    if (bMessge)
                    {
                        MessageBox.Show("Device Update Finish");
                    }
                }
                else
                {
                    MessageBox.Show("Device Update Error!!");
                    return;
                }
            }
            finally
            {
                this.Enabled         = true;
                progressBar1.Visible = false;
                progressBar1.Value   = 0;
            }
        }