在现代硬件和操作系统上通过 USB 适配器控制并行端口
我有一个 USB 转并行端口设备,我想在现代 Windows 操作系统(xp 及更高版本)上通过 c++ 与其进行交互。
我做了一些研究,但是当涉及到对这些 USB 转并行端口设备之一进行编程时,信息有点不完整(大多数信息都已过时,并且假设您有一个内置于主板中的并行端口,某些东西)我的全新电脑没有)。一篇参考文献甚至说,如果不进行某种软件更改,就不可能从 C++ 程序连接 USB 到并行端口。
我想要做的就是能够在运行现代 Windows 操作系统的现代计算机上通过 USB 转并行端口设备读取或写入 8 位并行端口(端口专用于读取或写入)。
有什么快速简便的方法可以做到这一点吗?一些示例代码将不胜感激。
另外,我的计算机可以连接多少个 USB 转并行端口?由于某种遗留寻址,我是否限制为 3 个,或者我可以拥有我的 USB 和 CPU 能够支持的尽可能多的数量吗?
使用 VC++ 2008,运行带有 Core i7 860 的 Windows 7 x64。
编辑:更多信息...
我尝试使用 inpout23 以及一些预先编写的测试程序。它编译得很好,运行得很好,声称可以读取和写入并行端口。我将 USB 转并行端口连接到计算机,并将该端口连接到一根电缆,在该电缆中,我已识别、剥离并焊接了其中 25 根电线,并将其焊接到某种插头上,以便快速插入面包板进行测试。所有输出引脚都没有更改为程序所说的写入它们的内容(相反,它们都设置为高电平并且从未更改)。
I have a USB to parallel port device that i want to interface with through c++ on a modern windows OS (xp and newer).
I've done a little research but the information is a bit patchy when it comes to programming to one of these USB to parallel port devices (most of the information is dated and assumes that you have a parallel port built right into the motherboard, something my brand new computer doesn't have). One reference even says that it is not possible to interface with a USB to parallel port from a C++ program without some sort of software changes.
All i want to do is to is be able to read or write 8 bits to the parallel port through a USB to parallel port device on a modern computer running a modern windows OS (with ports being dedicated to reading or writing only).
Is there any quick and easy way of doing this? Some sample code would be greatly appreciated.
Also, how many of these USB to parallel ports can I interface with my computer? Am i limited to 3 due to some sort of legacy addressing or can i have as many as my USB and CPU are able to support?
Working off VC++ 2008, running Windows 7 x64 with a Core i7 860.
Edit: a bit more information...
I've tried using inpout23 along with some prewritten test program. It compiled just fine and ran just fine claiming to have both read and written to a parallel port. I had my USB to parallel port connected to the computer and that port connected to a cable in which i had identified, stripped and soldered each of the 25 wires onto a sort of plug for quickly plugging into a breadboard for testing. None of the output pins had changed to what the program had said was written to them (instead they were all set to high and never changed).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我过去曾这样做过,有好消息也有坏消息。
好消息是它总是有效(有时需要调整),这是对设计极其强大协议的电子制造商的致敬。显然USB转并行转换器都提供了硬件端口模拟。
坏消息是“bitbanging”接口模型的性能很糟糕。如果您不介意缓慢的更新,这根本不是问题。我用它来对 uController 进行编程,很快串行或 USB 编程器的价格就因我的不耐烦而被压垮了。
只需使用 Windows API 来读/写 LPT 或 COM 端口,它就可以工作(速度很慢)。
I've done this in the past and I have good news and bad news.
The good news is that it always worked (sometimes with tweaking), which is a tribute to the electronic manufacturers of designing extremely robust protocols. Apparently the USB to parallel converters all provided the hardware port emulation.
The bad news is that performance was awful on the 'bitbanging' interface models. If you do not mind slow updates this is not an issue at all. I used it for programming uControllers and soon the price of serial or USB programmers was overcome by my impatience.
Just use the windows API to read/write the LPT or COM ports and it works (slowly).
我以前使用过 USB 转串口适配器,我想 USB 转并口应该是一样的。您应该拥有一个驱动程序和适配器 - 这会为您完成大部分工作,隐藏 USB 接口并将其作为传统并行端口呈现给操作系统。例如,当我将适配器插入 USB 端口时,它在设备管理器中仅显示为 COM4。我猜你的会显示为 LPT1 之类的。从那时起,就需要使用标准 Windows API 来访问这些端口了。 (请参阅 MSDN 上的通信资源)
I've worked with a USB-to-serial port adapter before and I guess USB-to-parallel should be the same. You should have got a driver along with the adapter - this does most of the work for you, hiding the USB interface and presenting it to the OS as a traditional parallel port. For example, when I plug my adapter into the USB port, it just shows up as COM4 in Device Manager. I'm guessing yours will show up as LPT1 or something. From there on, it's a matter of using the standard Windows API to access these ports. (see Communications Resources on MSDN)
神奇的是,我使用在 ebay.com 上购买的 USB 转 LPT-DB25 线成功了。
我们应该在 /LF Line Feed 和 GND 引脚之间连接一个 LED。
丢弃 USB 寄存器以便找到与 USB 电缆关联的寄存器后,我们应该构建一个 API(应用程序编程接口)来与输出/寄存器进行交互。
我将尝试附加一张图片来看看我是如何管理它的:
Misteriously I succeed with the USB to LPT-DB25 Wire bought in ebay.com.
We should connect a LED between the /LF Line Feed and GND pins.
After discard the USB registers in order to find that one associated to the USB Cable, we should build an API (Application Programming Interface) to interact with the outputs/Registers.
I'm going to try to attach a picture to have a look how I managed it: