本文整理汇总了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);
}
}
示例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;
}
示例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
}
示例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");
}
示例5: sport_init
/*!
* function definitions
*/
void sport_init(void)
{
sportSerial.begin(SPORT_BAUD);
}
示例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;
}
示例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) {
//.........这里部分代码省略.........
示例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;
}
}
示例9: ncArduinoPutData
void ncArduinoPutData(
ncPackageDataPtr_t ncPackageDataPtr,
ncPackageLength_t ncPackageLength)
{
mySerial.write(ncPackageDataPtr, ncPackageLength);
}
示例10: ResetAlarms
void ICACHE_FLASH_ATTR GlobalsClass::ResetAlarms()
{
ResetTimeCheck = 0;
qCon.println("/set?al=0,0,0,0,0,0,0,0"); delay(comdelay);
}
示例11: fWrite
//RS485 Schreibroutine
void fWrite (const byte what)
{
rs485.write (what);
}
示例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;
}
}
}
示例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");
}
}
示例14: Configure
void S4GPS::begin(int BaudRate)
{
gpsSerial.begin(BaudRate);
Configure();
}
示例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;
}