当前位置: 首页>>代码示例>>C#>>正文


C# CAN.CANMessage类代码示例

本文整理汇总了C#中TrionicCANLib.CAN.CANMessage的典型用法代码示例。如果您正苦于以下问题:C# CANMessage类的具体用法?C# CANMessage怎么用?C# CANMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CANMessage类属于TrionicCANLib.CAN命名空间,在下文中一共展示了CANMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: handleMessage

        public override void handleMessage(CANMessage a_message)
        {
            if (_queue == null)
            {
                _queue = new CANMessage[32];
                _receiveMessageIndex = 0;
                _readMessageIndex = 0;
            }

            // add the message to a queue for later processing ...
            // the queue is a ringbuffer for CANMessage objects.
            // X objects are supported
            // we need a receive and a read pointer for this to work properly
            messageReceived = false;
            //_queue[_receiveMessageIndex] = a_message;
            _queue[_receiveMessageIndex] = new CANMessage();
            _queue[_receiveMessageIndex].setData(a_message.getData());
            _queue[_receiveMessageIndex].setID(a_message.getID());
            _queue[_receiveMessageIndex].setLength(a_message.getLength());

            _receiveMessageIndex++;
            if(_receiveMessageIndex > _queue.Length - 1) _receiveMessageIndex = 0; // make it circular

            DetermineSize();
        }
开发者ID:ChrisPea,项目名称:Trionic,代码行数:25,代码来源:CANListener.cs

示例2: handleMessage

 public override void handleMessage(CANMessage a_message)
 {
     lock (m_canMessage)
     {
         if (a_message.getID() == m_waitMsgID)
         {
             m_canMessage.setData(a_message.getData());
             m_canMessage.setFlags(a_message.getFlags());
             m_canMessage.setID(a_message.getID());
             m_canMessage.setLength(a_message.getLength());
             m_canMessage.setTimeStamp(a_message.getTimeStamp());
             messageReceived = true;
             m_resetEvent.Set();
         }
     }
 }
开发者ID:ChrisPea,项目名称:Trionic,代码行数:16,代码来源:KWPCANListener.cs

示例3: handleMessage

        public override void handleMessage(CANMessage a_message)
        {
            if (_queue == null)
            {
                _queue = new CANMessage[16];
                _receiveMessageIndex = 0;
                _readMessageIndex = 0;
            }

            // add the message to a queue for later processing ...
            // the queue is a ringbuffer for CANMessage objects.
            // X objects are supported
            // we need a receive and a read pointer for this to work properly
            messageReceived = false;
            //_queue[_receiveMessageIndex] = a_message;
            _queue[_receiveMessageIndex] = new CANMessage();
            _queue[_receiveMessageIndex].setData(a_message.getData());
            _queue[_receiveMessageIndex].setID(a_message.getID());
            _queue[_receiveMessageIndex].setLength(a_message.getLength());

            _receiveMessageIndex++;
            if(_receiveMessageIndex > _queue.Length - 1) _receiveMessageIndex = 0; // make it circular

            //DetermineSize();

            /*
            lock (m_canMessage)
            {
                if (a_message.getID() == m_waitMsgID)
                {
                    m_canMessage = a_message;
                    messageReceived = true;
                }
            }
            if (messageReceived)
            {
                m_resetEvent.Set();
            }*/
        }
开发者ID:josla972,项目名称:Trionic,代码行数:39,代码来源:CANListener.cs

