mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
Serial: Add basic tests for throughput and latency
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
while (true) {
|
||||
Serial.write('.');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import processing.serial.*;
|
||||
Serial serial;
|
||||
int start;
|
||||
byte[] in = new byte[32768];
|
||||
long num_ok = 0;
|
||||
long num_fail = 0;
|
||||
long num_recv = 0;
|
||||
|
||||
void setup() {
|
||||
println(serial.list());
|
||||
// change this accordingly
|
||||
serial = new Serial(this, serial.list()[0], 115200);
|
||||
start = millis();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(255);
|
||||
if (0 < serial.available()) {
|
||||
int recv = serial.readBytes(in);
|
||||
for (int i=0; i < recv; i++) {
|
||||
if (in[i] == '.') {
|
||||
num_ok++;
|
||||
} else {
|
||||
num_fail++;
|
||||
println("Received "+num_fail+" unexpected bytes");
|
||||
}
|
||||
num_recv++;
|
||||
}
|
||||
}
|
||||
fill(0);
|
||||
text(num_recv/((millis()-start)/1000.0), 0, height/2);
|
||||
}
|
||||
Reference in New Issue
Block a user