本文整理汇总了C#中LibUsbDotNet.UsbDevice.OpenEndpointReader方法的典型用法代码示例。如果您正苦于以下问题:C# UsbDevice.OpenEndpointReader方法的具体用法?C# UsbDevice.OpenEndpointReader怎么用?C# UsbDevice.OpenEndpointReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LibUsbDotNet.UsbDevice
的用法示例。
在下文中一共展示了UsbDevice.OpenEndpointReader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TraqpaqDevice
/// <summary>
/// Class constructor for the traq|paq
/// </summary>
public TraqpaqDevice()
{
// find the device
traqpaqDeviceFinder = new UsbDeviceFinder(Constants.VID, Constants.PID);
// open the device
this.MyUSBDevice = UsbDevice.OpenUsbDevice(traqpaqDeviceFinder);
// If the device is open and ready
if (MyUSBDevice == null) throw new TraqPaqNotConnectedException("Device not found");
this.reader = MyUSBDevice.OpenEndpointReader(ReadEndpointID.Ep01);
this.writer = MyUSBDevice.OpenEndpointWriter(WriteEndpointID.Ep02);
// create the battery object
this.battery = new Battery(this);
// get a list of saved tracks
getAllTracks();
// get the record table data
tableReader = new RecordTableReader(this);
tableReader.readRecordTable();
this.recordTableList = tableReader.recordTable;
}
示例2: 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);
}
示例3: SmartScopeUsbInterfaceLibUsb
public SmartScopeUsbInterfaceLibUsb(UsbDevice usbDevice)
{
if (usbDevice is IUsbDevice)
{
bool succes1 = (usbDevice as IUsbDevice).SetConfiguration(1);
if (!succes1)
throw new ScopeIOException("Failed to set usb device configuration");
bool succes2 = (usbDevice as IUsbDevice).ClaimInterface(0);
if (!succes2)
throw new ScopeIOException("Failed to claim usb interface");
}
device = usbDevice;
serial = usbDevice.Info.SerialString;
dataEndpoint = usbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
commandWriteEndpoint = usbDevice.OpenEndpointWriter(WriteEndpointID.Ep02);
commandReadEndpoint = usbDevice.OpenEndpointReader(ReadEndpointID.Ep03);
Common.Logger.Debug("Created new ScopeUsbInterface from device with serial " + serial);
}
示例4: GarminUnit
public GarminUnit(UsbDevice Device)
{
Configuration = new Dictionary<string, ushort>();
IUsbDevice wholedevice = Device as IUsbDevice;
if ( !ReferenceEquals(wholedevice, null))
{
wholedevice.SetConfiguration(1);
wholedevice.ClaimInterface(0);
}
Reader = Device.OpenEndpointReader(ReadEndpointID.Ep01);
Writer = Device.OpenEndpointWriter(WriteEndpointID.Ep02);
}
示例5: PolhemusStream
public PolhemusStream()
{
try
{
// Find and open the usb device.
PolhemusUsbDevice = UsbDevice.OpenUsbDevice(UsbFinder);
// If the device is open and ready
if (PolhemusUsbDevice == null) throw new Exception("Polhemus 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 = PolhemusUsbDevice 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);
}
//Polhemus uses EndPoint 2 for both read and write
PolhemusReader = PolhemusUsbDevice.OpenEndpointReader(ReadEndpointID.Ep02);
PolhemusWriter = PolhemusUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep02);
}
catch (Exception e)
{
throw new Exception("Error in PolhemusStream constructor: " + e.Message);
}
}
示例6: OpenDevice
private void OpenDevice()
{
if(_usbDevice != null && _usbDevice.IsOpen)
return;
// Find and open the usb device.
_usbDevice = UsbDevice.OpenUsbDevice(_usbFinder);
// If the device is open and ready
Debug.Assert(_usbDevice != null, string.Format("No device with PID: {0:X4} & VID: {1:X4} Found!", _pid, _vid));
// 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)) {
// 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);
}
// open read endpoint 1.
_epReader = _usbDevice.OpenEndpointReader((ReadEndpointID) EpIn);
_epReader.Flush();
// open write endpoint 1.
_epWriter = _usbDevice.OpenEndpointWriter((WriteEndpointID) EpOut);
LibMain.OnConnectedChanged(true);
}
示例7: ServiceWorkerThread
/// <summary>
/// The method performs the main function of the service. It runs on
/// a thread pool worker thread.
/// </summary>
/// <param name="state"></param>
private void ServiceWorkerThread(object state)
{
GetIDs();
ErrorCode ec = ErrorCode.None;
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.");
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
wholeUsbDevice.SetConfiguration(1);
wholeUsbDevice.ClaimInterface(0);
}
// open read endpoint 1.
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
byte[] readBuffer = new byte[1024];
int bytesRead = 0;
// Periodically check if the service is stopping.
while (!this.stopping)
{
//Thread.Sleep(2000); // Simulate some lengthy operations.
ec = reader.Read(readBuffer, 30000, out bytesRead);
if (bytesRead > 0)
{
string trackString = Encoding.Default.GetString(readBuffer, 0, bytesRead);
string[] words = trackString.Split('?');
System.IO.StreamWriter fileReader2 = new System.IO.StreamWriter(trackFile, true);
if (words.Length > 0)
{
//Console.WriteLine();
string[] track1 = words[0].Split('%');
if (track1.Length > 1 && track1[1].Length > 0)
{
fileReader2.WriteLine(track1[1]);
//Console.WriteLine(track1[1]);
}
}
if (words.Length > 1)
{
string[] track2 = words[1].Split(';');
if (track2.Length > 1 && track2[1].Length > 0)
{
fileReader2.WriteLine(track2[1]);
//Console.WriteLine(track2[1]);
}
}
if (words.Length > 2)
{
string[] track3 = words[2].Split(';');
if (track3.Length > 1 && track3[1].Length > 0)
{
fileReader2.WriteLine(track3[1]);
//Console.WriteLine(track3[1]);
}
}
fileReader2.Close();
}
}
}
catch (Exception ex)
{
System.IO.StreamWriter file = new System.IO.StreamWriter(logFile, true);
file.WriteLine();
file.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
file.Close();
}
finally
{
if (MyUsbDevice != null)
{
if (MyUsbDevice.IsOpen)
{
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
// Release interface #0.
wholeUsbDevice.ReleaseInterface(0);
}
MyUsbDevice.Close();
}
MyUsbDevice = null;
UsbDevice.Exit();
}
}
// Signal the stopped event.
this.stoppedEvent.Set();
}
示例8: Battery
public Battery(UsbDevice usb = null)
{
usbDevice = usb;
// 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 = 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);
}
// open read endpoint 1
UsbEndpointReader batInfoReader = usbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
ErrorCode ec = ErrorCode.None;
byte[] batInfoReadBuffer = new byte[64];
int bytesRead = 0;
// If the device hasn't sent data in the last 100 milliseconds,
// a timeout error (ec = IoTimedOut) will occur.
ec = batInfoReader.Read(batInfoReadBuffer, 100, out bytesRead);
if (bytesRead == 0) throw new Exception("No more bytes!");
// create BinaryReader and set source to readBuffer
BatteryBinaryReader batInfoBReader = new BatteryBinaryReader(batInfoReadBuffer);
// set battery variables using binary reader
fwVersion = batInfoBReader.ReadByte() + ((float) batInfoBReader.ReadByte()) / 10;
id = new string(batInfoBReader.ReadChars(6));
name = new string(batInfoBReader.ReadChars(20));
currentTime = batInfoBReader.ReadInt32();
lastSyncTime = batInfoBReader.ReadInt32();
capacity = batInfoBReader.ReadUInt16();
lastFullCap = batInfoBReader.ReadUInt16();
factoryCap = batInfoBReader.ReadUInt16();
percentage = 100 * capacity / lastFullCap;
int eepromPages = batInfoBReader.ReadUInt16();
// get unix time
int time = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
// check if battery time is correct
if (currentTime != time || currentTime != time - 1)
{
// open write endpoint 1
UsbEndpointWriter writer = usbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
// convert time to byte array
byte[] timeArray = BitConverter.GetBytes(time);
int bytesWritten = 0;
// write time to endpoint 1
ec = writer.Write(timeArray, 100, out bytesWritten);
}
UsbTransfer usbReadTransfer;
UsbEndpointReader dataReader = usbDevice.OpenEndpointReader(ReadEndpointID.Ep02);
int bytesToRead = 128 * eepromPages;
byte[] dataReadBuffer = new byte[bytesToRead];
// reset error code
ec = ErrorCode.None;
// read logged data using async bulk transfer
ec = dataReader.SubmitAsyncTransfer(dataReadBuffer, 0, bytesToRead, 100, out usbReadTransfer);
// dispose of the usb transfer
usbReadTransfer.Dispose();
// create a string array with the lines of text
var dataReadString = System.Text.Encoding.Default.GetString(dataReadBuffer);
// Set a variable to the My Documents path
string docPath =
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
// write the string array to a new file named "DAS_battery.txt".
using (StreamWriter outputFile = new StreamWriter(docPath + @"\DAS_battery.txt"))
{
outputFile.Write(dataReadString);
}
}
示例9: Open
public bool Open()
{
bool success = true;
//
try
{
// Find and open the usb device.
myUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
//
// If the device is open and ready
if (myUsbDevice == null) throw new Exception("X10 CM15Pro device not connected.");
//
// 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);
}
//
// open read endpoint 1.
reader = myUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
// open write endpoint 2.
writer = myUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep02);
//
this.WriteData(new byte[] { 0x8B }); // status request
}
catch
{
success = false;
//throw new Exception("Error opening X10 CM15Pro device.");
}
return success;
}
示例10: Main
public static void Main(string[] args)
{
ErrorCode ec = ErrorCode.None;
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);
}
// open read endpoint 1.
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
// open write endpoint 1.
UsbEndpointWriter writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
// the write test data.
string testWriteString = "ABCDEFGH";
ErrorCode ecWrite;
ErrorCode ecRead;
int transferredOut;
int transferredIn;
UsbTransfer usbWriteTransfer;
UsbTransfer usbReadTransfer;
byte[] bytesToSend = Encoding.Default.GetBytes(testWriteString);
byte[] readBuffer = new byte[1024];
int testCount = 0;
do
{
// Create and submit transfer
ecRead = reader.SubmitAsyncTransfer(readBuffer, 0, readBuffer.Length, 100, out usbReadTransfer);
if (ecRead != ErrorCode.None) throw new Exception("Submit Async Read Failed.");
ecWrite = writer.SubmitAsyncTransfer(bytesToSend, 0, bytesToSend.Length, 100, out usbWriteTransfer);
if (ecWrite != ErrorCode.None)
{
usbReadTransfer.Dispose();
throw new Exception("Submit Async Write Failed.");
}
WaitHandle.WaitAll(new WaitHandle[] { usbWriteTransfer.AsyncWaitHandle, usbReadTransfer.AsyncWaitHandle },200,false);
if (!usbWriteTransfer.IsCompleted) usbWriteTransfer.Cancel();
if (!usbReadTransfer.IsCompleted) usbReadTransfer.Cancel();
ecWrite = usbWriteTransfer.Wait(out transferredOut);
ecRead = usbReadTransfer.Wait(out transferredIn);
usbWriteTransfer.Dispose();
usbReadTransfer.Dispose();
Console.WriteLine("Read :{0} ErrorCode:{1}", transferredIn, ecRead);
Console.WriteLine("Write :{0} ErrorCode:{1}", transferredOut, ecWrite);
Console.WriteLine("Data :" + Encoding.Default.GetString(readBuffer, 0, transferredIn));
testCount++;
} while (testCount < 5);
Console.WriteLine("\r\nDone!\r\n");
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
}
finally
{
if (MyUsbDevice != null)
{
if (MyUsbDevice.IsOpen)
{
// 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 = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
// Release interface #0.
wholeUsbDevice.ReleaseInterface(0);
}
MyUsbDevice.Close();
//.........这里部分代码省略.........
示例11: connect
//
//переделать всё
//
private void connect()
{
if (comboBox1.SelectedIndex != -1)
MyUsbFinder = new UsbDeviceFinder(Convert.ToInt32(devices_libusb[comboBox1.SelectedIndex].VID, 16),
Convert.ToInt32(devices_libusb[comboBox1.SelectedIndex].PID, 16));
DataPoint temp = new DataPoint();
ErrorCode ec = ErrorCode.None;
try
{
//открываем поток
MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
if (MyUsbDevice == null) throw new Exception("Device Not Found.");
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
wholeUsbDevice.SetConfiguration(1);
wholeUsbDevice.ClaimInterface(0);
}
//читает 1ый эндпоинт
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader((ReadEndpointID)comboBox2.SelectedItem);
byte[] readBuffer = new byte[1024];
int bytesRead;
//Возвращает данные или ошибку, если через 5 секунд ничего не было возвращено
ec = reader.Read(readBuffer, 5000, out bytesRead);
if (bytesRead == 0) throw new Exception(string.Format("{0}:No more bytes!", ec));
try
{
if (trying)
{
temp.SetValueXY(i,
Convert.ToDouble(Encoding.Default.GetString(readBuffer, 0, bytesRead).Replace('.', ',')));
i++;
chart1.Series[0].Points.Add(temp);
data.Add(Encoding.Default.GetString(readBuffer, 0, bytesRead));
}
}
catch
{
trying = false;
}
textBox2.AppendText(Encoding.Default.GetString(readBuffer, 0, bytesRead));
}
catch (Exception ex)
{
//кидает ошибку и останавливает таймер при ошибке
timer1.Stop();
MessageBox.Show((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
}
finally
{
//закрывает поток
if (MyUsbDevice != null)
{
if (MyUsbDevice.IsOpen)
{
IUsbDevice wholeUsbDevice = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
wholeUsbDevice.ReleaseInterface(0);
}
MyUsbDevice.Close();
}
MyUsbDevice = null;
UsbDevice.Exit();
}
}
}
示例12: button2_Click
private void button2_Click(object sender, EventArgs e)
{
try
{
MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);
if (MyUsbDevice == null)
{
throw new Exception("Device Not Found.");
//connected = false;
}
else
{
Device_l.Text = "Device: Connected";
//connected = true;
Scan_b.Enabled = true;
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);
}
reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep03);
writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep04);
}
}
catch (Exception ex)
{
MessageBox.Show((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
}
}
示例13: Main
public static void Main(string[] args)
{
ErrorCode ec = ErrorCode.None;
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-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 = 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);
}
// open read endpoint 1.
UsbEndpointReader reader = MyUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
// open write endpoint 1.
UsbEndpointWriter writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
// Remove the exepath/startup filename text from the begining of the CommandLine.
string cmdLine = Regex.Replace(
Environment.CommandLine, "^\".+?\"^.*? |^.*? ", "", RegexOptions.Singleline);
if (!String.IsNullOrEmpty(cmdLine))
{
reader.DataReceived += (OnRxEndPointData);
reader.DataReceivedEnabled = true;
int bytesWritten;
ec = writer.Write(Encoding.Default.GetBytes(cmdLine), 2000, out bytesWritten);
if (ec != ErrorCode.None) throw new Exception(UsbDevice.LastErrorString);
LastDataEventDate = DateTime.Now;
while ((DateTime.Now - LastDataEventDate).TotalMilliseconds < 100)
{
}
// Always disable and unhook event when done.
reader.DataReceivedEnabled = false;
reader.DataReceived -= (OnRxEndPointData);
Console.WriteLine("\r\nDone!\r\n");
}
else
throw new Exception("Nothing to do.");
}
catch (Exception ex)
{
Console.WriteLine();
Console.WriteLine((ec != ErrorCode.None ? ec + ":" : String.Empty) + ex.Message);
}
finally
{
if (MyUsbDevice != null)
{
if (MyUsbDevice.IsOpen)
{
// 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 = MyUsbDevice as IUsbDevice;
if (!ReferenceEquals(wholeUsbDevice, null))
{
// Release interface #0.
wholeUsbDevice.ReleaseInterface(0);
}
MyUsbDevice.Close();
}
}
MyUsbDevice = null;
// Free usb resources
UsbDevice.Exit();
// Wait for user input..
Console.ReadKey();
}
}
示例14: Get_connect_PlanetCNC
private static bool Get_connect_PlanetCNC()
{
//vid 2121 pid 2130 в десятичной системе будет как 8481 и 8496 соответственно
UsbDeviceFinder myUsbFinder = new UsbDeviceFinder(8481, 8496);
// Попытаемся установить связь
_myUsbDevice = UsbDevice.OpenUsbDevice(myUsbFinder);
if (_myUsbDevice == null)
{
string StringError = "Не найден подключенный контроллер.";
_connected = false;
AddMessage(StringError);
//запустим событие о разрыве связи
if (WasDisconnected != null) WasDisconnected(null, new DeviceEventArgsMessage(StringError));
return false;
}
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);
}
// open read endpoint 1.
_usbReader = _myUsbDevice.OpenEndpointReader(ReadEndpointID.Ep01);
// open write endpoint 1.
_usbWriter = _myUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep01);
return true;
}
示例15: iPhoneWrapper
public iPhoneWrapper(UsbDevice USBDevice, bool bAFC2)
{
if (USBDevice == null)
throw new Exception("Failed to create iPhone wrapper");
StartTime = DateTime.UtcNow;
iPhoneUSBDevice = USBDevice;
MUXConnections = new List<USBMUXConnection>();
IUsbDevice LibUsbDevice = iPhoneUSBDevice as IUsbDevice;
if (!ReferenceEquals(LibUsbDevice, null))
{
// This is a "whole" USB device. Before it can be used,
// the desired configuration and interface must be selected.
// Select config #3
LibUsbDevice.SetConfiguration(3);
// Claim interface #1.
LibUsbDevice.ClaimInterface(1);
}
// Open read endpoint 5.
iPhoneEndpointReader = iPhoneUSBDevice.OpenEndpointReader(ReadEndpointID.Ep05);
// Open write endpoint 4.
iPhoneEndpointWriter = iPhoneUSBDevice.OpenEndpointWriter(WriteEndpointID.Ep04);
// Say hello to the device and set up lockdown.
if (!Initialize())
throw new Exception("Couldn't initialize iPhone");
// Try to start AFC2 if requested. If it doesn't work (not jailbroken), start AFC.
int nAFCPort = 0;
if (bAFC2)
{
try { nAFCPort = Lockdown.StartService("com.apple.afc2"); }
catch
{
nAFCPort = Lockdown.StartService("com.apple.afc");
}
if (nAFCPort != 0)
{
AFC = new AFCConnection(this, 5, (ushort)nAFCPort);
MUXConnections.Add(AFC);
}
}
else
{
nAFCPort = Lockdown.StartService("com.apple.afc");
AFC = new AFCConnection(this, 5, (ushort)nAFCPort);
MUXConnections.Add(AFC);
}
int nNPPort = Lockdown.StartService("com.apple.mobile.notification_proxy");
NP = new NotificationProxyConnection(this, 6, (ushort)nNPPort);
MUXConnections.Add(NP);
Global.Log("Shutting down lockdownd (don't need it anymore).\n");
try { Lockdown.CloseConnection(); } catch { }
MUXConnections.Remove(Lockdown);
}