📄 testmodem.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/select.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include "serial.h"
int init_modem(int fd)
{
char buf[255];
char *bufptr;
int nbytes;
int tries;
nbytes=comm_write(fd, "AT\r", 3);
if(nbytes>0)
{
printf("nbytes=%d\n",nbytes);
sleep(2);
//fcntl(fd, F_SETFL, FNDELAY);
bufptr = buf;
while((nbytes=comm_read(fd,bufptr,1,gettickcount()+3000))>0)
{
printf("nbytes=%d\n",nbytes);
bufptr += nbytes;
if (bufptr[-1] == '\n' || bufptr[-1] == '\r')
break;
}
printf("nbytes=%d\n",nbytes);
if (nbytes>=0)
return (0);
else
return (-1);
}
else
return (-1);
}
int main(void)
{
int fd;
int check=1;
struct termios options;
//open the port
fd=comm_open("/dev/ttyS3",&options,(const char*)"9600, 8, 1, n,h");
check=init_modem(fd);
printf("check=%d\n",check);
if(check==0)
printf("modem ok...\n");
else
printf("modem bad...\n");
close(fd);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -