private void disconnectDevice() { string result = ""; string cmd = @"usbrcd.exe -disconnect " + usbPort; CmdHelper.RunCmd(cmd, out result); List <string> msgList = GetResult(result); if (msgList.Count > 0) { if (msgList[0] == "USB device disconnected") { resetOperator(); this.BeginInvoke(updateTxt, "远程连接已经断开。。。。"); } } }
/// <summary> /// status:0:服务未启动,1:无设备连接,2:设备等待连接,3:无效设备等待连接,4:设备已连接,5:连接中断 /// </summary> /// <returns></returns> private int CheckDevice() { string result = ""; int rtn = 0; string cmd = @"usbrcd.exe -list"; CmdHelper.RunCmd(cmd, out result); if (result.Length == 0) { rtn = 0; } else { List <string> msglist = GetResult(result); if (msglist.Count == 2) { rtn = 1; } else if (msglist.Count == 8) { if (msglist[2].Contains("callback connection") && msglist[7].Contains("available for connection")) { usbPort = getUsbPort(msglist); connectedSN = getDeviceSN(msglist); if (waitedSN != "" && waitedSN == connectedSN) { rtn = 2; } else { rtn = 3; } } else if (msglist[2].Contains("callback connection") && msglist[7].Contains("connected")) { rtn = 4; } } else { rtn = 5; } } return(rtn); }
private void autoStart() { try { string result = ""; string cmd = @"usbrcd.exe -list"; CmdHelper.RunCmd(cmd, out result); //先检查服务是否启动 if (result.Length == 0) { operatorStatus = 0; this.BeginInvoke(updateTxt, "本机远程服务未启动。。。"); XtraMessageBox.Show("本机远程服务未启动", "错误", MessageBoxButtons.OK, MessageBoxIcon.Stop); //txtOutput.AppendText("远程服务未启动\r\n"); } else { Task.Factory.StartNew(() => { this.btnOnline.Enabled = false; operatorStatus = 1; //上线中 this.BeginInvoke(updateTxt, "上线中。。。。"); msgTimer.Enabled = true; }).ContinueWith(x => { msgTick(); }); //if (jsonMsg == "") //{ // msgTimer.Enabled = true; // string haha = ""; //} //else //{ // operatorStatus = 2; // this.BeginInvoke(updateTxt, "远程设备信息已接收,等待远程设备接入。。。。"); //} } }catch (Exception ex) { LogHelper.WriteLog(ex.ToString()); } }
private void simpleButton1_Click(object sender, EventArgs e) { string result = ""; string cmd = @"usbrcd.exe -list"; CmdHelper.RunCmd(cmd, out result); if (result.Length == 0) { this.BeginInvoke(updateTxt, "本机远程服务未启动。。。"); //txtOutput.AppendText("远程服务未启动\r\n"); } else { string msg = GetResultString(result); List <string> msglist = GetResult(result); this.BeginInvoke(updateTxt, msg); //txtOutput.AppendText(msg + "\r\n"); } }
private void connectRemoteDevice() { string result = ""; string cmd = @"usbrcd.exe -connect " + usbPort; CmdHelper.RunCmd(cmd, out result); List <string> msgList = GetResult(result); if (msgList[0] == "USB device connected") { operatorStatus = 3; this.btnConnect.Enabled = false; this.btnDisconnect.Enabled = true; this.BeginInvoke(updateTxt, "远程设备连接成功。。。。"); checkCOM(Patient.w_deviceSN); DataProcess dp = new DataProcess(); int orderType = dp.getTL(Patient.w_code); startTest(orderType); //1检测,2理疗 } else { LogHelper.WriteLog(usbPort + "----" + msgList[0]); } }
private void msgTick() { try { if (operatorStatus == 1) { jsonMsg = getRemoteDevice(); if (jsonMsg == "调度服务出错") { this.BeginInvoke(updateTxt, "调度服务出错。。。。"); } else { if (jsonMsg != "") { RemoteJson rj = JsonConvert.DeserializeObject <RemoteJson>(jsonMsg); waitedSN = rj.deviceSN; Patient.w_birth_day = rj.patientDOB; Patient.w_code = rj.verifyCode; Patient.w_location = FromBase64(rj.patientLocation); Patient.w_name = FromBase64(rj.patientName); Patient.w_sex = rj.patientSex; Patient.w_username = rj.userName; Patient.w_deviceSN = rj.deviceSN; Patient.w_deviceCode = FromBase64(rj.deviceName); operatorStatus = 2; this.BeginInvoke(updateTxt, "远程设备信息已接收,等待远程设备" + waitedSN + "接入。。。。"); deviceTimer.Enabled = true; msgTimer.Enabled = false; dtTimeOut = DateTime.Now.AddMinutes(3); string result = ""; string cmd = @"usbrcd.exe -list"; CmdHelper.RunCmd(cmd, out result); List <string> msglist = GetResult(result); if (msglist.Count == 8) { if (msglist[2].Contains("callback connection") && msglist[7].Contains("available for connection")) { usbPort = getUsbPort(msglist); connectedSN = getDeviceSN(msglist); if (waitedSN != "" && waitedSN == connectedSN) { this.btnConnect.Enabled = true; this.BeginInvoke(updateTxt, "远程设备已接入,可以连接。。。"); connectRemoteDevice(); } } } } else { this.BeginInvoke(updateTxt, "已上线,等待远程设备信息。。。。"); } } } }catch (Exception ex) { LogHelper.WriteLog(ex.ToString()); } }