Ejemplo n.º 1
0
 private void SelectDevice()
 {
     try
     {
         // get selected device info
         deviceManager = VciServer.Instance().DeviceManager;
         deviceList    = deviceManager.GetDeviceList();
         deviceEnum    = deviceListCBox.Items.GetEnumerator();
         deviceEnum.MoveNext();
         mDevice = deviceEnum.Current as IVciDevice;
         IVciCtrlInfo info = mDevice.Equipment[0];
         // inform the user on the selected device
         MessageBox.Show("Selected Device:\n" + mDevice.ToString(), "INFO",
                         MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
         slctDevBtn.Enabled = true;
     }
     finally
     {
         // release the resources of the library
         DisposeVciObject(deviceManager);
         DisposeVciObject(deviceList);
         DisposeVciObject(deviceEnum);
         slctDevBtn.Enabled = false;
     }
 }
Ejemplo n.º 2
0
        /// <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(';'));
        }
Ejemplo n.º 3
0
        //************************************************************************
        /// <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);
            }
        }
Ejemplo n.º 4
0
        //************************************************************************
        /// <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);
        }
Ejemplo n.º 5
0
        static public void StartDeviceListMonitor()
        {
            IVciDeviceManager deviceManager = null;
            IVciDeviceList    deviceList    = null;

            deviceManager = VciServer.Instance().DeviceManager;
            deviceList    = deviceManager.GetDeviceList();
            ARE_Devices   = new AutoResetEvent(true);       //true запустит метод сразу
            deviceList.AssignEvent(ARE_Devices);

            ARE_Thread = new Thread(ARE_Thread_Devices);
            ARE_Thread.Start();
        }
Ejemplo n.º 6
0
        private CanManager()
        {
            _connectionEvent = new AutoResetEvent(true);

            using (IVciDeviceManager deviceManager = VciServer.Instance().DeviceManager)
            {
                _deviceList = deviceManager.GetDeviceList();
                _deviceList.AssignEvent(_connectionEvent);
            }

            Thread t = new Thread(ConnectionThread);

            t.IsBackground = true;
            t.Start();
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
            }
        }