【发布时间】:2017-03-26 01:09:14
【问题描述】:
我正在尝试通过 USB 使用 LIBUSING 和 C# 与诺基亚 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";
}
}
【问题讨论】:
-
你能分享一下描述符吗?我想你可以阅读你提到的那些你可以看到 VID 和 DID。
-
啊!我可能已经想通了。该设备有3个接口,其中一个是诺基亚护理套装,实际的WinUSB设备根本没有出现。我的程序正在向具有相同 VID 和产品 ID 的错误(驱动程序?)发送数据
-
我还没有看到描述符,这也是我要检查的内容。无论如何,看起来你有你的答案。 :)
-
写操作没有超时。但是,USB 设备对任何命令都没有响应。此外,写入命令之后的任何断点都不会被命中。