BrimStonePhoenix
Programmer
I've been charged with the task to interface with a device through the parallel port. After much searching, I discovered the CreateFile, ReadFile, and WriteFile functions on msdn.com. I've gottem them to work for text files and the like, but When I change my code to try to read/write to the parallel port, the program lock up when I try to write to the port.
Here is some code I have :
#include <Windows.h>
#include <stdio.h>
#define BUFFSIZE 1
#define GETDATA 0xFF
int main()
{
HANDLE test;
int success;
BYTE buffer[BUFFSIZE] = {GETDATA};
DWORD bytestowrite;
DWORD byteswritten;
DWORD bytesread;
test = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (test == INVALID_HANDLE_VALUE)
{
printf ("CreateFile1 failed - Invalid Handle Value\n");
return (1);
}
else
{
printf("CreateFile1 Successful\n");
}
printf("here1\n");
success = WriteFile(test, buffer, BUFFSIZE, &byteswritten, NULL);
printf("here2\n");
if (success)
{
printf("File Write Successful - %i bytes\n", byteswritten);
}
else
{
printf("File Write Failed\n");
return (1);
}
return (0);
}
It locks up during the WriteFile line. Anybody have any ideas on how to remedy this situation?
Output looks a bit like :
CreateFile1 Successful
here1
and it sits there forever, until I force quit.
Any ideas, or other ways to get data in and out of the parallel port?
Here is some code I have :
#include <Windows.h>
#include <stdio.h>
#define BUFFSIZE 1
#define GETDATA 0xFF
int main()
{
HANDLE test;
int success;
BYTE buffer[BUFFSIZE] = {GETDATA};
DWORD bytestowrite;
DWORD byteswritten;
DWORD bytesread;
test = CreateFile("LPT1", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (test == INVALID_HANDLE_VALUE)
{
printf ("CreateFile1 failed - Invalid Handle Value\n");
return (1);
}
else
{
printf("CreateFile1 Successful\n");
}
printf("here1\n");
success = WriteFile(test, buffer, BUFFSIZE, &byteswritten, NULL);
printf("here2\n");
if (success)
{
printf("File Write Successful - %i bytes\n", byteswritten);
}
else
{
printf("File Write Failed\n");
return (1);
}
return (0);
}
It locks up during the WriteFile line. Anybody have any ideas on how to remedy this situation?
Output looks a bit like :
CreateFile1 Successful
here1
and it sits there forever, until I force quit.
Any ideas, or other ways to get data in and out of the parallel port?