void WaitingCollect_L(object LockWatingThread)
        {
            int Tex;

            //double E;
            this.Invoke((EventHandler)(delegate
            {
                WFGlobal.WaitMS(1);
//                 exposureChart.Series["miu"].Points.Clear();
//                 exposureChart.Series["delta"].Points.Clear();
//                 tcpCCS.LightSet(SystemParam.lambda_Oe, 0);//暗场
            }));
            Tex = SystemParam.NTmin;
            //明场
            for (int i = 0; i < SystemParam.L; i++)
            {
                this.Invoke((EventHandler)(delegate
                {
                    //                     exposureListView.Items[2].SubItems[1].Text = (Imin.ToString("F2") + "-" + Imax.ToString("F2"));
                    //                     exposureListView.Items[3].SubItems[1].Text = oe_per.ToString("F2");
                    if (!UDPProc.CollectImage(this, Tex, 1))
                    {
                        ParamTestWaitingProc.ExitWatting();
                        return;
                    }
                    WriteTempFile(UDPProc.ccdImageList[0].byteList, i, L_TempFilePath);
                }));
                if (exposureWaitingProc.HasBeenCancelled())
                {
                    return;
                }
                ParamTestWaitingProc.SetProcessBarPerformStep();
            }
        }
        void WaitingCollect_Step_1(object LockWatingThread)
        {
            int    Oe = 0;
            double miu;
            double miuCC;
            double delta;

            //double E;
            this.Invoke((EventHandler)(delegate
            {
                WFGlobal.WaitMS(1);
                ParamTestChart1.Series["miu"].Points.Clear();
                ParamTestChart1.Series["delta"].Points.Clear();
                ParamTestChart1.Series["E"].Points.Clear();
            }));
            while (true)
            {
                this.Invoke((EventHandler)(delegate
                {
                    tcpCCS.LightSet(SystemParam.lambda_Oe, Oe);
                    //                     exposureListView.Items[2].SubItems[1].Text = (Imin.ToString("F2") + "-" + Imax.ToString("F2"));
                    //                     exposureListView.Items[3].SubItems[1].Text = oe_per.ToString("F2");
                    if (!UDPProc.CollectImage(this, SystemParam.NTmin, 2))
                    {
                        ParamTestWaitingProc.ExitWatting();
                        return;
                    }
                    UDPProc.ccdImageList[0].save(SystemParam.TempPicPath + "E" + Oe.ToString("") + "_0.bin");
                    UDPProc.ccdImageList[1].save(SystemParam.TempPicPath + "E" + Oe.ToString("") + "_1.bin");
                    ccdImage.Calc_miu_delta(UDPProc.ccdImageList[0], UDPProc.ccdImageList[1], out miu, out delta, out miuCC);
                    ParamTestChart1.Series["miu"].Points.AddXY(Oe, miu);
                    ParamTestChart1.Series["delta"].Points.AddXY(Oe, delta);
                    DeviceState ds = UDPProc.UDPCommand_04();
                    if (ds == null)
                    {
                        textBox1.AppendText("照度采集失败,测试终止\r\n");
                        ParamTestWaitingProc.ExitWatting();
                        return;
                    }
                    ParamTestChart1.Series["E"].Points.AddXY(Oe, ds.Illuminance);
                    Collect_Step_miu.Add(miu);
                    Collect_Step_delta.Add(delta);
                    Collect_Step_E.Add(ds.Illuminance);
                    if (miu >= SystemParam.miu_sat)//均值达到本文第二章(曝光步距)所确定的饱和均值
                    {
                        double max = Collect_Step_delta.Max();
                        if (Collect_Step_delta.Last() < max * 0.5)//方差由最大峰值迅速下降(超过50%)
                        {
                            return;
                        }
                    }
                    Oe += SystemParam.Oe;
                    ParamTestWaitingProc.SetProcessBarPerformStep();
                }));
                if (exposureWaitingProc.HasBeenCancelled())
                {
                    return;
                }
            }
        }
