示例#1
0
        /// <summary>
        /// Handles incomming messages and sends acknowledges back
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Port_MessageReceived(object sender, SerialMessageData e)
        {
            string msg;

            lock (locker)
            {
                msg = Encoding.ASCII.GetString(e.Message);
#if DEBUG
                //foreach (byte b in e.Message)
                //{
                //    Console.WriteLine(b);
                //}
                Console.WriteLine($"Received {msg}");
                //foreach (byte b in Encoding.ASCII.GetBytes($"ACK:{msg}"))
                //{
                //    Console.WriteLine(b);
                //}
                Console.WriteLine($"Trying to send {ReturnCommandList.acknowledge}{msg}");
#endif
                port.Write(Encoding.ASCII.GetBytes($"{ReturnCommandList.acknowledge}{msg}"));


                //signalWatchdog?.Invoke(msg);
            }
            messageEvent.Invoke(this, new MessageEventArgs(msg));
        }
示例#2
0
        private void Port_MessageReceived(object sender, SerialMessageData e)
        {
            string msg = Encoding.UTF8.GetString(e.Message);

            foreach (byte b in msg)
            {
                Console.WriteLine(b);
            }
            Console.WriteLine(msg);
            display.ClearLines();
            display.Write(msg);
            onboardLed.SetColor(Color.Red);             //So i knew it was receiving data before I connected display
            Thread.Sleep(500);
            onboardLed.SetColor(Color.Blue);
            port.Write(Encoding.UTF8.GetBytes($"Received and acknowledging! Msg: {msg}"));  //There is small issue that messages contain LF at the end and it's sent back too
                                                                                            //but nah, in target use it won't matter
        }