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


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

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


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

示例1: setName

/* This function sets the name of an RN-42 module
   name should be an up to 20-character value. It MUST BE TERMINATED by a 
   \r character */
uint8_t makeyMateClass::setName(char * name)
{
  if (bluetooth.available())
    bluetooth.flush();	// Get rid of any characters in the buffer, we'll need to check it fresh

  bluetooth.print("SN,");
  for (int i=0; i<20; i++)
  {
    if (name[i] != '\r')
      bluetooth.write(name[i]);
    else
      break;
  }
  bluetooth.write('\r');
  
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetoothReceive(rxBuffer);

  /* Double check the setting, output results in Serial monitor */
  bluetooth.flush();
  bluetooth.print("GN");
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  Serial.print("Name set to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());

  return bluetoothCheckReceive(rxBuffer, "AOK", 3);
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:32,代码来源:makeyMate.cpp

示例2: loop

void loop()
{
  if (Serial.available())
    if (mySerial.available())
      mySerial.println(Serial.read());
      Serial.write(mySerial.read());
}
开发者ID:badgerzz,项目名称:arduino,代码行数:7,代码来源:sim900.c

示例3: sendPacket

/* sendPacket() is called by just about every other member function. It calculates 
	some CRC bytes, then sends the message string.
	If a response is requested, it'll return that in the response array. Otherwise
	that and the responseLength variable should be 0.
	
	If you're using a bluetooth module that's not the RN-42, this'd be the place
	to modify.
*/
void SFE_MetaWatch::sendPacket(unsigned char * data, int length, unsigned char * response, int responseLength)
{
	int crc = ComputeCRC(data, length - 2);	// Get the crc values for our string
	data[length-1] = (crc & 0xFF00) >> 8;	// LSB goes first
	data[length-2] = crc & 0xFF;	// the MSB

	// If you want a response, let's flush out the bt buffer first.
	if (responseLength > 0)
		bt.flush();
	
	// Send the data out to the BlueSMiRF
	for (int i=0; i<length; i++)
	{
		bt.write(data[i]);
	}
	
	// If a response was requested, read that into the response array.
	if (responseLength > 0)
	{
		delay(BLUETOOTH_RESPONSE_DELAY);
		int i=0;
		while (bt.available() && (i < responseLength))
		{
			response[i++] = bt.read();
		}
	}
}
开发者ID:JLJames,项目名称:SparkFun_MetaWatch_Library,代码行数:35,代码来源:SparkFun_MetaWatch.cpp

示例4: loop

void loop()
{
    sendMsg = "";
    recvMsg = "";
    while (Serial.available()) {
        sendMsg += (char)Serial.read();
        delay(2);
    }

    if(sendMsg.length() > 0)
    {
        mySerial1.println(sendMsg);
        Serial.print("I send: ");
        Serial.println(sendMsg);
    }
    while (mySerial2.available()) {
        recvMsg += (char)mySerial2.read();
        delay(2);
    }
    if(recvMsg.length() > 0)
    {
        Serial.print("I recv: ");
        Serial.println(recvMsg);
    }
    //delay(20);
}
开发者ID:DreamtaleCore,项目名称:AndroidProfiles,代码行数:26,代码来源:arduinozigbee.cpp

示例5: loop

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}
开发者ID:epsilonrt,项目名称:avrio,代码行数:7,代码来源:SerialSoftwareExample.cpp

示例6: sendData

String sendData(String command, const int timeout, boolean debug)
{
    String response = "";
    
    esp8266.print(command); // send the read character to the esp8266
    
    long int time = millis();
    
    while( (time+timeout) > millis())
    {
      while(esp8266.available())
      {
        
        // The esp has data so display its output to the serial window 
        char c = esp8266.read(); // read the next character.
        response+=c;
      }  
    }
    
    if(debug)
    {
      Serial.print(response);
    }
    
    return response;
}
开发者ID:nicchan92,项目名称:ESP8266-webserver,代码行数:26,代码来源:esp8266+webserver.c

示例7: readRFID

boolean readRFID() {
	//if (RFID.available()) RFID.flush();
	digitalWrite(RFID_ENABLE, LOW);    // Activate the RFID reader
	
	for (byte i = 0; i < RFID_LENGTH; i++)
		rfidCode[i] = 0;

	if (RFID.available()) {
		int val = RFID.read();
		Serial.print(val);

		if (val == RFID_START_CHAR) {
			RFID.readBytes(rfidCode, RFID_LENGTH);

			Serial.print("RFID Read: ");
			Serial.println(rfidCode);

			digitalWrite(RFID_ENABLE, HIGH);   // deactivate the RFID reader for a moment so it will not flood
			RFID.flush();                      // clear the buffer
			delay(1500);                       // wait for a bit

			return true;
		 }
	}
	return false;
}
开发者ID:mikelduke,项目名称:DMS-RFID-Interlock,代码行数:26,代码来源:PowerInterlock.cpp

示例8: toSerial

void toSerial()
{
  while(gprsSerial.available()!=0)
  {
    Serial.write(gprsSerial.read());
  }
}
开发者ID:spojsolutions,项目名称:spoj,代码行数:7,代码来源:arduino_shuttle.cpp

示例9: loop

void loop() // run over and over
{
  int i = 0;
  bool found = false;

  raw_packet com;

  while(usb.available()){
    found = true;
    if(i < 8){
      com.raw[i] = usb.read();
    } else{
      break;
    }
    i++;
  }

  if(!found){
    return;
  }

  packet curpacket = com.nice;

  if(curpacket.cmd = 1){
    usb.print("hi");
    usb.print("\n");
  }

}
开发者ID:maxywb,项目名称:botserverthing,代码行数:29,代码来源:sketch.cpp

示例10: loop

void loop()
{
if (GPRS.available()) // if date is comming from software serial port
	{
	while(GPRS.available()) // reading data into char array
		{
		buffer[count++]=GPRS.read(); // writing data into array
		if(count == 64)	break;
		}

	Serial.write(buffer,count); // if no data transmission ends, write buffer to hardware serial port
	clearBufferArray(); // call clear BufferArray function to clear the storage data from the array
	count = 0; // set counter of while loop to zero
	}

 if (Serial.available()) // if data is available on hardware serial port ==> data is comming from PC or notebook
 GPRS.write(Serial.read()); // write it to the GPRS shield
 }
开发者ID:bl4ckic3,项目名称:GSM-Shield-Virtual-Port-for-Arduino,代码行数:18,代码来源:GSM-Relay.c

示例11: ncArduinoPollGetData

void ncArduinoPollGetData()
{
  int c;
  while (mySerial.available() > 0)
  {
    c = mySerial.read();
    byteStreamToPackageStream((unsigned char) c);
  }
}
开发者ID:NicolajHolm,项目名称:ncArduinoTimeSyncMaster,代码行数:9,代码来源:ncArduino.cpp

示例12: handle

void GlobalsClass::handle()
{
	if (qCon.available() > 0) checkSerialMsg();

	//alarm time checking
	if (ResetTimeCheck > 0) {
		if (millis() - ResetTimeCheck > (ResetAlarmSeconds * 1000)) { ResetAlarms(); }   //check to see if we've past resetalarm;
	}
}
开发者ID:nailbuster,项目名称:EspressModuleHM,代码行数:9,代码来源:globals.cpp

示例13: setupBlueToothConnection

void setupBlueToothConnection()
{
  blueToothSerial.begin(38400); 
  blueToothSerial.print("\r\n+STWMOD=1\r\n");
  blueToothSerial.print("\r\n+STNA=SeeedBTMaster\r\n");
  blueToothSerial.print("\r\n+STAUTO=0\r\n");
  delay(2000); 
  blueToothSerial.flush();
  blueToothSerial.print("\r\n+INQ=1\r\n");
  Serial.println("inquiring");
  delay(2000); 
  
  char recvChar;
 /* while(1){                                       //this part is for auto detecting and connecting to a slave but something is wrong with the parsing of the address, use this to print out the address and then put it in manulely 								below
    if(blueToothSerial.available()){
     recvChar = blueToothSerial.read();
      recvBuf += recvChar;
      nameIndex = recvBuf.indexOf(slaveName);
  
      if ( nameIndex != -1 ){
        
 	addrIndex = (recvBuf.indexOf(retSymb,(nameIndex - retSymb.length()- 18) ) + retSymb.length());	 		
 	slaveAddr = recvBuf.substring(addrIndex, nameIndex);			
 	break;
      }
   }
 }*/
  
  connectCmd += slaveAddr;
  connectCmd += "\r\n";
  int connectOK = 0;
  Serial.print("Connecting to slave:");
  Serial.print(slaveAddr);
  Serial.println(slaveName);

  do{
    blueToothSerial.print("/*put slave address here*/");
    recvBuf = "";
    while(1){
      if(blueToothSerial.available()){
        recvChar = blueToothSerial.read();
 	recvBuf += recvChar;
 	if(recvBuf.indexOf("CONNECT:OK") != -1){
          connectOK = 1;
 	  Serial.println("Connected!");
 	  blueToothSerial.print("Connected!");
 	  break;
 	}else if(recvBuf.indexOf("CONNECT:FAIL") != -1){
 	  Serial.println("Connect again!");
 	  break;
 	}
      }
    }
  }while(0 == connectOK);
}
开发者ID:Phendrana,项目名称:Capstone-Stuff,代码行数:55,代码来源:bluetooth.c

示例14: connect

/* This function will attempt a connection to the stored remote address
   The first time you connect the the RN-42 HID, the master device will
   need to initiate the connection. The first time a connection is made
   the bluetooth address of the master device will be stored on the RN-42.
   If no remote address is stored, a connection will not be made. */
uint8_t makeyMateClass::connect()
{
  freshStart();  // Get the module disconnected, and out of command mode
  
  while (!enterCommandMode())
  {  // Enter command mode
    delay(BLUETOOTH_RESPONSE_DELAY);
  }
  delay(BLUETOOTH_RESPONSE_DELAY);
  bluetooth.flush();
  
  /* get the remote address and print it in the serial monitor */
  bluetooth.print("GR");  // Get the remote address
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  if (bluetooth.peek() == 'N')  // Might say "No remote address stored */
  {  // (bluetooth address is hex values only, so won'te start with 'N'.
    Serial.println("Can't connect. No paired device!");
    bluetooth.flush();
    bluetooth.print("---");  // exit command mode
    bluetooth.write('\r');
    return 0;  // No connect is attempted
  }
  else if (bluetooth.available() == 0)  
  { // If we can't communicate with the module at all, print error
    Serial.println("ERROR!");
    return 0;  // return error
  }
  /* otherwise print the address we're trying to connect to */
  Serial.print("Attempting to connect to: ");
  while (bluetooth.available())
    Serial.write(bluetooth.read());
    
  /* Attempt to connect */
  bluetooth.print("C");  // The connect command
  bluetooth.write('\r');
  delay(BLUETOOTH_RESPONSE_DELAY);
  while (bluetooth.available())
    Serial.write(bluetooth.read());  // Should print "TRYING"
  
  return 1;
}
开发者ID:TildeWill,项目名称:MaKey-Mate-Bluetooth,代码行数:47,代码来源:makeyMate.cpp

示例15: read

 String read()
 {
   String msg = "";
   while (bluetoothModule->available() > 0)
   {
     char c = (char)bluetoothModule->read();
     if(c != '\n')
       msg += c;
   }
   return msg;
 }
开发者ID:cabraile,项目名称:Modular-Mobile-Robot,代码行数:11,代码来源:Bluetooth.cpp


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