Пример #1
0
        //-------------------------------------------------------------------------

        /**
         *  Sends a 11 bit CAN data frame.
         *
         *  @param      msg         CAN message
         *
         *  @return                 success (true/false)
         */
        public override bool sendMessage(CANMessage msg)
        {
            if (this.logging_enabled)
            {
                this.DumpCanMsg(msg, true);
            }

            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);
                return(true);
            }

            catch (Exception e)
            {
                return(false);
            }
        }
Пример #2
0
        //-------------------------------------------------------------------------

        /**
         *  Writes a CAN message to log file.
         *
         *  @param      r_canMsg        message
         *  @param      IsTransmit      ???
         */
        private void DumpCanMsg(CANMessage r_canMsg, bool IsTransmit)
        {
            DateTime dt = DateTime.Now;

            try
            {
                using (StreamWriter sw = new StreamWriter(Path.Combine(this.startup_path,
                                                                       dt.Year.ToString("D4") + dt.Month.ToString("D2") +
                                                                       dt.Day.ToString("D2") + "-CanTrace.log"), true))
                {
                    if (IsTransmit)
                    {
                        // get the byte transmitted
                        int transmitvalue = (int)(r_canMsg.getData() & 0x000000000000FF00);
                        transmitvalue /= 256;

                        sw.WriteLine(dt.ToString("dd/MM/yyyy HH:mm:ss") +
                                     " TX: id=" + r_canMsg.getID().ToString("D2") +
                                     " len= " + r_canMsg.getLength().ToString("X8") +
                                     " data=" + r_canMsg.getData().ToString("X16") +
                                     " " + r_canMsg.getFlags().ToString("X2") +
                                     " character = " + GetCharString(transmitvalue) +
                                     "\t ts: " + r_canMsg.getTimeStamp().ToString("X16") +
                                     " flags: " + r_canMsg.getFlags().ToString("X2"));
                    }
                    else
                    {
                        // get the byte received
                        int receivevalue = (int)(r_canMsg.getData() & 0x0000000000FF0000);
                        receivevalue /= (256 * 256);
                        sw.WriteLine(dt.ToString("dd/MM/yyyy HH:mm:ss") +
                                     " RX: id=" + r_canMsg.getID().ToString("D2") +
                                     " len= " + r_canMsg.getLength().ToString("X8") +
                                     " data=" + r_canMsg.getData().ToString("X16") +
                                     " " + r_canMsg.getFlags().ToString("X2") +
                                     " character = " + GetCharString(receivevalue) +
                                     "\t ts: " + r_canMsg.getTimeStamp().ToString("X16") +
                                     " flags: " + r_canMsg.getFlags().ToString("X2"));
                    }
                }
            }
            catch (Exception E)
            {
                Console.WriteLine("Failed to write to logfile: " + E.Message);
            }
        }
Пример #3
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();
            if (m_DoLogging)
            {
                DumpCanMsg(msg, true);
            }
            if (m_port.IsOpen)
            {
                m_port.Write("\r");
                string txstring = "t";
                txstring += msg.id.ToString("X3");
                txstring += "8"; // always 8 bytes to transmit
                for (int t = 0; t < 8; t++)
                {
                    byte b = (byte)(((msg.data >> t * 8) & 0x0000000000000000FF));
                    txstring += b.ToString("X2");
                }
                txstring += "\r";
                m_port.Write(txstring);
//                Console.WriteLine("Send: " + txstring);
                return(true);
            }
            return(false);

            /*
             * int writeResult;
             * writeResult = LAWICEL.canusb_Write(m_deviceHandle, ref msg);
             * if (writeResult == LAWICEL.ERROR_CANUSB_OK)
             *  return true;
             * else
             *  return false;
             */
        }