Beispiel #3
0
 private void ConnectForm_Shown(object sender, EventArgs e)
 {
     MainForm.serialPort          = new SerialPort();
     MainForm.serialPort.PortName = Properties.Settings.Default.SerialPortName;
     MainForm.serialPort.BaudRate = 115200;
     if (WFGlobal.OpenSerialPort(ref MainForm.serialPort, ""))
     {
         if (DLLWork.CheckDevice())
         {
             MainForm.bConnectedDevice = true;
             label1.Text        = "成功连接到硬件设备";
             progressBar1.Value = progressBar1.Maximum;
             WFGlobal.WaitMS(2000);
             this.Close();
             return;
         }
         else
         {
             MainForm.serialPort.Close();
         }
     }
     string[] ports = SerialPort.GetPortNames();
     Array.Sort(ports);
     progressBar1.Maximum = ports.Length - 1;
     progressBar1.Value   = 0;
     foreach (string port in ports)
     {
         Debug.WriteLine(port);
         progressBar1.PerformStep();
         WFGlobal.WaitMS(1);
         MainForm.serialPort.PortName = port;
         MainForm.serialPort.BaudRate = 115200;
         if (WFGlobal.OpenSerialPort(ref MainForm.serialPort, ""))
         {
             if (DLLWork.CheckDevice())
             {
                 Properties.Settings.Default.SerialPortName = port;
                 Properties.Settings.Default.Save();
                 MainForm.bConnectedDevice = true;
                 label1.Text        = "成功连接到硬件设备";
                 progressBar1.Value = progressBar1.Maximum;
                 WFGlobal.WaitMS(2000);
                 this.Close();
                 return;
             }
             else
             {
                 MainForm.serialPort.Close();
             }
         }
     }
     label1.Text = "未找到设备,请重新连接硬件设备";
     WFGlobal.WaitMS(2000);
     this.Close();
 }
 void NopCam(ushort count, uint ls)
 {
     while (true)
     {
         SerialFunc.SerialCommand3(count, ls);
         if (WaitCam(count))
         {
             break;
         }
     }
     WFGlobal.WaitMS(200);
 }
Beispiel #5
0
        bool OpenUart()
        {
            Uart.PortName = cbCom.Text;
            RxPacket      = new CP1616Packet();
            if (WFGlobal.OpenSerialPort(ref Uart) == false)
            {
                return(false);
            }
            Properties.Settings.Default.PortName = cbCom.Text;
            Properties.Settings.Default.Save();

            return(true);
        }
 void WaitingExposureVerify(object LockWatingThread)
 {
     while (true)
     {
         double miu;
         double delta;
         double miuCC;
         this.Invoke((EventHandler)(delegate
         {
             exposureVerifyChart.Series["miu"].Points.Clear();
             exposureVerifyChart.Series["delta"].Points.Clear();
             exposureVerifyChart.Series["miuCC"].Points.Clear();
             for (int step = 0; step < SystemParam.n; step++)
             {
                 WFGlobal.WaitMS(1);
                 int ex = SystemParam.NTmin + step * SystemParam.NTexp;
                 tcpCCS.LightSet(SystemParam.lambda_Oe, SystemParam.Oe);
                 exposureVerifyListView.Items[4].SubItems[1].Text = step.ToString();
                 if (!UDPProc.CollectImage(this, ex, 2))
                 {
                     exposureVerifyWaitingProc.ExitWatting();
                     return;
                 }
                 UDPProc.ccdImageList[0].save(SystemParam.TempPicPath + "Ev" + step.ToString() + "_0.bin");
                 UDPProc.ccdImageList[1].save(SystemParam.TempPicPath + "Ev" + step.ToString() + "_1.bin");
                 ccdImage.Calc_miu_delta(UDPProc.ccdImageList[0], UDPProc.ccdImageList[1], out miu, out delta, out miuCC);
                 exposureVerifyChart.Series["miu"].Points.AddXY(step, miu);
                 exposureVerifyChart.Series["delta"].Points.AddXY(step, delta);
                 exposureVerifyChart.Series["miuCC"].Points.AddXY(step, miuCC);
                 if (exposureVerifyWaitingProc.HasBeenCancelled())
                 {
                     return;
                 }
                 exposureVerifyWaitingProc.SetProcessBarPerformStep();
             }
         }));
         if (exposureVerifyWaitingProc.HasBeenCancelled())
         {
             return;
         }
         if (MessageBox.Show("测试完毕,是否修改要修改参数", "测试完成", MessageBoxButtons.YesNo) == DialogResult.Yes)
         {
             FormParam f = new FormParam();
             f.ShowDialog();
         }
         else
         {
             return;
         }
     }
 }
Beispiel #7
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            WFGlobal.WaitMS(200);
            DLLWork.MakeDLL();

            serialProcCallback  = new DLLWork.SerialProcCallback(serialProc);
            setProgressCallback = new DLLWork.SetProgressCallback(SetProgressCallBackProc);
            //serialTxCallback = new DLLWork.SerialTxCallback(serialTxProc);
            DLLWork.InitDllWork(serialProcCallback, setProgressCallback);
            bConnectedDevice = false;
            ConnectForm f = new ConnectForm();

            f.ShowDialog();
        }
