当前位置: 首页>>代码示例>>C++>>正文


C++ SoftwareSerial::end方法代码示例

本文整理汇总了C++中SoftwareSerial::end方法的典型用法代码示例。如果您正苦于以下问题:C++ SoftwareSerial::end方法的具体用法?C++ SoftwareSerial::end怎么用?C++ SoftwareSerial::end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SoftwareSerial的用法示例。


在下文中一共展示了SoftwareSerial::end方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setBaud

//-------------------------------------------------------------------------------------------
void LCD::setBaud(byte baud)
{
  //changes the baud rate.
  serial.write(0x7C);
  serial.write(0x07); //CTRL g
  serial.write(baud); //send a value of 49 - 54
  delay(100);

/*
“1” = 4800bps - 0x31 = 49
“2” = 9600bps - 0x32 = 50
“3” = 19,200bps - 0x33 = 51
“4” = 38,400bps - 0x34 = 52
“5” = 57,600bps - 0x35 = 53
“6” = 115,200bps - 0x36 = 54
*/

  //these statements change the SoftwareSerial baud rate to match the baud rate of the LCD. 
  if(baud == 49)
  {
	serial.end();
	serial.begin(4800);
  }
  if(baud == 50)
  {
	serial.end();
	serial.begin(9600);
  }
  if(baud == 51)
  {
	serial.end();
	serial.begin(19200);
  }
  if(baud == 52)
  {
	serial.end();
	serial.begin(38400);
  }
  if(baud == 53)
  {
	serial.end();
	serial.begin(57600);
  }
  if(baud == 54)
  {
	serial.end();
	serial.begin(115200);
  }
}
开发者ID:PerGronroos,项目名称:GraphicLCD_Serial_Backpack,代码行数:50,代码来源:SparkFunSerialGraphicLCD.cpp

示例2: end

// Herkulex end
void HerkulexClass::end()
{
	switch (port)
	{
	case SSerial:
		SwSerial.end();
		break;
    #if defined (__AVR_ATmega1280__) || defined (__AVR_ATmega128__) || defined (__AVR_ATmega2560__)
	case HSerial1:
		Serial1.end();
		break;
	case HSerial2:
		Serial2.end();
		break;
	case HSerial3:
		Serial3.end();
		break;
	#endif
	}
}
开发者ID:NickAlbers,项目名称:RoboCup,代码行数:21,代码来源:Herkulex.cpp

示例3: restoreDefaultBaud

//-------------------------------------------------------------------------------------------
void LCD::restoreDefaultBaud()
{
//This function is used to restore the default baud rate in case you change it 
//and forget to which rate it was changed. 


serial.end();//end the transmission at whatever the current baud rate is

//cycle through every other possible buad rate and attemp to change the rate back to 115200
serial.begin(4800);
serial.write(0x7C);
serial.write(0x07);
serial.write(54);//set back to 115200
serial.end();

serial.begin(9600);
serial.write(0x7C);
serial.write(0x07);
serial.write(54);//set back to 115200
serial.end();

serial.begin(19200);
serial.write(0x7C);
serial.write(0x07);
serial.write(54);//set back to 115200
serial.end();

serial.begin(38400);
serial.write(0x7C);
serial.write(0x07);
serial.write(54);//set back to 115200
serial.end();

serial.begin(57600);
serial.write(0x7C);
serial.write(0x07);
serial.write(54);//set back to 115200
serial.end();

serial.begin(115200);
delay(10);
serial.write(0x7C);
serial.write((byte)0); //clearScreen
serial.print("Baud restored to 115200!");
delay(5000);

}
开发者ID:PerGronroos,项目名称:GraphicLCD_Serial_Backpack,代码行数:48,代码来源:SparkFunSerialGraphicLCD.cpp

示例4: if