Пример #4
0
/*      public CANMessage waitForMessage(uint a_canID, int a_timeout)
 *      {
 *          CANMessage retMsg;
 *          lock (m_canMessage)
 *          {
 *              m_waitMsgID = a_canID;
 *          }
 *          m_resetEvent.WaitOne(a_timeout, false);
 *          lock (m_canMessage)
 *          {
 *              retMsg = m_canMessage;
 *          }
 *
 *          return retMsg;
 *      }
 */

        private void CheckRxMessage()
        {
            ulong data = m_canMessage.getData();

            if ((data & 0x00000000000000FF) == 0xA6)
            {
                // yes, write to designated file, 7 bytes at a time
                if (File.Exists(@"c:\dump.bin"))
                {
                    FileStream fs = new FileStream(@"c:\dump.bin", FileMode.Append);
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        for (int i = 1; i < 8; i++)
                        {
                            byte b = (byte)((ulong)(data >> i * 8) & 0x00000000000000FF);
                            bw.Write(b);
                        }
                    }
                    fs.Close();
                    fs.Dispose();
                }
                else
                {
                    FileStream fs = new FileStream(@"c:\dump.bin", FileMode.Create);
                    using (BinaryWriter bw = new BinaryWriter(fs))
                    {
                        for (int i = 1; i < 8; i++)
                        {
                            byte b = (byte)((ulong)(data >> i * 8) & 0x00000000000000FF);
                            bw.Write(b);
                        }
                    }
                    fs.Close();
                    fs.Dispose();
                }
            }
        }
Пример #5
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();
            if (m_DoLogging)
            {
                DumpCanMsg(msg, true);
            }

            int writeResult;

            writeResult = LAWICEL.canusb_Write(m_deviceHandle, ref msg);
            if (writeResult == LAWICEL.ERROR_CANUSB_OK)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #6
0
        private string waitForResponse(int mstimeout)
        {
            string returnString = "";
            bool timeout = false;
            CANMessage response = new CANMessage();
            m_canListener.setupWaitMessage(0x00c);
            response = m_canListener.waitMessage(mstimeout);
            if (timeout)
            {
                return TIMEOUT;
            }
            /* if ((byte)response.getData() == 0xC4)
             {
                 response = m_canListener.waitForMessage(0x00C, 1000);
                 DumpCanMsg(response, false);
                 Console.WriteLine("received C4 command");
                 //throw new Exception("Error receiving data (1)");
             }

             else */
            if ((byte)response.getData() != 0xC6)
            {
                //DumpCanMsg(response, false);
                //Console.WriteLine("Error rx data (1)");
                //throw new Exception("Error receiving data (1)");
                return TIMEOUT;
            }
            if (response.getLength() < 8)
            {
                returnString = TIMEOUT;
                return returnString;
            }
            returnString += (char)((response.getData() >> 16) & 0xFF);
            sendAck();
            return returnString;
        }
Пример #7
0
 private void findSynch()
 {
     //System.console.WriteLine("###### Looking for synch ######");
     string str = "";
     char ch;
     bool timeout = false;
     CANMessage ack = new CANMessage(0x006, 0, 2);
     CANMessage response = new CANMessage();
     ack.setData(0x00000000000000C6);
     do
     {
         m_canListener.setupWaitMessage(0x00c);
         if (!m_canDevice.sendMessage(ack))
             throw new Exception("Couldn't send message");
         response = m_canListener.waitMessage(1000);
         if (timeout)
         {
             return;
         }
         if ((byte)response.getData() != 0xC6)
         {
             //Console.WriteLine("Error rx data (3)");
             throw new Exception("Error receiving data (3)");
         }
         ch = (char)((response.getData() >> 16) & 0xFF);
         str += ch;
         if (str.EndsWith(CR + NL + NL + NL))
         {
             return;
         }
         if (str.EndsWith(NL + NL + NL + NL))
             str = sendCommand(CR, 1);
     }
     while (!str.EndsWith("END" + CR + NL));
 }
Пример #8
0
        // Stopwatch sw = new Stopwatch();
        // reading data from T5 ECU
        // address should only be a 16 bit address to read SRAM before the bootloader has been loaded
        // address can be a 32 bit address to read FLASH BIN only after the bootloader has been loaded
        private byte[] sendReadCommand(UInt32 address)
        {
            byte[] retData = new byte[6];
            CANMessage msg = new CANMessage(0x005, 0, 8);
            ulong cmd = 0x00000000000000C7;
            //            Console.WriteLine("Send read command");
            cmd |= (ulong)(byte)(address & 0x000000FF) << 4 * 8;
            cmd |= (ulong)(byte)((address & 0x0000FF00) >> 8) << 3 * 8;
            cmd |= (ulong)(byte)((address & 0x00FF0000) >> 2 * 8) << 2 * 8;
            cmd |= (ulong)(byte)((address & 0xFF000000) >> 3 * 8) << 8;
            //cmd |= (ulong)((byte)(address)) << 4 * 8;
            //cmd |= (ulong)((byte)(address >> 8)) << 3*8;
            msg.setData(cmd);
            m_canListener.setupWaitMessage(0x00c);
            //sw.Reset();
            //sw.Start();

            if (!m_canDevice.sendMessage(msg))
            {
                Console.WriteLine("Couldn't send message");
            }
            //sw.Stop();
            //Console.WriteLine("Send took " + sw.ElapsedMilliseconds.ToString() + " ms");
            CANMessage response = new CANMessage();
            //sw.Reset();
            //sw.Start();

            //response = m_canListener.waitForMessage(0x00C, 1000);
            //CANMessage response = new CANMessage();
            response = m_canListener.waitMessage(1000);
            //sw.Stop();
            //Console.WriteLine("Wait took " + sw.ElapsedMilliseconds.ToString() + " ms");
            ulong data = response.getData();
            for (int i = 2; i < 8; i++)
                retData[7 - i] = (byte)(data >> i * 8);

            return retData;
        }
