python ioctl_Python如何使用ioctl或spidev从设备读取输入?
我有一個hardware device,提供它的供應商提供了一些C代碼來監聽使用ioctl的按鈕按下。該設備有一個SSD1289控制器。在Push buttons require no additional pins, their status canbe read over SPI.
這就是我想要的,看看是哪個按鈕被按下的。在
我正試圖在Python中為我自己的應用程序復制這個腳本,但IOR和ioctl的要求讓我很困惑。在#include
#include
#include
#include
#include
#include
#define SSD1289_GET_KEYS _IOR('keys', 1, unsigned char *)
void get_keys(int fd)
{
unsigned char keys;
if (ioctl(fd, SSD1289_GET_KEYS, &keys) == -1)
{
perror("_apps ioctl get");
}
else
{
printf("Keys : %2x\n", keys);
}
}
int main(int argc, char *argv[])
{
char *file_name = "/dev/fb1";
int fd;
fd = open(file_name, O_RDWR);
if (fd == -1)
{
perror("_apps open");
return 2;
}
while(1)
get_keys(fd);
printf("Ioctl Number: (int)%d (hex)%x\n", SSD1289_GET_KEYS, SSD1289_GET_KEYS);
close (fd);
return 0;
}
現在我知道Python有一個ioctl模塊,在某個時候我應該調用
^{pr2}$
我不知道SSD1289_GET_KEYS應該是什么。我怎么得到這個,什么是_IOR?在
另外,如果這是一個錯誤的方法,知道這將是一個幫助。有一些像spidev這樣的庫應該是針對SPI的,但是我不知道用它讀什么。在
@alexis在下面提供了一些有用的步驟,讓我走到了這一步:import fcntl
import array
file = open("/dev/fb1")
buf = array.array('h', [0])
fcntl.ioctl(file, -444763391, buf, 1)
現在,按一個按鈕改變buf的值,如果我保持上面的循環。在
總結
以上是生活随笔為你收集整理的python ioctl_Python如何使用ioctl或spidev从设备读取输入?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 串口 驱动 热敏打印机_菜鸟裹裹x 快麦
- 下一篇: unity导出fbx模型_ARTBOOK