public XLDefine.XL_Status SetConfiguration() { bool existNotAssignedChannel = false; XLDefine.XL_Status[] status = new XLDefine.XL_Status[numberOfChannels]; for (int i = 0; i < numberOfChannels; i++) { status[i] = driver.XL_GetApplConfig(applicationName, (uint)i, ref hwType, ref hardwareIndex, ref hardwareChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_LIN); if (status[i] != XLDefine.XL_Status.XL_SUCCESS) { existNotAssignedChannel = true; } } if (existNotAssignedChannel) { Trace.WriteLine("Application configuration not found, creating new one."); for (int i = 0; i < numberOfChannels; i++) { driver.XL_SetApplConfig(applicationName, (uint)i, 0, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_LIN); } } XLDefine.XL_Status maxChannelStatus = status.Max(); Trace.WriteLine("Get Application Configuration: " + maxChannelStatus); return(maxChannelStatus); }
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); } }
private static bool GetAppChannelAndTestIsOk(uint appChIdx, ref UInt64 chMask, ref int chIdx) { XL_Status status = CANDriver.XL_GetApplConfig(appName, appChIdx, ref hwType, ref hwIndex, ref hwChannel, XL_BusTypes.XL_BUS_TYPE_CAN); if (status != XLDefine.XL_Status.XL_SUCCESS) { Console.WriteLine("XL_GetApplConfig : " + status); PrintFunctionError(); } chMask = CANDriver.XL_GetChannelMask(hwType, (int)hwIndex, (int)hwChannel); chIdx = CANDriver.XL_GetChannelIndex(hwType, (int)hwIndex, (int)hwChannel); if (chIdx < 0 || chIdx >= driverConfig.channelCount) { // the (hwType, hwIndex, hwChannel) triplet stored in the application configuration does not refer to any available channel. return(false); } // test if CAN is available on this channel return((driverConfig.channel[chIdx].channelBusCapabilities & XL_BusCapabilities.XL_BUS_ACTIVE_CAP_CAN) != 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); }
/// <summary> /// The initialization of the Vector CAN driver /// </summary> /// <param name="_iEventHandle"></param> /// <param name="_iPortHandle"></param> /// <param name="_ui64TransmitMask"></param> public void xlStartCan(ref int _iEventHandle, ref int _iPortHandle, ref UInt64 _ui64TransmitMask) { UInt64 ui64AccessMask = 0; UInt64 ui64PermissionMask = 0; uint uiHWType = 0; uint uiHWIndex = 0; uint uiHWChannel = 0; uint uiBusType = (uint)XLClass.XLbusTypes.XL_BUS_TYPE_CAN; uint uiFlags = 0; XLClass.XLstatus xlRet; if ((_xlDriverTx.XL_GetApplConfig("xlCANSimulator", 0, ref uiHWType, ref uiHWIndex, ref uiHWChannel, uiBusType) != XLClass.XLstatus.XL_SUCCESS) || (_xlDriverTx.XL_GetApplConfig("xlCANSimulator", 1, ref uiHWType, ref uiHWIndex, ref uiHWChannel, uiBusType) != XLClass.XLstatus.XL_SUCCESS)) { _xlDriverTx.XL_SetApplConfig("xlCANSimulator", 0, 0, 0, 0, 0); _xlDriverTx.XL_SetApplConfig("xlCANSimulator", 1, 0, 0, 0, 0); } log("DRIVER-Open xlCANSimulator configuration"); _xlDriverTx.XL_GetApplConfig("xlCANSimulator", 0, ref uiHWType, ref uiHWIndex, ref uiHWChannel, uiBusType); ui64AccessMask |= _xlDriverTx.XL_GetChannelMask((int)uiHWType, (int)uiHWIndex, (int)uiHWChannel); ui64PermissionMask = ui64AccessMask; _ui64TransmitMaskTx = ui64AccessMask; xlRet = _xlDriverTx.XL_OpenPort(ref _iPortHandle, "xlCANSimulator", ui64AccessMask, ref ui64PermissionMask, (uint)1024, uiBusType); if (XLClass.XLstatus.XL_SUCCESS != xlRet) { log("DRIVER-Open port failed"); } else { log("DRIVER-Open port success"); } xlRet = _xlDriverTx.XL_CanRequestChipState(_iPortHandle, ui64AccessMask); if (XLClass.XLstatus.XL_SUCCESS != xlRet) { log("DRIVER-Request chip state failed"); } else { log("DRIVER-Request chip state success"); } xlRet = _xlDriverTx.XL_ActivateChannel(_iPortHandle, ui64AccessMask, uiBusType, uiFlags); if (XLClass.XLstatus.XL_SUCCESS != xlRet) { log("DRIVER-Activate channel failed"); } else { log("DRIVER-Activate channel success"); } xlRet = _xlDriverTx.XL_SetNotification(_iPortHandle, ref _iEventHandle, 1); if (XLClass.XLstatus.XL_SUCCESS != xlRet) { log("DRIVER-Set notificaiton failed"); } else { log("DRIVER-Set notificaiton success"); } xlRet = _xlDriverTx.XL_ResetClock(_iPortHandle); if (XLClass.XLstatus.XL_SUCCESS != xlRet) { log("DRIVER-Reset clock failed"); } else { log("DRIVER-Reset clock success"); } }
public XLInterface() { MessageTypes = new Dictionary <int, string>(); MessageTypes.Add(FULL_THROTTLE_ON, "Throttle On"); MessageTypes.Add(FULL_THROTTLE_OFF, "Throttle Off"); MessageTypes.Add(FULL_BRAKE_ON, "Brake On"); MessageTypes.Add(FULL_BRAKE_OFF, "Brake Off"); XLDefine.XL_Status status; driver = new XLDriver(); driverConfig = new XLClass.xl_driver_config(); driver.XL_GetDriverConfig(ref driverConfig); // If the application name cannot be found in VCANCONF... if ((driver.XL_GetApplConfig(appName, 0, 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 status = driver.XL_SetApplConfig(appName, 0, XLDefine.XL_HardwareType.XL_HWTYPE_CANCASEXL, 0, 0, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN); Console.WriteLine(status); } // Read setting of CAN1 driver.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 = driver.XL_GetChannelMask(hwType, (int)hwIndex, (int)hwChannel); txMask = accessMask; // this channel is used for Tx PrintConfig(); permissionMask = accessMask; // Open port status = driver.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 = driver.XL_CanRequestChipState(portHandle, accessMask); Console.WriteLine("Can Request Chip State: " + status); if (status != XLDefine.XL_Status.XL_SUCCESS) { PrintFunctionError(); } // Activate channel status = driver.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(); } // Reset time stamp clock status = driver.XL_ResetClock(portHandle); Console.WriteLine("Reset Clock : " + status + "\n\n"); if (status != XLDefine.XL_Status.XL_SUCCESS) { PrintFunctionError(); } }
// ----------------------------------------------------------------------------------------------- /// <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()); }