📄 test_de.c
字号:
#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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -