• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# LibUsbDotNet.UsbDevice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中LibUsbDotNet.UsbDevice的典型用法代码示例。如果您正苦于以下问题:C# UsbDevice类的具体用法?C# UsbDevice怎么用?C# UsbDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UsbDevice类属于LibUsbDotNet命名空间,在下文中一共展示了UsbDevice类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: GetDelcomBuildLight

        private bool GetDelcomBuildLight()
        {
            try
            {
                MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

                // If the device is open and ready
                if (MyUsbDevice == null) throw new Exception("Device Not Found.");

                IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                if (!ReferenceEquals(wholeUsbDevice, null))
                {
                    // This is a "whole" USB device. Before it can be used,
                    // the desired configuration and interface must be selected.

                    // Select config #1
                    wholeUsbDevice.SetConfiguration(1);

                    // Claim interface #0.
                    wholeUsbDevice.ClaimInterface(0);
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
开发者ID:perkof,项目名称:LibUsbDotNet-Delcom804002_BDriver,代码行数:29,代码来源:LightDevice.cs


示例2: CrazyradioDriver

        /// <summary>
        ///     Creates and initializes an instance of a Crazyradio USB dongle driver.
        /// </summary>
        /// <param name="crazyradioUsbDevice"> The UsbDevice to use in this driver. </param>
        public CrazyradioDriver(UsbDevice crazyradioUsbDevice)
        {
            Log.Debug("Received UsbDevice to use in CrazyradioDriver.");

            if (crazyradioUsbDevice == null)
            {
                Log.Error("UsbDevice is null.");
                throw new ArgumentNullException("crazyradioUsbDevice");
            }

            _crazyradioUsbDevice = crazyradioUsbDevice;

            if (IsCrazyradioUsbDongle(_crazyradioUsbDevice))
            {
                Log.Debug("UsbDevice is in fact a Crazyradio USB dongle.");

                CheckFirmwareVersion();
            }
            else
            {
                const string message = "UsbDevice is not a Crazyradio USB dongle.";
                Log.Error(message);
                throw new CrazyradioDriverException(message);
            }

            if (_crazyradioUsbDevice.IsOpen)
            {
                Log.Debug("UsbDevice is open. Closing until user opens to prevent inconsistent driver state.");

                _crazyradioUsbDevice.Close();
            }
        }
开发者ID:chungInShing,项目名称:CrazyflieDotNet,代码行数:36,代码来源:CrazyradioDriver.cs


示例3: OpenDevice

		public override bool OpenDevice ()
		{
			// Find and open the usb device.
			if (device == null)
				device = UsbDevice.OpenUsbDevice (deviceFinder);

			// If the device is open and ready
			if (device == null)
				throw new Exception ("Device Not Found.");

			// If this is a "whole" usb device (libusb-win32, linux libusb)
			// it will have an IUsbDevice interface. If not (WinUSB) the 
			// variable will be null indicating this is an interface of a 
			// device.
			IUsbDevice wholeUsbDevice = device as IUsbDevice;
			if (!ReferenceEquals (wholeUsbDevice, null)) {
				// This is a "whole" USB device. Before it can be used, 
				// the desired configuration and interface must be selected.

				// Select config #1
				wholeUsbDevice.SetConfiguration (1);

				// Claim interface #0.
				wholeUsbDevice.ClaimInterface (0);
			} else {
				return false;
			}

			connectedToDriver = true;

			return true;
        }
开发者ID:pipermatt,项目名称:blinkstick-client,代码行数:32,代码来源:LinuxBlinkstickHid.cs


示例4: UsbTool

        public UsbTool()
        {
            if(MyUsbDevice == null)
            {
                // Find and open the usb device.
                MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

                // If the device is open and ready
                if (MyUsbDevice == null) throw new Exception("Device Not Found.");

                // If this is a "whole" usb device (libusb-win32, linux libusb)
                // it will have an IUsbDevice interface. If not (WinUSB) the
                // variable will be null indicating this is an interface of a
                // device.
                IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                if (!ReferenceEquals(wholeUsbDevice, null))
                {
                    // This is a "whole" USB device. Before it can be used,
                    // the desired configuration and interface must be selected.

                    wholeUsbDevice.SetConfiguration(1);

                    wholeUsbDevice.ClaimInterface(0);
                    wholeUsbDevice.ClaimInterface(1);
                }
            }
        }
开发者ID:hansfbaier,项目名称:nova-librarian,代码行数:27,代码来源:UsbTool.cs


示例5: CHDKPTPDevice

 public CHDKPTPDevice(UsbDevice dev)
     : base(dev)
 {
     this.CHDKVersionMajor = -1;
     this.CHDKVersionMinor = -1;
     this.CHDKSupported = false;
 }
开发者ID:postondemand,项目名称:CHDKPTPRemote,代码行数:7,代码来源:CHDKPTPDevice.cs


示例6: Connect

        // Connect to the arm
        public bool Connect()
        {
            // Vendor ID/Product ID here
            UsbDeviceFinder USBFinder = new UsbDeviceFinder(0x1267, 0x0);

            // Try to open the device
            RobotArm = UsbDevice.OpenUsbDevice(USBFinder);

            // Did we connect OK?
            if ((RobotArm == null))
                return false;

            // If this is a "whole" usb device (libusb-win32, linux libusb)
            // it will have an IUsbDevice interface. If not (WinUSB) the
            // variable will be null indicating this is an interface of a
            // device.
            IUsbDevice wholeUsbDevice = RobotArm as IUsbDevice;
            if (!ReferenceEquals(wholeUsbDevice, null))
            {
                // This is a "whole" USB device. Before it can be used,
                // the desired configuration and interface must be selected.

                // Select config #1
                wholeUsbDevice.SetConfiguration(1);

                // Claim interface #0.
                wholeUsbDevice.ClaimInterface(0);
            }

            // Connected and have interface to the arm
            return true;
        }
开发者ID:janires,项目名称:robotkinect,代码行数:33,代码来源:MaplinRobotArm.cs


示例7: CloseDevice

        public void CloseDevice()
        {
            if(_usbDevice == null || !_usbDevice.IsOpen)
                return;
            if(_epReader != null) {
                _epReader.Dispose();
                _epReader = null;
            }
            if(_epWriter != null) {
                _epWriter.Abort();
                _epWriter.Dispose();
                _epWriter = null;
            }

            // If this is a "whole" usb device (libusb-win32, linux libusb)
            // it will have an IUsbDevice interface. If not (WinUSB) the
            // variable will be null indicating this is an interface of a
            // device.
            var wholeUsbDevice = _usbDevice as IUsbDevice;
            if(!ReferenceEquals(wholeUsbDevice, null))
                wholeUsbDevice.ReleaseInterface(0); // Release interface #0.

            _usbDevice.Close();
            _usbDevice = null;
        }
开发者ID:GotoHack,项目名称:NANDORway,代码行数:25,代码来源:Teensy.cs


示例8: OpenAsync

        /// <summary>
        /// Open the connection
        /// </summary>
        /// <returns>whether the connection was opened successfully</returns>
        public async Task<bool> OpenAsync()
        {
            dev = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(0x10C4, 0xEAC9));
            if (dev == null)
            {
                dev = UsbDevice.OpenUsbDevice(new UsbDeviceFinder(0x10C4, 0xEACA));
                if (dev == null)
                    return false;
            }

            IUsbDevice wholeUsbDevice = dev as IUsbDevice;
            if (!ReferenceEquals(wholeUsbDevice, null))
            {
                // This is a "whole" USB device. Before it can be used, 
                // the desired configuration and interface must be selected.

                // Select config #1
                wholeUsbDevice.SetConfiguration(1);

                // Claim interface #0.
                wholeUsbDevice.ClaimInterface(0);
            }


            writer = dev.OpenEndpointWriter(WriteEndpointID.Ep01, EndpointType.Interrupt);
            reader = dev.OpenEndpointReader(ReadEndpointID.Ep01, 64, EndpointType.Interrupt);

            return true;
        }
开发者ID:treehopper-electronics,项目名称:treehopper-sdk,代码行数:33,代码来源:FirmwareConnection.cs


示例9: getControllers

        /**
         * Finds all of the connected Playstation controllers.
         */
        public static UsbDevice[] getControllers()
        {
            List<UsbDevice> controllersL = new List<UsbDevice>();
            //UsbDevice[] controllers = new UsbDevice[4];
            UsbDevice[] devices = new UsbDevice[20];

            UsbRegDeviceList allDevices = UsbDevice.AllDevices;
            Console.WriteLine("numDevices: " + allDevices.Count);
            int i = 0;
            foreach (UsbRegistry usbRegistry in allDevices)
            {
                //Console.WriteLine("device"+i);
                if (usbRegistry.Open(out devices[i]))
                {
                    Console.WriteLine(devices[i].Info.ToString());
                    if (devices[i].Info.ToString().Contains("PLAYSTATION"))
                    {
                        /*int index = 0;
                        for (int j = 0; j < 4; j++)
                        {
                            if (controllers[j] == null)
                            {
                                index = j;
                                break;
                            }
                        }
                        controllers[index] = devices[i];*/
                        controllersL.Add(devices[i]);
                    }
                }
                i++;
            }

            return controllersL.ToArray();
        }
开发者ID:RocHCI,项目名称:legion-gaming,代码行数:38,代码来源:Program.cs


示例10: open

 public void open()
 {
     // Find and open the usb device.
     MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
     if (MyUsbDevice == null) throw new Exception("Device Not Found.");
     UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
 }
开发者ID:pbomark,项目名称:L3-LagomLitenLED,代码行数:7,代码来源:LagomLitenLed.cs


示例11: CloseDevice

        public static void CloseDevice()
        {
            if (usbDevice != null)
            {
                if (usbDevice.IsOpen)
                {
                    Logger.Log("Closing device");

                    // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
                    // it exposes an IUsbDevice interface. If not (WinUSB) the
                    // 'wholeUsbDevice' variable will be null indicating this is
                    // an interface of a device; it does not require or support
                    // configuration and interface selection.
                    IUsbDevice wholeUsbDevice = usbDevice as IUsbDevice;
                    if (!ReferenceEquals(wholeUsbDevice, null))
                    {
                        // Release interface #0.
                        wholeUsbDevice.ReleaseInterface(0);
                    }

                    usbDevice.Close();
                }
                usbDevice = null;

                // Free usb resources
                UsbDevice.Exit();
            }
        }
开发者ID:DODMax,项目名称:serverScan,代码行数:28,代码来源:USBRead.cs


示例12: OpenDevice

        public static void OpenDevice(Int32 vid, Int32 pid)
        {
            if (usbDevice != null)
                Program.ShowError("A device is already openned, please close it first.");

            Logger.Log("Connecting to device vid." + vid + " pid." + pid);
            UsbDeviceFinder usbFinder = new UsbDeviceFinder(vid, pid);

            // Find and open the usb device.
            usbDevice = UsbDevice.OpenUsbDevice(usbFinder);

            // If the device is open and ready
            if (usbDevice == null) throw new Exception("Device Not Found.");

            // If this is a "whole" usb device (libusb-win32, linux libusb-1.0)
            // it exposes an IUsbDevice interface. If not (WinUSB) the
            // 'wholeUsbDevice' variable will be null indicating this is
            // an interface of a device; it does not require or support
            // configuration and interface selection.
            IUsbDevice wholeUsbDevice = usbDevice as IUsbDevice;
            if (!ReferenceEquals(wholeUsbDevice, null))
            {
                // This is a "whole" USB device. Before it can be used,
                // the desired configuration and interface must be selected.

                // Select config #1
                wholeUsbDevice.SetConfiguration(1);

                // Claim interface #0.
                wholeUsbDevice.ClaimInterface(0);
            }
        }
开发者ID:DODMax,项目名称:serverScan,代码行数:32,代码来源:USBRead.cs


示例13: LibUsb_AsyncUsbStream

		public LibUsb_AsyncUsbStream (string port)
		{
			var splited = port.Split ('-');
			var finder = new UsbDeviceFinder (int.Parse (splited [0]), int.Parse (splited [1]));
			device = UsbDevice.OpenUsbDevice (finder);
			if (device == null) {
				throw new Exception ("Failed to find device:" + port);
			}
			if (!device.IsOpen) {
				throw new Exception ("Device is not open:" + port);
			}

			var usbDevice = device as IUsbDevice;
			var interfaceInfo = device.Configs [0].InterfaceInfoList [0];

			if (usbDevice != null) {
				usbDevice.SetConfiguration (device.Configs [0].Descriptor.ConfigID);

				usbDevice.ClaimInterface (interfaceInfo.Descriptor.InterfaceID);
				deviceInterfaceId = interfaceInfo.Descriptor.InterfaceID;
			}

			foreach (var ep in interfaceInfo.EndpointInfoList) {
				if ((ep.Descriptor.EndpointID & 0x80) > 0) {
					reader = device.OpenEndpointReader ((ReadEndpointID)ep.Descriptor.EndpointID);
					reader.DataReceived += HandleDataReceived;
					reader.DataReceivedEnabled = true;
				} else {
					writer = device.OpenEndpointWriter ((WriteEndpointID)ep.Descriptor.EndpointID);
				}
			}
		}
开发者ID:Roddoric,项目名称:Monkey.Robotics,代码行数:32,代码来源:LibUsbStream.cs


示例14: getControllers

        /**
         * Finds all of the connected Playstation controllers.
         */
        public static UsbDevice[] getControllers()
        {
            UsbDevice[] controllers = new UsbDevice[4];
            UsbDevice[] devices = new UsbDevice[20];

            UsbRegDeviceList allDevices = UsbDevice.AllDevices;
            int i = 0;
            foreach (UsbRegistry usbRegistry in allDevices)
            {
                if (usbRegistry.Open(out devices[i]))
                {
                    if (devices[i].Info.ToString().Contains("PLAYSTATION"))
                    {
                        int index = 0;
                        for (int j = 0; j < 4; j++)
                        {
                            if (controllers[j] == null)
                            {
                                index = j;
                                break;
                            }
                        }
                        controllers[index] = devices[i];
                    }
                }
                i++;
            }

            return controllers;
        }
开发者ID:RocHCI,项目名称:legion-gaming,代码行数:33,代码来源:Program.cs


示例15: connect

        /// <summary>
        /// Try to connect to the device
        /// </summary>
        /// <returns>1 for success, 0 for fail</returns>
        public int connect()
        {
            try
            {
                // Find and open the usb device.
                MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

                // If the device is open and ready
                if (MyUsbDevice == null) throw new Exception("Device Not Found.");

                // If this is a "whole" usb device (libusb-win32, linux libusb)
                // it will have an IUsbDevice interface. If not (WinUSB) the
                // variable will be null indicating this is an interface of a
                // device.
                IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
                if (!ReferenceEquals(wholeUsbDevice, null))
                {
                    // This is a "whole" USB device. Before it can be used,
                    // the desired configuration and interface must be selected.

                    // Select config #1
                    wholeUsbDevice.SetConfiguration(1);

                    // Claim interface #0.
                    wholeUsbDevice.ClaimInterface(0);
                }

                return 1; // Device found!
            }
            catch
            {
                return 0; // Failed to find one.
            }
        }
开发者ID:beckettman,项目名称:Little-Wire,代码行数:38,代码来源:littleWire.cs


示例16: Close

        public override void Close()
        {
            try {
                write_lock.WaitOne ();

                if (ep_reader != null) {
                    // detach read event
                    ep_reader.DataReceivedEnabled = false;
                    ep_reader.DataReceived -= (read_usb);
                }

                ep_reader = null;
                ep_writer = null;

                if (IsOpen ()) {
                    // close devices
                    usb_device.Close ();
                    wholeUsbDevice.ReleaseInterface (1);
                    wholeUsbDevice.Close ();
                }

                // release devices
                usb_device = null;
                wholeUsbDevice = null;
                UsbDevice.Exit();
            } catch (Exception) {
                // Ignore everything
            } finally {
                write_lock.ReleaseMutex();
            }
        }
开发者ID:josla972,项目名称:combilib-mono,代码行数:31,代码来源:caLibUsbAdapter.cs


示例17: InitDevice

        private static void InitDevice()
        {
            MyUsbFinder = new UsbDeviceFinder(0x045E, 0x02B0);
            MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);

            // If the device is open and ready
            if (MyUsbDevice == null) throw new Exception("Device Not Found.");

            // If this is a "whole" usb device (libusb-win32, linux libusb)
            // it will have an IUsbDevice interface. If not (WinUSB) the
            // variable will be null indicating this is an interface of a
            // device.
            IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
            if (!ReferenceEquals(wholeUsbDevice, null))
            {
                // This is a "whole" USB device. Before it can be used,
                // the desired configuration and interface must be selected.

                // Select config #1
                wholeUsbDevice.SetConfiguration(1);

                // Claim interface #0.
                wholeUsbDevice.ClaimInterface(0);
            }
        }
开发者ID:Jerdak,项目名称:meshlab,代码行数:25,代码来源:KinectMotor.cs


示例18: Open

		public override bool Open(out UsbDevice usbDevice)
		{
			usbDevice = null;
			MacUsbDevice macUsbDevice;
			bool bSuccess = Open(out macUsbDevice);
			if (bSuccess)
				usbDevice = macUsbDevice;
			return bSuccess;
		}
开发者ID:treehopper-electronics,项目名称:treehopper-sdk,代码行数:9,代码来源:MacUsbRegistry.cs


示例19: Receiver

        public Receiver(USBManager manager, UsbDevice device)
        {
            //m_manager = manager;
            //m_reader = device.OpenEndpointReader(readEndpoint);                     // On ouvre le canal de lecture
            //m_engaged = true;
            //readThread = new Thread(this.doRead);

            //// Start to read
            //readThread.Start();
        }
开发者ID:Ace-Nanter,项目名称:SMS_on_PC,代码行数:10,代码来源:Receiver.cs


示例20: PTPDevice

 public PTPDevice(UsbDevice dev)
 {
     _Device = dev;
     PTPSupported = false;
     _Name = dev.Info.ProductString; // TODO: try get better name
     Reader = null;
     Writer = null;
     ConfigurationID = 1;
     InterfaceID = 0;
     ReaderEndpointID = ReadEndpointID.Ep01;
     WriterEndpointID = WriteEndpointID.Ep02;
 }
开发者ID:mweerden,项目名称:CHDKPTPRemote,代码行数:12,代码来源:PTPDevice.cs



注:本文中的LibUsbDotNet.UsbDevice类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Main.UsbSetupPacket类代码示例发布时间:2022-05-26
下一篇:
C# TestHelpers.TemporaryCloneOfTestRepo类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap