void Configure(SerialSettings& arSettings, boost::asio::serial_port& arPort) { //Set all the various options SetOption(arPort,ConvertBaud(arSettings.mBaud)); SetOption(arPort,ConvertDataBits(arSettings.mDataBits)); SetOption(arPort,ConvertParity(arSettings.mParity)); SetOption(arPort,ConvertStopBits(arSettings.mStopBits)); SetOption(arPort,ConvertFlow(arSettings.mFlowType)); // Hardwired to NONE currently }
void Configure(SerialSettings& arSettings, boost::asio::serial_port& arPort, error_code& ec) { //Set all the various options arPort.set_option(ConvertBaud(arSettings.mBaud), ec); if(ec) return; arPort.set_option(ConvertDataBits(arSettings.mDataBits), ec); if(ec) return; arPort.set_option(ConvertParity(arSettings.mParity), ec); if(ec) return; arPort.set_option(ConvertStopBits(arSettings.mStopBits), ec); if(ec) return; arPort.set_option(ConvertFlow(arSettings.mFlowType), ec); if(ec) return; }
int OpenSerialPort(int *fd,int iflow,struct termios *oldtio,char *sName,int nBauds,int parity,int nBits,int nStop) { int Of_Baud; int Of_Par; int Of_Bits; int Of_Stop; int HardFlow=0; int SoftFlow=0; struct termios newtio; switch(iflow) { case 1: HardFlow=CRTSCTS; break; case 2: SoftFlow=IXON | IXOFF | IXANY; break; case 3: HardFlow=CRTSCTS; SoftFlow=IXON | IXOFF | IXANY; break; } if ( (Of_Baud = ConvertBaudRate(nBauds)) == -1 ) return 1; if ( (Of_Par = ConvertParity(parity)) == -1 ) return 2; if ( (Of_Bits = ConvertDataBits(nBits)) == -1 ) return 3; if ( (Of_Stop = ConvertStopBits(nStop)) == -1 ) return 4; *fd=open(sName,O_RDWR | O_NOCTTY | O_NDELAY ); if ( (*fd) < 0 ) return 5; if (oldtio) { if ( tcgetattr (*fd,oldtio) == -1) { close(*fd); return 6; } } if (tcgetattr (*fd,&newtio) == -1 ) { close(*fd); return 6; } // cleaning default options newtio.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CRTSCTS); newtio.c_iflag &= ~( INPCK | ISTRIP | IGNPAR | IXON | IXOFF | IXANY | ICRNL | INLCR ); newtio.c_lflag &= ~( ICANON | ECHO | ECHOE | ISIG ); // setting options newtio.c_cflag= Of_Bits | Of_Stop | Of_Par | CLOCAL | CREAD | HUPCL | HardFlow; if ( Of_Par & PARENB ) newtio.c_iflag |= INPCK; // Why stripping the eight bit when parity is enabled?? | ISTRIP; else newtio.c_iflag |= IGNPAR; newtio.c_iflag |= SoftFlow; newtio.c_oflag=0; newtio.c_cc[VMIN]=1; newtio.c_cc[VTIME]=1; newtio.c_cc[VSTART]=17; //DC1; newtio.c_cc[VSTOP]=19; //DC3; cfsetispeed(&newtio,Of_Baud); cfsetospeed(&newtio,Of_Baud); tcflush(*fd,TCIFLUSH); if ( tcsetattr(*fd,TCSANOW,&newtio) == -1) { close(*fd); return 7; } return 0; }