Beispiel #8
0
 private void Form1_Load(object sender, EventArgs e)
 {
     toolStripStatusLabel1.Text    = "工作串口为" + serialPort1.PortName;
     CP1616PacketHead.Addr_SIZE    = 1;
     CP1616PacketHead.DataLen_SIZE = 1;
     CP1616PacketHead.CalcHeaderLen();
     if (!WFGlobal.OpenSerialPort(ref serialPort1, "工控机握手监测"))
     {
         this.Close();
         return;
     }
     RxCount = 0;
     TxCount = 0;
     HandWork();
     timer1.Enabled = true;
 }
Beispiel #9
0
        void WaitingCollect_DarkI(object LockWatingThread)
        {
            double miu = 0;
            double miuCC;
            double delta;
            int    Tex;

            //double E;
            this.Invoke((EventHandler)(delegate
            {
                WFGlobal.WaitMS(1);
                exposureChart.Series["miu"].Points.Clear();
                exposureChart.Series["delta"].Points.Clear();
                tcpCCS.LightSet(SystemParam.lambda_Oe, 0);//暗场
            }));
            Tex = SystemParam.NTdark;
            //明场
            for (int i = 0; i < 16; i++)
            {
                this.Invoke((EventHandler)(delegate
                {
                    //                     exposureListView.Items[2].SubItems[1].Text = (Imin.ToString("F2") + "-" + Imax.ToString("F2"));
                    //                     exposureListView.Items[3].SubItems[1].Text = oe_per.ToString("F2");
                    if (!UDPProc.CollectImage(this, Tex, 2))
                    {
                        ParamTestWaitingProc.ExitWatting();
                        return;
                    }
                    UDPProc.ccdImageList[0].save(SystemParam.TempPicPath + "DarkI" + Tex.ToString("") + "_0.bin");
                    UDPProc.ccdImageList[1].save(SystemParam.TempPicPath + "DarkI" + Tex.ToString("") + "_1.bin");
                    ccdImage.Calc_miu_delta(UDPProc.ccdImageList[0], UDPProc.ccdImageList[1], out miu, out delta, out miuCC);
                    exposureChart.Series["miu"].Points.AddXY(Tex, miu);
                    exposureChart.Series["delta"].Points.AddXY(Tex, delta);
                    Collect_DarkI_miu.Add(miu);
                    Collect_DarkI_delta.Add(delta);
                }));
                if (exposureWaitingProc.HasBeenCancelled())
                {
                    return;
                }
                Tex += SystemParam.delta_Tdark;
                ParamTestWaitingProc.SetProcessBarPerformStep();
            }
        }
        void WaitingCCS(object LockWatingThread)
        {
            List <double> OeList = new List <double>();
            List <double> EList  = new List <double>();

            for (double Oe = 0; Oe < 1; Oe += step)
            {
                OeList.Add(Oe);
                tcpCCS.LightSet(tcpCCS.lambdaList[lambadIndex], Oe);
                WFGlobal.WaitMS(100);
                DeviceState ds = UDPProc.UDPCommand_04();
                if (ds == null)
                {
                    MessageBox.Show("照度采集失败,测试终止\r\n");
                    ccsWaitingProc.ExitWatting();
                    return;
                }
                EList.Add(ds.Illuminance);
                this.Invoke((EventHandler)(delegate
                {
                    chart.Series[0].Points.AddXY(Oe, ds.Illuminance);
                }));
                if (ccsWaitingProc.HasBeenCancelled())
                {
                    return;
                }
            }
            double[] fitret = FittingMultiLine.MultiLine(OeList.ToArray(), EList.ToArray(), OeList.Count, 2);
            a2.Add(double.Parse(fitret[2].ToString(aFormat)));
            a1.Add(double.Parse(fitret[1].ToString(aFormat)));
            a0.Add(double.Parse(fitret[0].ToString(aFormat)));
            this.Invoke((EventHandler)(delegate
            {
                for (double Oe = 0; Oe < 1; Oe += step)
                {
                    chart.Series[1].Points.AddXY(Oe, a2.Last() * Oe * Oe + a1.Last() * Oe + a0.Last());
                }
                chart.SaveImage(SystemParam.TempPicPath + "ccs_" + tcpCCS.lambdaList[lambadIndex].ToString() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }));
        }
Beispiel #11
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (textBox1.Text.Length != 15)
     {
         MessageBox.Show("设备ID长度需要为15位");
         return;
     }
     if (oldID == textBox1.Text)
     {
         MessageBox.Show("不能两次连续下载相同ID");
         return;
     }
     if (button1.Text == "烧写")
     {
         progressBar1.Value = progressBar1.Minimum;
         serialPort1.Close();
         serialPort1.PortName = cbCom.Text;
         if (!WFGlobal.OpenSerialPort(ref serialPort1, "所选"))
         {
             return;
         }
         textBox1.Enabled = false;
         button1.Text     = "停止";
         bComRead         = true;
         Thread t = new Thread(ComProc_Read);
         t.Start();
     }
     else
     {
         bComRead = false;
         while (!bComReadExit)
         {
             ;
         }
         button1.Text = "烧写";
         serialPort1.Close();
         textBox1.Enabled = true;
     }
 }
