/// <summary> /// Проверка списка CAN-адаптеров /// </summary> public string[] ListOfDevices() { string CheckDevice = ""; IVciDeviceManager deviceManager = null; System.Collections.IEnumerator deviceEnum = null; try { deviceManager = VciServer.GetDeviceManager(); deviceList = deviceManager.GetDeviceList(); deviceEnum = deviceList.GetEnumerator(); deviceEnum.MoveNext(); do { mDevice = deviceEnum.Current as IVciDevice; object serialNumberGuid = mDevice.UniqueHardwareId; string serialNumberText = GetSerialNumberText(ref serialNumberGuid); CheckDevice += mDevice.Description + " " + mDevice.UniqueHardwareId.ToString() + ";"; } while (deviceEnum.MoveNext() != false); } catch (Exception) { CheckDevice = "Error: No VCI device installed"; } finally { DisposeVciObject(deviceManager); DisposeVciObject(deviceEnum); } return(CheckDevice.Split(';')); }
//************************************************************************ /// <summary> /// Selects the first CAN adapter. /// </summary> //************************************************************************ static void SelectDevice() { IVciDeviceManager deviceManager = null; IVciDeviceList deviceList = null; IEnumerator deviceEnum = null; try { // // Get device manager from VCI server // deviceManager = VciServer.GetDeviceManager(); // // Get the list of installed VCI devices // deviceList = deviceManager.GetDeviceList(); deviceList = deviceManager.GetDeviceList(); // // Get enumerator for the list of devices // deviceEnum = deviceList.GetEnumerator(); // // Get first device // deviceEnum.MoveNext(); mDevice = deviceEnum.Current as IVciDevice; // show the device name and serial number object serialNumberGuid = mDevice.UniqueHardwareId; string serialNumberText = GetSerialNumberText(ref serialNumberGuid); Console.Write(" Interface : " + mDevice.Description + "\n"); Console.Write(" Serial number: " + serialNumberText + "\n"); } catch (Exception) { Console.WriteLine("Error: No VCI device installed"); } finally { // // Dispose device manager ; it's no longer needed. // DisposeVciObject(deviceManager); // // Dispose device list ; it's no longer needed. // DisposeVciObject(deviceList); // // Dispose device list ; it's no longer needed. // DisposeVciObject(deviceEnum); } }
//************************************************************************ /// <summary> /// Selects the first LIN adapter. /// </summary> /// <return> true if succeeded, false otherwise</return> //************************************************************************ static bool SelectDevice() { bool succeeded = true; IVciDeviceManager deviceManager = null; IVciDeviceList deviceList = null; IEnumerator deviceEnum = null; try { // // Get device manager from VCI server // deviceManager = VciServer.GetDeviceManager(); // // Get the list of installed VCI devices // deviceList = deviceManager.GetDeviceList(); deviceList = deviceManager.GetDeviceList(); // // Get enumerator for the list of devices // deviceEnum = deviceList.GetEnumerator(); // // Get first device // deviceEnum.MoveNext(); mDevice = deviceEnum.Current as IVciDevice; } catch (Exception) { Console.WriteLine("Error: No VCI device installed"); succeeded = false; } finally { // // Dispose device manager ; it's no longer needed. // DisposeVciObject(deviceManager); // // Dispose device list ; it's no longer needed. // DisposeVciObject(deviceList); // // Dispose device list ; it's no longer needed. // DisposeVciObject(deviceEnum); } return(succeeded); }
public static bool InitDevice(byte canNo, int canSpeed, int adapterNo) { IBalObject bal = null; System.Collections.IEnumerator deviceEnum = null; int i = -1; try { deviceEnum = deviceList.GetEnumerator(); deviceEnum.MoveNext(); do { i++; if (i == adapterNo) { mDevice = deviceEnum.Current as IVciDevice; } } while (deviceEnum.MoveNext() != false); bal = mDevice.OpenBusAccessLayer(); mCanChn = bal.OpenSocket(canNo, typeof(ICanChannel)) as ICanChannel; mCanChn.Initialize(1024, 128, false); mReader = mCanChn.GetMessageReader(); mReader.Threshold = 1; mRxEvent = new AutoResetEvent(false); mReader.AssignEvent(mRxEvent); mWriter = mCanChn.GetMessageWriter(); mWriter.Threshold = 1; mCanChn.Activate(); int a = bal.Resources.Count - 1; mCanCtl = bal.OpenSocket(canNo, typeof(ICanControl)) as ICanControl; mCanCtl.InitLine(CanOperatingModes.Standard | CanOperatingModes.ErrFrame , CanBitrate.Cia250KBit); mCanCtl.SetAccFilter(CanFilter.Std, (uint)CanAccCode.All, (uint)CanAccMask.All); mCanCtl.StartLine(); return(true); } catch (Exception e) { MessageBox.Show("Error: Initializing socket failed: " + e.Message); return(false); } finally { DisposeVciObject(bal); DisposeVciObject(deviceEnum); IsOpen = true; } }
static IVciDevice GetDeviceByString(String adapterSerial) { IVciDevice _return = null; IVciDeviceManager deviceManager = null; IVciDeviceList deviceList = null; System.Collections.IEnumerator deviceEnum = null; String SerialNumber = String.Empty; try { deviceManager = VciServer.Instance().DeviceManager; deviceList = deviceManager.GetDeviceList(); deviceEnum = deviceList.GetEnumerator(); while (deviceEnum.MoveNext()) { _return = deviceEnum.Current as IVciDevice; object serialNumberGuid = _return.UniqueHardwareId; if (GetSerialNumberText(serialNumberGuid) == adapterSerial) { break; } } } catch (Exception exc) { Debug.WriteLine("Error: " + exc.Message + "\n"); } finally { DisposeVciObject(deviceManager); DisposeVciObject(deviceList); DisposeVciObject(deviceEnum); } return(_return); }
static void DeviceListEvent() { IVciDeviceManager _deviceManager = null; IVciDeviceList _deviceList = null; System.Collections.IEnumerator _deviceEnum = null; IVciDevice _mDevice = null; Devices = new List <string>(); Debug.WriteLine("DeviceListEvent\n"); try { _deviceManager = VciServer.Instance().DeviceManager; _deviceList = _deviceManager.GetDeviceList(); _deviceEnum = _deviceList.GetEnumerator(); for (int i = 1; _deviceEnum.MoveNext(); i++) { _mDevice = _deviceEnum.Current as IVciDevice; Devices.Add(Can.GetSerialNumberText(_mDevice.UniqueHardwareId)); Debug.WriteLine(" " + i + ":" + Can.GetSerialNumberText(_mDevice.UniqueHardwareId) + "\n"); } ListChanged(); } catch (Exception exc) { Debug.WriteLine("Error: " + exc.Message + "\n"); } finally { Can.DisposeVciObject(_mDevice); Can.DisposeVciObject(_deviceManager); Can.DisposeVciObject(_deviceList); Can.DisposeVciObject(_deviceEnum); } }