Пример #9
0
 /// <summary>
 /// Sends a free form command to the ECU or bootloader
 /// </summary>
 /// <param name="cmd"></param>
 /// <returns></returns>
 public byte[] sendFreeCommand(ulong cmd)
 {
     byte[] retData = new byte[8];
     CANMessage msg = new CANMessage(0x005, 0, 8);
     msg.setData(cmd);
     m_canListener.setupWaitMessage(0x00c);
     if (!m_canDevice.sendMessage(msg))
         throw new Exception("Couldn't send message");
     CANMessage response = new CANMessage();
     response = m_canListener.waitMessage(10000); // checksum command (C8) may take longer than 1 second, so set it to 10
     ulong data = response.getData();
     for (int i = 0; i < 8; i++)
         retData[7 - i] = (byte)(data >> i * 8);
     return retData;
 }
Пример #10
0
        private void DumpCanMsg(CANMessage canMsg, bool IsTransmit)
        {
            DateTime dt = DateTime.Now;
            try
            {
                using (StreamWriter sw = new StreamWriter(@"c:\" + dt.Year.ToString("D4") + dt.Month.ToString("D2") + dt.Day.ToString("D2") + "-CanTrace.log", true))
                {
                    if (IsTransmit)
                    {
                        // get the byte transmitted
                        int transmitvalue = (int)(canMsg.getData() & 0x000000000000FF00);
                        transmitvalue /= 256;

                        sw.WriteLine(dt.ToString("dd/MM/yyyy HH:mm:ss") + " TX: id=" + canMsg.getID().ToString("X2") + " len= " + canMsg.getLength().ToString("X8") + " data=" + canMsg.getData().ToString("X16") + " " + canMsg.getFlags().ToString("X2") + "\t ts: " + canMsg.getTimeStamp().ToString("X16") + " flags: " + canMsg.getFlags().ToString("X2"));
                    }
                    else
                    {
                        // get the byte received
                        int receivevalue = (int)(canMsg.getData() & 0x0000000000FF0000);
                        receivevalue /= (256 * 256);
                        sw.WriteLine(dt.ToString("dd/MM/yyyy HH:mm:ss") + " RX: id=" + canMsg.getID().ToString("X2") + " len= " + canMsg.getLength().ToString("X8") + " data=" + canMsg.getData().ToString("X16") + " " + canMsg.getFlags().ToString("X2") + "\t ts: " + canMsg.getTimeStamp().ToString("X16") + " flags: " + canMsg.getFlags().ToString("X2"));
                    }
                }
            }
            catch (Exception E)
            {
                Console.WriteLine("Failed to write to logfile: " + E.Message);
            }
        }
Пример #11
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();
            if (m_DoLogging)
            {
                DumpCanMsg(msg, true);
            }

            int writeResult;
            writeResult = LAWICEL.canusb_Write(m_deviceHandle, ref msg);
            if (writeResult == LAWICEL.ERROR_CANUSB_OK)
                return true;
            else
                return false;
        }
Пример #12
0
        //-------------------------------------------------------------------------
        /**
        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());
        }
Пример #13
0
        /// <summary>
        /// Sends a C9 command to the bootloader to get offset address and
        /// FLASH chip types
        /// </summary>
        /// <returns></returns>
        public byte[] GetChipTypes()
        {
            byte[] retData = new byte[6];
            CANMessage msg = new CANMessage(0x005, 0, 8);
            //            ulong cmd = 0xC000000000000000;
            ulong cmd = 0x00000000000000C9;
            msg.setData(cmd);

            m_canListener.setupWaitMessage(0x00c);
            if (!m_canDevice.sendMessage(msg))
                throw new Exception("Couldn't send message");

            CANMessage response = new CANMessage();
            response = m_canListener.waitMessage(1000);

            /*
            if (!m_canDevice.sendMessage(msg))
                throw new Exception("Couldn't send message");
            response = new CANMessage();
            response = m_canListener.waitForMessage(0x00C, 1000);*/
            ulong data = response.getData();
            for (int i = 2; i < 8; i++)
                retData[7 - i] = (byte)(data >> i * 8);
            return retData;
            // unit responded 20 01 00 00 04 00
            //                || || |      | - 0x40000 = T5.5
            //                || || - 0x01 = AMD
            //                || - 0x20 = 29F010
        }
