Esempio n. 1
0
        ////////////////////////////////////////////////////////////////////////////////////////////////////

        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            if (!Connected)
            {
                return;
            }

            // Show all the incoming data in the port's buffer
            string message = m_port.ReadLine();

            if (message == "")
            {
                return;
            }

            if (message[message.Length - 1] == '\r')
            {
                message = message.Substring(0, message.Length - 1);
            }

            if (message != "")
            {
                onMessageReceived?.Invoke(this, new ArduinoEventArgs(message));
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Method responsible for execute the callback of message received from client in server.
 /// </summary>
 /// <param name="client">The connected client.</param>
 /// <param name="kingBuffer">The king buffer received from message.</param>
 private void OnMessageReceived(IClient client, IKingBufferReader reader)
 {
     try
     {
         if (reader.Length > 0 && _serverPacketHandlers.Count > 0 && _serverPacketHandlers.TryGetValue(reader.ReadByte(), out var serverHandler))
         {
             serverHandler(client, reader);
         }
         else
         {
             OnMessageReceivedHandler?.Invoke(client, reader);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}.");
     }
 }