![]() |
RUI3 (RAK Unified Interface 3) - RAK4631
|
Functions | |
void | begin (uint32_t baud, RAK_SERIAL_MODE mode=RAK_DEFAULT_MODE) |
void | end (void) |
void | lock (bool locked) |
bool | password (char *new_passwd, size_t len) |
virtual size_t | write (const uint8_t *buf, size_t size) |
virtual int | available (void) |
virtual int | read (void) |
virtual int | peek (void) |
virtual void | flush (void) |
virtual uint32_t | getBaudrate (void) |
size_t | print (long, int=DEC) |
size_t | println (int, int=DEC) |
size_t | printf (const char *val,...) |
void | setTimeout (unsigned long timeout) |
unsigned long | getTimeout (void) |
size_t | readBytes (char *buffer, size_t length) |
size_t | readBytesUntil (char terminator, char *buffer, size_t length) |
String | readString () |
String | readStringUntil (char terminator) |
void begin | ( | uint32_t | baud, |
RAK_SERIAL_MODE | mode = RAK_DEFAULT_MODE |
||
) |
baud | The baudrate to set for the Serial |
mode(optinal) | The mode that use UART in different way (if not assigned, RAK_DEFAULT_MODE is chosen) List: RAK_AT_MODE RAK_API_MODE RAK_CUSTOM_MODE RAK_DEFAULT_MODE |
void setup() { Serial.begin(115200); Serial1.begin(9600, RAK_CUSTOM_MODE); } void loop() { }
void end | ( | void | ) |
void setup() { Serial.begin(115200); } void loop() { Serial.end(); }
void lock | ( | bool | locked | ) |
locked | giving true to lock the device,false to unlock the device |
void setup() { Serial.begin(115200); //Lock Serial(USB) with password => 12345678 string password = "12345678"; Serial.password(password); Serial.lock(true); } void loop() { }
bool password | ( | char * | new_passwd, |
size_t | len | ||
) |
str | a string to set for unlock the device |
new_passwd | an char array to set for unlock the device |
len | the length your password set |
TRUE | for success |
FALSE | for failure |
void setup() { Serial.begin(115200); //Lock Serial(USB) with password => 12345678 string password = "12345678"; Serial.password(password); Serial.lock(true); } void loop() { }
|
virtual |
val | a value to send as a single byte |
buf | an array to send as a series of bytes |
size | the number of bytes to be sent from the array |
void setup() { Serial.begin(115200); } void loop() { Serial.write(45); Serial.write("Hello"); }
Reimplemented from Print.
|
virtual |
the | number of bytes available for reading from the specified serial port(Type: int) |
void setup() { Serial.begin(115200, RAK_CUSTOM_MODE); } void loop() { //print if you receive data if (Serial.available() > 0) { Serial.print("Return Byte = "); Serial.println(Serial.read()); } }
Implements Stream.
|
virtual |
-1 | Read fail,get nothing from the specified serial port |
void setup() { Serial.begin(115200, RAK_CUSTOM_MODE); } void loop() { //print if you receive data if (Serial.available() > 0) { Serial.print("Return Byte = "); Serial.println(Serial.read()); } }
Implements Stream.
|
virtual |
void setup() { Serial.begin(115200, RAK_CUSTOM_MODE); } void loop() { //print if you receive data if (Serial.available() > 0) { //Peek the data first Serial.print("Peek the Byte = "); Serial.println(Serial.peek()); //Read the data you peeked Serial.print("Return Byte = "); Serial.println(Serial.read()); } }
Implements Stream.
|
virtual |
void setup() { Serial.begin(115200); } void loop() { Serial.write(45); Serial.write("Hello"); Serial.flush(); }
Implements Stream.
|
virtual |
void setup() { uint32_t baudrate = Serial.getBaudrate(); Serial.begin(baudrate); } void loop() { }
size_t print | ( | long | , |
int | = DEC |
||
) |
val | the value to print,Allow any data type |
void setup() { Serial.begin(9600); // open the serial port at 9600 bps: } void loop() { // print labels Serial.print("NO FORMAT"); // prints a label Serial.print("\t"); // prints a tab Serial.print("DEC"); Serial.print("\t"); Serial.print("HEX"); Serial.print("\t"); Serial.print("OCT"); Serial.print("\t"); Serial.print("BIN"); Serial.println(); // carriage return after the last label for (int x = 0; x < 64; x++) { // only part of the ASCII chart, change to suit // print it out in many formats: Serial.print(x); // print as an ASCII-encoded decimal - same as "DEC" Serial.print("\t\t"); // prints two tabs to accomodate the label lenght Serial.print(x, DEC); // print as an ASCII-encoded decimal Serial.print("\t"); // prints a tab Serial.print(x, HEX); // print as an ASCII-encoded hexadecimal Serial.print("\t"); // prints a tab Serial.print(x, OCT); // print as an ASCII-encoded octal Serial.print("\t"); // prints a tab Serial.println(x, BIN); // print as an ASCII-encoded binary // then adds the carriage return with "println" delay(200); // delay 200 milliseconds } Serial.println(); // prints another carriage return }
size_t println | ( | int | , |
int | = DEC |
||
) |
val | the value to print,Allow any data type |
int analogValue = 0; // variable to hold the analog value void setup() { // open the serial port at 9600 bps: Serial.begin(9600); } void loop() { // read the analog input on pin 0: analogValue = analogRead(0); // print it out in many formats: Serial.println(analogValue); // print as an ASCII-encoded decimal Serial.println(analogValue, DEC); // print as an ASCII-encoded decimal Serial.println(analogValue, HEX); // print as an ASCII-encoded hexadecimal Serial.println(analogValue, OCT); // print as an ASCII-encoded octal Serial.println(analogValue, BIN); // print as an ASCII-encoded binary // delay 10 milliseconds before the next reading: delay(10); }
size_t printf | ( | const char * | val, |
... | |||
) |
val |
int exampleNum = 123; void setup() { Serial.begin(115200); } void loop() { Serial.printf("The example number = %d\r\n", exampleNum); }
void setTimeout | ( | unsigned long | timeout | ) |
timeout | the timeout value |
void setup() { Serial.begin(115200); //Set Timeout to 5000 Serial.setTimeout(5000); Serial.print("Time out = "); Serial.println(Serial.getTimeout()); } void loop() { }
unsigned long getTimeout | ( | void | ) |
void setup() { Serial.begin(115200); //Set Timeout to 5000 Serial.setTimeout(5000); Serial.print("Time out = "); Serial.println(Serial.getTimeout()); } void loop() { }
size_t readBytes | ( | char * | buffer, |
size_t | length | ||
) |
buffer | The buffer to store the bytes in |
length | The number of bytes to read |
void setup() { Serial.begin(11500, RAK_CUSTOM_MODE); } void loop() { int returnBytes = 0; char readBuf[256]; if (Serial.available > 0) { //Read 5 characters in 1 second returnBytes = Serial.readBytes(readBuf, 5); if (returnBytes == 0) Serial.print("read nothing"); else { Serial.print("read: "); for (int i=0; i<returnBytes; i++) { Serial.print(readBuf[i]); } } Serial.println(""); } }
size_t readBytesUntil | ( | char | terminator, |
char * | buffer, | ||
size_t | length | ||
) |
terminator | The character to search for |
buffer | The buffer to store the bytes in |
length | The number of bytes to read |
void setup() { Serial.begin(11500, RAK_CUSTOM_MODE); } void loop() { int returnBytes = 0; char readBuf[256]; if (Serial.available > 0) { //Read 5 characters in 1 second,or Press ENTER to end reading returnBytes = Serial.readBytesUntil('\r', readBuf, 5); if (returnBytes == 0) Serial.print("read nothing"); else { Serial.print("read: "); for (int i=0; i<returnBytes; i++) { Serial.print(readBuf[i]); } } Serial.println(""); } }
String readString | ( | ) |
void setup() { Serial.begin(115200, RAK_CUSTOM_MODE); } void loop() { String returnString = ""; if (Serial.available() > 0) { //Read 5 characters in 1 second returnString = Serial.readString(); if (returnString == "") Serial.print("read nothing"); else { Serial.print("read: "); Serial.println(returnString); } Serial.println(""); } }
String readStringUntil | ( | char | terminator | ) |
void setup() { Serial.begin(115200, RAK_CUSTOM_MODE); } void loop() { String returnString = ""; if (Serial.available > 0) { //Read 5 characters in 1 second,or Press ENTER to end reading returnString = Serial.readStringUntil('\r'); if (returnString == "") Serial.print("read nothing"); else { Serial.print("read: "); Serial.println(returnString); } Serial.println(""); } }