Comments (1)
Some weeks later: i made a stable Python 3.7 script using PySerial library for polling out data. The following example code grabs ctrlmode and cuts out the mode number of the read line.
This script can be used to do things like sending values into an InfluxDB or whatever. It's stable enough to survive removed USB device, powered off Smart Stepper and other errors. I also configured it to set USB port to exclusive so no other connection can mess with the established one.
import serial
import time
import termios # workaround for IOError on resetting input/output buffers
import re
# note that when defining serial.Serial will automatically open the port!
ser=None
def createSerial():
global ser
time.sleep(1) # always wait one second before re-opening. This prevents hiccups
try:
#print("trying to open serial connection")
ser=serial.Serial(
port="/dev/ttyUSB-SMART-A-AXIS",
baudrate=115200,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=1,
xonxoff=False,
rtscts=False,
write_timeout=1,
dsrdtr=False,
inter_byte_timeout=None,
exclusive=True) # force to get behaviour "Cannot open line '/dev/ttyUSB-SMART-A-AXIS' for R/W: open() blocked, aborted." or "Error: read failed: device reports readiness to read but returned no data (device disconnected or multiple access on port?)"
except IOError as e: # the serial creation may fail if device not connected or not ready
print("Error:", e)
pass
while True:
if ser == None:
#print("serial is set to None. Creating new serial connection")
createSerial()
else:
try:
ser.reset_input_buffer()
ser.reset_output_buffer()
ser.write("ctrlmode".encode() + b'\r')
#time.sleep(0.05)
while ser.inWaiting() > 0:
line=ser.readline().decode()
#print(line)
p=re.compile(r'^controller\s.*\(\d\)$', re.M)
m=p.search(line)
if m:
print("ctrlmode =",m.group(0)[-2]) #extract the number from "controller <modeString> (<number>)"
except (IOError, termios.error) as e: # in case the USB device was removed or buffer reset fails try to close and re-open serial port
print("Error:", e)
ser.close()
ser = None #unset
createSerial()
pass
from nano_stepper.
Related Issues (20)
- Open Source License HOT 3
- Required Wiring Doc Update HOT 1
- Makerbase upload sources. HOT 1
- Smart Stepper N2P 100 35V capacitor getting really hot HOT 2
- Additions to docs HOT 1
- How to change vendor/product I or add iSerial HOT 2
- ERROR 'Serial5' was not declared in this scope HOT 2
- MKS SERVO 42 ERROR PIN? HOT 2
- Current Homing HOT 1
- INFO: MKS provided now source for fw and hw HOT 4
- INFO: bigtreetech hw/fw design of 42B and 42A shared on github HOT 2
- 2209 question HOT 2
- What magnets to use? HOT 2
- Convert to TMC2208? HOT 3
- Inquiry: Step interpolation mode HOT 1
- Retrofit for Nema 14 HOT 1
- Cannot Install misfitTech SAMD Boards in Arduino. HOT 1
- www.misifittech.net dead link
- setpos to negative number error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nano_stepper.