Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
            }
        }
Ejemplo n.º 4
0
 public void ExecuteReceivedDataHandler(Packet package, SenderSocket receiveSocket)
 {
     DataReceivedHandler?.Invoke(package, receiveSocket);
 }