Tag: ubuntu 14.04

如何编写一个使用GCC编译其他C程序的C程序?

我希望我的程序与下面的终端命令做同样的事情: gcc program1.c -o p1 funcs.c gcc program2.c -o p1 funcs.c 这就是我一直在尝试的: 制作一个C程序来编译另一个 我到目前为止在终端中调用我的程序( ./”programName” ),它取代了我对gcc的需求,但是我需要在其余部分输入。

用于Ubuntu 14.04的C中的UINPUT设备程序不起作用。 为什么? 第2部分:

我正在使用Ubuntu 14.04,我在c中设置了一个虚拟键盘,这需要输入才能工作。 我的程序应该将密钥’a’发送到终端,就像我按下键盘上的’a’键一样。 这是我的源代码: int main() { int uinp_fd; int i; /********** Open uinput file section. **********************/ uinp_fd = open(“/dev/uinput”, O_WRONLY|O_NDELAY); if(uinp_fd < 0) { printf("Unable to open /dev/uinput\n"); return -1; } else printf("Can open /dev/uinput\n"); /********* Setup input device structure section: ***********/ memset(&uinp,0,sizeof(uinp)); snprintf(uinp.name, UINPUT_MAX_NAME_SIZE, "The C Keyboard"); uinp.id.bustype = BUS_USB; uinp.id.version = 1; […]

为什么`ioctl(fd,EVIOCGRAB,1)`有时会导致密钥垃圾邮件?

我正在尝试编写自己的“键盘驱动程序”(没有实际编写内核模块),通过抓取键盘,我认为是userland中最低级别的抽象: /dev/input/event* 。 如果您将ioctl(fd, EVIOCGRAB, UNGRAB)的第一个更改更改为ioctl(fd, EVIOCGRAB, GRAB)以下代码执行此操作。 // gcc main.c -o main #include #include #include #include #include #include #define EXIT_KEY KEY_ESC #define UNGRAB 0 #define GRAB 1 const char* kbd_device = “/dev/input/event4”; // ———————————————————————————————— int main(void){ int fd = open(kbd_device, O_RDONLY); if(fd == -1){ printf(“Cannot open %s. %s.\n”, kbd_device, strerror(errno)); return -1; } if(ioctl(fd, […]

Ubuntu串行通信:读取失败然后立即进入

我正在编写一个在运行Ubuntu服务器14.04的MIO-3260单板计算机上运行的程序,并与AMC DPRANIE C100A400驱动器通信。 程序向驱动器发送一串hex代码,并且应该为它发送的每条消息接收响应。 当我在Windows上的realTerm中尝试它时效果很好所以我不认为这是驱动器的问题。 但是,当我尝试从串口读取时,read()几乎一直都会返回-1,直到突然在一个看似随机的点上,我立刻得到了大量的消息。 我正在使用termios来设置串口。 这是我的代码。 我已经尝试在阻塞配置中进行设置,但如果我这样做,代码只会在第一次读取()时无限期挂起。 int fd; fd = open(“/dev/ttyS0”,O_RDWR | O_NOCTTY | O_NDELAY); struct termios SerialPortSettings; tcgetattr(fd, &SerialPortSettings); //get current settings of serial port cfsetispeed(&SerialPortSettings,B115200);//set input baud rate cfsetospeed(&SerialPortSettings,B115200);//set output baud rate SerialPortSettings.c_cflag &= ~PARENB;//clear parity bit (no parity) SerialPortSettings.c_cflag &= ~CSTOPB;//Stop bits = 1 SerialPortSettings.c_cflag &= ~CSIZE;//clears the mask […]