uint8_t 	EV3_Setup(uint8_t port, uint8_t type)  // Sets up the sensor to data mode
{
	if(port == PORT_1){  // PORT_1
    DDRC |= 0x04;   // Set the Rx pin as output
    DDRC &= 0xFE;

    uint8_t mode;   // Calculate the mode as a number 
    if(type < TYPE_SENSOR_EV3_COLOR_M0)
      mode = type - TYPE_SENSOR_EV3_US_M0;
    else if(type < TYPE_SENSOR_EV3_GYRO_M0)
      mode = type - TYPE_SENSOR_EV3_COLOR_M0;
    else if(type < TYPE_SENSOR_EV3_INFRARED_M0)
      mode = type - TYPE_SENSOR_EV3_GYRO_M0;
    else if(type < TYPE_SENSOR_EV3_INFRARED_M5+1)
      mode = type - TYPE_SENSOR_EV3_INFRARED_M0;
    else mode = 0;


    data16[0] = dat16[type-43];
    sets[0] = setsd[type-43];

    sensor1.begin(2400);  // Start SoftwareSerial at base Baud rate
    sensor1.write(BYTE_ACK);  // Write ACK 
    setupDone=false;    
    while(!setupDone){
      if(sensor1.available()){   // Check if data is available 
        if(sensor1.read() == BYTE_ACK){   // if an ACK Byte was read
          delay(1);
          sensor1.write(BYTE_ACK);      // Write 2 ACKs (because, sometimes SoftwareSerial might not write the data properly)
          delay(1);
          sensor1.write(BYTE_ACK);
          sensor1.end();
          sensor1.flush();
          sensor1.begin(57600);     // Try to read at higher baud rate
          delay(10);
          if((sensor1.read() & CMD_MASK) == CMD_DATA){  // If the sensor had entered Data Mode
            sensor1.write(BYTE_NACK);     // Write NACK at higher baud rate
              setupDone=true;   // quit setup
          }
          else {        // if corrupt data or no data was received, go back to base baud rate
            sensor1.end();      
            sensor1.begin(2400);
          }
        }
      }
    }

    sensor1.write(BYTE_NACK);   // Keep the sensor in Data mode
    if(mode != 0){              // If a mode other than 0 is required, write the mode datas
      sensor1.write(CMD_SELECT);
      sensor1.write(mode);
      sensor1.write(check(0x00,CMD_SELECT,mode));
    }
    sensor1.write(BYTE_NACK);
  }
  else{                    // PORT_2
    DDRC |= 0x08; 
    DDRC &= 0xFD;

    uint8_t mode;
    if(type < TYPE_SENSOR_EV3_COLOR_M0)
      mode = type - TYPE_SENSOR_EV3_US_M0;
    else if(type < TYPE_SENSOR_EV3_GYRO_M0)
      mode = type - TYPE_SENSOR_EV3_COLOR_M0;
    else if(type < TYPE_SENSOR_EV3_INFRARED_M0)
      mode = type - TYPE_SENSOR_EV3_GYRO_M0;
    else if(type < TYPE_SENSOR_EV3_INFRARED_M5+1)
      mode = type - TYPE_SENSOR_EV3_INFRARED_M0;
    else mode = 0;

    data16[1] = dat16[type-43];
    sets[1] = setsd[type-43];

    sensor2.begin(2400);
    sensor2.write(BYTE_ACK);
    setupDone=false;
    while(!setupDone){
      if(sensor2.available()){
        if(sensor2.read() == BYTE_ACK){
          delay(1);
          sensor2.write(BYTE_ACK);
          delay(1);
          sensor2.write(BYTE_ACK);
          sensor2.end();
          sensor2.flush();
          sensor2.begin(57600);
          delay(10);
          if((sensor2.read() & CMD_MASK) == CMD_DATA){
            sensor2.write(BYTE_NACK);
              setupDone=true;
          }
          else {
            sensor2.end();
            sensor2.begin(2400);
          }
        }
      }
    }

    sensor2.write(BYTE_NACK);
//.........这里部分代码省略.........
开发者ID:gloomyandy,项目名称:BrickPi,代码行数:101,代码来源:BrickPiEV3.cpp

示例5: EV3_Reset

void EV3_Reset(){   // Called to reset the SoftwareSerial and use the pin for some other function
  sensor1.flush();
  sensor1.end();
  sensor2.flush();
  sensor2.end();
}
开发者ID:gloomyandy,项目名称:BrickPi,代码行数:6,代码来源:BrickPiEV3.cpp

示例6: read

int Teleinfos::read(SoftwareSerial &cptSerial, Print &debug) {
	#ifdef DEBUG
		debug << F(">>getTeleinfo") << endl;
	#endif
	uint32_t startMillis = millis();
	if ((lastRefresh !=0) && (startMillis - lastRefresh < VALID_FOR)) {
		return 1;
	}
	cptSerial.begin(1200);
	/* vider les infos de la dernière trame lue */
	memset(Ligne,'\0',sizeof(Ligne)); 
	int trameComplete=0;
	
	reset();
	while (!trameComplete) {
		while(CaractereRecu != 0x02) {
			if (millis()-startMillis > EDF_TIMEOUT) {
				cptSerial.end();
				return ERROR;
			}
		// boucle jusqu'a "Start Text 002" début de la trame
			if (cptSerial.available()) {
				CaractereRecu = cptSerial.read() & 0x7F;
			}
		}

		while (CaractereRecu != 0x03) {
			i=0; 
			while(CaractereRecu != 0x03 && CaractereRecu != 0x0D /* fin de ligne */) { 
				if (millis()-startMillis > EDF_TIMEOUT) {
					cptSerial.end();
					return ERROR;
				}
				// Tant qu'on est pas arrivé à "EndText 003" Fin de trame ou que la trame est incomplète
				int available = cptSerial.available();
				#ifdef DEBUG
				if (available > SERIAL_BUFFER_OVERFLOW) {
					debug << "O " << available << endl;
				}
				#endif
				if (available) {
					CaractereRecu = cptSerial.read() & 0x7F;
					Ligne[i++]=CaractereRecu;
				}	
			}
			if (i > 0) { 
				Ligne[i++] = '\0';
				#ifdef DEBUGLIGNE
				debug << Ligne << endl;
				#endif
				decodeLigne(Ligne, debug);
				memset(Ligne,'\0',sizeof(Ligne)); // on vide la ligne pour la lecture suivante
				if (CaractereRecu ==  0x0D) {
					CaractereRecu = '\0';
				}
			}
		}

		// on vérifie si on a une trame complète ou non
		trameComplete = isTrameComplete(debug);
		#ifdef DEBUG
		debug << F("complete ? ") << trameComplete << endl;
		#endif
	}
	#ifdef DEBUG
		debug <<  F("<<getTeleinfo") << endl;
	#endif
	cptSerial.end();
	lastRefresh = millis(); 
	return millis() - startMillis;
}
开发者ID:thibaut-fagart,项目名称:domotique,代码行数:71,代码来源:edf.cpp


注:本文中的SoftwareSerial::end方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。