1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <windows.h>
int main(int argc, char* argv[])
{
OVERLAPPED overlp = {0};
HANDLE hComm = CreateFileA("\\\\.\\LPT1", GENERIC_READ | GENERIC_WRITE,
0, 0, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, 0);
if (hComm == NULL || hComm == INVALID_HANDLE_VALUE)
{
std::cout << "Couldn't open handle to comm port" << std::endl;
return 1;
}
unsigned char i = 0
while (true)
{
DWORD bytesWritten, bytesRead;
unsigned char data;
if (!ReadFile(hComm, &data, 1, &bytesRead, &overlp))
std::cout << "Failed to read data " << GetLastError() << std::endl;
else
std::cout << "Data recieved: " << data << std::endl;
Sleep(250);
if (!WriteFile(hComm, &i, 1, &bytesWritten, &overlp))
std::cout << "Failed to write data " << GetLastError() < " " << i << std::endl;
Sleep(250);
if (++i == 256) i = 0;
}
}
|
Failed to read data 6
Failed to write data 6 a
Failed to read data 6
Failed to write data 6 b
Failed to read data 6
Failed to write data 6 c
Failed to read data 6
Failed to write data 6 d
... |