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


C++ SoftwareSerial类代码示例

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


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

示例1: delay

//-------------------------------------------------------------------------------------------
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:fjms,项目名称:GraphicLCD_Serial_Backpack,代码行数:50,代码来源:SerialGraphicLCD.cpp

示例2: 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

示例3: toggleSplash

//-------------------------------------------------------------------------------------------
void LCD::toggleSplash()
{
  //turns the splash screen on and off, the 1 second delay at startup stays either way.
  serial.write(0x7C);
  serial.write(0x13); //CTRL s
}
开发者ID:fjms,项目名称:GraphicLCD_Serial_Backpack,代码行数:7,代码来源:SerialGraphicLCD.cpp

示例4: report

void report(int *ranges){
	for(int i = 0; i < maxSteps; i++){
		Serial.print(String(ranges[i]) + ',' + String(i) + '\n'); // Convert ping time to distance in cm and print result (0 = outside set distance range)
	}
	mySerial.print("SCANEND");
}
开发者ID:petosegan,项目名称:home_robot,代码行数:6,代码来源:polar_range_pro.cpp

示例5: sport_init

/*!
 * function definitions
 */
void sport_init(void)
{
  sportSerial.begin(SPORT_BAUD);
}
开发者ID:wiresharks,项目名称:minimOSD_SPORT,代码行数:7,代码来源:SPort.cpp

示例6: updategga

// Function to update Number of Satellites used, HDOP, Altitude etc.
// from the incoming $GPGGA string
boolean dGPS::updategga(){  
  comandoGPG[0] = '$';          // initialization
  comandoGPG[1] = 'G';
  comandoGPG[2] = 'P';
  comandoGPG[3] = 'G';
  comandoGPG[4] = 'G';
  comandoGPG[5] = 'A';
  while(true){
  int byteGPS=-1;
  byteGPS=gpsSerial.read();      //read a byte from the serial port
  if (byteGPS == -1) {           // See if the port is empty yet
    delay(5); } 
  else {
    linea[conta]=byteGPS;        // If there is serial port data, it is put in the buffer
    conta++;                      
    if (byteGPS==13){            // If the received byte is = to 13, end of transmission 
      cont=0;
      bien=0;
      for (int i=1;i<7;i++){     // Verifies if the received command starts with $GPGGA
        if (linea[i]==comandoGPG[i-1]){
          bien++;
        }
      }
      if(bien==6){               // If yes, continue and process the data        
        Serial.print("");        // For some reason, this needs to be here or you won't populate variables.  If anyone solves this problem, let us know.
        Serial.print("");
        Serial.print("-");
        /*Serial.println(linea);   //Print out the GPGGA string (just for reference)*/
          
          //------------------------------------------          
          // Get Number of satellites in use
          char *data = "";
          memset(data, 0, sizeof(data));
          data = dGPS::subStr(linea, ",", 8);
          fSat = atoi(data);
          delay(5);
        
          //------------------------------------------
          // Get HDOP
          memset(data, 0, sizeof(data));
          data = dGPS::subStr(linea, ",", 9);
          hDop = atof(data);
          delay(5);
          
          //------------------------------------------
          // Get Altitude above sea-level (meters)
          memset(data, 0, sizeof(data));
          data = dGPS::subStr(linea, ",", 10);
          fAlt = atof(data);          
          delay(5);
          
          conta=0;                    // Reset the buffer
          memset(linea, 0, sizeof(linea));
	  break;
          
      }
      conta=0;                    // Reset the buffer
      memset(linea, 0, sizeof(linea));  
    }
  }
 } // END WHILE STATEMENT
 return true;  
}
开发者ID:SamBeastie,项目名称:DI_Arduino,代码行数:65,代码来源:dGPS.cpp

示例7: readData

