Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 无法使用outb()调用点亮键盘指示灯_C_Linux Device Driver_Device Driver_Hardware Port - Fatal编程技术网

C 无法使用outb()调用点亮键盘指示灯

C 无法使用outb()调用点亮键盘指示灯,c,linux-device-driver,device-driver,hardware-port,C,Linux Device Driver,Device Driver,Hardware Port,我试图用下面的程序点亮Linux中的键盘LED(在互联网上找到),但似乎什么也没发生。我遗漏了什么吗 /* sample.c: very simple example of port I/O * * This code does nothing useful, just a port write, a pause, * and a port read. Compile with `gcc -O2 -o example example.c', * and run as root with

我试图用下面的程序点亮Linux中的键盘LED(在互联网上找到),但似乎什么也没发生。我遗漏了什么吗

/* sample.c: very simple example of port I/O
 *
 * This code does nothing useful, just a port write, a pause,
 * and a port read. Compile with `gcc -O2 -o example example.c',
 * and run as root with `./example'.
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>

#define BASEPORT 0x0060 /* lp1 */

int main()
{
        /* Get access to the ports */
        if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}

        /* Set the data signals (D0-7) of the port to all low (0) */
        outb(0xED, BASEPORT);

        /* Sleep for a while (100 ms) */
        usleep(1000);
        printf("\n here ");
        outb(0x07, BASEPORT);
        usleep(1000);

        /* We don't need the ports anymore */
        if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
    exit(0);
}
/*sample.c:端口I/O的非常简单的示例
*
*这段代码没有任何用处,只是一个端口写入,一个暂停,
*和一个端口读取。使用'gcc-O2-o example.c'编译,
*并使用“./example”以root用户身份运行。
*/
#包括
#包括
#包括
#包括
#定义基本端口0x0060/*lp1*/
int main()
{
/*进入港口*/
if(ioperm(BASEPORT,3,1)){peror(“ioperm”);exit(1);}
/*将端口的数据信号(D0-7)设置为全低(0)*/
outb(0xED,基本端口);
/*睡眠一段时间(100毫秒)*/
usleep(1000);
printf(“\n此处”);
outb(0x07,基本端口);
usleep(1000);
/*我们不再需要港口了*/
if(ioperm(BASEPORT,3,0)){peror(“ioperm”);exit(1);}
出口(0);
}

我看不出该代码中有任何明显错误。然而,我在我的电脑上试过,caps lock led(大写锁定指示灯)是由该代码打开的(但不是在我的键盘上,而是只在笔记本电脑的led上)。这是USB键盘吗?该端口用于老式ps/2风格的键盘,当然USB键盘的工作方式完全不同。但是,在某些情况下,旧接口在某种程度上是模拟的。。。我对此了解不够,但可能有人会…这里有一些信息:。当我执行/proc/ioport时,我看到键盘端口为0x60-0x64,0x60用于接受命令。首先,我在我的笔记本电脑上的虚拟盒上运行ubuntu,它不起作用,然后在独立系统上运行,结果是一样的。我的钥匙不亮,门锁也没开。这是USB键盘。USB键盘通常通过HID协议发送命令。这可能不是正确的方法。