只需 USB 端口即可对 LED 进行编程
我想仅使用 USB 端口用 C# 控制 LED。我不想通过 USB 连接任何其他设备。我只想将 LED 直接连接到 USB 端口引脚并对其进行编程(闪烁等)。我怎样才能做到这一点?我是硬件编程新手,这将是我的第一个程序。
编辑:我已经可以使用打印机端口
通过将一个LED引脚连接到数据引脚
并将另一个引脚连接到接地
来做到这一点(闪烁LED)。我怎样才能用USB端口做同样的事情?我的主板没有打印机端口。 USB 是唯一的选择。
I want to control LED with C# using only USB port. I don't want to attach any other device with USB. I just want to attach LED directly to USB port pins and program it (blink etc). How can i do that? I am new to hardware programming and it will be my first program.
EDIT: I can do it already (blink LED) using printer port
by attaching one led pin to data pin
and other to ground
. How can i do the same with USB port? My motherboard does not have a printer port. USB is the only option.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(5)
这是不可能的。
数据引脚上的电流太低,因此如果连接到
5V
和任何数据引脚,LED 将永远不会亮起。因此,无法使用 USB 端口上的数据引脚直接控制 LEDThis is not possible.
Current on Data pins is too low therefore LED will never turn on if connected with
5V
and any Data pin. Hence LED can not be controlled directly using data pins on USB port许多主板将永久为 USB 端口提供电流。
理论上,您可以将 USB 控制器置于某种挂起模式并再次返回,但这很糟糕。
您需要某种控制器来接受 USB 上的命令,然后需要一些分立元件来打开/关闭来自永久 USB 电源的电流,并让它到达您的 LED。
Many mainboards will permanently supply USB ports with current.
You could theoretically put the USB controller into some suspend mode and back again but this is bad.
You'd need some sort of controller to accept commands over USB then some discrete elements to open/close current from the permanent USB supply and let it reach your LED.
你真的不能这样做。您可以使用并行端口来完成此操作,因为您可以单独控制数据引脚。使用 USB,您只能控制 USB 协议之上的数据。无论如何,协议很可能是由主板上的芯片在固件中运行的,所以很可能没有办法做你想做的事情,短接电源引脚上的 LED 并切换 USB 总线电源,这是你不应该做的出于各种各样的原因而做。
买个Arduino之类的就可以了。从长远来看,这会变得更加容易、更加灵活。
You really can't do this. You can do it with a parallel port because you have individual control over the data pins. With USB, you only have control over the data the rides on top of the USB protocol. It's likely that protocol is being run in firmware by a chip on the motherboard anyway, so there's most likely no way to do what you want to do, short connecting the LED across the power pins and toggling the USB bus power, which you should NOT do for a whole variety of reasons.
Just get an Arduino or something. In the long run it will be a lot easier and be more flexible.
好吧,那么为什么不购买 便宜的基于 USB 的打印机端口 并使用它?由于您已经有了可以运行的 LPT 端口代码,这为您提供了一个透明的解决方案。
OK, so why not buy a cheap USB based printer port and use that? Since you already have the LPT port code working, this gives you a transparent solution.
您可以使用 PIC 微控制器。 18f 系列可以通过 USB 直接连接 LED。也可以使用 C# 进行编码并仅使用 USB 端口来控制 LED 。我猜你实际上想要控制 LED 而不仅仅是让它发光。
You could use a PIC microcontroller . The 18f series can directly interface led's over the usb . It is also possible to code using c# and use only the USB port to control the led . I'm guessing you actually want to control the led and not just get it to glow .