Beispiel #12
0
        void WaitingCollect_etaCurve_2(object LockWatingThread)
        {
            double miu = 0;
            double miuCC;
            double delta;
            int    Tex;
            int    stepCount = 0;

            for (double lamba = SystemParam.L_lambda; lamba < SystemParam.H_lambda; lamba += SystemParam.delta_lambda)
            {
                stepCount = 0;
                List <double> eta_miu = new List <double>();
                Collect_etaCurve_delta = new List <double>();
                this.Invoke((EventHandler)(delegate
                {
                    WFGlobal.WaitMS(1);
                    ParamTestChart2.Series["miu"].Points.Clear();
                    ParamTestChart2.Series["delta"].Points.Clear();
                    ParamTestChart2.Series["miu_dark"].Points.Clear();
                    ParamTestChart2.Series["delta_dark"].Points.Clear();
                    tcpCCS.LightSet((int)lamba, SystemParam.Oe);
                }));
                Tex = SystemParam.NTmin;
                //明场
                while (true)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        //                     exposureListView.Items[2].SubItems[1].Text = (Imin.ToString("F2") + "-" + Imax.ToString("F2"));
                        //                     exposureListView.Items[3].SubItems[1].Text = oe_per.ToString("F2");
                        if (!UDPProc.CollectImage(this, Tex, 2))
                        {
                            ParamTestWaitingProc.ExitWatting();
                            return;
                        }
                        UDPProc.ccdImageList[0].save(SystemParam.TempPicPath + "ET" + Tex.ToString("") + "_0.bin");
                        UDPProc.ccdImageList[1].save(SystemParam.TempPicPath + "ET" + Tex.ToString("") + "_1.bin");
                        ccdImage.Calc_miu_delta(UDPProc.ccdImageList[0], UDPProc.ccdImageList[1], out miu, out delta, out miuCC);
                        ParamTestChart2.Series["miu"].Points.AddXY(Tex, miu);
                        ParamTestChart2.Series["delta"].Points.AddXY(Tex, delta);
                        DeviceState ds = UDPProc.UDPCommand_04();
                        if (ds == null)
                        {
                            textBox1.AppendText("照度采集失败,测试终止\r\n");
                            ParamTestWaitingProc.ExitWatting();
                            return;
                        }
                        eta_miu.Add(miu);
                        Collect_etaCurve_delta.Add(delta);
                        Collect_etaCurve_E.Add(ds.Illuminance);
                        Tex += SystemParam.NTexp;
                        stepCount++;
                        ParamTestWaitingProc.SetProcessBarPerformStep();
                    }));
                    if (miu >= SystemParam.miu_sat)//均值达到本文第二章(曝光步距)所确定的饱和均值
                    {
                        double max = Collect_etaCurve_delta.Max();
                        if (Collect_etaCurve_delta.Last() < max * 0.5)//方差由最大峰值迅速下降(超过50%)
                        {
                            Collect_etaCurve_miu.Add(eta_miu);
                            break;
                        }
                    }
                    if (exposureWaitingProc.HasBeenCancelled())
                    {
                        return;
                    }
                }
                this.Invoke((EventHandler)(delegate
                {
                    WFGlobal.WaitMS(1);
                    tcpCCS.LightSet(SystemParam.lambda_Oe, 0);
                }));
                Tex = SystemParam.NTmin;
                List <double> eta_miu_dark = new List <double>();
                for (int i = 0; i < stepCount; i++)
                {
                    this.Invoke((EventHandler)(delegate
                    {
                        //                     exposureListView.Items[2].SubItems[1].Text = (Imin.ToString("F2") + "-" + Imax.ToString("F2"));
                        //                     exposureListView.Items[3].SubItems[1].Text = oe_per.ToString("F2");
                        if (!UDPProc.CollectImage(this, Tex, 2))
                        {
                            ParamTestWaitingProc.ExitWatting();
                            return;
                        }
                        UDPProc.ccdImageList[0].save(SystemParam.TempPicPath + "EDT" + Tex.ToString("") + "_0.bin");
                        UDPProc.ccdImageList[1].save(SystemParam.TempPicPath + "EDT" + Tex.ToString("") + "_1.bin");
                        ccdImage.Calc_miu_delta(UDPProc.ccdImageList[0], UDPProc.ccdImageList[1], out miu, out delta, out miuCC);
                        ParamTestChart2.Series["miu_dark"].Points.AddXY(Tex, miu);
                        ParamTestChart2.Series["delta_dark"].Points.AddXY(Tex, delta);
                        eta_miu_dark.Add(miu);
                        Collect_etaCurve_delta_dark.Add(delta);
                    }));
                    if (exposureWaitingProc.HasBeenCancelled())
                    {
                        return;
                    }
                    Tex += SystemParam.NTexp;
                    ParamTestWaitingProc.SetProcessBarPerformStep();
                }
                Collect_etaCurve_miu_dark.Add(eta_miu_dark);
            }
        }
