Winapi 使用C打开LED

Winapi 使用C打开LED,winapi,led,parallel-port,Winapi,Led,Parallel Port,我想用C打开一个LED,这意味着我想在并行端口上写 但是代码不起作用 我使用char-ledStatus而不是BYTE-ledStatus。有什么区别吗 这段代码有什么问题 #include <windows.h> #include <conio.h> #include <staio.h> #define LED_ON 1 int main() { HANDLE h; unsigned long dwSize=1; int succes

我想用C打开一个LED,这意味着我想在并行端口上写

但是代码不起作用

我使用
char-ledStatus
而不是
BYTE-ledStatus
。有什么区别吗

这段代码有什么问题

#include <windows.h>
#include <conio.h>
#include <staio.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;
}
#包括
#包括
#包括
#在1上定义LED_
int main()
{
手柄h;
无符号长dwSize=1;
成功;
h=创建文件(
L“LPT1”,
通用_WRITE,//访问(读写)模式
0,//共享模式
NULL,//指向安全属性的指针
打开_EXISTING,//如何创建
文件属性正常,//文件属性
NULL//要复制属性的文件句柄
);
if(无效的\u句柄\u值==h)
{
//处理错误
printf(“CreateFile失败,错误为%d\n”,GetLastError());
出口(1);
}
其他的
{
printf(“CreateFile1成功\n”);
}
地位;
//打开LED
发光二极管状态=发光二极管亮起;
success=WriteFile(h,&ledStatus,1,&dwSize,NULL);
如果(成功)
{
printf(“文件写入成功-%i字节\n”,dwSize);
}
其他的
{
printf(“文件写入失败\n”);
}
//关闭端口
闭合手柄(h);
返回0;
}

您的问题记录得非常糟糕,您没有描述您使用的信号或LED的接线方式。很多方法都会弄错。但是,您没有希望让它与标准Windows并行驱动程序一起工作。它被写入接口并行设备,如打印机。这需要通过握手向设备发送一个字节的时钟。当驱动器打开选通信号时,设备必须打开ACK信号以确认它复制了字节。这当然不会发生,WriteFile()调用只会填充驱动程序中的缓冲区


您需要另一个驱动程序来直接控制输出线,Input32是一个常见的选择。在中找到基本建议,还包括到Input32的链接。

并行处理标签用于并行计算(即使用多个内核/CPU/计算机等处理数据),而不是使用并行端口:)