Duet3 - Python - Preliminary class for interfacing
-
I've created a preliminary module/class to allow Python programs on the Pi attached to a Duet3 to interact with the printer. It does so via the "Duet Control Server" socket (not websocket) connection in the "Duet Software Framework".
It is available on Github https://github.com/DanalEstes/PythonDSF
This is an early implementation and it may radically change in the near future. Nonetheless, if you are thinking about Python scripting, give it a try.
There is also an example script. This script is intended to do tool-to-tool measurement to derive offsets on a "Tool Changing" 3D printer of the E3D tool-changer type. Specifically, it is for my Jubilee. There are some instructions in the README about how all this works. This is a whole topic in and of itself.
A very minimal example of use might look something like this:
#!/usr/bin/env python3 import pythondcs dcs = pythondcs.PythonDCS() dcs.gCode('G0 Z10 F1000') # Lower bed to avoid collision with square hole plate. dcs.gCode('G0 Y225 F10000') # Move nozzle to avoid other tools r=getPos() print("X position ="+r[0])
There are several other modules, including a "r=getPos()" that returns a Python list containing the current position of the printer, in mm. See the example script.
-
Nice! Is it only working for Duet3, or also for Duet2 running RRF3?
-
@fma said in Duet3 - Python - Preliminary class for interfacing:
Is it only working for Duet3
for now only Duet 3 support Raspberry Pi and this class interfaces to a unix socket on the Pi; so this only works for Duet 3 + raspberry pi (i.e. not Duet 3 in stand alone mode)
-
Ok, I though you where connected on a Duet socket...
-
@fma said in Duet3 - Python - Preliminary class for interfacing:
Ok, I though you where connected on a Duet socket...
Correct, a socket, NOT a websocket.
The stack for a Duet 3 with a Pi is roughly:
Browser on PC or Mobile
<Wifi or Ethernet TCP/IP network - Websocket protocol>
Duet Software Framework Web Server on Pi
<Linux internal - Socket protocol>*
Duet Software Framework Control Server on Pi
<Ribbon Cable - SPI Protocol>
Firmware on Duet 3 6HC boardThe * indicates where this python connects; Therefore it must run on the Pi where that socket resides.
If enough people are interested, I can look into a Websocket version. This could theoretically run on any machine that has TCP/IP network connectivity to the Pi or a stand-alone D3.
-
Just stumbled on this. Many thanks for putting this together @Danal !
I decided to give it a whirl on my Pi and landed on an IncompatibleVersionException, which closed the connection immediately. Does something need to be updated? I'm running...
Firmware Version console output
echo "m115" | sudo /opt/dsf/bin/CodeConsoleFIRMWARE_NAME: RepRapFirmware for Duet 3 MB6HC FIRMWARE_VERSION: 3.1.1 ELECTRONICS: Duet 3 MB6HC v0.6 or 1.0 FIRMWARE_DATE: 2020-05-19b2
Apt Package Version
Package: duetsoftwareframework
Version: 3.1.1and the specific error is:
{"errorType":"IncompatibleVersionException","errorMessage":"Incompatible protocol version (got 0, need 7 or higher)","success":false}
Thanks for taking a look!
-
Ah, figured this out. It looks like the request to enter "command" mode must also include the protocol version.
j=json.dumps({"mode":"command", "version": 8}).encode()
The server picks up the missing field as 0 and closes the connection immediately.
It looks like this isn't stated yet in the Duet Software Framework docs, but I got a pro tip from @wilriker on this thread.
Thanks for the breadcrumbs everyone!