将原始数据写入 Android 串行端口 (USB)
我需要为我的一个项目向 USB 端口写入一些“原始”数据(如果需要 root 则没有问题)。
我找到了适用于 Android 的 libusb 端口,并设法使用 NDK 对其进行编译。我将该库链接到我的可执行文件(以 root 身份执行),但函数“libusb_init”总是返回错误(LIBUSB_ERROR_OTHER)。
我发现问题(现在......)出在文件“linux_usbfs.c”中,更准确地说是在这个函数中:
static const char *find_usbfs_path(void)
{
const char *path = "/dev/bus/usb";
const char *ret = NULL;
if (check_usb_vfs(path)) {
ret = path;
} else {
path = "/proc/bus/usb";
if (check_usb_vfs(path))
ret = path;
}
usbi_dbg("found usbfs at %s", ret);
return ret;
}
/dev/bus/usb
显然在我的 N1 上不存在。
I need to write some "raw" data to the usb port for a project of mine (no prob if root should be required).
I found a port of libusb for Android and managed to compile it with NDK. I linked the library to an executable of mine (executed as root), but the function "libusb_init" always returns an error (LIBUSB_ERROR_OTHER).
I found that the problem (by now...) is in the file "linux_usbfs.c", more precisely in this function:
static const char *find_usbfs_path(void)
{
const char *path = "/dev/bus/usb";
const char *ret = NULL;
if (check_usb_vfs(path)) {
ret = path;
} else {
path = "/proc/bus/usb";
if (check_usb_vfs(path))
ret = path;
}
usbi_dbg("found usbfs at %s", ret);
return ret;
}
/dev/bus/usb
obviously doesn't exist on my N1.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不尝试 pyserial? python 对我来说似乎更简单。您需要一个具有 USB 主机模式的内核,或者您的手机本身支持 ttyMSM0 上的串行,您需要找出这一点。一旦您确定手机上有串行端口,请查看此 link 适用于华为 ideos U8150,但我建议使用 python for android 完成的 pyserial 是替代方案。
Why not try pyserial? python seems simpler for me. You need either a kernel with usb host mode or your phone supports serial over a ttyMSM0 natively, which you need to find out. Once you are sure you have a serial port on your phone, look at this link which is meant for huawei ideos U8150, but the pyserial stuff done using python for android is the alternative I am suggesting.