Ejemplo n.º 1
0
        /// <summary>
        /// Send a KWP request.
        /// </summary>
        /// <param name="a_request">A KWP request.</param>
        /// <param name="r_reply">A KWP reply.</param>
        /// <returns>The status of the request.</returns>
        public RequestResult sendRequest(KWPRequest a_request, out KWPReply r_reply)
        {
            CANMessage msg = new CANMessage(0x240, 0, 8);
            uint       row = nrOfRowsToSend(a_request.getData());

            // Send one or several request messages.
            for (; row > 0; row--)
            {
                msg.setData(createCanMessage(a_request.getData(), row - 1));
                if (!m_canDevice.sendMessage(msg))
                {
                    r_reply = new KWPReply();
                    return(RequestResult.ErrorSending);
                }
            }
            msg = m_kwpCanListener.waitForMessage(0x258, timeoutPeriod);
            // Receive one or several replys and send an ack for each reply.
            if (msg.getID() == 0x258)
            {
                uint nrOfRows = (uint)(msg.getCanData(0) & 0x3F) + 1;
                row = 0;
                if (nrOfRows == 0)
                {
                    throw new Exception("Wrong nr of rows");
                }
                //Assume that no KWP reply contains more than 0x200 bytes
                byte[] reply = new byte[0x200];
                reply = collectReply(reply, msg.getData(), row);
                sendAck(nrOfRows - 1);
                nrOfRows--;
                while (nrOfRows > 0)
                {
                    msg = m_kwpCanListener.waitForMessage(0x258, timeoutPeriod);
                    if (msg.getID() == 0x258)
                    {
                        row++;
                        reply = collectReply(reply, msg.getData(), row);
                        sendAck(nrOfRows - 1);
                        nrOfRows--;
                    }
                    else
                    {
                        r_reply = new KWPReply();
                        return(RequestResult.Timeout);
                    }
                }
                r_reply = new KWPReply(reply, a_request.getNrOfPID());
                return(RequestResult.NoError);
            }
            else
            {
                r_reply = new KWPReply();
                return(RequestResult.Timeout);
            }
        }
Ejemplo n.º 2
0
 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();
         }
     }
 }
Ejemplo n.º 3
0
 override public 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();
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// sendMessage send a CANMessage.
        /// </summary>
        /// <param name="a_message">A CANMessage.</param>
        /// <returns>true on success, othewise false.</returns>
        override public 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");
            AddToCanTrace("Sending message: " + msg.id.ToString("X4") + " " + msg.data.ToString("X16"));
            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);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Send a KWP request.
        /// </summary>
        /// <param name="a_request">A KWP request.</param>
        /// <param name="r_reply">A KWP reply.</param>
        /// <returns>The status of the request.</returns>
        public RequestResult sendRequest(KWPRequest a_request, out KWPReply r_reply)
        {
            CANMessage msg = new CANMessage(0x240, 0, 8);
            uint row = nrOfRowsToSend(a_request.getData());
            // Send one or several request messages.
            for (; row > 0; row--)
            {
                msg.setData(createCanMessage(a_request.getData(), row - 1));
                if (!m_canDevice.sendMessage(msg))
                {
                    r_reply = new KWPReply();
                    return RequestResult.ErrorSending;
                }
            }
            msg = m_kwpCanListener.waitForMessage(0x258, timeoutPeriod);
            // Receive one or several replys and send an ack for each reply.
            if (msg.getID() == 0x258)
            {
                uint nrOfRows = (uint)(msg.getCanData(0) & 0x3F)+ 1;
                row = 0;
                if (nrOfRows == 0)
                    throw new Exception("Wrong nr of rows");
                //Assume that no KWP reply contains more than 0x200 bytes
                byte[] reply = new byte[0x200];
                reply = collectReply(reply, msg.getData(), row);
                sendAck(nrOfRows - 1);
                nrOfRows--;
                while (nrOfRows > 0)
                {
                    msg = m_kwpCanListener.waitForMessage(0x258, timeoutPeriod);
                    if (msg.getID() == 0x258)
                    {
                        row++;
                        reply = collectReply(reply, msg.getData(), row);
                        sendAck(nrOfRows - 1);
                        nrOfRows--;
                    }
                    else
                    {
                        r_reply = new KWPReply();
                        return RequestResult.Timeout;
                    }

                }
                r_reply = new KWPReply(reply, a_request.getNrOfPID());
                return RequestResult.NoError;
            }
            else
            {
                r_reply = new KWPReply();
                return RequestResult.Timeout;
            }
        }
Ejemplo n.º 6
0
 /// <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");
     AddToCanTrace("Sending message: " + msg.id.ToString("X4") + " " + msg.data.ToString("X16"));
     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;
     }
 }