控制USB端口
我可以使用 Ruby 或 C++ 向 USB 端口发送特定信号吗?操作系统也是 Windows,所以这就像全新的 4 me(为 Windows 编程),所以我尝试将其作为 DLL 文件来实现,可以吗DLL 包含 Ruby 代码?
顺便说一句,这只是一个培训项目,所以没关系,我只是在 Windows 下练习这些东西。
can i send specific signals to USB ports using Ruby or C++, also the operating system is Windows, so this is like totally new 4 me (to program for windows), so i'm trying to do it as a DLL file, can this DLL contain Ruby code ??
by the way this is just a training project, so it dosn't matter that much, i'm just practicing on those stuff under windows.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在这里看到两个不同的问题。所以我会尝试分别回答它们。
如何从您的代码控制 USB 设备
是的,您可以从您自己的代码控制 USB 设备。使用 libusb,您可以完成普通 USB 驱动程序所做的一切。请注意,您不是使用它们所在的端口来寻址它们,而是使用它们的制造商和设备 ID。在 Linux 下,这适用于任何 USB 设备。在 Windows 下,您必须以某种方式安装 libusb 作为您不想控制的设备的驱动程序。有关 libusb 的更多信息,请访问 http://www.libusb.org/。 win32 的 libusb 托管在 http://libusb-win32.sourceforge.net/。
如果您不想从 ruby 内部使用 libusb,则必须使用某种 C 绑定。您可以使用 http://www.akr.org/ruby-usb/ 或编写您自己的绑定。
如何编译 ruby 代码
这不是我的专业领域,但正如您将这两个问题作为一个问题提出的那样。我会尝试回答它。
实际上有多种编译 ruby 的方法。
您还应该考虑,在您的情况下编译 ruby 代码是否有意义。如果您正在编写混合 c ruby 程序,则可以为 ruby 制作所有 c 部分的 c 扩展。这样你的 ruby 就不需要编译了。你不想用 ruby 写一个 c 库吗?这可能意味着使用该库的 C 程序会产生巨大的性能影响。
I see two separate questions here. So I'll try to anwser them separatly.
How to control USB Devices from your code
Yes you can control USB Devices from your own code. With libusb you can do everything ordinary usb drivers do. Be aware you don't address them with the port they are on, but with their manufacterer and device ID. Under linux this work for any usb device. Under windows your have to somehow install libusb as a driver for the device you wan't to control. See more about libusb at http://www.libusb.org/. The libusb for win32 is hosted at http://libusb-win32.sourceforge.net/.
If you wan't to use libusb from inside ruby you have to use some kind of c bindings. You could ether use http://www.a-k-r.org/ruby-usb/ or write your own bindings.
How to compile ruby Code
This is not my field of expertise, but as you asked both questions as one. I will try to anwser it.
There are actually ways of compiling ruby.
You should also think about, whether it makes sense in your case to compile the ruby code. If you are writing a mixed c ruby program, you could make all c parts c extensions for ruby. This way your ruby could does not need to be compiled. Do you wan't to write a library for c in ruby? This would probably mean a huge performance impact for the c programs using this library.