Beispiel #13
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;  
            }
        }
Beispiel #14
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;
        }
Beispiel #15
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 = "";
                }
            }
        }
Beispiel #16
0
 private void btNetStart_Click(object sender, EventArgs e)
 {
     if (btNetStart.Text == "启动网络")
     {
         Uart.PortName = cbCom.Text;
         RxPacket      = new CP1616Packet();
         if (WFGlobal.OpenSerialPort(ref Uart) == false)
         {
             return;
         }
         Properties.Settings.Default.PortName = cbCom.Text;
         Properties.Settings.Default.Save();
         sensorSingIn.clearSignIn();
         listView1.Items.Clear();
         chart1.Series[0].Points.Clear();
         chart2.Series[0].Points.Clear();
         chart3.Series[0].Points.Clear();
         chart4.Series[0].Points.Clear();
         chart3.Series[1].Points.Clear();
         chart4.Series[1].Points.Clear();
         chart3.Series[2].Points.Clear();
         chart4.Series[2].Points.Clear();
         chart3.Series[3].Points.Clear();
         chart4.Series[3].Points.Clear();
         bStopNet = false;
         for (int i = 0; i < 3; i++)
         {
             startResult = 0;
             waitCommand = 1;
             CP1616Packet.CP1616ComSend(ref Uart, waitCommand, 0, (ushort)0);
             int x = 0;
             while (true)
             {
                 Thread.Sleep(1);
                 if (startResult != 0)
                 {
                     break;
                 }
                 x++;
                 if (x > 1000)
                 {
                     startResult = 0xff;
                     break;
                 }
             }
             if (startResult == 0xff)//超时了
             {
             }
             else
             {
                 break;
             }
         }
         if (startResult == 0xff)
         {
             MessageBox.Show("网络控制器未做应答!!!");
             Uart.Close();
             btNetStart.Text = "启动网络";
             return;
         }
         else if (startResult == 2)
         {
             bStopNet        = false;
             btNetStart.Text = "停止网络";
             MessageBox.Show("网络已经启动,等待接入");
         }
         else if (startResult == 3)
         {
             bStopNet        = false;
             btNetStart.Text = "停止网络";
             MessageBox.Show("标定网络已经启动,将自动转为测量网络,等待接入");
         }
         else
         {
             WaitSometingForm.WaitSometing_Init();
             waitCommand = 0x10;//点名完成
             if (!WaitSometingForm.WaitSometing(10, 3000, "等待无线节点组网,预计时长25s"))
             {
                 waitCommand = 0;
                 Uart.Close();
                 MessageBox.Show("组网失败");
                 return;
             }
             if (listView1.Items.Count != 0)
             {
                 WaitSometingForm.WaitSometing_Init();
                 waitCommand = 0x20;//等待测量数据
                 if (!WaitSometingForm.WaitSometing(10, 500, "等待网络数据,预计时长3s"))
                 {
                     waitCommand = 0;
                     MessageBox.Show("组网失败");
                     Uart.Close();
                     bStopNet = false;
                     return;
                 }
                 bStopNet        = false;
                 btNetStart.Text = "停止网络";
                 MessageBox.Show("网络启动成功");
             }
             else
             {
                 waitCommand = 0;
                 MessageBox.Show("当前网络没有发现任何无线节点,网络自动停止");
                 Uart.Close();
                 btNetStart.Text = "启动网络";
                 return;
             }
         }
     }
     else
     {
         bStopNet = true;
         WaitSometingForm.WaitSometing_Init();
         waitCommand = 0x02;//等待网络停止
         if (!WaitSometingForm.WaitSometing(10, 500, "等待网络停止,预计时长5s"))
         {
             waitCommand = 0;
             MessageBox.Show("网络停止失败");
             return;
         }
         MessageBox.Show("网络已停止");
         Uart.Close();
         btNetStart.Text = "启动网络";
     }
 }
