public void InitializeCAN() { XL_Status status; // Open XL Driver status = CANDriver.XL_OpenDriver(); status = CANDriver.XL_GetDriverConfig(ref driverConfig); while (!GetAppChannelAndTestIsOk(1, ref txMask, ref txCi) || !GetAppChannelAndTestIsOk(0, ref rxMask, ref rxCi)) { PrintAssignErrorAndPopupHwConf(); } accessMask = txMask | rxMask; permissionMask = accessMask; // Open port status = CANDriver.XL_OpenPort(ref portHandle, appName, accessMask, ref permissionMask, 1024, XLDefine.XL_InterfaceVersion.XL_INTERFACE_VERSION, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN); Console.WriteLine("\n\nOpen Port : " + status); if (status != XL_Status.XL_SUCCESS) { PrintFunctionError(); } // Check port status = CANDriver.XL_CanRequestChipState(portHandle, accessMask); Console.WriteLine("Can Request Chip State: " + status); if (status != XL_Status.XL_SUCCESS) { PrintFunctionError(); } // Activate channel status = CANDriver.XL_ActivateChannel(portHandle, accessMask, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN, XLDefine.XL_AC_Flags.XL_ACTIVATE_NONE); Console.WriteLine("Activate Channel : " + status); if (status != XL_Status.XL_SUCCESS) { PrintFunctionError(); } Console.WriteLine("Set Notification : " + status); if (status != XL_Status.XL_SUCCESS) { PrintFunctionError(); } status = CANDriver.XL_ResetClock(portHandle); Console.WriteLine("Reset Clock : " + status + "\n\n"); if (status != XL_Status.XL_SUCCESS) { PrintFunctionError(); } }
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); } }
public long CanTpCreateConnection(string appName, uint appChannel, XLDefine.XL_HardwareType hwType, uint hwIndex, uint hwChannel, XLDefine.XL_BusTypes busType) { XLDefine.XL_Status status; status = CANTPDriver.XL_OpenDriver(); Console.WriteLine("Open Driver : " + status); if (status != XLDefine.XL_Status.XL_SUCCESS) { return(-1); } status = CANTPDriver.XL_SetApplConfig(appName, appChannel, hwType, hwIndex, hwChannel, busType); Console.WriteLine("SetApplConfig : " + status); if (status != XLDefine.XL_Status.XL_SUCCESS) { return(-2); } accessMask = CANTPDriver.XL_GetChannelMask(hwType, (int)hwIndex, (int)hwChannel); permissionMask = accessMask; txMask = accessMask; status = CANTPDriver.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); if (status != XLDefine.XL_Status.XL_SUCCESS) { return(-3); } status = CANTPDriver.XL_CanRequestChipState(portHandle, accessMask); Console.WriteLine("Can Request Chip State: " + status); if (status != XLDefine.XL_Status.XL_SUCCESS) { return(-4); } status = CANTPDriver.XL_ActivateChannel(portHandle, accessMask, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN, XLDefine.XL_AC_Flags.XL_ACTIVATE_NONE); Console.WriteLine("Activate Channel : " + status); if (status != XLDefine.XL_Status.XL_SUCCESS) { return(-5); } status = CANTPDriver.XL_SetNotification(portHandle, ref eventHandle, 1); Console.WriteLine("Set Notification : " + status); if (status != XLDefine.XL_Status.XL_SUCCESS) { return(-6); } status = CANTPDriver.XL_ResetClock(portHandle); Console.WriteLine("Reset Clock : " + status + "\n\n"); if (status != XLDefine.XL_Status.XL_SUCCESS) { return(-7); } Console.WriteLine("Start Rx thread..."); rxThread = new Thread(new ThreadStart(CanTp_ReceptionInd)); rxThread.Start(); return(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); }
bool OpenDriver() { XLDefine.XL_Status status = driver.XL_OpenDriver(); return(DriverAction("Open driver", status)); }
// ----------------------------------------------------------------------------------------------- /// <summary> /// MAIN /// /// Sends and receives CAN messages using main methods of the "XLDriver" class. /// This demo requires two connected CAN channels (Vector network interface). /// The configuration is read from Vector Hardware Config (vcanconf.exe). /// </summary> // ----------------------------------------------------------------------------------------------- //[STAThread] public String InitCANtransmitter() { // Open XL Driver status = CANDemo.XL_OpenDriver(); //Console.WriteLine("Open Driver : " + status); //if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError(); // Get XL Driver configuration status = CANDemo.XL_GetDriverConfig(ref driverConfig); //Console.WriteLine("Get Driver Config : " + status); //if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError(); // If the application name cannot be found in VCANCONF... if ((CANDemo.XL_GetApplConfig(appName, 0, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN) != XLDefine.XL_Status.XL_SUCCESS) || (CANDemo.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 CANDemo.XL_SetApplConfig(appName, 0, XLDefine.XL_HardwareType.XL_HWTYPE_NONE, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN); CANDemo.XL_SetApplConfig(appName, 1, XLDefine.XL_HardwareType.XL_HWTYPE_NONE, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN); PrintAssignError(); } else // else try to read channel assignments { string str; // Read setting of CAN1 CANDemo.XL_GetApplConfig(appName, 0, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN); // Notify user if no channel is assigned to this application if (hwType == XLDefine.XL_HardwareType.XL_HWTYPE_NONE) { PrintAssignError(); } accessMask = CANDemo.XL_GetChannelMask(hwType, (int)hwIndex, (int)hwChannel); txMask = accessMask; // this channel is used for Tx /* * // Read setting of CAN2 * CANDemo.XL_GetApplConfig(appName, 1, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN); * * // Notify user if no channel is assigned to this application * if (hwType == XLDefine.XL_HardwareType.XL_HWTYPE_NONE) PrintAssignError(); * * accessMask |= CANDemo.XL_GetChannelMask(hwType, (int)hwIndex, (int)hwChannel); // OR: access both channels for RX later */ permissionMask = accessMask; // Open port status = CANDemo.XL_OpenPort(ref portHandle, appName, accessMask, ref permissionMask, 1024, XLDefine.XL_InterfaceVersion.XL_INTERFACE_VERSION, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN); //Console.WriteLine("\n\nOpen Port : " + status); //if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError(); // Check port status = CANDemo.XL_CanRequestChipState(portHandle, accessMask); //Console.WriteLine("Can Request Chip State: " + status); //if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError(); // Activate channel status = CANDemo.XL_ActivateChannel(portHandle, accessMask, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN, XLDefine.XL_AC_Flags.XL_ACTIVATE_NONE); //Console.WriteLine("Activate Channel : " + status); //if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError(); // Get RX event handle status = CANDemo.XL_SetNotification(portHandle, ref eventHandle, 1); //Console.WriteLine("Set Notification : " + status); //if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError(); // Reset time stamp clock CANDemo.XL_ResetClock(portHandle); //Console.WriteLine("Reset Clock : " + status + "\n\n"); //if (status != XLDefine.XL_Status.XL_SUCCESS) PrintFunctionError(); } return(status.ToString()); }