// * Receiving the lenght of bytes from Serial port
void HerkulexClass::readData(int size)
{
	int i = 0;
    int beginsave=0;
    int Time_Counter=0;
    switch (port)
	{
	case SSerial:

        while((SwSerial.available() < size) & (Time_Counter < TIME_OUT)){
        		Time_Counter++;
        		delayMicroseconds(1000);  //wait 1 millisecond for 10 times
		}
        	
		while (SwSerial.available() > 0){
			byte inchar = (byte)SwSerial.read();
			if ( (inchar == 0xFF) & ((byte)SwSerial.peek() == 0xFF) ){
					beginsave=1; 
					i=0; 				 // if found new header, begin again
			}
			if (beginsave==1 && i<size) {
				   dataEx[i] = inchar;
				   i++;
			}
		}
		SwSerial.flush();
		break;
	
	#if defined (__AVR_ATmega1280__) || defined (__AVR_ATmega128__) || defined (__AVR_ATmega2560__)
	case HSerial1:
		while((Serial1.available() < size) & (Time_Counter < TIME_OUT)){
				Time_Counter++;
				delayMicroseconds(1000);
		}
		while (Serial1.available() > 0){
			byte inchar = (byte)Serial1.read();
			//printHexByte(inchar);
			if ( (inchar == 0xFF) & ((byte)Serial1.peek() == 0xFF) ){
				beginsave=1;
				i=0;
			}
            if (beginsave==1 && i<size) {
                       dataEx[i] = inchar;
                       i++;
			}
		}
		break;
	
	case HSerial2:
	    while((Serial2.available() < size) & (Time_Counter < TIME_OUT)){
        		Time_Counter++;
        		delayMicroseconds(1000);
		}
        	
		while (Serial2.available() > 0){
			byte inchar = (byte)Serial2.read();
			if ( (inchar == 0xFF) & ((byte)Serial2.peek() == 0xFF) ){
					beginsave=1;
					i=0; 					
			}
			if (beginsave==1 && i<size) {
				   dataEx[i] = inchar;
				   i++;
			}
		}
		break;

	case HSerial3:
		while((Serial3.available() < size) & (Time_Counter < TIME_OUT)){
			Time_Counter++;
			delayMicroseconds(1000);
		}
		
		while (Serial3.available() > 0){
			byte inchar = (byte)Serial3.read();
			if ( (inchar == 0xFF) & ((byte)Serial3.peek() == 0xFF) ){
					beginsave=1;
					i=0; 
			}
			if (beginsave==1 && i<size) {
				   dataEx[i] = inchar;
				   i++;
			}
		}
		break;
	#elif (__AVR_ATmega32U4__)
	case HSerial1:
		while((Serial1.available() < size) & (Time_Counter < TIME_OUT)){
			Time_Counter++;
			delayMicroseconds(1000);
		}
		while (Serial1.available() > 0){
			byte inchar = (byte)Serial1.read();
			//printHexByte(inchar);
			if ( (inchar == 0xFF) & ((byte)Serial1.peek() == 0xFF) ){
				beginsave=1;
				i=0;
			}
            if (beginsave==1 && i<size) {
//.........这里部分代码省略.........
开发者ID:MechanicalCoder,项目名称:Prosthetic-Hands,代码行数:101,代码来源:Herkulex.cpp

示例8: Pro_W2D_ErrorCmdHandle

void Pro_W2D_ErrorCmdHandle(Error_PacketsTypeDef Error_Type, uint8_t flag)
{
	Pro_ErrorCmdTypeDef           	 Pro_ErrorCmdStruct;       //4.7 ??????

    memcpy(&Pro_ErrorCmdStruct, UART_HandleStruct.Message_Buf, sizeof(Pro_ErrorCmdStruct));
    if(flag == 1)
    {
        goto Print_O;
    }
	
    Pro_ErrorCmdStruct.Pro_HeadPart.Head[0] = 0xFF; 
    Pro_ErrorCmdStruct.Pro_HeadPart.Head[1] = 0xFF; 
    Pro_ErrorCmdStruct.Pro_HeadPart.Len = exchangeBytes(sizeof(Pro_ErrorCmdStruct) - 4); 
    Pro_ErrorCmdStruct.Pro_HeadPart.Cmd = Pro_D2W_ErrorPackage_Ack_Cmd; 
    Pro_ErrorCmdStruct.Error_Packets = Error_Type;
    Pro_ErrorCmdStruct.Sum = CheckSum((uint8_t *)&Pro_ErrorCmdStruct, sizeof(Pro_ErrorCmdStruct)); 
    Pro_UART_SendBuf((uint8_t *)&Pro_ErrorCmdStruct, sizeof(Pro_ErrorCmdStruct), 0); 

	#if(DEBUG==1)
    mySerial.print(F("Error :")); mySerial.println(Error_Type, HEX); 
		mySerial.print("[");mySerial.print(SystemTimeCount,DEC);mySerial.print("]");mySerial.print(" MCU   :");
		for(uint8_t i = 0; i < (sizeof(Pro_ErrorCmdStruct)); i++)
		{
		  mySerial.print(" "); mySerial.print(*((uint8_t *)&Pro_ErrorCmdStruct + i),HEX);
		}
		mySerial.println("");
	#endif
    
    return;

Print_O:
	/*************************错误类型*****************************/
	
	switch (Pro_ErrorCmdStruct.Error_Packets)
	{
		case Error_AckSum:

			#if(DEBUG==1)
				mySerial.println(F("ACK : Error_AckSum OK"));
			#endif
			
			break;
		case Error_Cmd:

			#if(DEBUG==1)
            mySerial.println(F("ACK : Error_Cmd OK")); 
			#endif
			
			break;
		case Error_Other:

			#if(DEBUG==1)
            mySerial.println(F("ACK : Error_Other OK")); 
			#endif
			break;
		default:
			#if(DEBUG==1)
            mySerial.println(F("ACK : Error! ")); 
			#endif
			break;
	}	
}	
开发者ID:curiousguy98,项目名称:KidsBox,代码行数:62,代码来源:GizWits.cpp

示例9: ncArduinoPutData

void ncArduinoPutData(
	ncPackageDataPtr_t ncPackageDataPtr, 
	ncPackageLength_t ncPackageLength) 
{
   mySerial.write(ncPackageDataPtr, ncPackageLength);
}
开发者ID:NicolajHolm,项目名称:ncArduinoTimeSyncMaster,代码行数:6,代码来源:ncArduino.cpp

示例10: ResetAlarms

void ICACHE_FLASH_ATTR GlobalsClass::ResetAlarms()
{
	ResetTimeCheck = 0;
	qCon.println("/set?al=0,0,0,0,0,0,0,0"); delay(comdelay);
	
}
开发者ID:nailbuster,项目名称:EspressModuleHM,代码行数:6,代码来源:globals.cpp

示例11: fWrite

//RS485 Schreibroutine
void fWrite (const byte what)
{
	rs485.write (what);
}
开发者ID:wolfi-by,项目名称:Beleuchtung,代码行数:5,代码来源:WelcomeSaeule_Nano.cpp

示例12: while

  bool S4GPS::getGPS(char* gps)
  {
       
     char c;
     uint8_t sum;
     while (gpsSerial.available())  // this might break it.
     {
       c = gpsSerial.read();
          
       if (bufferidx == 0) 
       {
                     
          while (c != '$')
          {
             c = gpsSerial.read(); 
          }
       }
       buffer[bufferidx] = c;
       if (c == '\n') 
       {
         buffer[bufferidx-1] = '\0'; // delete end line
         buffer[bufferidx+1] = 0; // terminate it
         
         if (buffer[bufferidx-4] != '*') 
         {
           bufferidx = 0;
          // return;
         }
          
          sum = parseHex(buffer[bufferidx-3]) * 16;
          sum += parseHex(buffer[bufferidx-2]);

          for (i=1; i < (bufferidx-4); i++) 
          {
            sum ^= buffer[i];
          }
          if (sum != 0) 
          {
            bufferidx = 0;
          //  return;
          }
          
          
          bufferidx++;
      
      
          //Serial.print(buffer);
         for(int i = 0; i < 90; i++)
         {
           gps[i] = buffer[i];
           }
      
         
          bufferidx = 0;
          
          return true;
        }
        bufferidx++;
        if (bufferidx == BUFFSIZE-1) 
        {
          bufferidx = 0;
        }
      }

}
开发者ID:notkevinjohn,项目名称:S4Payload,代码行数:65,代码来源:S4GPS.cpp

示例13: loop

void loop() {
  mySerial.print("Mode: ");
  char mode = mySerial.read();

// ------------------ SET MODE ------------------
  if(mode == 'S'){
    //Set Command - Digital Support Only
    mySerial.print("Set Digital: ");
    int digital = ( int(mySerial.read()) - 48 );
    mySerial.print(digital);
    
    if(digital == 1){
      //Digital Pins
      mySerial.print(" PinNum: ");
      char pinTens = mySerial.read();
      char pinOnes = mySerial.read();
      int pinNum = (int(pinOnes) - 48) + ( (int(pinTens) - 48) * 10 );
      mySerial.print(pinNum);
      mySerial.print(" Value: ");
    
      int pinVal = int(mySerial.read() - 48);
      mySerial.print(pinVal);
    
      setDigital(pinNum, pinVal);
      mySerial.println(" - OK");
    }else if(digital == 0){
      //Analog Pins
      mySerial.println(" Analog pins unsupported.");
    }else{
      //Invalid Input
      mySerial.println("Invalid Input");
    }

// ------------------ READ MODE ------------------
  }else if(mode == 'R'){
    //Read Command - Digital Support Only
    mySerial.print("Read Digital: ");
    int digital = ( int(mySerial.read()) - 48 );
    mySerial.print(digital);
    
    if(digital == 1){
      //Digital Pins
      mySerial.print(" PinNum: ");
      char pinTens = mySerial.read();
      char pinOnes = mySerial.read();
      int pinNum = (int(pinOnes) -48) + ( (int(pinTens) - 48) * 10 );
      mySerial.print(pinNum);
    
      int pinVal = digitalRead(pinNum);
      mySerial.print(" Value: ");
      mySerial.print(pinVal);
      mySerial.println(" - OK");
    }else if(digital == 0){
      //Analog Pins
      mySerial.print(" PinNum: ");
      char pinOnes = mySerial.read();
      int pinNum = (int(pinOnes) -48);
      mySerial.print(pinNum);
    
      int pinVal = analogRead(pinNum);
      mySerial.print(" Value: ");
      mySerial.print(pinVal);
      mySerial.println(" - OK");
    }else{
      //Invalid Input
      mySerial.println(" Invalid Input");
    }
  }else if(mode == 'V'){
    mySerial.print(" Information Kernel: ");
    mySerial.print(KERNEL_VERSION); 
  }else{
    mySerial.println("Invalid Input");
  }
}
开发者ID:JnthnShar,项目名称:hal-project,代码行数:74,代码来源:kernel.cpp

示例14: Configure

 void S4GPS::begin(int BaudRate)               
 {       
     gpsSerial.begin(BaudRate);
     Configure();
 }
开发者ID:notkevinjohn,项目名称:S4Payload,代码行数:5,代码来源:S4GPS.cpp

示例15: loop

void loop()
{
   // initialize http service
   if(count%10 == 0){
     count= 0 ;
     gprsSerial.flush();
      Serial.flush();
      gprsSerial.println("AT+CIPSHUT");
      delay(100);
      toSerial();
      gprsSerial.println("AT+CGATT?");
      delay(100);
      toSerial();
    
      // attach or detach from GPRS service 
      gprsSerial.println("AT+CGATT=1");
      delay(100);
      toSerial();
    
    
      // bearer settings
      gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
      delay(2000);
      toSerial();
    
      // bearer settings
      gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"airtelgprs.com\"");
      delay(2000);
      toSerial();
    
      // bearer settings
      gprsSerial.println("AT+SAPBR=1,1");
      delay(2000);
      toSerial();
   }
   count++;
   Receive_GPS_Data();
   gprsSerial.println("AT+HTTPINIT");
   delay(2000); 
   toSerial();

   // set http param value
   gprsSerial.println("AT+HTTPPARA=\"URL\",\"http://shuttletracker.hostei.com/?lat="+save_lati+"&long="+save_lg+"&speed="+save_spd+"\"");
   delay(2000);
   toSerial();

   // set http action type 0 = GET, 1 = POST, 2 = HEAD
   gprsSerial.println("AT+HTTPACTION=0");
   delay(6000);
   toSerial();

   // read server response
   gprsSerial.println("AT+HTTPREAD"); 
   delay(1000);
   toSerial();

   gprsSerial.println("");
   gprsSerial.println("AT+HTTPTERM");
   toSerial();
   delay(300);

   gprsSerial.println("");
   delay(30000);
   finish=0;pos_cnt = 0;
}
开发者ID:spojsolutions,项目名称:spoj,代码行数:65,代码来源:arduino_shuttle.cpp


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