private void button1_Click(object sender, EventArgs e) //连接ABB机器人socket { if (ConnectABBflag == true) { ShowABBflagOK = true; ShowABBflagNO = true; if (ABBClientConnectInforStr != NetConnected) { CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] Connect to robot ABB ..." + "\r\n")); IPEndPoint remoteEP = new IPEndPoint(System.Net.IPAddress.Parse(ABBRemoteIPAddress), int.Parse(ABBRemotePort)); ABBClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ABBClientSocket.ReceiveBufferSize = 2000; ABBClientSocket.SendBufferSize = 2000; ABBClientSocket.SendTimeout = 4; ABBClientSocket.BeginConnect(remoteEP, new AsyncCallback(ABBClientConnectCallback), ABBClientSocket); CommunicationMsg.AppendText("aaaaa1\n"); //字符戳,是有执行到这一步的 if (ABBClientConnectInforStr != NetConnected) { IPEndPoint clientipe = (IPEndPoint)ABBClientSocket.LocalEndPoint; CommunicationMsg.AppendText("aaaaa"); } } } else { if (ABBClientSocket != null) { ABBClientSocket.Close(); ABBClientSocket.Dispose(); ConnectABB.ForeColor = Color.Red; CommunicationMsg.AppendText(System.Convert.ToString("Disconnect to robot ABB" + "\r\n")); } ABBClientConnectInforStr = NetDisConnected; } }
async void UpdateNotification(object sender, CommunicationMsg msg) { if (msg.Id != DeviceResponseType.BPCONCHEC || msg.Id != DeviceResponseType.BPCONMSG) { string[] res = msg.Msg.Split('>'); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { BtnConnect.IsEnabled = true; switch (msg.Id) { case DeviceResponseType.BPCONMSG: TxtConnectionstatus.Text = res[1].Split(':')[1]; // BtnGlucoResult.IsEnabled = true; break; case DeviceResponseType.BPCONCHEC: // "BPCONCTED>M:{0}>T:{1}"; if (res[1].Split(':')[1].ToLower().Equals("true")) { TxtConnectionstatus.Text = "Connected: " + msg.Msg.Split('>')[2]; } else { TxtConnectionstatus.Text = "BP Monitor is Not Connected. Please connect. "; } // BtnGlucoResult.IsEnabled = true; break; } }); } }
private void ExecuteDeletePendingMsgCommand(CommunicationMsg deleteMsg) { var MessageCollection = ConnectionHelper.DB.GetCollection <MessageEntity>("MessageEntity"); var FindMessageQuery = Query <MessageEntity> .EQ(m => m.Id, new ObjectId(deleteMsg.Id)); MessageCollection.Remove(FindMessageQuery); this.Messages.Remove(deleteMsg); }
private void UpdateSendMessage(SendingMsgResult result, ICommunicationMsgInfo communicationMsg, MongoCollection <MessageEntity> msgCollection, string strContent, string strSendMsgId) { var FindMsgQuery = Query <MessageEntity> .EQ(m => m.Id, new ObjectId(strSendMsgId)); if (200 == result.Status) { CommunicationMsg SentMsg = communicationMsg as CommunicationMsg; try { var RecentSuccessMsg = this.Messages.OfType <CommunicationMsg>().Last(m => m.MsgStatus != MsgStatus.Failed && m.MsgStatus != MsgStatus.Sending); Application.Current.Dispatcher.Invoke(() => { this.Messages.Remove(SentMsg); int nIndexOfRecentSuccessdMsg = this.Messages.IndexOf(RecentSuccessMsg); this.Messages.Insert(nIndexOfRecentSuccessdMsg + 1, SentMsg); }); } catch (InvalidOperationException) { //If you cannot find RecentSuccessMsg Application.Current.Dispatcher.Invoke(() => { this.Messages.Remove(SentMsg); this.Messages.Insert(0, SentMsg); }); } communicationMsg.MsgStatus = MsgStatus.Sent; communicationMsg.SendTime = result.SentTime; var UpdateMsgQuery = Update <MessageEntity> .Set(m => m.State, (int)MsgStatus.Sent) .Set(m => m.SendTime, result.SentTime) .Set(m => m.Sid, result.MsgSid); msgCollection.Update(FindMsgQuery, UpdateMsgQuery); this.m_RoomsController.UpdateLastMsg(this.RoomSID, strContent, result.SentTime); } else { communicationMsg.MsgStatus = MsgStatus.Failed; var UpdateMsgQuery = Update <MessageEntity> .Set(m => m.State, (int)MsgStatus.Failed); msgCollection.Update(FindMsgQuery, UpdateMsgQuery); } }
async void UpdateNotification(object sender, CommunicationMsg msg) { if (msg.Id != DeviceResponseType.PULSEOXIMETERSTATUS) { return; } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { switch (msg.Id) { case DeviceResponseType.PULSEOXIMETERSTATUS: BtnStreamdata.IsEnabled = true; TxtSpiroMeterConnectionStatus.Text = msg.Msg.Split('>')[1]; break; } }); }
async void UpdateNotification(object sender, CommunicationMsg msg) { if (msg.Id != DeviceResponseType.GLUCORESULTSTATUS) { return; } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { switch (msg.Id) { case DeviceResponseType.GLUCORESULTSTATUS: TxtGlucoTestStatus.Text = msg.Msg.Split('>')[1]; BtnGlucoResult.IsEnabled = true; break; } }); }
async void UpdateNotification(object sender, CommunicationMsg msg) { if (msg.Id != DeviceResponseType.THERMORESTULTSTATUS) { return; } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { BtnCMD.IsEnabled = true; switch (msg.Id) { case DeviceResponseType.THERMORESTULTSTATUS: TxtConnectionstatus.Text = msg.Msg.Split('>')[1]; break; } }); }
private void ExecuteReSendCommand(CommunicationMsg resendMsg) { Task.Run(() => { var MessageCollection = ConnectionHelper.DB.GetCollection <MessageEntity>("MessageEntity"); var RoomCollection = ConnectionHelper.DB.GetCollection <RoomEntity>("RoomEntity"); var FindRoomQuery = Query <RoomEntity> .EQ(r => r.Sid, this.RoomSID); var FindedRoom = RoomCollection.FindOne(FindRoomQuery); if (null != FindedRoom) { resendMsg.MsgStatus = MsgStatus.Sending; var ActiveMemberSids = FindedRoom.ActiveMemberSids; ActiveMemberSids.Remove(AuthRepository.MQKeyInfo.UserSid); SendingMsg WillSendMsg = new SendingMsg(ActiveMemberSids, resendMsg.RoomSid, (int)resendMsg.ContentType, resendMsg.Content, AuthRepository.MQKeyInfo.UserSid, resendMsg); var Result = this.m_SendMessageService.SendMessage(WillSendMsg); this.UpdateSendMessage(Result, resendMsg, MessageCollection, resendMsg.Content, resendMsg.Id.ToString()); } }); }
private void TimerNetMonitor_Tick(object sender, EventArgs e) { TextBox1.Text = System.Convert.ToString(PlateCheck) + System.Convert.ToString(finishMoveFlag); if (CommunicationMsg.Lines.Length > 50) { textLast1 = CommunicationMsg.Text[49]; textLast2 = CommunicationMsg.Text[50]; textLast3 = CommunicationMsg.Text[51]; CommunicationMsg.Text = ""; CommunicationMsg.AppendText(textLast1 + "\r\n"); CommunicationMsg.AppendText(textLast2 + "\r\n"); CommunicationMsg.AppendText(textLast3 + "\r\n"); } if (ConnectABBflag == true) { lock (ABBClientSyncObject) { if (ABBClientConnectInforStr != NetConnected) { if (ABBClientSocket != null) { ABBClientSocket.Close(); ABBClientSocket.Dispose(); } IPEndPoint remoteEP = new IPEndPoint(System.Net.IPAddress.Parse(ABBRemoteIPAddress), int.Parse(ABBRemotePort)); ABBClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); ABBClientSocket.ReceiveBufferSize = 2000; ABBClientSocket.SendBufferSize = 2000; ABBClientSocket.SendTimeout = 4; ABBClientSocket.BeginConnect(remoteEP, new AsyncCallback(ABBClientConnectCallback), ABBClientSocket); } else { byte[] byteData = Encoding.ASCII.GetBytes("OK" + "\r\n"); try { //Begin sending the data to the remote device.StockIsOK ABBClientSocket.BeginSend(byteData, 0, byteData.Length, (System.Net.Sockets.SocketFlags) 0, new AsyncCallback(ABBClientSendCallback), ABBClientSocket); } catch (Exception) { ABBClientConnectInforStr = NetError; } } } if (PlateCheck == true && finishMoveFlag == true) { byte[] byteData = Encoding.ASCII.GetBytes("PlateIsOK" + "\r\n"); try { //Begin sending the data to the remote device.StockIsOK TextBoxInfo.Text = TextBoxInfo.Text + "SendToABBOnce" + "\r\n"; ABBClientSocket.BeginSend(byteData, 0, byteData.Length, (System.Net.Sockets.SocketFlags) 0, new AsyncCallback(ABBClientSendCallback), ABBClientSocket); } catch (Exception) { ABBClientConnectInforStr = NetError; } PlateCheck = false; // finishMoveFlag = False } if (ABBClientConnectInforStr == NetConnected) { ConnectABB.ForeColor = Color.Green; if (ShowABBflagOK == true) { CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] Connect to robot ABB successly" + "\r\n")); ShowABBflagOK = false; ShowABBflagNO = true; } } else { ConnectABB.ForeColor = Color.Red; if (ShowABBflagNO == true) { CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] Wait for robot ABB connection" + "\r\n")); ShowABBflagNO = false; ShowABBflagOK = true; } } } }
private void ABBShowInfoSub(string Info) { CogToolBlock myToolBlock; CogToolBlock myRunToolblock3; //= myToolBlock.Tools("MyToolBlock3") // static string SaveInfo = ""; //VBConversions Note: Static variable moved to class level and renamed ABBShowInfoSub_SaveInfo. Local static variables are not supported in C#. if (ABBShowInfoSub_SaveInfo != Info) { TextBoxInfo.Text = Info + "\r\n" + TextBoxInfo.Text; } ABBShowInfoSub_SaveInfo = Info; if (Info == "WorkpieceArrived") { CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] From robot ABB : " + "\r\n")); CommunicationMsg.AppendText(System.Convert.ToString("Workpiece arrived target position" + "\r\n")); } else if (Info == "StartPlateMove") { finishMoveFlag = false; startMoveFlag = true; CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] From robot ABB : " + "\r\n")); CommunicationMsg.AppendText(System.Convert.ToString("Start move platform ..." + "\r\n")); } //下面开始的代码就会闪退 else if (Info == "TriggerCam") { TriggerCamNum++; //本身定义为0,+1代表可以执行拍照了 CommunicationMsg.AppendText(System.Convert.ToString("[" + Strings.Format(DateTime.Now, "hh:mm:ss") + "] From robot ABB : " + "\r\n")); CommunicationMsg.AppendText(System.Convert.ToString("Robot ABB camera trigger " + Conversion.Str(TriggerCamNum) + "\r\n")); CogToolGroup myTG = (CogToolGroup)myJob.VisionTool; myToolBlock = (CogToolBlock)myTG.Tools["AcquireImageAndProcessLeft"]; myRunToolblock3 = (CogToolBlock)myToolBlock.Tools["MyToolBlock3"]; if (TriggerCamNum == 1) { myRunToolblock3.Inputs["TriggerCamNum"].Value = 0; } else { myRunToolblock3.Inputs["TriggerCamNum"].Value = 1; TriggerCamNum = 0; } } // try // { // ModuleCard.d1000_out_bit((short)10, (short)0); // System.Threading.Thread.Sleep(50); // int num = 0; // myRunToolblock3.Inputs["Input2dImage"].Value = AcqFifoTool4.Operator.Acquire(out num); //应该是获取图像 // myRunToolblock3.Run(); //这个myruntoolblock3是一个模块,和外部的拍照组件链接(确信) // } // catch (Exception) // { // MessageBox.Show("error"); // } //} //判断定位是否正确 //ABB_Result = System.Convert.ToString(myRunToolblock3.Outputs["ABB_Result"].Value); //这里是怎么判断的呢????? //if (ABB_Result == "OK") //{ // if (ABBClientConnectInforStr == NetConnected) // { // byte[] byteData = Encoding.ASCII.GetBytes("WorkpieceLocationOK" + "\r\n"); // try // { // //Begin sending the data to the remote device.StockIsOK // ABBClientSocket.BeginSend(byteData, 0, byteData.Length, (System.Net.Sockets.SocketFlags)0, new AsyncCallback(ABBClientSendCallback), ABBClientSocket); // } // catch (Exception) // { // ABBClientConnectInforStr = NetError; // } // } //} //else //{ // if (ABBClientConnectInforStr == NetConnected) // { // byte[] byteData = Encoding.ASCII.GetBytes("WorkpieceLocationNO" + "\r\n"); // try // { // //Begin sending the data to the remote device.StockIsOK // ABBClientSocket.BeginSend(byteData, 0, byteData.Length, (System.Net.Sockets.SocketFlags)0, new AsyncCallback(ABBClientSendCallback), ABBClientSocket); // } // catch (Exception) // { // ABBClientConnectInforStr = NetError; // } // } //} //} //else if (Info == "IsPlateOK") //{ // PlateCheck = true; //} //else //{ // //CommunicationMsg.AppendText(Info + vbCrLf) //} }
private void CommChannel_MessageReceived(object sender, CommunicationMsg msg) { switch (msg.Msg.ToLower()) { case "<mccs>": case "<smcc>": commChannel.SendMessageToMCC(CommunicationCommands.SBCConnectionResponseCmd); break; case "<p1d>": // StartDeviceCommand("<P1D>"); break; case "<p1ds>": // StopTimer(); break; case "<pulsestart>": MainPage.TestresultModel.oxymeter.Connect(); break; case "<glucmd>": // TestresultModel.GlucoCMDUtitlity.LatestTestResult(); GlucoCMDUtitlity.LatestTestResult(); break; case "<thermocmd>": //< THERMOCMD > MainPage.TestresultModel.Thermo.Connect(); break; case "<bpcmd>": //BPCMD TestresultModel.bpcuff?.Connect(); break; case "<bpconcmd>": //<BPCONCMD> string res = string.Format(CommunicationCommands.BPCONNECTIONTIME, TestresultModel.IsBpConnected.ToString(), TestresultModel.BpCuffConnectionTime); commChannel.SendMessageToMCC(res); break; case "<appc>": // DataacqAppComm.SendMessageToDataacquistionapp(CommunicationCommands.DATAACQSTATUS); break; case "<apps>": IsDatacquistionappconnected = true; // DataacqAppComm.SendMessageToDataacquistionapp(CommunicationCommands.DATAACQSTATUS); break; case "<startdermo>": // if( IsDatacquistionappconnected) { StartDermascope(); } break; case "<stopdermo>": // if (IsDatacquistionappconnected) { StopDermascope(); } break; case "<startoto>": // if (IsDatacquistionappconnected) { StartOtosope(); } break; case "<stopoto>": // if (IsDatacquistionappconnected) { StopOtoscope(); } break; case "<pic>": // if (IsDatacquistionappconnected) { TakePic(); } break; case "<startstchecst>": StartStethoscope?.Invoke(); break; case "<otosaveimage>": { SaveImage(); } break; case "<dersaveimage>": { SaveImage(true); } break; case "<startspirofvc>": case "<startspirovc>": case "<stopspiro>": { MainPage.mainPage.DataacqAppComm.SendMessageToDataacquistionapp(msg.Msg); } break; } if (msg.Msg.ToLower().Contains("stpic>") || msg.Msg.ToLower().Contains("drpic>") || msg.Msg.ToLower().Contains("mrpic>") || msg.Msg.ToLower().Contains("mrexp>") || msg.Msg.ToLower().Contains("imagesaved>")) { commChannel.SendMessageToMCC(msg.Msg); } }
private void CommChannel_ErrorMessage(object sender, CommunicationMsg e) { }
async void UpdateNotification(object sender, CommunicationMsg msg) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { string[] res = msg.Msg.Split('>'); switch (msg.Id) { case DeviceResponseType.PULSEOXIMETERRESULT: ShowHidePulseoximeterdata(true); BtnPulseoximeter.Background = new SolidColorBrush(Windows.UI.Colors.LightSeaGreen); TxtResultPulseOximeter.Text = res[1].Split(':')[1]; TxtResultPulseOximeterpulse.Text = res[2].Split(':')[1]; TxtResultPulseOximeterpulsedate.Text = res[4]; break; case DeviceResponseType.GLUCORESULT: ShowHideglucodata(true); BtnGlucometer.Background = new SolidColorBrush(Windows.UI.Colors.LightSeaGreen); //"GLUCMDRES>V:{0}>U:{1}>T:{2}>M:{3}>D:{4}>T:{5}"; TxtResultgluco.Text = res[1].Split(':')[1] + " " + res[2].Split(':')[1]; TxtTestType.Text = res[3].Split(':')[1]; TxtResultglucoTestMode.Text = res[4].Split(':')[1]; TxtDate.Text = res[5].Split(':')[1]; TxtTime.Text = res[7]; break; case DeviceResponseType.THERMORESTULT: { if (res[2].Split(':')[1].ToLower().Contains("object")) { return; } BtnThermoMeter.Background = new SolidColorBrush(Windows.UI.Colors.LightSeaGreen); tempresultreceived = true; //"THERMORES>R:{0}>M:{1}>S:{2}>DT:{3}" string tempformat = "{0}°{1}"; decimal Conversion = Convert.ToDecimal(res[1].Split(':')[1]); tempResult = Conversion; if (MainPage.mainPage.mainpagecontext.ThermometerUnitF) { Conversion = decimal.Round((Conversion * (decimal)1.8), 1) + 32; } else { Conversion = decimal.Round(Conversion, 1); } if (Convert.ToBoolean(res[3].Split(':')[1])) { /// TxtTemprature.Text = string.Format(tempformat, Conversion.ToString(), TxtTmpUnitbtn.IsOn ? TxtTmpUnitbtn.OnContent : TxtTmpUnitbtn.OffContent); TxtTemprature.Text = string.Format(tempformat, Conversion.ToString(), MainPage.mainPage.mainpagecontext.ThermometerUnitF ? "F" : "C"); } else { TxtTemprature.Text = "Error: Lo"; } TxtMode.Text = res[2].Split(':')[1]; // "THERMORES>R:{0}>M:{1}>S:{2}>{3}"; TxtDateTime.Text = res[4]; } break; case DeviceResponseType.BPRES: ShowHidebpdata(true); BtnBP.Background = new SolidColorBrush(Windows.UI.Colors.LightSeaGreen); // "BPRES>D:{0}>S:{1}>P:{2}>DT:{3}>T:{4}"; TxtSys.Text = res[2].Split(':')[1]; TxtDia.Text = res[1].Split(':')[1]; TxtPulse.Text = res[3].Split(':')[1]; // TxttestTime.Text = res[4].Split(':')[1] + " " + res[5]; break; } }); }
private void SMCCommChannel_MessageReceived(object sender, CommunicationMsg msg) { string[] cmd = msg.Msg.ToLower().Split('>'); switch (cmd[0]) { case "<smcr": mainpagecontext.IsSMCConnected = true; break; case "<smpulr": break; case "pulseres": mainpagecontext.NotifyResult?.Invoke(this, new CommunicationMsg(DeviceResponseType.PULSEOXIMETERRESULT, msg.Msg.ToLower())); break; case "pulsestatus": mainpagecontext.NotifyResult?.Invoke(this, new CommunicationMsg(DeviceResponseType.PULSEOXIMETERSTATUS, msg.Msg.ToLower())); break; case "glucmdres": mainpagecontext.NotifyResult?.Invoke(this, new CommunicationMsg(DeviceResponseType.GLUCORESULT, msg.Msg.ToLower())); break; case "glucoresultresstatus": mainpagecontext.NotifyResult?.Invoke(this, new CommunicationMsg(DeviceResponseType.GLUCORESULTSTATUS, msg.Msg.ToLower())); break; case "thermores": mainpagecontext.NotifyResult?.Invoke(this, new CommunicationMsg(DeviceResponseType.THERMORESTULT, msg.Msg)); break; case "thermocon": mainpagecontext.NotifyResult?.Invoke(this, new CommunicationMsg(DeviceResponseType.THERMORESTULTSTATUS, msg.Msg.ToLower())); break; case "bpres": mainpagecontext.NotifyResult?.Invoke(this, new CommunicationMsg(DeviceResponseType.BPRES, msg.Msg)); break; case "bpconected": //BPCONECTED mainpagecontext.NotifyResult?.Invoke(this, new CommunicationMsg(DeviceResponseType.BPCONCHEC, msg.Msg)); break; case "bpconn": //BPCONN BPCONECTED>M:False>T: mainpagecontext.NotifyResult?.Invoke(this, new CommunicationMsg(DeviceResponseType.BPCONMSG, msg.Msg)); break; case "streadey": StethoscopeNotification?.Invoke(msg.Msg.ToLower().Split('>')[1]); if (msg.Msg.ToLower().Split('>')[1].Contains(("Ready for streaming at").ToLower())) { isStethoscopeReadystreaming = true; StethoscopeStartStop?.Invoke("Ready", 1); } break; case "stmsg": StethoscopeNotification?.Invoke(msg.Msg.ToLower().Split('>')[1]); if (msg.Msg.ToLower().Split('>')[1].Contains(("streaming stopped").ToLower())) { isStethoscopeReadystreaming = false; } break; case "stpic": // ImageDisplay?.Invoke(msg.Msg); break; case "derpic": // ImageDisplay?.Invoke(msg.Msg); break; case "mrpic": ImageDisplay?.Invoke(msg.Msg); break; case "mrexp": UpdateNotification(cmd[1], 0); // ImageDisplay?.Invoke(msg.Msg); break; case "<imagesaved": ImageDisplay?.Invoke("imagesaved"); UpdateNotification("Image Saved.", 0); break; case "connectedmcc": isDataAcquitionappConnected = true; DQConnectionCallback?.Invoke(true); break; case "spirofvc": isDataAcquitionappConnected = true; SPirotResults?.Invoke(msg.Msg); break; case "spirovc": isDataAcquitionappConnected = true; SPirotResults?.Invoke(msg.Msg); break; case "spirofvcvt": isDataAcquitionappConnected = true; SPirotResults?.Invoke(msg.Msg); break; case "spirostatussucess": case "stoppedspirometer": isDataAcquitionappConnected = true; SPirotResults?.Invoke(msg.Msg); break; case "spirostatusfailed": isDataAcquitionappConnected = true; SPirotResults?.Invoke(msg.Msg); break; case "spirovcresult": case "spirofvcresult": isDataAcquitionappConnected = true; SPirotResults?.Invoke(msg.Msg); break; } }