Exemplo n.º 1
0
        private void bt_teststart_Click(object sender, EventArgs e)
        {
            if (bt_teststart.Text.ToString() == "连接设备")
            {
                usbHIDreality = usbHID;
                if (lb_hiddevice.SelectedItem == null)
                {
                    MessageBox.Show("请从设备列表中选择设备");
                    return;
                }

                #region Initial UI
                bt_teststart.Text = "断开连接";
                lb_ttstatus.Text = "测试工具运行中";
                #endregion

                string conndev=this.lb_hiddevice.SelectedItem.ToString().Substring(6);
                if (usbHIDreality.OpenUSBHid(conndev))
                {
                    string idx = conndev.Substring(conndev.IndexOf("pid_16b4") + 11, 1);
                    this.gb_dev1.Text = idx + "号设备";
                    this.lb_dev1_status.Text = "已连接";
                    usbHIDreality.DataReceived += usbHID_DataReceived;
                    usbHIDreality.DeviceRemoved += usbHID_DeviceRemoved;
                }
                else
                    this.lb_dev1_status.Text = "连接失败";

            }
            else
            {
                bt_teststart.Text = "连接设备";
                lb_ttstatus.Text = "测试工具等待中";
                this.lb_dev1_rlt.Text = "测试结果";
                lb_dev1_rlt.ForeColor = Color.Blue;
                this.lb_dev1_status.Text = "等待连接";
                lib_dev1_ng.Items.Clear();
                this.pb_dev1_barcode.Image = null;

                //enumdevice.Abort();
                try
                {
                     usbHIDreality.CloseDevice();
                }
                catch (Exception err)
                {
                    err.ToString();
                }
            }
        }
Exemplo n.º 2
0
        private void hid_discovery()
        {
            while (true)
            {
                usbHID = new USBHID();
                #region add HID dev into listbox
                foreach (string device in usbHID.GetDeviceList())
                {
                    if ((device.IndexOf("vid_0451") >= 0) && (device.IndexOf("pid_16b4") >= 0))
                    {
                        string idx = device.Substring(device.IndexOf("pid_16b4")+11,1);
                        this.lb_hiddevice.Invoke((MethodInvoker)delegate()
                        {
                            updatedevlist(idx+"号设备--"+device);
                        });
                    }
                }
                #endregion

                Thread.Sleep(5000);
                this.lb_hiddevice.Invoke((MethodInvoker)delegate()
                {
                    cleardevlist();
                });
            }
        }
Exemplo n.º 3
0
        private void usbHID_DataReceived(object sender, EventArgs e)
        {
            report myRP = (report)e;

            if (InvokeRequired)
            {
                Invoke(new EventHandler(usbHID_DataReceived), new object[] { sender, e });
            }
            else
            {
                lib_dev1_ng.Items.Clear();
                //if (myRP.reportBuff[0] == 0x00)

                if ((myRP.reportBuff[0] & 0x27) == 0x00)
                {
                    lib_dev1_ng.Items.Add(lb_dev1_rlt.Text);
                    if ((int)(myRP.reportBuff[7] - 128) <= Convert.ToInt16(this.rssimin.Text.Substring(1)))
                    {
                        lb_dev1_rlt.Text      = "OK" + " , -" + Convert.ToString((int)(myRP.reportBuff[7] - 128)) + "dB";
                        lb_dev1_rlt.ForeColor = Color.Green;
                    }
                    else
                    {
                        lb_dev1_rlt.Text      = "信号强度低";
                        lb_dev1_rlt.ForeColor = Color.Red;
                    }
                }
                //receive disconnect report
                else if (System.Text.Encoding.ASCII.GetString(myRP.reportBuff).IndexOf("disconne") > -1)
                {
                    this.lb_dev1_rlt.Text = "测试结果";
                    lb_dev1_rlt.ForeColor = Color.Blue;
                }
                else if (System.Text.Encoding.ASCII.GetString(myRP.reportBuff).IndexOf("goahead") > -1)
                {
                    this.lb_dev1_rlt.Text = "检测中,勿开箱";
                    lb_dev1_rlt.ForeColor = Color.Red;
                }
                //receive scantimeout report
                else if (System.Text.Encoding.ASCII.GetString(myRP.reportBuff).IndexOf("nodevice") > -1)
                {
                    this.lb_dev1_rlt.Text = "搜索失败";
                    lb_dev1_rlt.ForeColor = Color.Red;
                }
                else
                {
                    lb_dev1_rlt.Text      = "NG";
                    lb_dev1_rlt.ForeColor = Color.Red;
                    if ((myRP.reportBuff[0] & 0x01) == 0x01)
                    {
                        lib_dev1_ng.Items.Add("Flash ID错误");
                    }
                    if ((myRP.reportBuff[0] & 0x02) == 0x02)
                    {
                        lib_dev1_ng.Items.Add("Flash 读写错误");
                    }
                    if ((myRP.reportBuff[0] & 0x04) == 0x04)
                    {
                        lib_dev1_ng.Items.Add("G-sensor ID错误");
                    }
                    if ((myRP.reportBuff[0] & 0x08) == 0x08)
                    {
                        lib_dev1_ng.Items.Add("G-sensor 自检失败");
                    }

                    /*if ((myRP.reportBuff[0] & 0x10) == 0x10)
                     * {
                     *  lib_dev1_ng.Items.Add("PPG传感器错误");
                     * }*/
                    if ((myRP.reportBuff[0] & 0x20) == 0x20)
                    {
                        lib_dev1_ng.Items.Add("ADC错误");
                    }

                    /*if ((myRP.reportBuff[0] & 0x40) == 0x40)
                     * {
                     *  lib_dev1_ng.Items.Add("PPG电流检测失败");
                     * }
                     * if ((myRP.reportBuff[0] & 0x80) == 0x80)
                     * {
                     *  lib_dev1_ng.Items.Add("没有检测到充电状态");
                     * }*/
                }
                byte[] byte_macaddr = new byte[6];
                for (cid = 0; cid < 6; cid++)
                {
                    byte_macaddr[cid] = myRP.reportBuff[6 - cid];
                }
                string str_macaddr = USBHID.ByteToHexString(byte_macaddr);

                this.pb_dev1_barcode.Image = null;
                System.Drawing.Image image;
                int    width = pb_dev1_barcode.Size.Width, height = pb_dev1_barcode.Size.Height;
                string fileSavePath = AppDomain.CurrentDomain.BaseDirectory + "barcode.jpg";

                GetBarcode(height, width, BarcodeLib.TYPE.CODE128, str_macaddr, out image, fileSavePath);

                FileStream fileStream = new FileStream(fileSavePath, FileMode.Open, FileAccess.Read);
                this.pb_dev1_barcode.Image = Image.FromStream(fileStream);
                fileStream.Close();
                fileStream.Dispose();
                //this.pb_dev1_barcode.Image = Image.FromFile("barcode.jpg");
            }
        }