Пример #14
0
        private string waitNoAck()
        {
            string returnString = "";
            bool timeout = false;
            CANMessage response = new CANMessage();
            m_canListener.setupWaitMessage(0x00c);
            response = m_canListener.waitMessage(2000);
            if (timeout)
            {
                return TIMEOUT;
            }
            if ((byte)response.getData() != 0xC6)
            {
                byte b = (byte)response.getData();
                Console.WriteLine("Error rx data (2): "  + b.ToString("X2"));
                //throw new Exception("Error receiving data (2)");

            }
            if (response.getLength() < 8)
            {
                returnString = "";
                return returnString;
            }
            returnString += (char)((response.getData() >> 16) & 0xFF);
            return returnString;
        }
Пример #15
0
        //-------------------------------------------------------------------------
        /**
        Sends a 11 bit CAN data frame.

        @param      msg         CAN message

        @return                 success (true/false)
        */
        public override bool sendMessage(CANMessage msg)
        {
            if (this.logging_enabled)
            {
            this.DumpCanMsg(msg, true);
            }

            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);
            return true;
            }

            catch (Exception e)
            {
            return false;
            }
        }
Пример #16
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)
        {
            EASYSYNC.CANMsg msg = new EASYSYNC.CANMsg();
            msg.id = (ushort)a_message.getID();
            msg.len = a_message.getLength();
            msg.flags = a_message.getFlags();
            ulong msgdata = a_message.getData();
            // store in data (ulong)
            /*byte databyte = a_message.getCanData(7);
            msg.data_1 = GetDataMSBADCII(databyte);
            msg.data_2 = GetDataLSBADCII(databyte);
            databyte = a_message.getCanData(6);
            msg.data_3 = GetDataMSBADCII(databyte);
            msg.data_4 = GetDataLSBADCII(databyte);
            databyte = a_message.getCanData(5);
            msg.data_5 = GetDataMSBADCII(databyte);
            msg.data_6 = GetDataLSBADCII(databyte);
            databyte = a_message.getCanData(4);
            msg.data_7 = GetDataMSBADCII(databyte);
            msg.data_8 = GetDataLSBADCII(databyte);
            databyte = a_message.getCanData(3);
            msg.data_9 = GetDataMSBADCII(databyte);
            msg.data_10 = GetDataLSBADCII(databyte);
            databyte = a_message.getCanData(2);
            msg.data_11 = GetDataMSBADCII(databyte);
            msg.data_12 = GetDataLSBADCII(databyte);
            databyte = a_message.getCanData(1);
            msg.data_13 = GetDataMSBADCII(databyte);
            msg.data_14 = GetDataLSBADCII(databyte);
            databyte = a_message.getCanData(0);
            msg.data_15 = GetDataMSBADCII(databyte);
            msg.data_16 = GetDataLSBADCII(databyte);
            */

            msg.data = a_message.getData(); // this data should be in ascii: unsigned char data[16];			// Databytes 0...7
            // example:
            /*
            msg.data[0]='A';
            msg.data[1]='1';

            msg.data[2]='B';
            msg.data[3]='2';

            msg.data[4]='C';
            msg.data[5]='3';

            msg.data[6]='D';
            msg.data[7]='4';

            msg.data[8]='E';
            msg.data[9]='5';

            msg.data[10]='F';
            msg.data[11]='6';

            msg.data[12]='1';
            msg.data[13]='2';

            msg.data[14]='3';
            msg.data[15]='4'; * */
            if (m_DoLogging)
            {
                DumpCanMsg(msg, true);
            }

            int writeResult;
            Console.WriteLine("Writing to handle: " + m_deviceHandle.ToString("X8"));
            writeResult = EASYSYNC.canusb_Write(m_deviceHandle, ref msg);

            if (writeResult == EASYSYNC.ERROR_CANUSB_OK)
                return true;
            else
            {
                //EASYSYNC.canusb_Flush(m_deviceHandle);
                Console.WriteLine("Failed to send message: " + writeResult.ToString("X8"));
                return false;
            }
        }
