test_de.c

来自「linux 基于 s3c2440 的rs485驱动及测试程序,可正常收发16Mh」· C语言 代码 · 共 58 行

C
58
字号
#include <stdio.h>     
#include <stdlib.h>
#include <sys/ioctl.h>  
#include <unistd.h>
#include <fcntl.h>

//#include <asm/arch/major.h>

#define DEVICE_485 "/dev/rs485driver"

struct rs485de_ctl
{
	long BaudRate;
	int parity;
	int dataBits;
	int stopBits;	
	long count;
};

int main()
{
	int fd; 
	int val=-1;
	int ret = 0;
  struct rs485de_ctl *dep;   	  
	if((fd=open(DEVICE_485,O_RDONLY | O_NONBLOCK))<0)
	{
		perror("can not open device\n");
		exit(1);
	}
 // struct rs485de_ctl *dep;
  dep=malloc(sizeof(struct rs485de_ctl));
  memset(dep,0,sizeof(*dep));
  dep->BaudRate=9600;
  dep->parity=0;
  dep->dataBits=8;
  dep->stopBits=1;
  dep->count=1000;
	while(1)
	{
		  printf("\n1:SEND ,2:RECEIVE,0:quit :");
		  scanf("%d",&val);
			if(val==1){
				ret =ioctl(fd,1,dep);//  command 1 ---  SEND
				printf("result: %d\n", ret);
				}
			else if (val==2){        
				ret =ioctl(fd,2,dep);          //command 2 ---  RECEIVE
				printf("result: %d\n", ret);
				}
			else if(val==0){
				close(fd);
				exit(0);
				}
	}
	return 0;
}

⌨️ 快捷键说明

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