Пример #1
0
        private bool checkDriver(string driverName)
        {
            string result = "";
            string cmd    = @"sc query " + driverName;

            CmdHelper.RunCmd(cmd, out result);
            string msg = GetResultString(result);

            if (msg.Contains("指定的服务未安装"))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #2
0
 public void resetDevice(int waitSeconds, string msgbox)
 {
     Task.Factory.StartNew(() =>
     {
         Thread.Sleep(waitSeconds * 1000);
     }).ContinueWith(x =>
     {
         string cmd    = "usbrdd.exe -closecallback " + remoteAdd;
         string result = "";
         CmdHelper.RunCmd(cmd, out result);
         cmd = "usbrdd.exe -unshare " + usbCode;
         CmdHelper.RunCmd(cmd, out result);
         deviceName       = "";
         deviceNo         = "";
         deviceStatus     = 0;
         usbCode          = "";
         remoteAdd        = "";
         txtTimer.Enabled = false;
         if (!msgbox.Contains("结束"))
         {
             this.BeginInvoke(updateTxt, "开始前请先连接设备,并确保绑带已经绑好");
         }
         this.Invoke((MethodInvoker)(() =>
         {
             this.txtLabel.ForeColor = Color.WhiteSmoke;
             btnTest.Enabled = true;
             simpleButton2.Visible = false;
             btnBack.Visible = true;
         }));
         if (msgbox.Length > 0 && msgbox != "close")
         {
             XtraMessageBox.Show(msgbox, "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         if (msgbox == "close")
         {
             System.Environment.Exit(0);
         }
     });
 }
Пример #3
0
        private bool checkDevice()
        {
            bool   rtn    = false;
            string result = "";
            string cmd    = @"usbrdd.exe -list";

            CmdHelper.RunCmd(cmd, out result);
            List <string> msglist = GetResult(result);

            if (msglist.Count > 0)
            {
                for (int i = 0; i < msglist.Count; i++)
                {
                    if (msglist[i].Contains("FT232R USB UART"))
                    {
                        if (msglist[i + 2].Contains("not plugged"))
                        {
                            return(false);
                        }
                        if (msglist[i].Split(':').Length > 1)
                        {
                            deviceName = msglist[i].Split(':')[1].Trim();
                            usbCode    = msglist[i].Split(':')[0].Trim();
                        }
                        if (msglist[i + 1].Split(':').Length > 3)
                        {
                            deviceNo = msglist[i + 1].Split(':')[3].Trim();
                        }
                        deviceStatus = 1;
                        rtn          = true;
                        return(rtn);
                    }
                }
            }

            return(rtn);
        }
Пример #4
0
        private void doTest()
        {
            //this.BeginInvoke(updateTxt, "设备自检中。。。");
            //txtTimer.Enabled = true;
            //btnTest.Enabled = false;
            //if(!checkSetup())
            //{
            //    XtraMessageBox.Show("驱动未安装!请先安装驱动再使用本程序!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            //    resetLabel();
            //    return;
            //}
            //if (!checkDevice())
            //{
            //    XtraMessageBox.Show("检测设备没有连接,请先启动检测设备!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            //    resetLabel();
            //    return;
            //}
            deviceReady = true;
            Task.Factory.StartNew(() =>
            {
                this.BeginInvoke(updateTxt, "设备自检中。。。");
                this.Invoke((MethodInvoker)(() =>
                {
                    txtTimer.Enabled = true;
                    btnTest.Enabled = false;
                    btnBack.Visible = false;
                    simpleButton2.Visible = true;
                }));

                if (!checkSetup())
                {
                    XtraMessageBox.Show("驱动未安装!请先安装驱动再使用本程序!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    resetLabel();
                    deviceReady = false;
                    return;
                }
                if (!checkDevice())
                {
                    XtraMessageBox.Show("检测设备没有连接,请先启动检测设备!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    resetLabel();
                    deviceReady = false;
                    return;
                }
                //共享设备
                shareDevice();
            }).ContinueWith(x =>
            {
                if (deviceReady)
                {
                    if (deviceStatus == 1)
                    {
                        this.BeginInvoke(updateTxt, "获取远程检测师信息。。。");
                        remoteAdd = getRemoteAdd();
                        if (remoteAdd == "")
                        {
                            resetDevice(30, "没有空闲的远程检测师,请稍后再试!");

                            //XtraMessageBox.Show("没有空闲的远程检测师,请稍后再试!", "忙碌", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        else if (remoteAdd == "调度服务出错")
                        {
                            resetDevice(30, "调度服务出错,请稍后再试!");
                        }
                        else
                        {
                            this.BeginInvoke(updateTxt, "等待与远程检测师建立连接。。。");
                            string cmd    = "usbrdd.exe -createcallback " + remoteAdd;
                            string result = "";
                            CmdHelper.RunCmd(cmd, out result);
                            string msg = GetResultString(result);
                            if (msg.Replace("\r\n", "") == "Callback connection to remote USB client has been added")
                            {
                                deviceStatus     = 2;
                                DateTime dt1     = DateTime.Now;
                                DateTime dt2     = dt1.AddMinutes(3);
                                bool isConnected = false;
                                while (!isConnected && dt2 > dt1)
                                {
                                    dt1 = DateTime.Now;
                                    cmd = "usbrdd.exe -list";
                                    CmdHelper.RunCmd(cmd, out result);
                                    string msgC = GetResultString(result);
                                    string ip   = remoteAdd.Split(':')[0];
                                    if (msgC.Contains("in use by " + ip))
                                    {
                                        isConnected = true;
                                    }
                                }
                                if (!isConnected)
                                {
                                    resetDevice(1, "等待远程连接超时,请稍后再试!");
                                    //XtraMessageBox.Show("等待远程连接超时,请稍后再试!", "超时", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                }
                                else
                                {
                                    deviceStatus = 3;
                                    this.BeginInvoke(updateTxt, "远程连接成功,检测中。。。");
                                    //XtraMessageBox.Show("远程连接成功,检测开始!", "检测中", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                    string outMsg = "本次远程连接已结束!";
                                    while (isConnected)
                                    {
                                        cmd = "usbrdd.exe -list";
                                        CmdHelper.RunCmd(cmd, out result);
                                        string msgC = GetResultString(result);
                                        string ip   = remoteAdd.Split(':')[0];
                                        if (msgC.Contains("in use by " + ip))
                                        {
                                            isConnected = true;
                                        }
                                        else
                                        {
                                            if (msgC.Contains("not plugged"))
                                            {
                                                outMsg = "远程连接已经断开。。。。!";
                                            }
                                            isConnected = false;
                                        }
                                        Thread.Sleep(10 * 1000);
                                    }
                                    if (!isConnected)
                                    {
                                        resetDevice(1, outMsg);
                                        this.BeginInvoke(updateTxt, outMsg);
                                        this.Invoke((MethodInvoker)(() =>
                                        {
                                            this.btnTest.Visible = false;
                                            this.btnFinish.Visible = true;
                                            this.txtLabel.Text = outMsg;
                                        }));
                                        //XtraMessageBox.Show("本次远程连接已结束!", "结束", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                        //GoBack();
                                    }
                                }
                            }
                            else
                            {
                                resetDevice(30, "远程连接失败,请稍后再试!");
                                //XtraMessageBox.Show("远程连接失败,请稍后再试!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            }
                        }
                    }
                    else
                    {
                        resetDevice(30, "远程连接初始化失败,请重新接入设备再试!");
                        //XtraMessageBox.Show("远程连接初始化失败,请重新接入设备再试!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            });
        }