Esempio n. 1
0
        public bool OpenDriver()
        {
            status = CANDriver.XL_OpenDriver();
            info  += "Open Driver       : ";
            if (status == XLDefine.XL_Status.XL_SUCCESS)
            {
                info  += "Succesfull\n";
                status = CANDriver.XL_GetDriverConfig(ref driverConfig);
                info  += "DLL Version       : " + CANDriver.VersionToString(driverConfig.dllVersion) + "\n" +
                         "Channels found    : " + driverConfig.channelCount + "\n";

                for (int i = 0; i < driverConfig.channelCount; i++)
                {
                    info += "       " + driverConfig.channel[i].name + "\n";

                    if ((driverConfig.channel[i].channelCapabilities & XLDefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_ISO_SUPPORT) == XLDefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_ISO_SUPPORT)
                    {
                        info += "       - CAN FD Support  : yes\n";
                    }
                    else
                    {
                        info += "        - CAN FD Support  : no\n";
                    }

                    info += "                    - Channel Mask    : " + driverConfig.channel[i].channelMask + "\n";
                    info += "                    - Transceiver Name: " + driverConfig.channel[i].transceiverName + "\n";
                    info += "                    - Serial Number: " + driverConfig.channel[i].serialNumber + "\n";
                }

                // If the application name cannot be found in VCANCONF...
                if ((CANDriver.XL_GetApplConfig(appName, 0, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN) != XLDefine.XL_Status.XL_SUCCESS) ||
                    (CANDriver.XL_GetApplConfig(appName, 1, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN) != XLDefine.XL_Status.XL_SUCCESS))
                {
                    //...create the item with two CAN channels
                    CANDriver.XL_SetApplConfig(appName, 0, XLDefine.XL_HardwareType.XL_HWTYPE_NONE, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN);
                    CANDriver.XL_SetApplConfig(appName, 1, XLDefine.XL_HardwareType.XL_HWTYPE_NONE, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN);
                    CANDriver.XL_PopupHwConfig();
                }

                accessMask     = txMask | rxMask;
                permissionMask = accessMask;

                return(true);
            }
            else
            {
                info += "NOT Succesfull\n";
                return(false);
            }
        }
Esempio n. 2
0
        // -----------------------------------------------------------------------------------------------



        // -----------------------------------------------------------------------------------------------
        /// <summary>
        /// Displays the Vector Hardware Configuration.
        /// </summary>
        // -----------------------------------------------------------------------------------------------
        private void PrintConfig()
        {
            channelIndex = driver.XL_GetChannelIndex(hwType, (int)hwIndex, (int)hwChannel);

            if (channelIndex > -1)
            {
                Console.WriteLine("\n\nAPPLICATION CONFIGURATION");
                Console.WriteLine("-------------------------------------------------------------------\n");
                Console.WriteLine("Configured Hardware Channel : " + driverConfig.channel[channelIndex].name);
                Console.WriteLine("Hardware Driver Version     : " + driver.VersionToString(driverConfig.channel[channelIndex].driverVersion));
                Console.WriteLine("Used Transceiver            : " + driverConfig.channel[channelIndex].transceiverName);
                Console.WriteLine("Baudrate                    : " + driverConfig.channel[channelIndex].busParams.bitrate);
                Console.WriteLine("-------------------------------------------------------------------\n");
            }
        }
