Esempio n. 1
0
        public void _0001_MALT132_TesterPresent()
        {
            UInt32 txId     = 0x15510403;
            UInt32 rxId     = 0x15520403;
            UInt32 baudRate = 250000;
            var    canLink  = new NiCanInterface("CAN0", true, txId, rxId, baudRate);

            canLink.Connect();
            canLink.BusTerminationEnable = true;
            canLink.Open();

            Iso15765NetwrorkLayer network = new Iso15765NetwrorkLayer(canLink);

            try
            {
                byte[] response;
                network.Transport(new byte[] { 0x3E, 0x00 }, out response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //network.SaveFrameLog("D:\\" + this.GetType().FullName + ".csv");
                canLink.Close();
                canLink.Disconnect();
            }
        }
Esempio n. 2
0
        private void ButtonWrite_Click(object sender, EventArgs e)
        {
            byte address = MainForm.Address;

            UInt32 txId     = (UInt32)0x600 | address;
            UInt32 rxId     = (UInt32)0x700 | address;
            UInt32 baudRate = 250000;

            NiCanInterface = new NiCanInterface("CAN0", false, txId, rxId, baudRate);
            NiCanInterface.Connect();
            NiCanInterface.BusTerminationEnable = true;
            NiCanInterface.Open();


            MainForm.WriteEnabled = false;

            var network = new Iso15765NetwrorkLayer(NiCanInterface);

            network.ReadTimeoutMs    = 1000;
            network.Log              = Settings.Default.LogEnable;
            Settings.Default.LogPath = AppConstants.LogPath + "_" + DateTime.Now.ToString(AppConstants.FileNameTimestampFormat) + ".txt";
            network.LogPath          = Settings.Default.LogPath;

            var dfu = new AppDfu(network);


            dfu.ProgressChange += (o, ev) =>
            {
                MainForm.PoregressValue = ev.ProgressPercentage;
                MainForm.LabelStatus    = ev.UserState.ToString();
            };


            byte[] firmware = Tools.OpenFile(Settings.Default.LastPath);
            dfu.Begin(firmware);

            Action syncCompleted = () => {
            };

            dfu.Completed += (o, ev) =>
            {
                NiCanInterface.Close();
                MainForm.WriteEnabled = true;

                if (App.SyncContext != null)
                {
                    App.SyncContext.Post((e1) => { syncCompleted(); }, null);
                }

                if (ev.Result is Exception)
                {
                    MessageBox.Show((ev.Result as Exception).Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            };
        }
Esempio n. 3
0
        private void MainForm_DeviceRestart(object sender, EventArgs e)
        {
            UInt32 baudRate = 250000;

            NiCanInterface = new NiCanInterface("CAN0", baudRate);
            NiCanInterface.Connect();
            NiCanInterface.BusTerminationEnable = true;
            NiCanInterface.Open();
            NiCanInterface.RestartCard(MainForm.Address);
            NiCanInterface.Close();
        }
Esempio n. 4
0
        public void _0002_Bxxx_TesterPresent()
        {
            UInt32         txId     = 0x714;
            UInt32         rxId     = 0x734;
            UInt32         baudRate = 500000;
            NiCanInterface canLink  = new NiCanInterface("CAN0", false, txId, rxId, baudRate);

            canLink.Connect();
            canLink.BusTerminationEnable = true;
            canLink.Open();

            Iso15765NetwrorkLayer network = new Iso15765NetwrorkLayer(canLink);

            try
            {
                byte[] response;

                Console.WriteLine("Tester Present:");
                network.Transport(new byte[] { 0x3E, 0x00 }, out response);
                Assert.AreEqual(new byte[] { 0x7E, 0x00 }, response);

                Console.WriteLine("Diag Session:");
                network.Transport(new byte[] { 0x10, 0x03 }, out response);
                Assert.AreEqual(new byte[] { 0x50, 0x03, 0x00, 0x32, 0x01, 0xF4 }, response);

                Console.WriteLine("Read Dtc:");
                network.Transport(new byte[] { 0x19, 0x02, 0x08 }, out response);
                Console.WriteLine("Dtc:");
                Console.WriteLine(Tools.ByteArrayToCStyleString(response));
                Assert.AreEqual(new byte[] { 0x59, 0x02, 0xCA, 0x90, 0xB5, 0x15, //6
                                             0x0A, 0x90, 0xB6, 0x15,             //4
                                             0x0A, 0x90, 0xB9, 0x12,             //4
                                             0x0A, 0x9A, 0x61, 0x15,             //4
                                             0x0A, 0x9A, 0x63, 0x15,             //4
                                             0x0A, 0x9A, 0x64, 0x15,
                                             0x0A, 0xC1, 0x40, 0x00,
                                             0x0A, 0xC1, 0x55, 0x00,             //
                                             0x0A }, response);                  //Szum: 35
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //network.SaveFrameLog("D:\\" + this.GetType().FullName + ".csv");
                canLink.Close();
                canLink.Disconnect();
            }
        }
Esempio n. 5
0
        public void _0003_Tachograph_TesterPresent()
        {
            UInt32 txId     = 0x38DAEEFB;
            UInt32 rxId     = 0x38DAFBEE;
            UInt32 baudRate = 250000;

            NiCanInterface canLink = new NiCanInterface("CAN0", true, txId, rxId, baudRate);

            canLink.Connect();
            canLink.BusTerminationEnable = true;
            canLink.Open();

            Iso15765NetwrorkLayer network = new Iso15765NetwrorkLayer(canLink);

            try
            {
                byte[] response;

                Console.WriteLine("Tester Present:");
                network.Transport(new byte[] { 0x3E, 0x00 }, out response);
                Assert.AreEqual(new byte[] { 0x7E, 0x00 }, response);

                Console.WriteLine("DiagnosticSession:");
                network.Transport(new byte[] { 0x10, 0x7E }, out response);
                Assert.AreEqual(new byte[] { 0x50, 0x7E }, response);

                Console.WriteLine("CloseRemoteAuthentication:");
                network.Transport(new byte[] { 0x31, 0x01, 0x01, 0x80, 0x09 }, out response);
                Assert.AreEqual(new byte[] { 0x71, 0x01, 0x01, 0x80, 0x0A }, response);

                Console.WriteLine("RemoteCompanyCardReady:");
                network.Transport(new byte[] { 0x31, 0x01, 0x01, 0x80, 0x01, 0x3B, 0x3B, 0x9A,
                                               0x96, 0xC0, 0x10, 0x31, 0xFE, 0x5D, 0x00, 0x64,
                                               0x05, 0x7B, 0x01, 0x02, 0x31, 0x80, 0x90, 0x00,
                                               0x76 }, out response); //25:Length
                Assert.AreEqual(new byte[] { 0x71, 0x01, 0x01, 0x80, 0x02 }, response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                //network.SaveFrameLog("D:\\" + this.GetType().FullName + ".csv");
                canLink.Close();
                canLink.Disconnect();
            }
        }
Esempio n. 6
0
        public void _Basic_DFU_Test()
        {
            UInt32 txId     = 0x603;
            UInt32 rxId     = 0x703;
            UInt32 baudRate = 250000;
            var    canLink  = new NiCanInterface("CAN0", false, txId, rxId, baudRate);

            canLink.Connect();
            canLink.BusTerminationEnable = true;
            canLink.Open();

            var network = new Iso15765NetwrorkLayer(canLink);

            network.Log = false;
            var dfu = new AppDfu(network);

            IoLog.Instance.FilePath = @"D:\io_log.txt";
            Console.WriteLine("LogPath:" + IoLog.Instance.FilePath);

            int firmwareLength = 100;

            byte[] firmware = new byte[firmwareLength];
            for (int i = 0; i < 100; i++)
            {
                firmware[i] = (byte)i;
            }

            byte blockSize;
            byte blockSequenceCoutner = 0;
            int  dataPtr = 0;

            dfu.TesterPresent(0);
            dfu.DiagSession(AppDfu.Session.ProgrammingMode);
            dfu.FlashErase();


            /*FIGYELJ ARRA HOGY A blockSize csak páros lehet, a szerver 0xFE-jelez vissza!*/
            blockSize = (byte)(dfu.RequestDwonLoad(firmware.Length) - 2);

            /* first block*/
            blockSequenceCoutner++;
            if (firmware.Length > blockSize)
            {
                byte[] block = new byte[blockSize];
                Buffer.BlockCopy(firmware, 0, block, 0, blockSize);
                dataPtr = blockSize;
                dfu.TransferData(blockSequenceCoutner, block);

                do
                {
                    blockSequenceCoutner++;

                    if (blockSequenceCoutner == 0xFF)
                    {
                        blockSequenceCoutner = 0;
                    }

                    if (firmware.Length - dataPtr > blockSize)
                    {
                        block = new byte[blockSize];
                        Buffer.BlockCopy(firmware, dataPtr, block, 0, blockSize);
                        dfu.TransferData(blockSequenceCoutner, block);
                        dataPtr += blockSize;
                    }
                    else
                    {
                        block = new byte[firmware.Length - dataPtr];
                        Buffer.BlockCopy(firmware, dataPtr, block, 0, firmware.Length - dataPtr);
                        dfu.TransferData(blockSequenceCoutner, block);
                        dataPtr += firmware.Length - dataPtr;
                    }
                } while (dataPtr != firmware.Length);
            }
            else
            {
                /*itt vége ha nem kellett hozzá egy egész block...*/
                dfu.TransferData(blockSequenceCoutner, firmware);
            }
            dfu.TransferExit();
            UInt16 expected = Tools.CalcCrc16Ansi(0, firmware);

            Debug.WriteLine("Cheksum:0x" + dfu.GetChecksum().ToString("X04") + ", Expected 0x" + expected.ToString("X04"));

            dfu.EcuReset(AppDfu.ResetType.HardReset);
        }