Пример #17
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)
        {
            EASYSYNC.CANMsg msg = new EASYSYNC.CANMsg();
            msg.id    = (ushort)a_message.getID();
            msg.len   = a_message.getLength();
            msg.flags = a_message.getFlags();
            ulong msgdata = a_message.getData();

            // store in data (ulong)

            /*byte databyte = a_message.getCanData(7);
             * msg.data_1 = GetDataMSBADCII(databyte);
             * msg.data_2 = GetDataLSBADCII(databyte);
             * databyte = a_message.getCanData(6);
             * msg.data_3 = GetDataMSBADCII(databyte);
             * msg.data_4 = GetDataLSBADCII(databyte);
             * databyte = a_message.getCanData(5);
             * msg.data_5 = GetDataMSBADCII(databyte);
             * msg.data_6 = GetDataLSBADCII(databyte);
             * databyte = a_message.getCanData(4);
             * msg.data_7 = GetDataMSBADCII(databyte);
             * msg.data_8 = GetDataLSBADCII(databyte);
             * databyte = a_message.getCanData(3);
             * msg.data_9 = GetDataMSBADCII(databyte);
             * msg.data_10 = GetDataLSBADCII(databyte);
             * databyte = a_message.getCanData(2);
             * msg.data_11 = GetDataMSBADCII(databyte);
             * msg.data_12 = GetDataLSBADCII(databyte);
             * databyte = a_message.getCanData(1);
             * msg.data_13 = GetDataMSBADCII(databyte);
             * msg.data_14 = GetDataLSBADCII(databyte);
             * databyte = a_message.getCanData(0);
             * msg.data_15 = GetDataMSBADCII(databyte);
             * msg.data_16 = GetDataLSBADCII(databyte);
             */

            msg.data = a_message.getData(); // this data should be in ascii: unsigned char data[16];			// Databytes 0...7
            // example:

            /*
             * msg.data[0]='A';
             *          msg.data[1]='1';
             *
             *          msg.data[2]='B';
             *          msg.data[3]='2';
             *
             *          msg.data[4]='C';
             *          msg.data[5]='3';
             *
             *          msg.data[6]='D';
             *          msg.data[7]='4';
             *
             *          msg.data[8]='E';
             *          msg.data[9]='5';
             *
             *          msg.data[10]='F';
             *          msg.data[11]='6';
             *
             *          msg.data[12]='1';
             *          msg.data[13]='2';
             *
             *          msg.data[14]='3';
             *          msg.data[15]='4'; * */
            if (m_DoLogging)
            {
                DumpCanMsg(msg, true);
            }

            int writeResult;

            Console.WriteLine("Writing to handle: " + m_deviceHandle.ToString("X8"));
            writeResult = EASYSYNC.canusb_Write(m_deviceHandle, ref msg);

            if (writeResult == EASYSYNC.ERROR_CANUSB_OK)
            {
                return(true);
            }
            else
            {
                //EASYSYNC.canusb_Flush(m_deviceHandle);
                Console.WriteLine("Failed to send message: " + writeResult.ToString("X8"));
                return(false);
            }
        }
Пример #18
0
 /// <summary>
 /// Gets the checksum (C8 command) from the bootloader (non native command)
 /// </summary>
 /// <returns></returns>
 public byte[] getChecksum()
 {
     byte[] retData = new byte[8];
     CANMessage msg = new CANMessage(0x005, 0, 8);
     //            ulong cmd = 0xC000000000000000;
     ulong cmd = 0x00000000000000C8;
     msg.setData(cmd);
     m_canListener.setupWaitMessage(0x00c);
     if (!m_canDevice.sendMessage(msg))
         throw new Exception("Couldn't send message");
     CANMessage response = new CANMessage();
     response = m_canListener.waitMessage(10000);
     ulong data = response.getData();
     for (int i = 0; i < 8; i++)
         retData[7 - i] = (byte)(data >> i * 8);
     return retData;
 }
