Sending GCode commands to duet3D Mini 5+ using python
-
@marco13 said in Sending GCode commands to duet3D Mini 5+ using python:
also what does this line mean?
b'Messages queued 244, send timeouts 242, received 0, lost 0, longest wait 0ms for reply type 0, free buffers 15\n'Those are statistics about CAN messages sent and received. You are running on old version of RRF, so they are less meaningful than in later versions.
-
@dc42 From what I experienced, raising the RTS signal once the serial connection is open made the things to work.
Opening a serial connection using
picocom -c --imap lfcrlf /dev/ttyACM0
and issuingM122
doesn't get any output and I can't even close picocom (because it can't reset the tty, I believe).Opening a serial connection using
picocom -c --raiserts --imap lfcrlf /dev/ttyACM0
and issuingM122
works. -
@Falcounet I was able to get the motor to rotate with your code:
import serial
with serial.Serial('/dev/ttyACM0') as ser:
ser.setRTS(True)
ser.write(b'\n')
ser.write(bG0 Y30 F50000\n')
eof = False
while not eof:
line = ser.readline()
if line == b'ok\n':
eof = True
print(line)thank you very much!!!!!!!!
-
@Falcounet my guess is that it's a function of the Linux driver you are using that it requires RTS to be raised. Using YAT under Windows, I can set RTS and DTR to any states, and communication works.
RTS has no real meaning when the connection is USB from end to end, without a serial element, because flow control is handled by the USB protocol.
-
@Falcounet Is it possible to communicate back from the Duet to the Raspberry Pi such as if a condition is met stop the python code?
I would really appreciate your help again -
@marco13 What you mean ? Was an exception raised and thus stopped your script running ?
-
@Falcounet I am performing some image classification in a loop on the RPi and based on that the duet will perform some actions. But sometimes the mechanism controlled by the duet gets jammed and the python code keeps running. So for each time the Rpi sends a command I would like the duet to be able to send back a signal/command in order for RPi to perform the next image classification.
-
@sarco13 Hard to help you more without code or details.
What commands are you sending ?
If you want to sync a macro and python code, you can maybe use a global variable that you increment on one side and check the value on another side. Something like that. -
@Falcounet I am calling macros to rotate motors and control sensors.
the code is something like this:def send_command_duet(command):
with serial.Serial('/dev/ttyACM0') as ser:
ser.setRTS(True)
ser.write(b'\n')
ser.write(command)
eof = False
while not eof:
line = ser.readline()
if line == b'ok\n':
eof = True
print(line)while True:
Capture image
classify image
send_command_duet(command) #perform action
receive signal from duet to go to next iteration