[英]How to set and read pins on the parallel port from C++?
I am helping a friend to finish a final year project in which he has this circuit that we want to switch on and off using a C++ program. 我正在帮助一个朋友完成最后一个项目,在这个项目中他拥有我们想要使用C ++程序打开和关闭的电路。
I initially thought it would be easy, but I have failed to implement this program. 我最初以为这很容易,但是我没有实现该程序。 The main problem is that
主要的问题是
Question: 题:
You shouldn't need to write a driver or anything -- you just call CreateFile
with a filename like "LPT1"
to open up a handle to the parallel port, and then you can use WriteFile
to write data to it. 您不需要编写驱动程序或任何东西-您只需使用诸如
"LPT1"
类的文件名调用CreateFile
即可打开并行端口的句柄,然后可以使用WriteFile
向其中写入数据。 For example: 例如:
HANDLE parallelPort = CreateFile("LPT1", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
if(parallelPort == INVALID_HANDLE_VALUE)
{
// handle error
}
...
// Write the string "foobar" (and its null terminator) to the parallel port.
// Error checking omitted for expository purposes.
const char *data = "foobar";
WriteFile(parallelPort, data, strlen(data)+1, NULL, NULL);
...
CloseHandle(parallelPort);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.