private void ServerThread() { while (true) { string text; using (var server = new NamedPipeServerStream(_UID)) { server.WaitForConnection(); using (StreamReader reader = new StreamReader(server)) { text = reader.ReadToEnd(); } } if (text == EXIT_STRING) { break; } ReceiveString?.Invoke(text); if (_isRunning == false) { break; } } }
void GenericEvent(ReceiveString func, string msg) { if (func != null) { func.Invoke(msg); } }
public async Task ExecuteOnClient() { ReceiveString rs = new ReceiveString(new ReceiveBytes(Transport)); string ser = await rs.AwaitFlowResult(); using (StringReader sr = new StringReader(ser)) { using (JsonReader jr = new JsonTextReader(sr)) { Result = Serializer.Deserialize <T>(jr); } } }
public void GetInfo() { if (!IsGetNewData) { return; } if (string.IsNullOrEmpty(ReceiveString)) { return; } if (ReceiveString.Length < 24) { TengDa.LogHelper.WriteError("测试仪传输的数据异常:" + ReceiveString); return; } this.Resistance = TengDa._Convert.StrToFloat(ReceiveString.Substring(6, 5), 0); this.Voltage = Current.Option.ConstVoltage; this.TimeSpan = Current.Option.ConstTimeSpan; if (this.Resistance == 0) { this.Resistance = 999; } InsulationData.Resistance = this.Resistance; InsulationData.Voltage = this.Voltage; InsulationData.TimeSpan = this.TimeSpan; this.RealtimeStatus = string.Format("获得电阻:{0}", Resistance); this.CollectorIsReadyCollect = true; Current.ShowResistanceData.Add(this.Resistance); Current.ShowResistanceData.RemoveAt(0); Current.AnimatedPlot(); IsGetNewData = false; var t = new Thread(() => { Thread.Sleep(1000); this.RealtimeStatus = "等待数据"; }); t.IsBackground = true; t.Start(); }
/// <summary> /// Returns the message recieved and spawns a new server disposing of the previous backgroundworker /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { string result = e.Result as string; if (result != EXIT_STRING) { StartServer(); //If not exit then start a new server instance ReceiveString?.Invoke(result); //Send signal we've received a new file to open } //Dispose background worker BackgroundWorker bw = (sender as BackgroundWorker); bw.RunWorkerCompleted -= Bw_RunWorkerCompleted; bw.DoWork -= Bw_DoWork; Task.Run(() => bw.Dispose()); }
public async Task ExecuteOnClient() { ReceiveString rs = new ReceiveString(new ReceiveBytes(Transport)); string ser = await rs.AwaitFlowResult(); NetworkSelectionResult result; using (StringReader sr = new StringReader(ser)) { using (JsonReader jr = new JsonTextReader(sr)) { result = Serializer.Deserialize <NetworkSelectionResult>(jr); result.FileSystem = FileSystem; result.Serializer = Serializer; result.Transport = Transport; Result = result.AsSelectionResult(); } } }
/// <summary> /// ComCallBack /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <returns></returns> public static void ComCallBack(object sender, SerialDataReceivedEventArgs e) { int x = 15, y = 17, len = 46; if (sender != null) { SerialPort sp = (SerialPort)sender; string InData = sp.ReadExisting(); ReceiveString += InData; } ReceiveString = ReceiveString.Replace("\r", "*").Replace("\n", "*").Replace("\t", "*"); if (ReceiveString.Length > len - 3) { ReceiveString = ReceiveString.Substring(ReceiveString.Length - (len - 3)); } ScreenOutput(x, y + 0, "+-- Receive Buffer ---------------------------+"); ScreenOutput(x, y + 1, "|"); ScreenOutput(x + len, y + 1, "|"); ScreenOutput(x, y + 2, "|"); ScreenOutput(x + 2, y + 2, ReceiveString); ScreenOutput(x + len, y + 2, "|"); ScreenOutput(x, y + 3, "|"); ScreenOutput(x + len, y + 3, "|"); ScreenOutput(x, y + 4, "+---------------------------------------------+"); }
public static void receive() { byte[] Receivebyte = new byte[2000]; // Receive data by this array to save. string ReceiveString; int ReceivedataLength; while (true) { try { m_Socket.Receive(Receivebyte); ReceiveString = Encoding.Default.GetString(Receivebyte); ReceivedataLength = Encoding.Default.GetByteCount(ReceiveString.ToString()); _header ack = new _header(); ack.Deserialize(Receivebyte); switch ((Protocol)ack.protocolID) { case Protocol.PROTOCOL_JOIN_ACK: S_PROTOCOL_JOIN_ACK join_ack = new S_PROTOCOL_JOIN_ACK(); join_ack.Deserialize(Receivebyte); Communicator.I().cb.Enqueue(ack); Communicator.I().cb.Enqueue(join_ack); break; case Protocol.PROTOCOL_LOGIN_ACK: S_PROTOCOL_LOGIN_ACK login_ack = new S_PROTOCOL_LOGIN_ACK(); login_ack.Deserialize(Receivebyte); Communicator.I().cb.Enqueue(ack); Communicator.I().cb.Enqueue(login_ack); break; } } catch (SocketException err) { Debug.Log("Socket send or receive error! : " + err.ToString()); } } }
public async Task ExecuteOnClient() { ReceiveString rs = new ReceiveString(new ReceiveBytes(Transport)); string ser = await rs.AwaitFlowResult(); IEnumerable <NetworkClientEntry> entries; using (StringReader sr = new StringReader(ser)) { using (JsonReader jr = new JsonTextReader(sr)) { entries = Serializer.Deserialize <NetworkClientEntry[]>(jr).Where(x => x != null); } } NetworkClientCollection ncc = Root as NetworkClientCollection; //Parallel.ForEach(entries, nce => { // nce.ParentSetup(ncc); //}); foreach (var nce in entries) { nce.ParentSetup(ncc); } Result = entries.ToArray(); }
private void OnReceiveString(string text) => ReceiveString?.Invoke(text);
/// <summary> /// Called when data is received. /// </summary> /// <param name="text"></param> protected virtual void OnReceiveString(string text) => ReceiveString?.Invoke(text);
private void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { ReceiveString?.Invoke(e.UserState as string); }