From fc4551bfbf4d40846eb0d14f347ae5b827dd5950 Mon Sep 17 00:00:00 2001 From: Neil Gershenfeld <gersh@cba.mit.edu> Date: Wed, 31 Mar 2021 21:39:57 -0400 Subject: [PATCH] start comm --- comm/SerialUSB/ring.SerialUSB.ino | 25 ++++++++++++++++++++ comm/pySerial/ring.pySerial.py | 38 +++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 comm/SerialUSB/ring.SerialUSB.ino create mode 100755 comm/pySerial/ring.pySerial.py diff --git a/comm/SerialUSB/ring.SerialUSB.ino b/comm/SerialUSB/ring.SerialUSB.ino new file mode 100644 index 0000000..bbd5f9e --- /dev/null +++ b/comm/SerialUSB/ring.SerialUSB.ino @@ -0,0 +1,25 @@ +// +// ring.SerialUSB.ino +// +// SerialUSB communication ring test +// +// Neil Gershenfeld 3/31/21 +// +// This work may be reproduced, modified, distributed, +// performed, and displayed for any purpose, but must +// acknowledge this project. Copyright is retained and +// must be preserved. The work is provided as is; no +// warranty is provided, and users accept all liability. +// + +void setup() { + SerialUSB.begin(0); + } + +void loop() { + while (true) { + if (SerialUSB.available()) { + SerialUSB.write(1+SerialUSB.read()); + } + } + } diff --git a/comm/pySerial/ring.pySerial.py b/comm/pySerial/ring.pySerial.py new file mode 100755 index 0000000..560aafd --- /dev/null +++ b/comm/pySerial/ring.pySerial.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python +# +# ring.pySerial.py +# +# pySerial communication ring test +# +# Neil Gershenfeld 3/31/21 +# +# This work may be reproduced, modified, distributed, +# performed, and displayed for any purpose, but must +# acknowledge this project. Copyright is retained and +# must be preserved. The work is provided as is; no +# warranty is provided, and users accept all liability. +# + +import serial,sys,time + +nloop = 10 + +if (len(sys.argv) != 3): + print("command line: ring.pyserial.py serial_port port_speed") + sys.exit() +port = sys.argv[1] +speed = int(sys.argv[2]) + +ser = serial.Serial(port,speed) +ser.flushInput() +x = 0 +start = time.time() +for i in range(nloop): + while True: + ser.write(x.to_bytes(1,byteorder='big')) + x = int.from_bytes(ser.read(1),byteorder='big') + if (x == 0): + break +end = time.time() +print(f"byte ring cycles per second: {nloop*256/(end-start):6.3g}") + -- GitLab