PDA

View Full Version : سوال: مشکل در نوشتن روی پورت موازی



mahnaz0098
جمعه 28 مهر 1391, 16:10 عصر
سلام
من میخوام با استفاده از کد زیر یه LED رو روشن کنم . . یعنی بتونم رو پورت موازی بنویسم ولی ظاهرا کد مشکل داره و این کارو انجام نمی ده . من از char ledstatus به جای byte ledstatus
استفاده کردم . آیا تفاوتی داره و مشکل ایجاد میکنه؟؟
لطفا راهنماییم کنید .


# include <windows.h>
# include <conio.h>
#include <stdio.h>
#define LED_ON 1


int main()
{
HANDLE h;
unsigned long dwSize=1;
int success;


h = CreateFile(
L"LPT1",
GENERIC_WRITE, // access (read-write) mode
0, // share mode
NULL, // pointer to security attributes
OPEN_EXISTING, // how to create
FILE_ATTRIBUTE_NORMAL, // file attributes
NULL // handle to file with attributes to copy
);
if(INVALID_HANDLE_VALUE == h)
{
//Handle Error
printf("CreateFile failed with error %d\n", GetLastError());
exit(1);
}
else
{
printf("CreateFile1 Successful\n");
}

char ledStatus;
// turn on LED
ledStatus = LED_ON;
success = WriteFile(h, &ledStatus, 1, &dwSize, NULL);
if (success)
{
printf("File Write Successful - %i bytes\n", dwSize);
}
else
{
printf("File Write Failed\n");

}


// close port
CloseHandle(h);


return 0;
}