python ioctl_Python如何使用ioctl或spidev从设备读取输入?
我有一個(gè)hardware device,提供它的供應(yīng)商提供了一些C代碼來(lái)監(jiān)聽(tīng)使用ioctl的按鈕按下。該設(shè)備有一個(gè)SSD1289控制器。在Push buttons require no additional pins, their status canbe read over SPI.
這就是我想要的,看看是哪個(gè)按鈕被按下的。在
我正試圖在Python中為我自己的應(yīng)用程序復(fù)制這個(gè)腳本,但I(xiàn)OR和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;
}
現(xiàn)在我知道Python有一個(gè)ioctl模塊,在某個(gè)時(shí)候我應(yīng)該調(diào)用
^{pr2}$
我不知道SSD1289_GET_KEYS應(yīng)該是什么。我怎么得到這個(gè),什么是_IOR?在
另外,如果這是一個(gè)錯(cuò)誤的方法,知道這將是一個(gè)幫助。有一些像spidev這樣的庫(kù)應(yīng)該是針對(duì)SPI的,但是我不知道用它讀什么。在
@alexis在下面提供了一些有用的步驟,讓我走到了這一步:import fcntl
import array
file = open("/dev/fb1")
buf = array.array('h', [0])
fcntl.ioctl(file, -444763391, buf, 1)
現(xiàn)在,按一個(gè)按鈕改變buf的值,如果我保持上面的循環(huán)。在
總結(jié)
以上是生活随笔為你收集整理的python ioctl_Python如何使用ioctl或spidev从设备读取输入?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 串口 驱动 热敏打印机_菜鸟裹裹x 快麦
- 下一篇: unity导出fbx模型_ARTBOOK