控制USB端口 [英] Control USB ports

查看:204
本文介绍了控制USB端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用Ruby或C ++发送特定的信号到USB端口,操作系统也是Windows,所以这就像全新的4我(为Windows编程),所以我试图做一个DLL文件,可以这个DLL包含Ruby代码??



这样只是一个训练项目,所以它不重要,我只是练习那些

解决方案

我在这里看到两个单独的问题。



如何通过代码控制USB设备



是的可以从您自己的代码控制USB设备。有了libusb,你可以做一切普通的usb驱动程序。请注意,您不使用他们所在的端口,而是使用他们的制造商和设备ID来解决它们。在linux下这个工作任何usb设备。在windows下,你必须以某种方式安装libusb作为你不能控制的设备的驱动程序。有关libusb的更多信息,请访问 http://www.libusb.org/ 。 libusb for win32托管在 http://libusb-win32.sourceforge.net/ 。 p>

如果你不想在ruby里面使用libusb,你必须使用某种c绑定。您可以使用 http://www.akr.org/ruby-usb/ 或写作你自己的绑定。



如何编译ruby代码



这不是我的专业领域,问两个问题。







  • ruby​​2c项目可以将一些ruby代码(不是全部)翻译成c。你可以编写一个C程序,其中包括ruby解释器和eval的一串ruby代码。这个c代码可以被编译。有关详情,请访问 http://rubyforge.org/projects/ruby2c/



你还应该考虑一下,在你的情况下编译ruby代码是否有意义。如果你正在写一个混合的c ruby​​程序,你可以使所有c部分c扩展为ruby。这样你的ruby可以不需要编译。你不会为ruby写一个c的库吗?这可能意味着对使用此库的c程序的巨大性能影响。


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.

解决方案

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 could write a C program which includes the ruby interpreter and eval's a string of ruby code.
  • The ruby2c project can translate some ruby code (not all) into c. This c code could be compiled. See more at http://rubyforge.org/projects/ruby2c/.

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.

这篇关于控制USB端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