在arm做接收DTU参数的时候,始终无法获取到DTU映射文件(/dev/dtu)里面的数据(可能没找到方法
)
刚开始用os去打开
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
fd = os.open('/dev/dtu',os.O_RDWR)
ret = os.read(fd,10)
print ret
得到的始终为空,后来发现用C语言里面的函数可以得到数据,写了一个check.c文件:
#include <stdarg.h>
#include <termio.h>
#include <sys/timeb.h>
#include <pthread.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <errno.h>
#include <stdlib.h>
#define MCU_DIDO_IOC_MAGIC 'd'
#define IO_GPIO_SET_OUTPUT _IO(MCU_DIDO_IOC_MAGIC,0)
#define IO_GPIO_RESET_OUTPUT _IO(MCU_DIDO_IOC_MAGIC,1)
#define IO_GPIO_GET_INPUT _IOR(MCU_DIDO_IOC_MAGIC,2,int)
int testdi()
{
int dtu_fd;
unsigned int input_value = 0 ;
int i;
int ret;
if((dtu_fd = open("/dev/dtu", O_RDWR)) < 0)
{
perror("open /dev/dtu error");
return -1;
}
ret = ioctl(dtu_fd,IO_GPIO_GET_INPUT,&input_value);
close(dtu_fd);
if(ret == 0)
return input_value;
else
return -1
}
用arm-linux-gcc -o check.so -shared -fPIC check.c生成check.so文件(每个人的交叉编译链不一样)
写一个get_value.py:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import ctypes
ll = ctypes.cdll.LoadLibrary
lib = ll("/check.so")
print lib.testdi()
运行后得到自己想要的数据