testpe4302.c

来自「linux下」· C语言 代码 · 共 36 行

C
36
字号
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#define DEVICE	"/dev/PE4302"
int main()
{
	int fd,ret;
	unsigned short send,tmp;
	if((fd=open(DEVICE,O_RDWR | O_NONBLOCK))<0)
	{
		perror("can not open device");
		exit(1);
	}
	printf("open device: %s\n",DEVICE);
	printf("now input your data to be send:");
	scanf("%x",&tmp);
  send=tmp&0x00ff;
  printf("send: %x\n",send);
	ret=write(fd,&send,1);
  if (ret!=1)
  {
    printf("write error\n");
  }
  else
  {
    printf("send data ok\n");
  }
  
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?