private void WindowsOperate_Closing(object sender, System.ComponentModel.CancelEventArgs e) { if (selectSlave.state == "busy") { mode = "operate"; wsOperate = new WebSocket("ws://" + server + "/mode=" + mode); wsOperate.OnMessage += (s, ee) => { var recData = JsonConvert.DeserializeObject <BasicData>(ee.Data); }; wsOperate.OnClose += (s, ee) => { // AppendLog("服务器通讯结束!"); }; wsOperate.Connect(); selectSlave.state = "free"; var data = new StopData { id = account_id, slave = selectSlave, experiment = selectExperiment }; wsOperate.Send(JsonConvert.SerializeObject(data)); } }
private void BtnStop_Click(object sender, RoutedEventArgs e) { Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new Action(() => { GridModbus.IsEnabled = false; BtnStop.IsEnabled = false; BtnStart.IsEnabled = true; BtnDownload.IsEnabled = true; })); mode = "operate"; wsOperate = new WebSocket("ws://" + server + "/mode=" + mode); wsOperate.OnMessage += (s, ee) => { var recData = JsonConvert.DeserializeObject <BasicData>(ee.Data); if (recData.code == "404") { AppendLog("关闭" + recData.mes); } else { AppendLog("错误代码:" + recData.code + ",错误信息:" + recData.mes); } }; wsOperate.OnClose += (s, ee) => { // AppendLog("服务器通讯结束!"); }; wsOperate.Connect(); selectSlave.state = "free"; var data = new StopData { id = account_id, slave = selectSlave, experiment = selectExperiment }; wsOperate.Send(JsonConvert.SerializeObject(data)); }