示例4: sendMessageDevice

 /// <summary>
 /// sendMessage send a CANMessage.
 /// </summary>
 /// <param name="a_message">A CANMessage.</param>
 /// <returns>true on success, othewise false.</returns>
 protected override bool sendMessageDevice(CANMessage a_message)
 {
     Lawicel.CANUSB.CANMsg msg = new Lawicel.CANUSB.CANMsg();
     msg.id = a_message.getID();
     msg.len = a_message.getLength();
     msg.flags = a_message.getFlags();
     msg.data = a_message.getData();
     int writeResult;
     writeResult = Lawicel.CANUSB.canusb_Write(m_deviceHandle, ref msg);
     if (writeResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
     {
         return true;
     }
     else
     {
         logger.Debug("tx failed writeResult: " + writeResult);
         return false;
     }
 }
开发者ID:ChrisPea,项目名称:Trionic,代码行数:24,代码来源:CANUSBDevice.cs

示例5: success

        //---------------------------------------------------------------------------------------------
        /**
        Sends a 11 bit CAN data frame.

        @param      msg         CAN message

        @return                 success (true/false)
        */
        public override bool sendMessage(CANMessage msg)
        {
            this.AddToCanTrace("Sending message: " + msg.getID().ToString("X4") + " " + msg.getData().ToString("X16") + " " + msg.getLength().ToString("X2"));

            try
            {
            Combi.caCombiAdapter.caCANFrame frame;
            frame.id = msg.getID();
            frame.length = msg.getLength();
            frame.data = msg.getData();
            frame.is_extended = 0;
            frame.is_remote = 0;

            this.combi.CAN_SendMessage(ref frame);

            this.AddToCanTrace("Message sent successfully");
            return true;
            }

            catch (Exception e)
            {
            this.AddToCanTrace("Message failed to send: " + e.Message);
            return false;
            }
        }
开发者ID:josla972,项目名称:Trionic,代码行数:33,代码来源:LPCCANDevice.cs

示例6: sendSessionRequest

        /// <summary>
        /// Send a message that starts a session. This is used to test if there is 
        /// a connection.
        /// </summary>
        /// <returns></returns>
        private bool sendSessionRequest()
        {
            CANMessage msg1 = new CANMessage(0x220, 0, 8);
            EASYSYNC.CANMsg msg = new EASYSYNC.CANMsg();
            msg1.setData(0x000040021100813f);

            if (!sendMessage(msg1))
                return false;
            if (waitForMessage(0x238, 1000, out msg) == 0x238)
            {
                //Ok, there seems to be a ECU somewhere out there.
                //Now, sleep for 10 seconds to get a session timeout. This is needed for
                //applications on higher level. Otherwise there will be no reply when the
                //higher level application tries to start a session.
                Thread.Sleep(10000);
                return true;
            }
            return false;
        }
开发者ID:josla972,项目名称:Trionic,代码行数:24,代码来源:EasySyncUSBDevice.cs

示例7: InformationFrameEventArgs

 public InformationFrameEventArgs(CANMessage message)
 {
     this._message = message;
 }
开发者ID:josla972,项目名称:Trionic,代码行数:4,代码来源:ICANDevice.cs

示例8: waitForMessage

 /// <summary>
 /// waitForMessage waits for a specific CAN message give by a CAN id.
 /// </summary>
 /// <param name="a_canID">The CAN id to listen for</param>
 /// <param name="timeout">Listen timeout</param>
 /// <param name="r_canMsg">The CAN message with a_canID that we where listening for.</param>
 /// <returns>The CAN id for the message we where listening for, otherwise 0.</returns>
 public override uint waitForMessage(uint a_canID, uint timeout, out CANMessage canMsg)
 {
     Lawicel.CANUSB.CANMsg r_canMsg;
     canMsg = new CANMessage();
     int readResult = 0;
     int nrOfWait = 0;
     while (nrOfWait < timeout)
     {
         r_canMsg = new Lawicel.CANUSB.CANMsg();
         readResult = Lawicel.CANUSB.canusb_Read(m_deviceHandle, out r_canMsg);
         if (readResult == Lawicel.CANUSB.ERROR_CANUSB_OK)
         {
             Thread.Sleep(1);
             AddToCanTrace("rx: 0x" + r_canMsg.id.ToString("X4") + r_canMsg.data.ToString("X16"));
             if (r_canMsg.id == 0x00)
             {
                 nrOfWait++;
             }
             else if (r_canMsg.id != a_canID)
                 continue;
             canMsg.setData(r_canMsg.data);
             canMsg.setID(r_canMsg.id);
             canMsg.setLength(r_canMsg.len);
             return (uint)r_canMsg.id;
         }
         else if (readResult == Lawicel.CANUSB.ERROR_CANUSB_NO_MESSAGE)
         {
             Thread.Sleep(1);
             nrOfWait++;
         }
     }
     r_canMsg = new Lawicel.CANUSB.CANMsg();
     return 0;
 }
开发者ID:josla972,项目名称:Trionic,代码行数:41,代码来源:CANUSBDevice.cs

示例9: waitMessage

        public CANMessage waitMessage(int a_timeout)
        {
            sw.Reset();
            sw.Start();
            CANMessage retMsg = new CANMessage();
            while (sw.ElapsedMilliseconds < a_timeout)
            {
                // search queue for the desired message
                if (_receiveMessageIndex < _readMessageIndex)
                {
                    // first upto (_queue.Length - 1)
                    for (int idx = _readMessageIndex; idx < _queue.Length; idx++)
                    {
                        if (_queue[idx].getID() == this.m_waitMsgID)
                        {
                            retMsg = _queue[idx];
                            _readMessageIndex = idx + 1;
                            if (_readMessageIndex > _queue.Length - 1) _readMessageIndex = 0; // make it circular

                            sw.Stop();
                            return retMsg;
                        }
                    }
                    for (int idx = 0; idx < _receiveMessageIndex; idx++)
                    {
                        if (_queue[idx].getID() == this.m_waitMsgID)
                        {
                            retMsg = _queue[idx];
                            _readMessageIndex = idx + 1;
                            if (_readMessageIndex > _queue.Length - 1) _readMessageIndex = 0; // make it circular
                            sw.Stop();
                            return retMsg;
                        }
                    }
                }
                else
                {
                    for (int idx = _readMessageIndex; idx < _receiveMessageIndex; idx++)
                    {
                        if (_queue[idx].getID() == this.m_waitMsgID)
                        {
                            retMsg = _queue[idx];
                            _readMessageIndex = idx + 1;
                            if (_readMessageIndex > _queue.Length - 1) _readMessageIndex = 0; // make it circular
                            sw.Stop();
                            return retMsg;
                        }
                    }
                }
                Thread.Sleep(1);
            }
            sw.Stop();
            return retMsg;

            /*
            CANMessage retMsg;

            m_resetEvent.WaitOne(a_timeout, true);
            lock (m_canMessage)
            {
                retMsg = m_canMessage;
            }
            messageReceived = false;
            return retMsg;*/
        }
开发者ID:josla972,项目名称:Trionic,代码行数:65,代码来源:CANListener.cs

示例10: waitAnyMessage

        /// <summary>
        /// waitAnyMessage waits for any message to be received.
        /// </summary>
        /// <param name="timeout">Listen timeout</param>
        /// <param name="r_canMsg">The CAN message that was first received</param>
        /// <returns>The CAN id for the message received, otherwise 0.</returns>
        private uint waitAnyMessage(uint timeout, out CANMessage canMessage)
        {
            canMessage = new CANMessage();
            Debug.Assert(canMessage != null);

            int wait_cnt = 0;
            uint id;
            byte length;
            ulong data;
            while (wait_cnt < timeout)
            {
            if (MctAdapter_ReceiveMessage(out id, out length, out data))
            {
                // message received
                canMessage.setID(id);
                canMessage.setLength(length);
                canMessage.setData(data);

                return id;
            }

            // wait a bit
            Thread.Sleep(1);
            ++wait_cnt;
            }

            // nothing was received
            return 0;
        }
开发者ID:josla972,项目名称:Trionic,代码行数:35,代码来源:MictronicsCanDevice.cs

示例11: readMessages

 /// <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);
         }
     }
 }
