使用 C# 的简单 USB 按钮 [英] Simple USB button using C#

查看:35
本文介绍了使用 C# 的简单 USB 按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做一些从外围设备读出信号的游戏.我想做以下事情:

I want to do some playing around with reading out signals from pheriperals. I want to do the following:

以前我在一家小 IT 公司实习,LPT 线坏了,他们把它剪开,用两条线连接一个按钮,如果按钮坏了,他们还有一个软件可以做一些事情按下.

In the past I had an internship at a small IT company, the had a broken LPT cable, they cut it open and used two cables to attach a button, they also had a piece of software to do something if the button was pressed.

现在我想使用损坏的 USB 电缆做同样的事情,看看 D+ 和 D- 是否相互接触,如果是,我想让我的软件做一些事情.有没有一个库可以让我检查两个是否接触?(如果我必须使用 5v 和 grnd 或 d+ 和 d-,现在不要使用)还是无法使用 USB?

Now I want to do the same using a broken USB cable and see if the D+ and D- are touching each other, if they are I want my software to do something. Is there a library that lets me check if two are touching? (don't now if I have to use the 5v and grnd or d+ and d-) or is it not possible using USB?

推荐答案

D+ 和 D- 是差分对.你不能只是缩短它们并用 PC 捕获它.

D+ and D- is a differential pair. You cannot just short them and capture that with PC.

要实现 USB 按钮,您需要使用一些微控制器(例如 AT90USB162)读取按钮状态,并将有关按钮状态的数据发送到 PC.一种简单的方法是将微控制器配置为虚拟串行端口(参见 LUFA 项目).通过这种方式,您可以像从真正的串行端口读取数据一样从微控制器读取数据(请参阅 SerialPort 类).

To implement USB button, you will need to read button state with some microcontroller, like AT90USB162, and send data about button state to PC. One easy way is to configure microcontroller to work as a virtual serial port (see LUFA project). This way you can read data from microcontroller the same way as from real serial port (see SerialPort class).

这篇关于使用 C# 的简单 USB 按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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