#include typedef int u16;
typedef char u8;
#define DATA_LEN200
u16 openSerial(u16 iPort)
{
u16 iFd;
struct termios opt;
u8 cSerialName[15];
if(iPort >= 10){
printf("no this serial:ttySP%d
", iPort);
exit(1); //err return
}
sprintf(cSerialName, "/dev/ttySP%d", iPort - 1);
printf("open serial name:%s
", cSerialName);
iFd = open(cSerialName, O_RDWR | O_NOCTTY);
if( iFd < 0){
perror(cSerialName);
return -1;
}
//串口输入输出模式 各种参数配置
tcgetattr(iFd, &opt);
cfsetispeed(&opt, B115200);
cfsetospeed(&opt, B115200);
//raw mode
opt.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);
opt.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);