File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
libraries/RPC/examples/PortentaX8_EchoServer Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ #include " SerialRPC.h"
2+
3+ /*
4+ * This sketch demonstrates how to interact with the Portenta X8 Serial port (over USB)
5+ * On the board, launch both 'proxy' and 'example' binaries (from https://github.com/bcmi-labs/portentax8-m4-proxy)
6+ * The M4 provides the 'subtract' API (which will be invoked by 'example'
7+ * It also provides a full duplex Serial-like interface that is proxies through the serial monitor
8+ * Last but not leas, when you write 'echo' the corresponding function in 'example' will be triggered
9+ */
10+
11+ int subtract (int a, int b) {
12+ return a-b;
13+ }
14+
15+ void setup () {
16+ // put your setup code here, to run once:
17+ Serial.begin (115200 );
18+ RPC.bind (" subtract" , subtract);
19+ delay (1000 );
20+ }
21+
22+ int i = 0 ;
23+ void loop () {
24+
25+ // RPC.print("hello");
26+ // RPC.send("echo", "test");
27+ // auto res = RPC.call("add", 5, 8).as<int>();
28+ // RPC.send("echo", String(res).c_str());
29+
30+ String str = " " ;
31+ while (Serial.available ()) {
32+ str += (char )Serial.read ();
33+ }
34+ if (str != " " ) {
35+ Serial.print (str);
36+ }
37+ if (str.startsWith (" echo" )) {
38+ delay (100 );
39+ RPC.send (" echo" , " test" );
40+ }
41+ }
You can’t perform that action at this time.
0 commit comments