iOS--串口通讯初始化
+(int)PKOpenSerial
{
int fd = open("/dev/tty.iap", O\_RDWR | O\_NOCTTY| O\_NONBLOCK);//
if(fd == -1)
\{
printf("open serial error!");
\}
if (ioctl(fd, TIOCEXCL) == -1)
\{
printf("Error setting TIOCEXCL on %s - %s(%d).\\n",
"/dev/tty.iap", strerror(errno), errno);
\}
struct termios options;
struct termios oldoptions;
tcgetattr(fd,&oldoptions);
options = oldoptions;
// cfmakeraw(&options);//配为原始模式
//配置波特率为115200
cfsetispeed(&options,B115200);
cfsetospeed(&options,B115200);
// 配置串口属性
options.c\_cflag |= (CLOCAL | CREAD);
options.c\_cflag &= ~PARENB;
options.c\_cflag &= ~CSTOPB;
options.c\_cflag &= ~CSIZE;
options.c\_cflag |= CS8;
// 启用设置
tcsetattr(fd,TCSANOW,&options);
return fd;
}
还没有评论,来说两句吧...