+(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;
}