protected override void DataReceived(object sender, SerialDataReceivedEventArgs e) { try { var port = sender as SerialPort; while (port.BytesToRead > 0) { var d = port.ReadLine(); if (d.Equals("OK\r", StringComparison.InvariantCultureIgnoreCase)) { if (TargetPose != null) { CurrentPose = TargetPose; TargetPose = null; } } DataReceivedHandler?.Invoke(d); } } finally { lock (Syncroot) { IsIdel = true; } } }
protected void BeginReceiving(Socket socket) { while (socket.Connected()) { try { int dataLenght = BitConverter.ToInt32(socket.Receive(4), 0); byte[] data = socket.Receive(dataLenght); DataReceived?.Invoke(socket, data); } catch (ObjectDisposedException) { break; } catch (SocketException) { break; } } Disconnected(socket); }
private void MonitorIncomingData() { bool incomingData = false; EventHandler <TcpDataReceivedEventArgs> DataReceivedHandler; while (MonitoringThreadActive) //Loop forever { DataReceivedHandler = DataReceived; if (DataReceivedHandler != null) { if (!incomingData) { if (TcpStream.DataAvailable) { lock (LockHandler) { incomingData = true; byte[] data = ReadRawBytes(); if (data.Length > 0) { DataReceivedHandler.Invoke(this, new TcpDataReceivedEventArgs() { Data = data }); } } } } else { if (!TcpStream.DataAvailable) { incomingData = false; } } } Thread.Sleep(50); } }
public void ExecuteReceivedDataHandler(Packet package, SenderSocket receiveSocket) { DataReceivedHandler?.Invoke(package, receiveSocket); }