gpt4 book ai didi

C# - 使用 LIBUSB 与 WinUSB 设备通信

转载 作者:行者123 更新时间:2023-11-30 18:17:41 25 4
gpt4 key购买 nike

我正在尝试使用 LIBUSING 和 C# 通过 USB 与诺基亚 Lumia 手机 (RM-917) 进行通信。 LIBUSB 能够查看设备的信息(pid、vid 等)。但是,我无法成功写入任何端点,即使发送确切的命令作为 Windows 设备恢复工具也是如此。

根据 WinUSB,写入端点是 EP07,但是,这个端点只是超时。我已经尝试了所有其他端点,但都失败了。

`
public void initDevice()
{


if(this.lumiaDevice == null)
{
throw new Exception("LumiaPhoneManager does not have a selected device");
}

UsbDeviceFinder MyUsbFinder = new UsbDeviceFinder(0x0421, 0x0661);
MyUsbDevice = UsbDevice.OpenUsbDevice(MyUsbFinder);


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(1);
}

if (this.writer == null)
{
writer = MyUsbDevice.OpenEndpointWriter(WriteEndpointID.Ep07);
}



}


public void readPCode()

{
currentID++;
var _x = new jsonPkt();
ErrorCode ec = ErrorCode.None;
int bytesWritten;
_x.id = this.currentID + 1;
_x.method = "ReadProductCode";

string value = @"{""jsonrpc"":""<JSONRPC>"",""id"":<ID>,""method"":""<METHOD>"",""params"":null}";
value = value.Replace("<JSONRPC>", "2.0");
value = value.Replace("<ID>", currentID.ToString());
value = value.Replace("<METHOD>", _x.method.ToString());


ec = writer.Write(Encoding.Default.GetBytes(value), 8000, out bytesWritten);
currentID++;

if (ec != ErrorCode.None) throw new Exception(UsbDevice.LastErrorString);

byte[] readBuffer = new byte[1024];
while (ec == ErrorCode.None)
{
int bytesRead;

// If the device hasn't sent data in the last 100 milliseconds,
// a timeout error (ec = IoTimedOut) will occur.
ec = reader.Read(readBuffer, 100, out bytesRead);

// if (bytesRead == 0) throw new Exception("No more bytes!");

// Write that output to the console.
this.rtb.Text += Encoding.Default.GetString(readBuffer, 0, bytesRead).ToString() + "\n";

}
}

最佳答案

找到解决方案

调试了 OEM 软件,发现程序使用了不同的 USB 设备路径。之后我收到访问被拒绝的错误,通过将项目移动到不同的驱动器解决了这个问题。不知为何,程序在c盘运行时,CreateFile函数失败,拒绝访问

关于C# - 使用 LIBUSB 与 WinUSB 设备通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43023847/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com