Beispiel #1
0
        static void _port_MessageReceived2(object sender, MonoSerialPort.MessageReceivedEventArgs args)
        {
            //string data = ByteArrayToHexString(args.Data);
            //System.Console.WriteLine("Reply:-> {0}", System.Text.Encoding.Default.GetString(args.Data));
            //System.Console.WriteLine("Reply:-> {0}", BitConverter.ToString(args.Data));


            int offset = 0;

            while (true)
            {
                int newlineIndex = Array.IndexOf(args.Data, Delimiter, offset);
                if (newlineIndex < offset)
                {
                    leftover = ConcatArray(leftover, args.Data, offset, args.Data.Length - offset);
                    return;
                }

                ++newlineIndex;
                byte[] full_line = ConcatArray(leftover, args.Data, offset, newlineIndex - offset);
                leftover = null;
                offset   = newlineIndex;
                //LineReceived?.Invoke(full_line); // raise an event for further processing
                System.Console.WriteLine("Reply:-> {0}", BitConverter.ToString(full_line));
            }
        }
        static void _port_MessageReceived2(object sender, MonoSerialPort.MessageReceivedEventArgs args)
        {
            //string data = ByteArrayToHexString(args.Data);
            //System.Console.WriteLine("Reply:-> {0}", System.Text.Encoding.Default.GetString(args.Data));
            //System.Console.WriteLine("Reply:-> {0}", BitConverter.ToString(args.Data));
            int offset = 0;
            //while (true)
            {
                ////int newlineIndex = Array.IndexOf(args.Data, Delimiter, offset);
                ////if (newlineIndex < offset)
                ////{
                ////    leftover = ConcatArray(leftover, args.Data, offset, args.Data.Length - offset);
                ////    return;
                ////}

                ////++newlineIndex;
                ////byte[] full_line = ConcatArray(leftover, args.Data, offset, newlineIndex - offset);
                ////leftover = null;
                ////offset = newlineIndex;
                //////LineReceived?.Invoke(full_line); // raise an event for further processing
                ////System.Console.WriteLine("Reply:-> {0}", BitConverter.ToString(full_line));


                //concatena array finchè byte 0 e byte 1 non sono uguali a 43 e 54 e la lunghennza non è > 4
                leftover = ConcatArray(leftover, args.Data, offset, args.Data.Length);
                if (leftover.Length < 4)
                {
                    return;
                }

                //riposta da client?
                if (leftover[0] == Head0 && leftover[1] == Head1)
                {
                    //calcola lunghezza frame
                    UInt16 length = BitConverter.ToUInt16(new byte[2] {
                        leftover[3], leftover[2]
                    }, 0);
                    if (leftover.Length - 4 >= length)
                    {   //manageframe
                        completeFrame = new byte[length + 4];
                        Array.Copy(leftover, 0, completeFrame, 0, length + 4);
                        //System.Console.WriteLine("manageframe:-> {0}", BitConverter.ToString(completeFrame));
                        leftover = leftover.Skip(length + 4).ToArray();
                        RfidEnetCustomReply reply = new RfidEnetCustomReply(completeFrame);

                        if (reply.Status)
                        {
                            switch (reply.Command)
                            {
                            case 0x80:
                                //pressed button
                                Console.WriteLine("pressed button {0}", reply.Payload[0]);
                                break;

                            case 0x45:
                                System.Console.WriteLine("TAG {0}", BitConverter.ToString(reply.Payload));
                                //ISO18000TAG tag = new ISO18000TAG(e.DataStream);
                                //if (tag.Status == 0x01 && tag.Command == 0x01)
                                //{
                                //    _rfidService.EnqueueTag(tag.Payload);
                                //}
                                break;

                            case 0x81:
                                Console.WriteLine("Cleared");
                                break;

                            case 0x82:
                                Console.WriteLine("LCD Stopped");
                                break;

                            case 0x84:
                                Console.WriteLine("Printed screen");
                                break;

                            default:
                                System.Console.WriteLine("to discover:-> {0}", BitConverter.ToString(leftover));
                                break;
                            }
                        }
                    }
                    else
                    {
                        System.Console.WriteLine("reply:-> {0}", BitConverter.ToString(leftover));
                    }
                }

                //i 2 byte sono la lunghezza del frame da leggere
                //int newlineIndex = Array.IndexOf(args.Data, new byte[2] { 0x43, 0x54 }, offset);
                //poi legge tanti byte quanti la lunghezza e compone il frame
            }
        }
 static void _port_MessageReceived(object sender, MonoSerialPort.MessageReceivedEventArgs args)
 {
     System.Console.WriteLine("Reply:-> {0}", BitConverter.ToString(args.Data));
 }
Beispiel #4
0
 /// <summary>
 /// Raises the message received event.
 /// </summary>
 /// <param name="args">Arguments.</param>
 protected virtual void OnMessageReceived(MessageReceivedEventArgs args)
 {
     MessageReceived?.Invoke(this, args);
 }
Beispiel #5
0
 private static void _port_MessageReceived(object sender, MonoSerialPort.MessageReceivedEventArgs args)
 {
     System.Console.WriteLine("Reply:-> {0}", Encoding.ASCII.GetString(args.Data));
 }