Esempio n. 3
0
        public void INITLOG()
        {
            //starting app
            Console.WriteLine("UDS- Vector Client Started \n");
            Console.WriteLine("Vector XL Driver Version: " + typeof(XLDriver).Assembly.GetName().Version + "\n");
            //opening driver
            status = UDSDemo.XL_OpenDriver();
            Console.WriteLine("Opening vector CAN Driver.... \n");
            if (status != XLDefine.XL_Status.XL_SUCCESS)
            {
                PrintFunctionError();
            }
            status = UDSDemo.XL_GetDriverConfig(ref driverConfig);
            //getting config
            Console.WriteLine("Getting CAN Driver Config: \n");
            Console.WriteLine(status + Environment.NewLine);
            if (status != XLDefine.XL_Status.XL_SUCCESS)
            {
                PrintFunctionError();
            }
            //getting DLL info
            Console.WriteLine("Getting Vector DLL Version: ");
            Console.WriteLine(UDSDemo.VersionToString(driverConfig.dllVersion) + Environment.NewLine);
            //Getting channels...
            Console.WriteLine("Channels found: " + driverConfig.channelCount + Environment.NewLine);
            for (int i = 0; i < driverConfig.channelCount; i++)
            {
                Console.WriteLine("   Channel Name:" + driverConfig.channel[i].name);
                Console.WriteLine("   Channel Mask:" + driverConfig.channel[i].channelMask);
                Console.WriteLine("   Transceiver Name:" + driverConfig.channel[i].transceiverName);
                Console.WriteLine("   Serial Number:" + driverConfig.channel[i].serialNumber);
                Console.WriteLine("\n\n");
            }

            //Check config
            if ((UDSDemo.XL_GetApplConfig(appName, 0, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN) != XLDefine.XL_Status.XL_SUCCESS) ||
                (UDSDemo.XL_GetApplConfig(appName, 1, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN) != XLDefine.XL_Status.XL_SUCCESS))
            {
                //...create the item with two CAN channels
                UDSDemo.XL_SetApplConfig(appName, 0, XLDefine.XL_HardwareType.XL_HWTYPE_NONE, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN);
                UDSDemo.XL_SetApplConfig(appName, 1, XLDefine.XL_HardwareType.XL_HWTYPE_NONE, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN);
                //PrintAssignErrorAndPopupHwConf();
                ThreadMutex = 1;
            }
            // Request the user to assign channels until both CAN1 (Tx) and CAN2 (Rx) are assigned to usable channels
            if (!GetAppChannelAndTestIsOk(0, ref txMask, ref txCi) || !GetAppChannelAndTestIsOk(1, ref rxMask, ref rxCi))
            {
                ThreadMutex = 0;
            }
            //Printing application configuration on log screen
            //PrintConfig();
            //making masks
            accessMask     = txMask | rxMask;
            permissionMask = accessMask;
            //opening port
            status = UDSDemo.XL_OpenPort(ref portHandle, appName, accessMask, ref permissionMask, 1024, XLDefine.XL_InterfaceVersion.XL_INTERFACE_VERSION, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN);
            Console.WriteLine("Open Port  :" + status + Environment.NewLine);
            if (status != XLDefine.XL_Status.XL_SUCCESS)
            {
                PrintFunctionError();
            }
            //chip state checking
            status = UDSDemo.XL_CanRequestChipState(portHandle, accessMask);
            Console.WriteLine("CAN Request Chip state  :" + status + Environment.NewLine);
            if (status != XLDefine.XL_Status.XL_SUCCESS)
            {
                PrintFunctionError();
            }
            //ON Bus
            status = UDSDemo.XL_ActivateChannel(portHandle, accessMask, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN, XLDefine.XL_AC_Flags.XL_ACTIVATE_NONE);
            Console.WriteLine("Activate Channel  :" + status + Environment.NewLine);
            if (status != XLDefine.XL_Status.XL_SUCCESS)
            {
                PrintFunctionError();
            }
            //can ids display
            Console.WriteLine("TESTER REQUEST CAN ID: 0x735" + Environment.NewLine);
            Console.WriteLine("ECU RESPONSE CAN ID: 0x73D" + Environment.NewLine);
            //giving info

            //putting notifications on can
            int tempInt = -1;

            status = UDSDemo.XL_SetNotification(portHandle, ref tempInt, 1);
            xlEvWaitHandle.SafeWaitHandle = new SafeWaitHandle(new IntPtr(tempInt), true);
            Console.WriteLine("Set Notification  :" + status + Environment.NewLine);
            if (status != XLDefine.XL_Status.XL_SUCCESS)
            {
                PrintFunctionError();
            }

            if (TimerRate == 1)
            {
                TimerRate = 0;
            }
            else
            {
                TimerRate = 20000;
            }
            status = UDSDemo.XL_SetTimerRate(portHandle, TimerRate);
            Console.WriteLine("setTimer  :" + status + Environment.NewLine);
            //resetting clock
            status = UDSDemo.XL_ResetClock(portHandle);
            Console.WriteLine("Reset Clock  :" + status + Environment.NewLine);
            if (status != XLDefine.XL_Status.XL_SUCCESS)
            {
                PrintFunctionError();
            }
            //TPLOCK = 1;
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nDevice Connected " + driverConfig.channel[0].name + " and " + driverConfig.channel[1].name + " active\n");
            Console.ForegroundColor = ConsoleColor.White;
            //starting rx thread
            Console.WriteLine("Starting Receive Thread........" + Environment.NewLine);
            rxThread = new Thread(new ThreadStart(RXHANDLER));
            rxThread.Start();
            Console.WriteLine("Is main thread is alive" +
                              " ? : {0}", rxThread.IsAlive);
        }