private bool GetApplicationChannel(int appChIdx, ref UInt64 chMask, ref int chIdx) { XLDefine.XL_Status status = driver.XL_GetApplConfig(applicationName, (uint)appChIdx, ref hwType, ref hardwareIndex, ref hardwareChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_LIN); Trace.WriteLine("XL_GetApplConfig : " + status); chMask = driver.XL_GetChannelMask(hwType, (int)hardwareIndex, (int)hardwareChannel); chIdx = driver.XL_GetChannelIndex(hwType, (int)hardwareIndex, (int)hardwareChannel); Trace.WriteLine("chMask : " + chMask + " chIdx: " + chIdx); if (chIdx < 0 || chIdx >= driverConfig.channelCount) { return(false); } return((driverConfig.channel[chIdx].channelBusCapabilities & XLDefine.XL_BusCapabilities.XL_BUS_ACTIVE_CAP_LIN) != 0); }
///////////////////////////////////////////////////////////////////////// /// public bool GetAppChannelAndTestIsOk(uint appChIdx, ref UInt64 chMask, ref int chIdx) { XLDefine.XL_Status status = UDSDemo.XL_GetApplConfig(appName, appChIdx, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN); { Console.WriteLine("XL_Get application Configuration:" + status + Environment.NewLine); } chMask = UDSDemo.XL_GetChannelMask(hwType, (int)hwIndex, (int)hwChannel); chIdx = UDSDemo.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 & XLDefine.XL_BusCapabilities.XL_BUS_ACTIVE_CAP_CAN) != 0); ///////////////////////////////////////////////////////////////////////// /// }
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); }
private bool GetAppChannelAndTestIsOk(uint appChIdx, ref UInt64 chMask, ref int chIdx) { XLDefine.XL_Status status = CANDriver.XL_GetApplConfig(appName, appChIdx, ref hwType, ref hwIndex, ref hwChannel, XLDefine.XL_BusTypes.XL_BUS_TYPE_CAN); if (status != XLDefine.XL_Status.XL_SUCCESS) { info += "XL_GetApplConfig : " + status + "\n"; } chMask = CANDriver.XL_GetChannelMask(hwType, (int)hwIndex, (int)hwChannel); chIdx = CANDriver.XL_GetChannelIndex(hwType, (int)hwIndex, (int)hwChannel); if (chIdx < 0 || chIdx >= driverConfig.channelCount) { return(false); } if ((driverConfig.channel[chIdx].channelBusCapabilities & XLDefine.XL_BusCapabilities.XL_BUS_ACTIVE_CAP_CAN) == 0) { return(false); } if (canFdModeNoIso > 0) { if ((driverConfig.channel[chIdx].channelCapabilities & XLDefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_BOSCH_SUPPORT) == 0) { info += driverConfig.channel[chIdx].name.TrimEnd(' ', '\0') + " " + driverConfig.channel[chIdx].transceiverName.TrimEnd(' ', '\0') + " does not support CAN FD NO-ISO"; return(false); } } else { if ((driverConfig.channel[chIdx].channelCapabilities & XLDefine.XL_ChannelCapabilities.XL_CHANNEL_FLAG_CANFD_ISO_SUPPORT) == 0) { info += driverConfig.channel[chIdx].name.TrimEnd(' ', '\0') + " " + driverConfig.channel[chIdx].transceiverName.TrimEnd(' ', '\0') + " does not support CAN FD ISO"; return(false); } } return(true); }
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); }
/// <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()); }