开发者ID:josla972,项目名称:Trionic,代码行数:46,代码来源:CANUSBDevice.cs

示例12: waitForMessage

        /// <summary>
        /// waitForMessage waits for a specific CAN message give by a CAN id.
        /// </summary>
        /// <param name="a_canID">The CAN id to listen for</param>
        /// <param name="timeout">Listen timeout</param>
        /// <param name="r_canMsg">The CAN message with a_canID that we where listening for.</param>
        /// <returns>The CAN id for the message we where listening for, otherwise 0.</returns>
        public override uint waitForMessage(uint a_canID, uint timeout, out CANMessage canMessage)
        {
            canMessage = new CANMessage();
            Debug.Assert(canMessage != null);

            int wait_cnt = 0;
            uint id;
            byte length;
            ulong data;
            while (wait_cnt < timeout)
            {
            if (MctAdapter_ReceiveMessage(out id, out length, out data))
            {
                // message received
                canMessage.setID(id);
                canMessage.setLength(length);
                canMessage.setData(data);

                if (canMessage.getID() != a_canID)
                    continue;
                return (uint)canMessage.getID();
            }

            // wait a bit
            Thread.Sleep(1);
            ++wait_cnt;
            }

            // nothing was received
            return 0;
        }
开发者ID:josla972,项目名称:Trionic,代码行数:38,代码来源:MictronicsCanDevice.cs

示例13: read_messages

        //-------------------------------------------------------------------------
        /**
        Handles incoming messages.
        */
        private void read_messages()
        {
            uint id;
            byte length;
            ulong data;

            CANMessage msg = new CANMessage();
            Debug.Assert(msg != null);

            // main loop
            while (true)
            {
            // check for thread termination request
            Debug.Assert(this.term_mutex != null);
            lock (this.term_mutex)
            {
                if (this.term_requested)
                {
                    return;
                }
            }

            // receive messages
            while (MctAdapter_ReceiveMessage(out id, out length, out data))
            {
                if (acceptMessageId(id))
                {
                    // convert message
                    msg.setID(id);
                    msg.setLength(length);
                    msg.setData(data);

                    // pass message to listeners
                    lock (this.m_listeners)
                    {
                        AddToCanTrace("RX: " + id.ToString("X4") + " " + data.ToString("X16"));
                        foreach (ICANListener listener in this.m_listeners)
                        {
                            listener.handleMessage(msg);
                        }
                    }
                }
            }

            // give up CPU for a moment
            Thread.Sleep(1);
            }
        }
开发者ID:josla972,项目名称:Trionic,代码行数:52,代码来源:MictronicsCanDevice.cs

示例14: success

        //-------------------------------------------------------------------------
        /**
        Sends a 11 bit CAN data frame.

        @param      message     CAN message

        @return                 success (true/false)
        */
        public override bool sendMessage(CANMessage message)
        {
            return MctAdapter_SendMessage(message.getID(), message.getLength(),
            message.getData());
        }
开发者ID:josla972,项目名称:Trionic,代码行数:13,代码来源:MictronicsCanDevice.cs

示例15: readMessages

 /// <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);
         }
     }
 }
开发者ID:josla972,项目名称:Trionic,代码行数:38,代码来源:EasySyncUSBDevice.cs


注:本文中的TrionicCANLib.CAN.CANMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。