Beispiel #17
0
        private void checkForDeviceUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (HIDDevice.TheHIDDevice == null)
            {
                toolStripStatusLabel3.Text = "No Device,Cann't Update";
                MessageBox.Show("No Device,Cann't Update,Please insert the Device!!!");
                return;
            }
            toolStripStatusLabel3.Text = "connecting to server for device update";
            System.Windows.Forms.Application.DoEvents();
            WFHttpWebResponse WebResponse = new WFHttpWebResponse();
            string            url;

            url  = "http://qc.iehlj.com/index.php?m=content&a=yingupdate&device=";
            url += WFNetLib.Strings.StringsFunction.byteToHexStr(HIDDevice.TheHIDDevice.HexID, "");
            HttpWebResponse            hr = WebResponse.CreateGetHttpResponse(url);
            DataContractJsonSerializer s  = new DataContractJsonSerializer(typeof(JsonSoftData));
            MemoryStream stream           = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(WebResponse.Content));
            JsonSoftData calldata         = (JsonSoftData)s.ReadObject(stream);

            if (calldata.status == 0)//有更新
            {
                string strcurBin = HIDDevice.TheHIDDevice.HexVer[0].ToString("X2") + "." + HIDDevice.TheHIDDevice.HexVer[1].ToString("X2");
                float  serBin    = float.Parse(calldata.to_version.Substring(1));
                float  curBin    = float.Parse(strcurBin);
                if (serBin > curBin)
                {
                    //下载lic
                    toolStripStatusLabel3.Text = "Updating for Device";
                    progressBar1.Value         = 0;
                    progressBar1.Visible       = true;
                    System.Windows.Forms.Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息
                    float percent = 0;
                    try
                    {
                        string URL = calldata.fileurl;
                        //string filename = "123.lic";
                        System.Net.HttpWebRequest  Myrq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
                        System.Net.HttpWebResponse myrp = (System.Net.HttpWebResponse)Myrq.GetResponse();
                        long             totalBytes     = myrp.ContentLength;
                        byte[]           theBIN         = new byte[totalBytes];
                        long             BINOffset      = 0;
                        System.IO.Stream st             = myrp.GetResponseStream();
                        //System.IO.Stream so = new System.IO.FileStream("123.bin", System.IO.FileMode.Create);
                        long   totalDownloadedByte = 0;
                        byte[] by    = new byte[1024];
                        int    osize = st.Read(by, 0, (int)by.Length);
                        while (osize > 0)
                        {
                            totalDownloadedByte = osize + totalDownloadedByte;
                            System.Windows.Forms.Application.DoEvents();
                            //so.Write(by, 0, osize);
                            for (int i = 0; i < osize; i++)
                            {
                                theBIN[BINOffset++] = by[i];
                            }
                            osize                      = st.Read(by, 0, (int)by.Length);
                            percent                    = (float)totalDownloadedByte / (float)totalBytes * 100;
                            progressBar1.Value         = (int)(percent);
                            toolStripStatusLabel3.Text = "Download for device " + percent.ToString("f2") + "%";
                            System.Windows.Forms.Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息
                        }
                        toolStripStatusLabel3.Text = "Download device OK,wait for update device...";
                        System.Windows.Forms.Application.DoEvents();
                        //so.Close();
                        st.Close();
                        WFGlobal.WaitMS(2000);
                        UpdateDevice(theBIN);
                        progressBar1.Visible = false;
                        progressBar1.Value   = 0;
                    }
                    catch (System.Exception ex)
                    {
                        if (bMessge)
                        {
                            MessageBox.Show(ex.Message);
                        }
                        toolStripStatusLabel3.Text = "Device Update is error";
                        progressBar1.Visible       = false;
                        progressBar1.Value         = 0;
                        //throw;
                        //break;
                    }
                }
                else
                {
                    svd.SetVerifyData_BINUpdateTime(DateTime.Now);
                    if (bMessge)
                    {
                        MessageBox.Show("This is the latest Device version");
                    }
                    toolStripStatusLabel3.Text = "This is the latest Device version";
                }
            }
            else
            {
                toolStripStatusLabel3.Text = "This is the latest Device version";
                if (bMessge)
                {
                    MessageBox.Show("This is the latest Device version");
                }
                svd.SetVerifyData_BINUpdateTime(DateTime.Now);
            }
        }
        void WaitingExposureTest(object LockWatingThread)
        {
            Imin = 0;
            Imax = 100;
            while (true)
            {
                double[] miu   = new double[10];
                double[] delta = new double[10];
                double[] miuCC = new double[10];
                exposureWaitingProc.SetProcessBar(0);
                this.Invoke((EventHandler)(delegate
                {
                    WFGlobal.WaitMS(1);
                    exposureChart.Series["miu"].Points.Clear();
                    exposureChart.Series["delta"].Points.Clear();
                    double gap = (Imax - Imin) / 9;
                    for (int step = 0; step < 10; step++)
                    {
                        double oe_per = Imin + gap * step;
                        tcpCCS.LightSet(SystemParam.lambda_Oe, oe_per);
                        exposureListView.Items[2].SubItems[1].Text = (Imin.ToString("F2") + "-" + Imax.ToString("F2"));
                        exposureListView.Items[3].SubItems[1].Text = oe_per.ToString("F2");
                        if (!UDPProc.CollectImage(this, NT, 2))
                        {
                            exposureWaitingProc.ExitWatting();
                            return;
                        }
                        UDPProc.ccdImageList[0].save(SystemParam.TempPicPath + "E" + step.ToString() + "_0.bin");
                        UDPProc.ccdImageList[1].save(SystemParam.TempPicPath + "E" + step.ToString() + "_1.bin");
                        ccdImage.Calc_miu_delta(UDPProc.ccdImageList[0], UDPProc.ccdImageList[1], out miu[step], out delta[step], out miuCC[step]);
                        exposureChart.Series["miu"].Points.AddXY(oe_per, miu[step]);
                        exposureChart.Series["delta"].Points.AddXY(oe_per, delta[step]);
                        if (exposureWaitingProc.HasBeenCancelled())
                        {
                            return;
                        }
                        exposureWaitingProc.SetProcessBarPerformStep();
                    }
                }));
                if (exposureWaitingProc.HasBeenCancelled())
                {
                    return;
                }
                // 方差全部相等(且接近0),则在之前照度第一个区间分10个照度等级
                double close0 = 0.01;
                if (delta[0] < close0 && delta[1] < close0)
                {
                    Imax = (Imax - Imin) / 9;
                }
                //如果方差单调升则修改NT=10*NT_min
                else if (delta[0] < delta[1])//单调增
                {
                    bool bMonotonicity = true;
                    for (int i = 0; i < 9; i++)
                    {
                        if (delta[i + 1] < delta[i])//增减转折
                        {
                            Imin          = (Imax - Imin) * (i + 1);
                            bMonotonicity = false;
                            break;
                        }
                    }
                    if (bMonotonicity)
                    {
                        NT = NT * 10;
//                         while(true)
//                         {
//                             string strNTmin = InputBox.ShowInputBox("请重新设定最小曝光周期数", SystemParam.NTmin.ToString());
//                             if (!int.TryParse(strNTmin, out SystemParam.NTmin))
//                             {
//                                 MessageBox.Show("所设定的最小曝光周期数有误!!!");
//                             }
//                             break;
//                         }
                    }
                }
                else//第一个就是减,那应该都是减函数
                {
                    SystemParam.Oe = tcpCCS.Per2LX(Imin / (SystemParam.n - 5));
                    iniFileOP.Write("Light Param", "Oe", SystemParam.Oe.ToString());
                    SystemParam.Osat = tcpCCS.Per2LX(Imin);
                    iniFileOP.Write("CCD Param", "Osat", SystemParam.Osat.ToString(), strCCDINIPath);
                    SystemParam.miu_sat = miu[0];
                    iniFileOP.Write("CCD Param", "miu_sat", SystemParam.miu_sat.ToString(), strCCDINIPath);
                    SystemParam.NTexp = SystemParam.NTmin * (SystemParam.n - 5) / SystemParam.n;
                    iniFileOP.Write("Collect Param", "NTexp", SystemParam.NTexp.ToString());
                    this.Invoke((EventHandler)(delegate
                    {
                        exposureListView.Items[4].SubItems[1].Text = SystemParam.Oe.ToString("F2");
                        exposureListView.Items[5].SubItems[1].Text = miu[0].ToString("F2");
                        exposureListView.Items[6].SubItems[1].Text = SystemParam.NTexp.ToString("F2");
                    }));
                    MessageBox.Show("曝光步距测试完毕");
                    return;
                }
            }
        }