Пример #19
0
        // sending data from bootloader or flash file
        public byte[] sendBootloaderDataCommand(byte[] data, byte len)
        {
            byte[] retData = new byte[8];
            CANMessage msg = new CANMessage(0x005, 0, 8);
            ulong cmd = 0x0000000000000000;
            //cmd |= (ulong)((byte)(len)) << 7 * 8;
              //  cmd |= (ulong)((byte)(len)) ;
            /*int cnt = 0;
            foreach (byte b in data)
            {
                cmd |= (ulong)((byte)b) << (7-cnt) * 8;
                cnt++;
            }*/
            int cnt = 0;
            foreach (byte b in data)
            {
                //if (cnt > 0)
                {
                    cmd |= (ulong)((byte)b) << (cnt) * 8;
                }
                cnt++;
            }
            //cmd &= 0xFFFFFFFFFFFFFF00;

            //cmd |= (ulong)((byte)(len));
            msg.setData(cmd);
            m_canListener.setupWaitMessage(0x00c);
            if (!m_canDevice.sendMessage(msg))
                throw new Exception("Couldn't send message");
            CANMessage response = new CANMessage();
            response = m_canListener.waitMessage(1000);
            ulong uldata = response.getData();
            for (int i = 0; i < 8; i++)
                retData[7 - i] = (byte)(uldata >> i * 8);
            return retData;
        }
Пример #20
0
        //-------------------------------------------------------------------------

        /**
         *  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()));
        }
Пример #21
0
        public byte[] sendBootVectorAddressSRAM(Int32 address)
        {
            byte[] retData = new byte[8];
            CANMessage msg = new CANMessage(0x005, 0, 8);
            /*            ulong cmd = 0xC100000000000000;
            cmd |= (ulong)((byte)(address >> 8)) << 4 * 8;
            cmd |= (ulong)((byte)(address)) << 3 * 8;*/
            ulong cmd = 0x00000000000000C1;
            cmd |= (ulong)(byte)(address & 0x0000FF) << 4 * 8;
            cmd |= (ulong)(byte)((address & 0x00FF00) >> 8) << 3 * 8;
            cmd |= (ulong)(byte)((address & 0xFF0000) >> 2 * 8) << 2 * 8;

            /*            cmd |= (ulong)((byte)(address >> 2 * 8)) << 2 * 8;
            cmd |= (ulong)((byte)(address >> 8)) << 3 * 8;
            cmd |= (ulong)((byte)(address)) << 4 * 8;
            */
            msg.setData(cmd);
            m_canListener.setupWaitMessage(0x00c);
            if (!m_canDevice.sendMessage(msg))
                throw new Exception("Couldn't send message");
            CANMessage response = new CANMessage();
            response = m_canListener.waitMessage(1000);
            ulong data = response.getData();
            for (int i = 0; i < 8; i++)
                retData[7 - i] = (byte)(data >> i * 8);
            return retData;
        }
Пример #22
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();
            if (m_DoLogging)
            {
                DumpCanMsg(msg, true);
            }
            if (m_port.IsOpen)
            {
                m_port.Write("\r");
                string txstring = "t";
                txstring += msg.id.ToString("X3");
                txstring += "8"; // always 8 bytes to transmit
                for (int t = 0; t < 8; t++)
                {
                    byte b = (byte)(((msg.data >> t * 8) & 0x0000000000000000FF));
                    txstring += b.ToString("X2");
                }
                txstring += "\r";
                m_port.Write(txstring);
            //                Console.WriteLine("Send: " + txstring);
                return true;
            }
            return false;

            /*
            int writeResult;
            writeResult = LAWICEL.canusb_Write(m_deviceHandle, ref msg);
            if (writeResult == LAWICEL.ERROR_CANUSB_OK)
                return true;
            else
                return false;
             */
        }
Пример #23
0
 /// <summary>
 /// Sends a C3 command to the ECU or bootloader
 /// </summary>
 /// <returns></returns>
 public byte[] sendC3Command()
 {
     byte[] retData = new byte[6];
     CANMessage msg = new CANMessage(0x005, 0, 8);
     //            ulong cmd = 0xC000000000000000;
     ulong cmd = 0x00000000000000C3;
     msg.setData(cmd);
     m_canListener.setupWaitMessage(0x00c);
     if (!m_canDevice.sendMessage(msg))
         throw new Exception("Couldn't send message");
     CANMessage response = new CANMessage();
     response = m_canListener.waitMessage(1000);
     ulong data = response.getData();
     for (int i = 2; i < 8; i++)
         retData[7 - i] = (byte)(data >> i * 8);
     return retData;
     // unit responded B8 89 FF FF 07 00
 }