Ejemplo n.º 1
0
Asynch::Asynch(unsigned char p,unsigned int b)
// Class constructor - set base address and irq number.
// This particular constructor also sets the baud rate to the
// specified speed
{
    switch(p)   // set up correct base address and irq for this port
    {
        case COM1:  // serial port 1
            _ainfo.base = 0x03f8;   // base address for port 1
            _ainfo.irq  = 4;        // interrupt number for port 1
            break;
        case COM2:  // serial port 2
            _ainfo.base = 0x02f8;   // base address for port 2
            _ainfo.irq  = 3;        // interrupt number for port 2
            break;
        case COM3:   // serial port 3
            _ainfo.base = 0x03e8;   // base address for port 3
            _ainfo.irq  = 4;        // interrupt number for port 3
            break;
        case COM4:  // serial port 4
            _ainfo.base = 0x02e8;   // base address for port 4
            _ainfo.irq  = 3;        // interrupt number for port 4
            break;
        default:    // defaults to com2
            _ainfo.base = 0x02f8;   // base address for port 2
            _ainfo.irq  = 3;        // interrupt number for port 2
            break;
    }

    _ainfo.baud = b;                // Default baud rate is 2400

    asynchInit();                   // call interrupt initialization
    setBaud(_ainfo.baud);           // set to default baud rate
}
Ejemplo n.º 2
0
Asynch::Asynch(unsigned char p)
// Class constructor - set base address and irq number.
{
    switch(p)   // set up correct base address and irq for this port
    {
        case COM1:  // serial port 1
            _ainfo.base = 0x03f8;   // base address for port 1
            _ainfo.irq  = 4;        // interrupt number for port 1
            break;
        case COM2:  // serial port 2
            _ainfo.base = 0x02f8;   // base address for port 2
            _ainfo.irq  = 3;        // interrupt number for port 2
            break;
        case COM3:  // serial port 3
            _ainfo.base = 0x03e8;   // base address for port 3
            _ainfo.irq  = 4;        // interrupt number for port 3
            break;
        case COM4:  // serial port 4
            _ainfo.base = 0x02e8;   // base address for port 4
            _ainfo.irq  = 3;        // interrupt number for port 4
            break;
        default:  // defaults to com2, cuz that's what I have!
            _ainfo.base = 0x02f8;   // base address for port 2
            _ainfo.irq  = 3;        // interrupt number for port 2
            break;
    }

    _ainfo.baud = 2400;             // Default baud rate is 2400

    asynchInit();                   // call interrupt initialization
    setBaud(_ainfo.baud);           // set to default baud rate
}
Ejemplo n.º 3
0
static int openTouchDev( char const *devName ){
   int fd = -1 ;
   if( !isSerial(devName) ){
      fd = open(devName, O_RDONLY);
   }
   else {
      printf( "Serial touch screen\n" );
      char const *end = strchr( devName, ',' );
      if( 0 == end )
         end = devName + strlen(devName);
      unsigned nameLen = end-devName ;
      printf( "nameLen: %u, end %p\n", nameLen, end );
      char deviceName[512];
      if( nameLen < sizeof(deviceName) ){
         memcpy( deviceName, devName, nameLen );
         deviceName[nameLen] = '\0' ;
         unsigned baud = 9600 ;
         unsigned databits = 8 ;
         char parity = 'N' ;
         unsigned stop = 1 ;
         if( '\0' != *end ){
            end++ ;
            baud = 0 ; 
            while( isdigit(*end) ){
               baud *= 10 ;
               baud += ( *end-'0' );
               end++ ;
            }

            if( ',' == *end ){
               end++ ;
               databits = *end-'0' ;
               end++ ;
               if( ',' == *end ){
                  end++ ;
                  parity = *end++ ;
                  if( ',' == *end ){
                     stop = end[1] - '0';
                  }
               }
            }
         }
         fd = open( deviceName, O_RDWR );
         if( 0 < fd ){
            printf( "settings: %s,%u,%u,%c,%u\n", deviceName, baud, databits, parity, stop );
            setBaud( fd, baud );
            setRaw( fd );
            setDataBits( fd, databits );
            setStopBits( fd, stop );
            setParity( fd, parity );
         }
         else
            perror( deviceName );
      }
      else
         fprintf( stderr, "Invalid touch device name\n" );
   }

   return fd ;
}
Ejemplo n.º 4
0
void NetworkManager::SerialSetting::fromMap(const QVariantMap &setting)
{
    if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BAUD))) {
        setBaud(setting.value(QLatin1String(NM_SETTING_SERIAL_BAUD)).toUInt());
    }

    if (setting.contains(QLatin1String(NM_SETTING_SERIAL_BITS))) {
        setBits(setting.value(QLatin1String(NM_SETTING_SERIAL_BITS)).toUInt());
    }

    if (setting.contains(QLatin1String(NM_SETTING_SERIAL_PARITY))) {
        QChar character = setting.value(QLatin1String(NM_SETTING_SERIAL_PARITY)).toChar();

        if (character == 'n') {
            setParity(NoParity);
        } else if (character == 'E') {
            setParity(EvenParity);
        } else if (character == 'o') {
            setParity(OddParity);
        }
    }

    if (setting.contains(QLatin1String(NM_SETTING_SERIAL_STOPBITS))) {
        setStopbits(setting.value(QLatin1String(NM_SETTING_SERIAL_STOPBITS)).toUInt());
    }

    if (setting.contains(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY))) {
        setSendDelay((Setting::SecretFlagType)setting.value(QLatin1String(NM_SETTING_SERIAL_SEND_DELAY)).toULongLong());
    }
}
Ejemplo n.º 5
0
int8_t GSwifi::factorySetup(uint32_t initial_baud) {
    clear();

    // version 2.5.1 firmware starts with 115200 baud rate
    // version 2.5.1 (Tue, Dec 10, 2013 at 2:14 PM) firmware starts with 9600 baud rate
    // version 2.4.3 firmware starts with 9600 baud rate
    serial_->begin(initial_baud);

    // need this to ignore invalid response
    command(PB("AT",1), GSCOMMANDMODE_NORMAL, GS_TIMEOUT_SHORT);
    if (did_timeout_) {
        return -1;
    }

    setBaud(57600);

    command(PB("ATE0",1), GSCOMMANDMODE_NORMAL);

    // enable bulk data mode
    command(PB("AT+BDATA=1",1), GSCOMMANDMODE_NORMAL);

    command(PB("AT&W0",1), GSCOMMANDMODE_NORMAL);
    if (did_timeout_) {
        return -1;
    }
    return 0;
}
Ejemplo n.º 6
0
void
SerialPort::setSerial(int baud, int dataBits, int parity, int stopBits)
{
    setBaud(baud);
    setDataBits(dataBits);
    setParity(parity);
    setStopBits(stopBits);
}
Ejemplo n.º 7
0
void UART::BreakCOM(void)
{
	while(tx_counter > 0);
	unsigned short int tempUBRR = *_ubrr;
	setBaud(4800);
	putch(0x00);
	while(tx_counter > 0);
	*_ubrr = tempUBRR;
}
Ejemplo n.º 8
0
NetworkManager::SerialSetting::SerialSetting(const Ptr &other):
    Setting(other),
    d_ptr(new SerialSettingPrivate())
{
    setBaud(other->baud());
    setBits(other->bits());
    setParity(other->parity());
    setStopbits(other->stopbits());
    setSendDelay(other->sendDelay());
}
Ejemplo n.º 9
0
McoStatus SpectroChart::Initialize(void)
{
McoStatus state = MCO_SUCCESS;
char st[5000];
int		dum,type,error;

if (sp == 0L) return MCO_SERIAL_ERROR;

// set baud
state = setBaud(GT_DEFALUT_BAUD);
if (state != MCO_SUCCESS) goto bail;

// check device type
sp->sendData("; 43\r\n",6);
sp->getNextLine(st,5000,thermd);

sscanf_n_i(st,27,1,&type);
if (type !=2) goto bail;

//reset
sp->sendData("; 90 1 4 5\r\n",12);
state = CheckError();
if (state != MCO_SUCCESS) goto bail;

//set measurment type
sp->sendData("; 77 155\r\n",10);
state = CheckError();
if (state != MCO_SUCCESS) goto bail;

// set the illuminante, angle
sp->sendData("; 22 1 1 3 0\r\n",14);
state = CheckError();
if (state != MCO_SUCCESS) goto bail;

// set the type of output desired (Cie Lab)
//sp->sendData("; 177 2 2\r\n",11);
//state = CheckError();
//if (state != MCO_SUCCESS) goto bail;


bail:
if (thermd != 0L)
	{
	thermd->DisplayTherm(4,4,0L);	
	thermd->RemoveTherm();
	delete thermd; 
	}
thermd = 0L;


return state;
}
Ejemplo n.º 10
0
int main( int argc, char const * const argv[] )
{
   if( 2 <= argc )
   {
      char const *const deviceName = argv[1];
      serialSignal_t ss( deviceName, handler );
      if( ss.isOpen() )
      {
         unsigned baud = ( 2 < argc ) ? strtoul( argv[2], 0, 0 ) : 115200 ;
         int rval = setBaud( ss.getFd(), baud );
         if( 0 == rval )
            debugPrint( "set baud to %u\n", baud );
         else
            printf( "error setting baud to %u\n", baud );

         unsigned dataBits = ( 3 < argc ) ? strtoul( argv[3], 0, 0 ) : 8 ;
         rval = setDataBits( ss.getFd(), dataBits );
         if( 0 == rval )
            debugPrint( "set data bits to %u\n", dataBits );
         else
            printf( "error setting data bits to %u\n", dataBits );

         char parity = ( 4 < argc ) ? toupper( *argv[4] ) : 'N' ;
         rval = setParity( ss.getFd(), parity );
         if( 0 == rval )
            debugPrint( "set parity to %c\n", parity );
         else
            printf( "error setting parity to %c\n", parity );

         unsigned stopBits = ( ( 5 < argc ) && ( '2' == *argv[5] ) ) ? 2  : 1 ;
         rval = setStopBits( ss.getFd(), stopBits );
         if( 0 == rval )
            debugPrint( "set stop bits to %u\n", stopBits );
         else
            printf( "error setting stop bits to %u\n", stopBits );

         debugPrint( "device opened\n" );
         while( 1 ){
            pause();
         }
      }
      else
         perror( deviceName );
   }
   else
      fprintf( stderr, "Usage: serialSignal deviceName [baud=115200 [databits=8 [parity=N]]]\n" );

   return 0 ;
}
Ejemplo n.º 11
0
void setOutput(byte pin) {
	chkpin(pin);
	outpin = pin;

#ifdef HARDWARE_SERIAL_TX
	// skip soft baud check for the hardware uart
	if (outpin != DEFAULT_OUTPIN)
#endif
#ifdef ALTERNATE_OUTPIN
	if (outpin != ALTERNATE_OUTPIN)
#endif

	// set the softserial baud if it's not already set
	if (!bittime[outpin]) setBaud(pin, DEFAULT_SECONDARY_BAUD);
}
Ejemplo n.º 12
0
McoStatus Techkon::Initialize(void)
{
McoStatus state;
Str255	the_string;

if (sp == 0L) return MCO_SERIAL_ERROR;

state = setBaud(TK_DEFALUT_BAUD);

sendCommand(Tech_Illum_D50);
sendCommand(Tech_Obs_2);


return MCO_SUCCESS;
}
Ejemplo n.º 13
0
NetworkManager::PppSetting::PppSetting(const Ptr &other):
    Setting(other),
    d_ptr(new PppSettingPrivate())
{
    setNoAuth(other->noAuth());
    setRefuseEap(other->refuseEap());
    setRefusePap(other->refusePap());
    setRefuseChap(other->refuseChap());
    setRefuseMschap(other->refuseMschap());
    setRefuseMschapv2(other->refuseMschapv2());
    setNoBsdComp(other->noBsdComp());
    setNoDeflate(other->noDeflate());
    setNoVjComp(other->noVjComp());
    setRequireMppe(other->requireMppe());
    setRequireMppe128(other->requireMppe128());
    setMppeStateful(other->mppeStateful());
    setCRtsCts(other->cRtsCts());
    setBaud(other->baud());
    setMru(other->mru());
    setMtu(other->mtu());
    setLcpEchoFailure(other->lcpEchoFailure());
    setLcpEchoInterval(other->lcpEchoInterval());
}
Ejemplo n.º 14
0
bool __fastcall TComto8051::SetCommData(int baud,int databits,int parity,int stopbits,int port,bool dtron)
{
 COMMTIMEOUTS commtimeouts;

 if(setPort(port)==false)
 {
  CloseHandle(commhandle);
  Terminate();
  return false;
 }
 setBaud(baud);
 setDatabits(databits);
 setParity(parity);
 setStopbits(stopbits);

 GetCommTimeouts(commhandle,&commtimeouts);
 commtimeouts.ReadTotalTimeoutConstant=1;
 commtimeouts.WriteTotalTimeoutConstant=1;
 SetCommTimeouts(commhandle,&commtimeouts);

 setdtrstate(dtron);
 Resume();
 return true;
}
Ejemplo n.º 15
0
Archivo: HC05.cpp Proyecto: MEXXIO/HC05
// Usually parity is none, and there is only one stop bit, so this
// simpler call will do the job.
void HC05::setBaud(unsigned long baud)
{
    setBaud(baud, 0, 0);
}
AREXPORT int ArSerialConnection::internalOpen(void)
{
  struct termios tio;

  if (myStatus == STATUS_OPEN) 
  {
    ArLog::log(ArLog::Terse, "ArSerialConnection::internalOpen: Serial port already open");
    return OPEN_ALREADY_OPEN;
  }

  if (myIs422)
    ArLog::log(ArLog::Verbose, "ArSerialConnection::internalOpen: Connecting to serial422 port '%s'", myPortName.c_str());
  else
    ArLog::log(ArLog::Verbose, "ArSerialConnection::internalOpen: Connecting to serial port '%s'", myPortName.c_str());

  /* open the port */
  if (!myIs422)
  {
	  if ((myPort = ArUtil::open(myPortName.c_str(),O_RDWR | O_NDELAY)) < 0)
	  {
		  ArLog::logErrorFromOS(ArLog::Terse, "ArSerialConnection::open: Could not open serial port '%s'", myPortName.c_str());
		  return OPEN_COULD_NOT_OPEN_PORT;
	  }
  }
  else
  {
	  // PS 9/9/11 - the RDONLY worked for the s3series as it did not
	  // do any writes, but the sZseries needs to do writes, so changed the
	  // flag to RDWR
	  //	 if ((myPort = ArUtil::open(myPortName.c_str(),O_RDONLY | O_NOCTTY)) < 0)
	  if ((myPort = ArUtil::open(myPortName.c_str(),O_RDWR | O_NOCTTY)) < 0)
	  {
		  ArLog::logErrorFromOS(ArLog::Terse, "ArSerialConnection::open: Could not open serial port '%s'", myPortName.c_str());
		  return OPEN_COULD_NOT_OPEN_PORT;
	  }
  }

  
  /* set the tty baud, buffering and modes */
  if (tcgetattr(myPort, &tio) != 0)
  {
    ArLog::logErrorFromOS(ArLog::Terse, "ArSerialConnection::open: Could not get port data to set up port");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_COULD_NOT_SET_UP_PORT;
  }    

  /* turn off echo, canonical mode, extended processing, signals */
  tio.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);

  /* turn off break sig, cr->nl, parity off, 8 bit strip, flow control */
  tio.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);

  /* clear size, turn off parity bit */
  tio.c_cflag &= ~(CSIZE | PARENB);

  /* set size to 8 bits */
  tio.c_cflag |= CS8;

  /* turn output processing off */
  tio.c_oflag &= ~(OPOST);

  /* Set time and bytes to read at once */
  tio.c_cc[VTIME] = 0;
  tio.c_cc[VMIN] = 0;

  // PS 7/3/11 - check if dev is RS422, if so then the cflags need
  // to be set different, for now test for dev/ttyS3, later we need to input that
  // the device is RS422

  // PS 9/9/11 - taking out the B38500, we now set the baud below
  if (myIs422)
	  tio.c_cflag = CS8 | CLOCAL | CREAD |IGNPAR;
      //tio.c_cflag = B57600 | CS8 | CLOCAL | CREAD |IGNPAR;

  if (tcflush(myPort,TCIFLUSH) == -1)
  {
	  ArLog::logErrorFromOS(ArLog::Terse,
			  "ArSerialConnection::open: Could not set up port tcflush failed");
	  close();
	  myStatus = STATUS_OPEN_FAILED;
	  return OPEN_COULD_NOT_SET_UP_PORT;
  }

  if (tcsetattr(myPort,TCSAFLUSH,&tio) == -1)
  {
	  ArLog::logErrorFromOS(ArLog::Terse,
			  "ArSerialConnection::open: Could not set up port");
	  close();
	  myStatus = STATUS_OPEN_FAILED;
	  return OPEN_COULD_NOT_SET_UP_PORT;
  }

  myStatus = STATUS_OPEN;

  // PS 7/3/11 - only set the baud and hw control if RS232
  // for now test for dev/ttyS3, later we need to input that
  // the device is RS422

  if (!myIs422)
  {
	  if (myBaudRate != 0 && rateToBaud(myBaudRate) == -1)
	  {
		  ArLog::logErrorFromOS(ArLog::Terse, "ArSerialConnection::open: Invalid baud rate.");
		  close();
		  myStatus = STATUS_OPEN_FAILED;
		  return OPEN_INVALID_BAUD_RATE;
	  }

	  //printf("my baud rate = %d\n",myBaudRate);
	  if (myBaudRate != 0 && !setBaud(myBaudRate))
	  {
		  ArLog::log(ArLog::Terse,
				  "ArSerialConnection::open: Could not set baud rate.");
		  close();
		  myStatus = STATUS_OPEN_FAILED;
		  return OPEN_COULD_NOT_SET_BAUD;
	  }

	  if (!setHardwareControl(myHardwareControl))
	  {
		  ArLog::log(ArLog::Terse,
				  "ArSerialConnection::open: Could not set hardware control.");
		  close();
		  myStatus = STATUS_OPEN_FAILED;
		  return OPEN_COULD_NOT_SET_UP_PORT;
	  }
  }
  // PS 9/9/11 - added else for SZ
  else
  {
	  if (myBaudRate != 0 && rateToBaud(myBaudRate) == -1)
	  {
		  ArLog::logErrorFromOS(ArLog::Terse, "ArSerialConnection::open: Invalid baud rate.");
		  close();
		  myStatus = STATUS_OPEN_FAILED;
		  return OPEN_INVALID_BAUD_RATE;
	  }

	  //printf("my baud rate = %d\n",myBaudRate);
	  if (myBaudRate != 0 && !setBaud(myBaudRate))
	  {
		  ArLog::log(ArLog::Terse,
				  "ArSerialConnection::open: Could not set baud rate.");
		  close();
		  myStatus = STATUS_OPEN_FAILED;
		  return OPEN_COULD_NOT_SET_BAUD;
	  }
  }

  ArLog::log(ArLog::Verbose, "ArSerialConnection::open: Successfully opened and configured serial port '%s'.", myPortName.c_str());
  return 0;
}
Ejemplo n.º 17
0
void HardwareSerial::begin(int baud)
{
    if (openDevice())
	setBaud(baud);
}
bool ofSerial::setBaud(const std::string& baud_str)
{
	unsigned long b;
	if (!isInteger(baud_str)) return false;
	return setBaud((int)b);
}
//----------------------------------------------------------------
bool ofSerial::setup(std::string portName, int baud){

	close();

	std::cout << "setup serial" << "\r\n";
	port_is_open = false;


    //lets account for the name being passed in instead of the device path
    if( portName.size() > 5 && portName.substr(0, 5) != "/dev/" ){
        portName = "/dev/" + portName;
    }

    baud_rate = baud;

    std::cout << "opening " << portName << " @ " << baud << " bps" << "\r\n";
	struct serial_struct kernel_serial_settings;
	int bits;
	port_fd = open(portName.c_str(), O_RDWR | O_NOCTTY | O_NONBLOCK);
	if (port_fd < 0) {
		if (errno == EACCES) {
			error_msg = "Unable to access " + portName + ", insufficient permission";
			// TODO: we could look at the permission bits and owner
			// to make a better message here
		} else if (errno == EISDIR) {
			error_msg = "Unable to open " + portName +
				", Object is a directory, not a serial port";
		} else if (errno == ENODEV || errno == ENXIO) {
			error_msg = "Unable to open " + portName +
				", Serial port hardware not installed";
		} else if (errno == ENOENT) {
			error_msg = "Unable to open " + portName +
				", Device name does not exist";
		} else {
			error_msg = "Unable to open " + portName;
		}

        std::cout << error_msg << "\r\n";
		return false;
	}
	if (ioctl(port_fd, TIOCMGET, &bits) < 0) {
		::close(port_fd);
		error_msg = "Unable to query serial port signals";
        std::cout << error_msg << "\r\n";
		return false;
	}
	bits &= ~(TIOCM_DTR | TIOCM_RTS);
	if (ioctl(port_fd, TIOCMSET, &bits) < 0) {
		::close(port_fd);
		error_msg = "Unable to control serial port signals";
        std::cout << error_msg << "\r\n";
		return false;
	}
	if (tcgetattr(port_fd, &settings_orig) != 0) {
		::close(port_fd);
		error_msg = "Unable to query serial port settings (perhaps not a serial port)";
        std::cout << error_msg << "\r\n";
		return false;
	}
	memset(&settings, 0, sizeof(settings));
	settings.c_iflag = IGNBRK | IGNPAR;
	settings.c_cflag = CS8 | CREAD | HUPCL | CLOCAL;
	setBaud(baud_rate);
	if (ioctl(port_fd, TIOCGSERIAL, &kernel_serial_settings) == 0) {
		kernel_serial_settings.flags |= ASYNC_LOW_LATENCY;
		ioctl(port_fd, TIOCSSERIAL, &kernel_serial_settings);
	}
	tcflush(port_fd, TCIFLUSH);

	port_name = portName;
	port_is_open = true;
    std::cout << "opened " << portName << " sucessfully @ " << baud << " bps" << "\r\n";
	return true;
}
Ejemplo n.º 20
0
void UART::begin(long baud_rate)
{
	begin();
	setBaud(baud_rate);
}
Ejemplo n.º 21
0
bool BT_HC06::configure(String name, uint16_t pin, enumBaudRates baud)
{
	Serial.println("Looking for connected HC-06 modules");

	//find connected device
	int32_t current_baud = ValidBauds[findConnectedBaud()];
	if (current_baud == 0)
	{
		Serial.println("ERROR: Failed to detect connected HC-06!");
		return false;
	}
	else
	{
		Serial.print("Found device HC-06 at ");
		Serial.print(current_baud);
		Serial.println("bps");
	}

	//set name	
	if (!setName(name))
	{
		Serial.println("ERROR: Failed to set device name! (Over 20 Characters?)");
		return false;
	}
	else
	{
		Serial.print("Device Name successfully set to ");
		Serial.println(name);
	}

	//set PIN
	if (!setPin(pin))
	{
		Serial.println("ERROR: Failed to set device PIN! (less than 9999?)");
		return false;
	}
	else
	{
		Serial.print("Device PIN successfully set to ");
		Serial.println(Pin);
	}

	//set baud if different from detected baud
	if (current_baud != ValidBauds[baud])
	{
		if (!setBaud(baud))
		{
			Serial.println("ERROR: Failed to set baud rate!");
		}
		else
		{
			
			Serial.print("Baud configured at ");
			Serial.print(ValidBauds[baud]);
			Serial.println("bps");

			//test connection at new baud		
			HC06Serial.begin(ValidBauds[baud]);

			if (!testConnection())
			{
				Serial.println("ERROR: Failed to connect at new baud rate!");
				return false;
			}
			else
			{
				Serial.println("Successfully connected at new baud rate");
			}
		}
	}
	else
	{
		Serial.print("Baud already configured correctly at ");
		Serial.print(ValidBauds[baud]);
		Serial.println("bps");
	}

	Serial.println("Configuration completed successfully.");

	return true;
}
Ejemplo n.º 22
0
AREXPORT int ArSerialConnection::internalOpen(void)
{
  DCB dcb;


  if (myStatus == STATUS_OPEN)
  {
    ArLog::log(ArLog::Terse,
	       "ArSerialConnection::open: Serial port already open");
    return OPEN_ALREADY_OPEN;
  }

  myPort = CreateFileA(myPortName.c_str(),
		      GENERIC_READ | GENERIC_WRITE,
		      0,	/* exclusive access  */
		      NULL,	/* no security attrs */
		      OPEN_EXISTING,
		      0,
		      NULL );

  if (myPort == INVALID_HANDLE_VALUE) {
    ArLog::log(ArLog::Terse,
	       "ArSerialConnection::open: Could not open serial port '%s'",
	       myPortName.c_str());
    return OPEN_COULD_NOT_OPEN_PORT;
  }

  if ( !GetCommState(myPort, &dcb) )
  {
    ArLog::log(ArLog::Terse,
	       "ArSerialConnection::open: Could not get port data to set up port");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_COULD_NOT_SET_UP_PORT;
  }

  dcb.ByteSize = 8;
  dcb.Parity = NOPARITY;
  dcb.StopBits = ONESTOPBIT;
  dcb.fOutxCtsFlow = FALSE;
  dcb.fOutxDsrFlow = 0;
  dcb.fBinary = TRUE;
  dcb.fParity = FALSE;
  dcb.fNull = FALSE;
  dcb.fOutX = FALSE;
  dcb.fInX =  FALSE;

  if ( !SetCommState(myPort, &dcb) )
  {
    ArLog::log(ArLog::Terse,
	       "ArSerialConnection::open: Could not set up port");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_COULD_NOT_SET_UP_PORT;
  }

  myStatus = STATUS_OPEN;

  if (!setBaud(myBaudRate))
  {
    ArLog::log(ArLog::Terse,
	       "ArSerialConnection::open: Could not set baud rate.");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_COULD_NOT_SET_BAUD;
  }

  if (!setHardwareControl(myHardwareControl))
  {
    ArLog::log(ArLog::Terse,
	       "ArSerialConnection::open: Could not set hardware control.");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_COULD_NOT_SET_UP_PORT;
  }

  ArLog::log(ArLog::Verbose,
	     "ArSerialConnection::open: Successfully opened and configured serial port.");
  return 0;
}
Ejemplo n.º 23
0
AREXPORT int ArSerialConnection::internalOpen(void)
{
  struct termios tio;

  if (myStatus == STATUS_OPEN) 
  {
    ArLog::log(ArLog::Terse, "ArSerialConnection::open: Serial port already open");
    return OPEN_ALREADY_OPEN;
  }

  /* open the port */
  if ((myPort = ::open(myPortName.c_str(),O_RDWR | O_NDELAY)) < 0) 
  {
    ArLog::log(ArLog::Terse, "ArSerialConnection::open: Could not open serial port '%s'", myPortName.c_str());
    return OPEN_COULD_NOT_OPEN_PORT;
  }
  
  /* set the tty baud, buffering and modes */
  if (tcgetattr(myPort, &tio) != 0)
  {
    ArLog::log(ArLog::Terse, "ArSerialConnection::open: Could not get port data to set up port");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_COULD_NOT_SET_UP_PORT;
  }    

  /* turn off echo, canonical mode, extended processing, signals */
  tio.c_lflag &= ~(ECHO | ICANON | IEXTEN | ISIG);

  /* turn off break sig, cr->nl, parity off, 8 bit strip, flow control */
  tio.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);

  /* clear size, turn off parity bit */
  tio.c_cflag &= ~(CSIZE | PARENB);

  /* set size to 8 bits */
  tio.c_cflag |= CS8;

  /* turn output processing off */
  tio.c_oflag &= ~(OPOST);

  /* Set time and bytes to read at once */
  tio.c_cc[VTIME] = 0;
  tio.c_cc[VMIN] = 0;

  if (tcsetattr(myPort,TCSAFLUSH,&tio) < 0) 
  {
    ArLog::log(ArLog::Terse, 
	       "ArSerialConnection::open: Could not set up port");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_COULD_NOT_SET_UP_PORT;
  }
  
  myStatus = STATUS_OPEN;

  if (rateToBaud(myBaudRate) == -1) 
  {
    ArLog::log(ArLog::Terse, "ArSerialConnection::open: Invalid baud rate.");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_INVALID_BAUD_RATE;
  }

  if (!setBaud(myBaudRate)) 
  {
    ArLog::log(ArLog::Terse, 
	       "ArSerialConnection::open: Could not set baud rate.");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_COULD_NOT_SET_BAUD;
  }
  
  if (!setHardwareControl(myHardwareControl)) 
  {
    ArLog::log(ArLog::Terse,
	       "ArSerialConnection::open: Could not set hardware control.");
    close();
    myStatus = STATUS_OPEN_FAILED;
    return OPEN_COULD_NOT_SET_UP_PORT;
  }

  ArLog::log(ArLog::Verbose, "ArSerialConnection::open: Successfully opened and configured serial port.");
  return 0;
}
Ejemplo n.º 24
0
void NetworkManager::PppSetting::fromMap(const QVariantMap &setting)
{
    if (setting.contains(QLatin1String(NM_SETTING_PPP_NOAUTH))) {
        setNoAuth(setting.value(QLatin1String(NM_SETTING_PPP_NOAUTH)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_EAP))) {
        setRefuseEap(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_EAP)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_PAP))) {
        setRefusePap(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_PAP)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_CHAP))) {
        setRefuseChap(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_CHAP)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP))) {
        setRefuseMschap(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAP)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2))) {
        setRefuseMschapv2(setting.value(QLatin1String(NM_SETTING_PPP_REFUSE_MSCHAPV2)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_NOBSDCOMP))) {
        setNoBsdComp(setting.value(QLatin1String(NM_SETTING_PPP_NOBSDCOMP)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_NODEFLATE))) {
        setNoDeflate(setting.value(QLatin1String(NM_SETTING_PPP_NODEFLATE)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_NO_VJ_COMP))) {
        setNoVjComp(setting.value(QLatin1String(NM_SETTING_PPP_NO_VJ_COMP)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE))) {
        setRequireMppe(setting.value(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128))) {
        setRequireMppe128(setting.value(QLatin1String(NM_SETTING_PPP_REQUIRE_MPPE_128)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL))) {
        setMppeStateful(setting.value(QLatin1String(NM_SETTING_PPP_MPPE_STATEFUL)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_CRTSCTS))) {
        setCRtsCts(setting.value(QLatin1String(NM_SETTING_PPP_CRTSCTS)).toBool());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_BAUD))) {
        setBaud(setting.value(QLatin1String(NM_SETTING_PPP_BAUD)).toUInt());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_MRU))) {
        setMru(setting.value(QLatin1String(NM_SETTING_PPP_MRU)).toUInt());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_MTU))) {
        setMtu(setting.value(QLatin1String(NM_SETTING_PPP_MTU)).toUInt());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE))) {
        setLcpEchoFailure(setting.value(QLatin1String(NM_SETTING_PPP_LCP_ECHO_FAILURE)).toUInt());
    }

    if (setting.contains(QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL))) {
        setLcpEchoInterval(setting.value(QLatin1String(NM_SETTING_PPP_LCP_ECHO_INTERVAL)).toUInt());
    }
}