Ejemplo n.º 1
0
        private void ReadMessages()
        {
            while (true)
            {
                try
                {
                    var message = JsonConvert.DeserializeObject <Message>(_reader.ReadString());
                    ReadQueue.Add(message);

                    if (string.Equals(message.MessageType, "TestHost.Acknowledge"))
                    {
                        _ackWaitHandle.Set();
                        ReadQueue.CompleteAdding();
                        break;
                    }
                }
                catch (Exception ex)
                {
                    TestHostTracing.Source.TraceEvent(
                        TraceEventType.Error,
                        0,
                        "[ReportingChannel]: Waiting for message failed {0}",
                        ex);
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Data received handler.
        /// </summary>
        /// <param name="sender">[in]</param>
        /// <param name="args">[in]</param>
        private void SerialPortDataReceived(object sender, SerialDataReceivedEventArgs args)
        {
            var count = Port.BytesToRead;
            var bytes = new byte[count];

            Port.Read(bytes, 0, count);
            foreach (var data in bytes)
            {
                ReadQueue.Add(data);
            }
        }