Beispiel #19
0
        private void tcpAsyncServer_ReceiveServerEvent(object sender, ReceiveServerEventArgs e)
        {
            this.Invoke((EventHandler)(delegate
            {
                string strRx = (string)e.netPacket;
                string[] rxList = strRx.Split(',');
                string key = e.Client.ClientSocket.RemoteEndPoint.ToString();
                //if(rxList.Length==2)
                {
                    int index = int.Parse(rxList[0]);
                    if (index == 1)//学号等信息
                    {
                        textBox1.AppendText(strRx + "\r\n");
                        CurveData cd = new CurveData();
                        string[] infoList = rxList[1].Split('|');
                        if (infoList.Length == 4)
                        {
                            cd.ZuoWeiHao = infoList[0];
                            cd.BanJi = infoList[1];
                            cd.XueHao = infoList[2];
                            cd.exWorkTepy = byte.Parse(infoList[3]);
                            CurveDataTable[key] = cd;
                            WFGlobal.WaitMS(1000);
                            textBox1.AppendText("学号信息\r\n");
                            tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket("01,OK"));
                        }
                    }
                    else if (index <= 7 && index >= 2)
                    {
                        CurveData cd = (CurveData)CurveDataTable[key];
                        if (cd != null)
                        {
                            int nCount = int.Parse(rxList[1]);
                            string[] infoList = rxList[2].Split('|');
                            if (infoList.Length == nCount)
                            {
                                cd.VADataCount[index - 2] = nCount;
                                for (int i = 0; i < nCount; i++)
                                {
                                    cd.VAData[index - 2, i] = (float)(float.Parse(infoList[i]) * 0.000763);
                                }
                                cd.bVAExist[index - 2] = true;
                                CurveDataTable[key] = cd;
                                WFGlobal.WaitMS(1000);
                                textBox1.AppendText("实验数据\r\n");
                                tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket(index.ToString("d2") + ",OK"));
//                                 if (index == 7)
//                                 {
//                                     ReportPrint(cd);
//                                 }
                            }
                        }
                    }
                    else if (index <= 11 && index >= 8)
                    {
                        CurveData cd = (CurveData)CurveDataTable[key];
                        int gqIndex = index - 8;
                        if (cd != null)
                        {
                            int nCount = int.Parse(rxList[1]);
                            string[] infoList = rxList[2].Split('|');
                            if (infoList.Length == nCount)
                            {
                                cd.GQDataCount[gqIndex] = nCount;
                                for (int i = 0; i < nCount; i++)
                                {
                                    cd.GQData[gqIndex, i] = (float)(float.Parse(infoList[i]) * 0.000763);
                                }
                                cd.bGQExist[gqIndex] = true;
                                CurveDataTable[key] = cd;
                                WFGlobal.WaitMS(1000);
                                textBox1.AppendText("实验数据\r\n");
                                tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket(index.ToString("d2") + ",OK"));
                                //                                 if (index == 7)
                                //                                 {
                                //                                     ReportPrint(cd);
                                //                                 }
                            }
                        }
                    }
                    else if (index == 12)
                    {
                        CurveData cd = (CurveData)CurveDataTable[key];
                        if (cd != null)
                        {
                            string[] infoList = rxList[1].Split('|');
                            if (infoList.Length == 9)
                            {
                                for (int i = 0; i < 9; i++)
                                {
                                    cd.PLKData[i] = float.Parse(infoList[i]);
                                }
                                cd.bPLKExist = true;
                                CurveDataTable[key] = cd;
                                WFGlobal.WaitMS(1000);
                                textBox1.AppendText("实验数据\r\n");
                                tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket(index.ToString("d2") + ",OK"));
                                //                                 if (index == 7)
                                //                                 {
                                //                                     ReportPrint(cd);
                                //                                 }
                            }
                        }
                    }
                    else if (index == 99)//请求打印帧
                    {
                        CurveData cd = (CurveData)CurveDataTable[key];
                        if (cd != null)
                        {
                            WFGlobal.WaitMS(1000);
                            textBox1.AppendText("开始打印\r\n");
                            tcpAsyncServer.Send(e.Client, easyStringPacket.MakePacket(index.ToString("d2") + ",OK"));
                            ReportPrint(cd);
                        }
                    }
                }
                //textBox1.AppendText(strRx + "\r\n");
