コード例 #1
0
        /// <summary>
        /// readMessages is the "run" method of this class. It reads all incomming messages
        /// and publishes them to registered ICANListeners.
        /// </summary>
        public void readMessages()
        {
            byte[] msg = new byte[8];
            int    dlc;
            int    flag, id;
            long   time;

            Canlib.canStatus status;
            CANMessage       canMessage = new CANMessage();

            logger.Debug("readMessages started");
            while (true)
            {
                lock (m_synchObject)
                {
                    if (m_endThread)
                    {
                        logger.Debug("readMessages thread ended");
                        return;
                    }
                }
                status = Canlib.canReadWait(handleRead, out id, msg, out dlc, out flag, out time, 250);
                if ((flag & Canlib.canMSG_ERROR_FRAME) == 0)
                {
                    if (status == Canlib.canStatus.canOK)
                    {
                        if (acceptMessageId((uint)id))
                        {
                            canMessage.setID((uint)id);
                            canMessage.setTimeStamp((uint)time);
                            canMessage.setFlags((byte)flag);
                            canMessage.setCanData(msg, (byte)dlc);

                            receivedMessage(canMessage);
                        }
                    }
                    else if (status == Canlib.canStatus.canERR_NOMSG)
                    {
                        Thread.Sleep(1);
                    }
                    else
                    {
                        logger.Debug("error" + status);
                    }
                }
                else
                {
                    logger.Debug("error frame");
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// readMessages is the "run" method of this class. It reads all incomming messages
        /// and publishes them to registered ICANListeners.
        /// </summary>
        public void readMessages()
        {
            uint       id;
            int        numMsgs    = 1;
            const int  timeout    = 1000;
            CANMessage canMessage = new CANMessage();

            logger.Debug("readMessages started");
            while (true)
            {
                lock (m_synchObject)
                {
                    if (m_endThread)
                    {
                        logger.Debug("readMessages thread ended");
                        return;
                    }
                }
                IntPtr rxMsgs = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(PassThruMsg)));
                m_status = passThru.PassThruReadMsgs(m_channelId, rxMsgs, ref numMsgs, timeout);
                if (m_status == J2534Err.STATUS_NOERROR)
                {
                    if (numMsgs > 0)
                    {
                        PassThruMsg msg = rxMsgs.AsMsgList(numMsgs)[0];

                        byte[] all = msg.GetBytes();
                        id = (uint)(all[2] * 0x100 + all[3]);
                        uint   length = msg.DataSize - 4;
                        byte[] data   = new byte[length];
                        Array.Copy(all, 4, data, 0, length);

                        if (acceptMessageId(id))
                        {
                            canMessage.setID(id);
                            canMessage.setTimeStamp(msg.Timestamp);
                            canMessage.setCanData(data, (byte)(length));

                            receivedMessage(canMessage);
                        }
                    }
                }
                else
                {
                    logger.Debug(String.Format("PassThruReadMsgs, status:{0}", m_status));
                }
                Marshal.FreeHGlobal(rxMsgs);
            }
        }
コード例 #3
0
        /// <summary>
        /// readMessages is the "run" method of this class. It reads all incomming messages
        /// and publishes them to registered ICANListeners.
        /// </summary>
        public void readMessages()
        {
            int readResult = 0;

            Lawicel.CANUSB.CANMsg r_canMsg   = new Lawicel.CANUSB.CANMsg();
            CANMessage            canMessage = new CANMessage();

            Console.WriteLine("readMessages started");
            while (true)
            {
                lock (m_synchObject)
                {
                    if (m_endThread)
                    {
                        Console.WriteLine("readMessages ended");
                        return;
                    }
                }
                readResult = Lawicel.CANUSB.canusb_Read(m_deviceHandle, out r_canMsg);
                if (readResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
                {
                    if (acceptMessageId(r_canMsg.id))
                    {
                        canMessage.setID(r_canMsg.id);
                        canMessage.setLength(r_canMsg.len);
                        canMessage.setTimeStamp(r_canMsg.timestamp);
                        canMessage.setFlags(r_canMsg.flags);
                        canMessage.setData(r_canMsg.data);
                        lock (m_listeners)
                        {
                            AddToCanTrace(string.Format("RX: {0} {1}", canMessage.getID().ToString("X3"), canMessage.getData().ToString("X16")));
                            foreach (ICANListener listener in m_listeners)
                            {
                                listener.handleMessage(canMessage);
                            }
                        }
                    }
                }
                else if (readResult == Lawicel.CANUSB.ERROR_CANUSB_NO_MESSAGE)
                {
                    Thread.Sleep(1);
                }
            }
        }
コード例 #4
0
ファイル: CANUSBDevice.cs プロジェクト: tomyqg/Trionic
        /// <summary>
        /// readMessages is the "run" method of this class. It reads all incomming messages
        /// and publishes them to registered ICANListeners.
        /// </summary>
        public void readMessages()
        {
            int readResult = 0;

            Lawicel.CANUSB.CANMsg r_canMsg   = new Lawicel.CANUSB.CANMsg();
            CANMessage            canMessage = new CANMessage();

            logger.Debug("readMessages started");
            while (true)
            {
                lock (m_synchObject)
                {
                    if (m_endThread)
                    {
                        logger.Debug("readMessages thread ended");
                        return;
                    }
                }
                readResult = Lawicel.CANUSB.canusb_Read(m_deviceHandle, out r_canMsg);
                if (readResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
                {
                    if (acceptMessageId(r_canMsg.id))
                    {
                        canMessage.setID(r_canMsg.id);
                        canMessage.setLength(r_canMsg.len);
                        canMessage.setTimeStamp(r_canMsg.timestamp);
                        canMessage.setFlags(r_canMsg.flags);
                        canMessage.setData(r_canMsg.data);

                        receivedMessage(canMessage);
                    }
                }
                else if (readResult == Lawicel.CANUSB.ERROR_CANUSB_NO_MESSAGE)
                {
                    Thread.Sleep(1);
                }
            }
        }
コード例 #5
0
ファイル: EasySyncUSBDevice.cs プロジェクト: josla972/Trionic
        /// <summary>
        /// readMessages is the "run" method of this class. It reads all incomming messages
        /// and publishes them to registered ICANListeners.
        /// </summary>
        public void readMessages()
        {
            int readResult = 0;

            EASYSYNC.CANMsg r_canMsg   = new EASYSYNC.CANMsg();
            CANMessage      canMessage = new CANMessage();

            while (true)
            {
                lock (m_synchObject)
                {
                    if (m_endThread)
                    {
                        return;
                    }
                }
                readResult = EASYSYNC.canusb_Read(m_deviceHandle, out r_canMsg);
                if (readResult == EASYSYNC.ERROR_CANUSB_OK)
                {
                    canMessage.setID(r_canMsg.id);
                    canMessage.setLength(r_canMsg.len);
                    canMessage.setTimeStamp(r_canMsg.timestamp);
                    canMessage.setFlags(r_canMsg.flags);
                    canMessage.setData(r_canMsg.data);
                    lock (m_listeners)
                    {
                        foreach (ICANListener listener in m_listeners)
                        {
                            listener.handleMessage(canMessage);
                        }
                    }
                }
                else if (readResult == EASYSYNC.ERROR_CANUSB_NO_MESSAGE)
                {
                    Thread.Sleep(1);
                }
            }
        }
コード例 #6
0
ファイル: CANUSBDevice.cs プロジェクト: josla972/Trionic
 /// <summary>
 /// readMessages is the "run" method of this class. It reads all incomming messages
 /// and publishes them to registered ICANListeners.
 /// </summary>
 public void readMessages()
 {
     int readResult = 0;
     Lawicel.CANUSB.CANMsg r_canMsg = new Lawicel.CANUSB.CANMsg();
     CANMessage canMessage = new CANMessage();
     Console.WriteLine("readMessages started");
     while (true)
     {
         lock (m_synchObject)
         {
             if (m_endThread)
             {
                 Console.WriteLine("readMessages ended");
                 return;
             }
         }
         readResult = Lawicel.CANUSB.canusb_Read(m_deviceHandle, out r_canMsg);
         if (readResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
         {
             if (acceptMessageId(r_canMsg.id))
             {
                 canMessage.setID(r_canMsg.id);
                 canMessage.setLength(r_canMsg.len);
                 canMessage.setTimeStamp(r_canMsg.timestamp);
                 canMessage.setFlags(r_canMsg.flags);
                 canMessage.setData(r_canMsg.data);
                 lock (m_listeners)
                 {
                     AddToCanTrace(string.Format("RX: {0} {1}", canMessage.getID().ToString("X3"), canMessage.getData().ToString("X16")));
                     foreach (ICANListener listener in m_listeners)
                     {
                         listener.handleMessage(canMessage);
                     }
                 }
             }
         }
         else if (readResult == Lawicel.CANUSB.ERROR_CANUSB_NO_MESSAGE)
         {
             Thread.Sleep(1);
         }
     }
 }
コード例 #7
0
ファイル: CANUSBDevice.cs プロジェクト: ChrisPea/Trionic
        /// <summary>
        /// readMessages is the "run" method of this class. It reads all incomming messages
        /// and publishes them to registered ICANListeners.
        /// </summary>
        public void readMessages()
        {
            int readResult = 0;
            Lawicel.CANUSB.CANMsg r_canMsg = new Lawicel.CANUSB.CANMsg();
            CANMessage canMessage = new CANMessage();
            logger.Debug("readMessages started");
            while (true)
            {
                lock (m_synchObject)
                {
                    if (m_endThread)
                    {
                        logger.Debug("readMessages thread ended");
                        return;
                    }
                }
                readResult = Lawicel.CANUSB.canusb_Read(m_deviceHandle, out r_canMsg);
                if (readResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
                {
                    if (acceptMessageId(r_canMsg.id))
                    {
                        canMessage.setID(r_canMsg.id);
                        canMessage.setLength(r_canMsg.len);
                        canMessage.setTimeStamp(r_canMsg.timestamp);
                        canMessage.setFlags(r_canMsg.flags);
                        canMessage.setData(r_canMsg.data);

                        receivedMessage(canMessage);
                    }
                }
                else if (readResult == Lawicel.CANUSB.ERROR_CANUSB_NO_MESSAGE)
                {
                    Thread.Sleep(1);
                }
            }
        }
コード例 #8
0
ファイル: EasySyncUSBDevice.cs プロジェクト: josla972/Trionic
 /// <summary>
 /// readMessages is the "run" method of this class. It reads all incomming messages
 /// and publishes them to registered ICANListeners.
 /// </summary>
 public void readMessages()
 {
     int readResult = 0;
     EASYSYNC.CANMsg r_canMsg = new EASYSYNC.CANMsg();
     CANMessage canMessage = new CANMessage();
     while (true)
     {
         lock (m_synchObject)
         {
             if (m_endThread)
                 return;
         }
         readResult = EASYSYNC.canusb_Read(m_deviceHandle, out r_canMsg);
         if (readResult == EASYSYNC.ERROR_CANUSB_OK)
         {
             canMessage.setID(r_canMsg.id);
             canMessage.setLength(r_canMsg.len);
             canMessage.setTimeStamp(r_canMsg.timestamp);
             canMessage.setFlags(r_canMsg.flags);
             canMessage.setData(r_canMsg.data);
             lock (m_listeners)
             {
                 foreach (ICANListener listener in m_listeners)
                 {
                     listener.handleMessage(canMessage);
                 }
             }
         }
         else if (readResult == EASYSYNC.ERROR_CANUSB_NO_MESSAGE)
         {
             Thread.Sleep(1);
         }
     }
 }