本文整理汇总了C#中LibUsbDotNet.UsbDevice类的典型用法代码示例。如果您正苦于以下问题:C# UsbDevice类的具体用法?C# UsbDevice怎么用?C# UsbDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UsbDevice类属于LibUsbDotNet命名空间,在下文中一共展示了UsbDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
}
示例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();
}
}
示例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;
}
示例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);
}
}
}
示例5: CHDKPTPDevice
public CHDKPTPDevice(UsbDevice dev)
: base(dev)
{
this.CHDKVersionMajor = -1;
this.CHDKVersionMinor = -1;
this.CHDKSupported = false;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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);
}
}
}
示例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;
}
示例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.
}
}