文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>ldd3 驱动--测试scull

ldd3 驱动--测试scull

时间:2010-08-11  来源:hunaiquan

scull驱动模拟设备。编写读写设备的控制文件testscull.c向scull发送和接收数据。 1 安装scull.ko   在ldd3驱动源码文件夹中,进入scull文件夹,make,生成scull.ko,运行其中的shell文件:scull_load,完成scull.ko的安装。   # cd /sys/module/scull/parameters/   #cat scull_major   253   #cat scull_minor   0   可知scull.ko的主次设备号为253 0   进入/dev 创建设备文件:   #cd /dev   #mknod sculldev c 253 0 2 编写测试文件testscull.c   代码: #include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<error.h>
#include<fcntl.h>
#include<sys/types.h>
int main()
{
  int fd,len;
  char inbuf[20];
  char outbuf[20]="scull dev test!";
  fd=open("/dev/sculldev",O_WRONLY);
  if(fd<0)
  {printf("Error openning the device of sculldev for wrITing!\n");
  exit(1);
  }
  len=write(fd,outbuf,strlen(outbuf));
  if(len<0)
    { printf("Error writing to the device!\n");
      close(fd);
      exit(1);
   
    }
  printf("writing %d bytes to the device!\n",len);
  close(fd);
  fd=open("/dev/sculldev",O_RDONLY);
  if(fd<0)
  {
    printf("Error openning the device of sculldev for reading!\n");
    exit(1);
  }
  len=read(fd,inbuf,len);
  if(len<0)
    {printf("Error reading from the device!\n ");
     close(fd);
     exit(1);
    }
  printf("reading %d bytes from the device!\n",len);
  printf("%s\n",outbuf);
}
3 测试 #gcc testscull.c -o testscull #./testscull
 
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载