コード例 #1
0
        /*        public CANMessage waitForMessage(uint a_canID, int a_timeout)
        {
            CANMessage retMsg;
            m_canMessage.setID(0);  // init so we cannot receive the same frame twice <GS-10022010>
            lock (m_canMessage)
            {
                m_waitMsgID = a_canID;
            }
            m_resetEvent.WaitOne(a_timeout, true);
            lock (m_canMessage)
            {
                retMsg = m_canMessage;
            }

            return retMsg;
        }
        */
        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());
                    m_resetEvent.Set();
                }
            }
        }
コード例 #2
0
ファイル: CANUSBDevice.cs プロジェクト: ChrisPea/TuningSuites
 /// <summary>
 /// sendMessage send a CANMessage.
 /// </summary>
 /// <param name="a_message">A CANMessage.</param>
 /// <returns>true on success, othewise false.</returns>
 public override bool sendMessage(CANMessage a_message)
 {
     LAWICEL.CANMsg msg = new LAWICEL.CANMsg();
     msg.id = a_message.getID();
     msg.len = a_message.getLength();
     msg.flags = a_message.getFlags();
     msg.data = a_message.getData();
     int writeResult;
     AddToCanTrace("Sending message");
     writeResult = LAWICEL.canusb_Write(m_deviceHandle, ref msg);
     if (writeResult == LAWICEL.ERROR_CANUSB_OK)
     {
         AddToCanTrace("Message sent successfully");
         return true;
     }
     else
     {
         switch (writeResult)
         {
             case LAWICEL.ERROR_CANUSB_COMMAND_SUBSYSTEM:
                 AddToCanTrace("Message failed to send: ERROR_CANUSB_COMMAND_SUBSYSTEM");
                 break;
             case LAWICEL.ERROR_CANUSB_INVALID_PARAM:
                 AddToCanTrace("Message failed to send: ERROR_CANUSB_INVALID_PARAM");
                 break;
             case LAWICEL.ERROR_CANUSB_NO_MESSAGE:
                 AddToCanTrace("Message failed to send: ERROR_CANUSB_NO_MESSAGE");
                 break;
             case LAWICEL.ERROR_CANUSB_NOT_OPEN:
                 AddToCanTrace("Message failed to send: ERROR_CANUSB_NOT_OPEN");
                 break;
             case LAWICEL.ERROR_CANUSB_OPEN_SUBSYSTEM:
                 AddToCanTrace("Message failed to send: ERROR_CANUSB_OPEN_SUBSYSTEM");
                 break;
             case LAWICEL.ERROR_CANUSB_TX_FIFO_FULL:
                 AddToCanTrace("Message failed to send: ERROR_CANUSB_TX_FIFO_FULL");
                 break;
             default:
                 AddToCanTrace("Message failed to send: " + writeResult.ToString());
                 break;
         }
         return false;
     }
 }