//                 NetPacket np = (NetPacket)e.netPacket;
//                 switch (np.PacketHead.PType)
//                 {
//                     case NetPacket.NetPacketType.STRING:
//                         textBox1.AppendText("收到字符串" + np.Data.ToString() + "\r\n");
//                         tcpAsyncServer.Send(e.Client, NetPacket.MakeStringPacket("服务器收到数据" + np.Data.ToString()));
//                         break;
//                     case NetPacket.NetPacketType.BINARY:
//                         NetFile nf = (NetFile)np.Data;
//                         textBox1.AppendText("收到文件" + nf.FileName + ",正在后台生成.....\r\n");
//                         string file = System.Windows.Forms.Application.StartupPath + "\\收到的文件\\" + nf.FileName;
//                         FileInfo f = new FileInfo(file);
//                         if (!Directory.Exists(f.DirectoryName))
//                             Directory.CreateDirectory(f.DirectoryName);
//                         FileStream fs = null;
//                         fs = new FileStream(file, FileMode.Create);
//                         fs.BeginWrite(nf.Content, 0, nf.Content.Length, NetFileWriteOK, fs);
//                         break;
//                     case NetPacket.NetPacketType.COMPLEX:
//                         NetObject no = (NetObject)np.Data;
//                         textBox1.AppendText("收到序列对象" + no.TypeName + ",正在后台生成.....\r\n");
//                         break;
//                 }
            }));
        }
Beispiel #20
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;
        }
Beispiel #21
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;
            }
        }