本文整理汇总了C++中HardwareSerial类的典型用法代码示例。如果您正苦于以下问题:C++ HardwareSerial类的具体用法?C++ HardwareSerial怎么用?C++ HardwareSerial使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HardwareSerial类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: FifoTest
//! Test function to validate that the fifo works as expected.
//! It is always a good idea to validate your data structures. Languages like
//! Python or Perl have such validation built in, while C++ does not. This function
//! can be used in a special build to run through some test cases and make sure
//! that the fifo behaves as we exect, especially in the edge cases, such as when
//! it gets full, wraps around, etc.
void FifoTest(HardwareSerial& ds)
{
Fifo f1(20);
Fifo::FifoType x;
char buffer[128];
for (x=1;x<25;x++) {
f1.push(&x);
sprintf(buffer,"Fifo push %d count %d\n",x,f1.count());
ds.print(buffer);
}
f1.clear();
sprintf(buffer,"Fifo count %d\n",f1.count());
ds.print(buffer);
for (x=0;x<10;x++) {
f1.push(&x);
}
sprintf(buffer,"Fifo count %d. Expected 10\n",f1.count());
ds.print(buffer);
Fifo::FifoType y;
for (x=1;x<15;x++) {
f1.pop(&y);
sprintf(buffer,"Fifo pop %d count %d\n",y,f1.count());
ds.print(buffer);
}
}
示例2: writeObject
template<class T> int writeObject(HardwareSerial ser, T& value, char name) {
unsigned char* p = (unsigned char*) (void*) &value;
unsigned int i;
char checksum = '0';
ser.write('@');
ser.write(name);
for (i = 0; i < sizeof(value); i++) {
ser.write(*p++);
checksum = checksum ^ *p;
}
ser.write(checksum);
ser.write('\n');
return i;
}
示例3: execute
void GetDataSpace::execute (HardwareSerial& stream, McuState&) const {
unsigned char* ptr = (unsigned char*)address;
unsigned char value = *ptr;
char response[MAX_NUMBER_LENGTH];
Utils::toDecimal (response, sizeof (response), value);
stream.println (response);
}
示例4: serialRead
//call like : serialRead (Serial1, buffer, 12, 5)
uint8_t serialRead (HardwareSerial theSerial,
uint8_t *buf, uint8_t leng, uint8_t timeout) {
int sub;
if (theSerial.available ()) {
for (sub=0; sub<leng; sub++) {
uint32_t start_time = millis ();
while (!theSerial.available ()) {
if (millis () - start_time > timeout)
return sub;
}
buf[sub] = theSerial.read ();
}
return sub;
}
return 0;
}
示例5: create_gps_file
File create_gps_file() {
int year;
unsigned long age;
byte month, day, hour, minute, second, hundredth;
gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredth, &age);
String filename;
filename.concat(GPS_DIR);
filename.concat('/');
filename.concat(year);
filename.concat('/');
filename.concat(month);
filename.concat('/');
filename.concat(day);
filename.concat('/');
filename.concat(hour);
filename.concat(minute);
filename.concat(second);
filename.concat(".GPS");
char buf[filename.length() + 1];
filename.toCharArray(buf, sizeof(buf));
Serial.print("Criando arquivo... ");
Serial.println(buf);
return create_file(buf);
}
示例6: cmdRead
/***
* Read [pin1] [pin2] ...
*
* Read pin values
* Pins are given in the following way: A0 A1 ... for analog pins
* D0 D1 ... for digital pins
* Answer is: val1 val2 ...
*/
void cmdRead(int argC, char **argV) {
char pinType[2];
int pin;
int value;
for (int i = 1; i <= argC; i++) {
pinType[0] = argV[i][0];
pinType[1] = NULL;
pin = strtol(&(argV[i][1]), NULL, 10);
if (strcasecmp(pinType, "D") == 0) {
value = digitalRead(pin);
} else if (strcasecmp(pinType, "A") == 0) {
value = analogRead(pin);
} else {
return;
}
// Add read values to answer string
Serial.print(value);
if (i < argC) {
Serial.print(' ');
}
}
}
示例7: setup
void setup()
{
// Set up serial port for debugging
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
// Fullfil the data array
createDataArray();
// Read and set the key from the EEPROM
readKey(KEYLENGTH);
// Inicialization of the key
time = micros(); // time start
aes192_init(key, &key_init);
emit = micros(); // time start
Serial.print(F("Inicialisation total takes: "));
Serial.print(emit - time);
Serial.println(F(" [us]"));
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(ledPin, OUTPUT);
}
示例8: setup
void setup() {
Serial.begin(115200);
nss.begin(9600);
pinMode(10, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(RED_LED, OUTPUT);
Serial.println("Iniciando...");
if (!SD.begin())
Serial.println("SD Erro!");
}
示例9: serial_get
// get next byte from serial stream
byte Comm::serial_get(bool block)
{
if (block) {
while (true) {
if (Serial.available() > 0) {
break;
}
}
}
return Serial.read();
}
示例10: cmdSerSend
/***
* SerSend [hard | soft] [port]
*
* After this command, each character sent is mirrored to the chosen serial
* port until the NULL character (0x00) is sent (also mirrored)
*/
void cmdSerSend(char **argV) {
boolean isSoftSerial = (strcasecmp(argV[1], "soft") == 0);
int currPort = strtol(argV[2], NULL, 10);
Serial.println(doneString);
if (currPort < 1 || currPort > ((isSoftSerial)? SOFT_SER_MAX_PORTS : HARD_SER_MAX_PORTS)) {
return;
}
if (isSoftSerial) {
#ifdef USE_SOFTWARE_SERIAL
softSerDescs[currPort-1].txMsgLen = 0;
#endif
}
// mirror the hardware serial and the software serial
while (true) {
if (Serial.available()) {
char c = Serial.read();
if (isSoftSerial) {
#ifdef USE_SOFTWARE_SERIAL
softSerDescs[currPort-1].txMsg[softSerDescs[currPort-1].txMsgLen++] = c;
#endif
} else {
#if HARD_SER_MAX_PORTS > 0
hardSerHandler[currPort-1]->write(c);
#else
return;
#endif
}
if (c == '\0') {
// acknowledge
Serial.println(doneString);
delay(10);
#ifdef USE_SOFTWARE_SERIAL
if (isSoftSerial) {
// send the message, and remember the answer
for (int i = 0; i < softSerDescs[currPort-1].txMsgLen; i++) {
softSerDescs[currPort-1].handler->write(softSerDescs[currPort-1].txMsg[i]);
}
softSerDescs[currPort-1].rxMsgLen = 0;
while (!Serial.available()) {
if (softSerDescs[currPort-1].handler->available() && softSerDescs[currPort-1].rxMsgLen < SOFT_SER_MSG_SIZE) {
softSerDescs[currPort-1].rxMsg[softSerDescs[currPort-1].rxMsgLen++] = softSerDescs[currPort-1].handler->read();
}
}
}
#endif
return;
}
}
}
}
示例11: loop2
void loop2()
{
vw_wait_rx();
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int port=parse();
switchState(port);
Serial.print(port);
Serial.println();
}
}
示例12: ajuste_pinos
void Node::ajuste_pinos(){
if (sizeof(this->comandos) > 0 ){
if(this->_debug) Serial.println("Ajustando pinagem: ");
for (int i = 0; i < sizeof(this->comandos)-1; i++){
pinMode(this->comandos[i].pino, OUTPUT);
if(this->_debug) Serial.print(this->comandos[i].pino+" ");
};
if(this->_debug) Serial.println("Fim de Ajuste.");
}
}
示例13: calcDeltaT
int calcDeltaT(){
lastLoopUsefulTime = millis()-loopStartTime;
if(lastLoopUsefulTime<STD_LOOP_TIME) {
delay(STD_LOOP_TIME-lastLoopUsefulTime);
if (debugSerial && debugLoopTime){
Serial.print(" Esperei: ");
Serial.println(STD_LOOP_TIME-lastLoopUsefulTime);
}
}
lastLoopTime = millis() - loopStartTime;
loopStartTime = millis();
return lastLoopTime;
}
示例14: setup
void setup() {
Serial.begin(9600);
Serial.println("setup");
relays[0] = createRelay(PORT_0);
relays[1] = createRelay(PORT_1);
relays[2] = createRelay(PORT_2);
relays[3] = createRelay(PORT_3);
vw_set_rx_pin(PORT_RF);
vw_setup(4000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
示例15: serialEventRun
void serialEventRun(void) {
#ifdef serialEvent_implemented
if (Serial.available())
serialEvent();
#endif
#ifdef serialEvent1_implemented
if (Serial1.available()) serialEvent1();
#endif
#ifdef serialEvent2_implemented
if (Serial2.available()) serialEvent2();
#endif
#ifdef serialEvent3_implemented
if (Serial3.available()) serialEvent3();
#endif
}