How to establish and read contacts on a parallel port with C ++?

I help a friend finish a project of the last year in which he has this scheme, which we want to turn on and off using a C ++ program.

image of what i want

Initially, I thought it would be easy, but I could not implement this program. The main problem is that

  • Windows XP and above do not allow direct access to hardware, so some websites indicate that I need to write a driver or find a driver.
  • I also looked at several projects on the Internet, but they seem to work for Windows XP, but they do not work for Windows 7.
  • In addition, most of the projects were written in VB or C #, which I am not familiar with.

Question:

  • Is there a suitable driver for Windows XP and Windows 7, and if so, how can I use it in my code? (code fragments will be appreciated)
  • Is there a cross-platform way to interact with parallel ports?
+4
source share
2 answers

Take a look at codeproject: here , here and here . You will find treasures.

The first link works for Windows 7 - both 32-bit and 64-bit.

+3
source

You do not need to write a driver or anything else - you just call CreateFile with the file name, for example, "LPT1" to open it and then you can use WriteFile to write data to it. For instance:

 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); 
+3
source

Source: https://habr.com/ru/post/1339571/


All Articles