Esempio n. 1
0
        void PortManager_NewSerialDataRecieved(object sender, SerialDataEventArgs received)
        {
            var data = received.Data;

            for (int i = 0; i < data.Length; i++)
            {
                var currentByte = data[i];

                if (currentIndex == 0 && IsFirstByteOfPacket(currentByte))
                {
                    // First package
                    currentPackage[currentIndex] = currentByte;
                    currentIndex++;
                }
                else if (currentIndex > 0 && !IsFirstByteOfPacket(currentByte))
                {
                    // Next package
                    currentPackage[currentIndex] = currentByte;
                    currentIndex++;
                }
                else if (currentIndex > 0 && IsFirstByteOfPacket(currentByte))
                {
                    // Bad package
                    currentIndex = 0;
                    //Console.WriteLine("Bad Packet");
                }

                if (currentIndex == 5)
                {
                    currentIndex = 0;

                    // Submit package
                    var info = new PulseNotification(currentPackage);
                    OnInfoReceived?.Invoke(this, info);
                }
            }
        }
Esempio n. 2
0
 public RPCThread(string serverName, int serverPort, OnInfoReceived onInfoReceived)
 {
     _serverName = serverName;
     _serverPort = serverPort;
     _onInfoReceived = onInfoReceived;
 }
Esempio n. 3
0
 public RPCThread(string serverName, int serverPort, OnInfoReceived onInfoReceived)
 {
     _serverName     = serverName;
     _serverPort     = serverPort;
     _onInfoReceived = onInfoReceived;
 }