Beispiel #1
0
 public CommandHandler(CANInterface canInterface, TransportLayer transportLayer, Serial serial)
 {
     this.canInterface   = canInterface;
     this.transportLayer = transportLayer;
     this.serial         = serial;
     logger = LogManager.GetCurrentClassLogger();
 }
Beispiel #2
0
 public CANInterface(TransportLayer transportLayer, Serial serial)
 {
     this.transportLayer = transportLayer;
     //this.queProvider = queProvider;
     this.serial = serial;
     threadSerialPacketReader = new Thread(ReadSerialPackets);
     threadSerialPacketReader.Start();
 }
Beispiel #3
0
        public Serial(GlobalData globalData, TransportLayer transportLayer)
        {
            this.globalData        = globalData;
            this.transportLayer    = transportLayer;
            serialPort             = new SerialPortInput();
            responseQueue          = new BlockingCollection <CANPacket>();
            eventQueue             = new BlockingCollection <CANPacket>();
            responseTimer          = new System.Timers.Timer(100);
            eventTimer             = new System.Timers.Timer(100);
            responseTimer.Elapsed += new ElapsedEventHandler(responseTimer_Elapsed);
            eventTimer.Elapsed    += new ElapsedEventHandler(eventTimer_Elapsed);

            eventTimer.Start();
            responseTimer.Start();

            serialPort.ConnectionStatusChanged += (obj, args) =>
            {
                if (args.Connected)
                {
                    transportLayer.setPacketCollectorStaus(PacketCollectorStates.STATE_STX_1);
                    globalData.showSuccess("Data Com", "Serial Connected.(" + globalData.serialPort + ")");
                }
                else
                {
                    transportLayer.close();
                    globalData.showError("Data Com", "Serial Disconnect.");
                    globalData.serialPort = null;
                }
            };

            serialPort.MessageReceived += (obj, args) =>
            {
                for (int i = 0; i < args.Data.Length; i++)
                {
                    transportLayer.PacketDecoder(args.Data[i]);
                }
                //logger.Info("Received data from serial port message: {0}", BitConverter.ToString(args.Data));
            };
            responseTimer.Start();
        }