本文整理汇总了C++中HardwareSerial::write方法的典型用法代码示例。如果您正苦于以下问题:C++ HardwareSerial::write方法的具体用法?C++ HardwareSerial::write怎么用?C++ HardwareSerial::write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HardwareSerial
的用法示例。
在下文中一共展示了HardwareSerial::write方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseRequest
void parseRequest(const char* line)
{
readingRequest = false;
int code = parseNumber(line);
switch(code)
{
case POSITION: //return position
Serial.write('X');
Serial.write( ((double)axis[0].position) / PULSES_PER_MM);
Serial.write('Y');
Serial.write( ((double)axis[1].position) / PULSES_PER_MM);
Serial.write('Z');
Serial.println( ((double)axis[2].position) / PULSES_PER_MM);
break;
case DESTINATION: //return destination
Serial.write('X');
Serial.write( ((double)axis[0].expected) / PULSES_PER_MM);
Serial.write('Y');
Serial.write( ((double)axis[1].expected) / PULSES_PER_MM);
Serial.write('Z');
Serial.println( ((double)axis[2].expected) / PULSES_PER_MM);
break;
case PAUSE:
serialSleepDelegate();
break;
case CONTINUE:
serialWakeDelegate();
break;
}
}
示例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: millis
int
main(int argc,char **argv) {
pinMode(led_pin, OUTPUT);
digitalWrite(led_pin, led_off);
digitalWrite(reset_pin, HIGH);
pinMode(reset_pin, OUTPUT);
Serial.begin(baud); // USB, communication to PC or Mac
Uart.begin(baud); // UART, communication to Dorkboard
for (;;) {
unsigned char c, dtr;
static unsigned char prev_dtr = 0;
if (Serial.available()) {
c = Serial.read();
Uart.write(c);
digitalWrite(led_pin, led_on);
led_on_time = millis();
continue;
}
if (Uart.available()) {
c = Uart.read();
Serial.write(c);
digitalWrite(led_pin, led_on);
led_on_time = millis();
continue;
}
dtr = Serial.dtr();
if (dtr && !prev_dtr) {
digitalWrite(reset_pin, LOW);
delayMicroseconds(250);
digitalWrite(reset_pin, HIGH);
}
prev_dtr = dtr;
if (millis() - led_on_time > 3) {
digitalWrite(led_pin, led_off);
}
if (Serial.baud() != baud) {
baud = Serial.baud();
if (baud == 57600) {
// This ugly hack is necessary for talking
// to the arduino bootloader, which actually
// communicates at 58824 baud (+2.1% error).
// Teensyduino will configure the UART for
// the closest baud rate, which is 57143
// baud (-0.8% error). Serial communication
// can tolerate about 2.5% error, so the
// combined error is too large. Simply
// setting the baud rate to the same as
// arduino's actual baud rate works.
Uart.begin(58824);
} else {
Uart.begin(baud);
}
}
}
}
示例4: cmdSerReceive
/***
* SerReceive [hard | soft] [port]
*
* Empty the RX buffer of a serial port to the control serial port
*/
void cmdSerReceive(char **argV) {
boolean isSoftSerial = (strcasecmp(argV[1], "soft") == 0);
int currPort = strtol(argV[2], NULL, 10);
if (currPort < 1 || currPort > (isSoftSerial)? SOFT_SER_MAX_PORTS : HARD_SER_MAX_PORTS) {
return;
}
if (isSoftSerial) {
#ifdef USE_SOFTWARE_SERIAL
for (int i = 0; i < softSerDescs[currPort-1].rxMsgLen && i < SOFT_SER_MSG_SIZE; i++) {
Serial.write(softSerDescs[currPort-1].rxMsg[i]);
}
#endif
} else {
#if HARD_SER_MAX_PORTS > 0
while (hardSerHandler[currPort-1]->available()) {
Serial.write(hardSerHandler[currPort-1]->read());
}
#endif
}
}