Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printer instance has no attribute 'try_load_module' #73

Closed
markwinger opened this issue May 9, 2020 · 77 comments
Closed

Printer instance has no attribute 'try_load_module' #73

markwinger opened this issue May 9, 2020 · 77 comments

Comments

@markwinger
Copy link

I have been trying to install dwc2 for 2 days. I was running octoprint with klipper and tried installing as described at:

https://github.com/Stephan3/dwc2-for-klipper

but that fails at wget https://github.com/chrishamm/DuetWebControl/releases/download/2.1.6/DuetWebControl-SBC.zip
with the error indicating 2.1.6 does not exist. I tried using:
wget https://github.com/chrishamm/DuetWebControl/releases/download/2.0.0-RC5/DuetWebControl.zip

which is described at:https://klipper.info/klipper-+-dwc2-1/installing-dwc2

That installed but the gui would not come up. If I open octoprint the klipper console "status" says:

Internal error during connect: Printer instance has no attribute 'try_load_module'

I even tried installing on a clean raspbian system with the installer.sh descibed at:https://github.com/manu7irl/klipper-DWC2-installer?files=1.
I only have one printer so this is more that I need but I tried it anyway.
With this I could not get dwc2, or octoprint guis to open and of course klipper then is not running.

I did install this a few months ago and it worked but I decided not to switch then so went back to octoprint. (no longer installed).

The dwc2 gui fails to open(Unable to connect), and klipper does not start with this try_load_module error.

What next????

@manu7irl
Copy link

manu7irl commented May 9, 2020 via email

@markwinger
Copy link
Author

On github 2.1.7 it showed a duetwebcontrol-SD.zip so I tried that too. No difference.

@Stephan3
Copy link
Owner

Stephan3 commented May 9, 2020

@manu7irl you pointed the Klipper commit allready. I have not the time doing much theese days.

@manu7irl
Copy link

manu7irl commented May 9, 2020 via email

@markwinger
Copy link
Author

Octoprint works with klipper if I comment out the [web_dwc2] section.

@BlackStump
Copy link

If you are desperate to try something other then Octoprint you could try
Mainsail
It is alpha but seems to be quite functional, it has a DWC2 look about it.

@pajak15
Copy link

pajak15 commented May 10, 2020

I had the same issue today while doing a fresh install. Try changing at line 49 in the web_dwc2.py "try_load_module" with "load_object". As stated before there was a commit in klipper where they renamed try_load_module() to load_object().

@pluuuk
Copy link

pluuuk commented May 10, 2020

a simple sed command to replace try_load_module with load_object works.

@Szeker
Copy link

Szeker commented May 10, 2020

@pluuuk: Are you on the latest Klipper? Simply replacing the "try_load..." to "load_object" seems not enough. "gcode.py" also has been modified in the latest version, so the original patch probably needs to be updated also.

@pluuuk
Copy link

pluuuk commented May 10, 2020

@Szeker , I opened #75 with the fixes to get dwc2 working again.

@markwinger
Copy link
Author

markwinger commented May 10, 2020 via email

@markwinger
Copy link
Author

OK, one install says to use wget https://github.com/chrishamm/DuetWebControl/releases/download/2.1.6/DuetWebControl-SBC.zip. But this does not exist, I get 2020-05-11 06:55:38 ERROR 404: Not Found.

The other: wget https://github.com/chrishamm/DuetWebControl/releases/download/2.0.0-RC5/DuetWebControl.zip is well over a year old.

There are no SBC files after 2.1.4. What do you recommend?

@manu7irl
Copy link

wget https://github.com/chrishamm/DuetWebControl/releases/download/2.1.7/DuetWebControl-SD.zip

@markwinger
Copy link
Author

OK, that was the last one I pulled. So just to clarify (I don't understand git) if I just repeat the install process these fixes will get installed?

@markwinger
Copy link
Author

Ok, I tried again and installed using the method here: https://github.com/Stephan3/dwc2-for-klipper

Same problem. I modified klippy/extras/web_dwc2.py changing try_load_object to load_object. But the klipper logs show:
File "/home/pi/klipper/klippy/extras/web_dwc2.py", line 49, in init
self.stepper_enable = self.printer.try_load_module(config, "stepper_enable")
This line is now at line 50. I assume I need to compile it but I don't know how. What should I do?

@manu7irl
Copy link

you need to clone @pluuuk folder instaed of Stephan because this work is not merged yet...
git clone https://github.com/pluuuk/dwc2-for-klipper

@markwinger
Copy link
Author

markwinger commented May 11, 2020

Ok, still no joy.

I used the instructions on the page you pointed to, substituting pluuuk for Stephan3 on the clode of dwc2-for-klipper.git. The install seems to work. Octoprint no longer complains about try_load_module, but when I open ip:4750, no gui. (Unable to connect)

@manu7irl
Copy link

manu7irl commented May 11, 2020 via email

@markwinger
Copy link
Author

I just tried to install dwc2 with it and it complains that the PrinterFarm direcoty does not exist. Do I need to unistall everything and install everything with you script to move it all to the PrinterFarm?

@pluuuk
Copy link

pluuuk commented May 11, 2020

@markwinger, did you configure the virtual_sdcard and patched gcode.py using the sed commands?

@pluuuk
Copy link

pluuuk commented May 11, 2020

@manu7irl, the dwc2-for-klipper repo is 7 months old. I'm not sure if @markwinger will be able to use your installer.

@pluuuk
Copy link

pluuuk commented May 12, 2020

These are the ammended instructions to run the fork that fixes these issues:

sudo systemctl stop klipper
cd ~
mv klipper klipper_backup 
PYTHONDIR="${HOME}/klippy-env"
virtualenv ${PYTHONDIR}
${PYTHONDIR}/bin/pip install tornado==5.1.1

git clone https://github.com/KevinOConnor/klipper.git
git clone https://github.com/pluuuk/dwc2-for-klipper.git
ln -s ~/dwc2-for-klipper/web_dwc2.py ~/klipper/klippy/extras/web_dwc2.py

mkdir -p ~/sdcard/dwc2/web
mkdir -p ~/sdcard/sys
cd ~/sdcard/dwc2/web 
wget https://github.com/chrishamm/DuetWebControl/releases/download/2.1.6/DuetWebControl-SBC.zip
unzip *.zip && for f_ in $(find . | grep '.gz');do gunzip ${f_};done
sudo systemctl start klipper

You will still need to configure the virtual_sdcard as in the readme

@markwinger
Copy link
Author

Yes:
[virtual_sdcard]
path: ~/.octoprint/uploads/

and yes
gcode=$(sed 's/self.bytes_read = 0/self.bytes_read = 0\n self.respond_callbacks = []/g' klipper/klippy/gcode.py)
gcode=$(echo "$gcode" | sed 's/# Response handling/def register_respond_callback(self, callback):\n self.respond_callbacks.append(callback)/')
gcode=$(echo "$gcode" | sed 's/os.write(self.fd, msg+"\n")/os.write(self.fd, msg+"\n")\n for callback in self.respond_callbacks:\n callback(msg+"\n")/')
echo "$gcode" > klipper/klippy/gcode.py

What about PrinterFarm directory? Do I have to uninstall klipper and resinstall it with your script? Klipper is installed and running with octoprint and I would like to keep it and add dwc2 so I can use either as I did when I tried it a few months ago. Can that be done with you installer.sh script?

@pluuuk
Copy link

pluuuk commented May 12, 2020

@markwinger , please see my last comment, I changed some things in the fork to remove the need to run the sed commands to modify gcode.py. This should allow you to install this much easier.
I'm not familiar with @manu7irl install scripts.

@markwinger
Copy link
Author

This still fails:
wget https://github.com/chrishamm/DuetWebControl/releases/download/2.1.6/DuetWebControl-SBC.zip

I changed it to 2.1.7/DuetWebControl-SD.zip.

Installed ok, but klipper fails to start again with a new error as shown in octoprints klipper console:
Internal error during connect: GCodeParser instance has no attribute 'register_respond_callback'

@pluuuk
Copy link

pluuuk commented May 12, 2020 via email

@markwinger
Copy link
Author

No change. So I deleted gcode.py, then did checkout again. Still no change.

@pluuuk
Copy link

pluuuk commented May 12, 2020

Can you run this and see if you still see the issue?

  cd dwc2-for-klipper
  git checkout -- .
  git pull

@tripstar76
Copy link

tripstar76 commented May 12, 2020 via email

@markwinger
Copy link
Author

G29 is already caps and it does not work. (long print still running so I cant change anything yet)

None of my macros can be executed or edited in the file management section. Should I be able to edit them?

@tripstar76
Copy link

@pluuuk

Is this a typo?
line 1074:

def cmd_M32(self, gcmd):
	self.sdcard.cmd_M23(gcmd)

@Szeker
Copy link

Szeker commented May 12, 2020

I beleive, it is "UPLOAD AND START" = select file and start SD print, so first load the file => M23, than start printing => M24.

So NOT a typo.

@pluuuk
Copy link

pluuuk commented May 12, 2020

@tripstar76 and @Szeker, can you provide your comments about the fixes on #75?
It's hard to keep track of the conversation.
@tripstar76, Szeker is correct. M24 starts the print, M32 is the reprapfirmware command that is natively implemented by klipper as M23+ M24.
Regarding the macros, I can take a look and see if I broke something when re implementing the gcodes for macro management. I will provide feedback to @markwinger here.

@markwinger
Copy link
Author

Changed the macro to MY_PAUSE. No Change.

@pluuuk
Copy link

pluuuk commented May 13, 2020

@markwinger , I have fixed the macro issue.
Please do a git pull of the latest commit on the fork in #75 .

@markwinger
Copy link
Author

Again, I don't know how git works so what commands do I issue to pull from #75.

@pluuuk
Copy link

pluuuk commented May 13, 2020

I'm assuming that you installed using my instructions, so simply running git pull works.

@markwinger
Copy link
Author

Progress, I can now run macros.
I still cannot edit from file management. Is that supported?

@pluuuk
Copy link

pluuuk commented May 13, 2020 via email

@markwinger
Copy link
Author

Macros are working. So I wanted to try get the pause/resume buttons to run custom pause/resume gcode. Things you should know says:
For pause and resume macros you can use:
kliper gcode macros pause_print resume_print cancel_print (not case sensitive)

So I simply changed my_pause, my_resume macro names to pause_print and resume_print, restarted firmware and stated a print. While printing I paused the print. The printer stopped and dwc2 pops up: connection interupted attempting to reconnect. The gui is continuously flashing with this error. The klipper log shows:
Exiting SD card print (position 3628)
Uncaught exception GET /rr_status?type=3 (192.168.1.118)
HTTPServerRequest(protocol='http', host='192.168.1.107:4750', method='GET', uri='/rr_status?type=3', version='HTTP/1.1', remote_ip='192.168.1.118')
Traceback (most recent call last):
File "/home/pi/klippy-env/local/lib/python2.7/site-packages/tornado/web.py", line 1592, in _execute
result = yield result
File "/home/pi/klippy-env/local/lib/python2.7/site-packages/tornado/gen.py", line 1133, in run
value = future.result()
File "/home/pi/klippy-env/local/lib/python2.7/site-packages/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "/home/pi/klippy-env/local/lib/python2.7/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/home/pi/klipper/klippy/extras/web_dwc2.py", line 272, in get
self.web_dwc2.rr_status_3()
File "/home/pi/klipper/klippy/extras/web_dwc2.py", line 898, in rr_status_3
"status": self.get_printer_status() ,
File "/home/pi/klipper/klippy/extras/web_dwc2.py", line 1359, in get_printer_status
self.pause_macro()
File "/home/pi/klipper/klippy/extras/web_dwc2.py", line 1226, in pause_macro
self.gcode_queue.append(parse_params('PAUSE_PRINT'))
NameError: global name 'parse_params' is not defined
DWC2:76510.02 - 192.168.1.118 - GET - /rr_connect?password=reprap&time=2020-5-13T8%3A28%3A31
Unhandled exception during run
Traceback (most recent call last):
File "/home/pi/klipper/klippy/klippy.py", line 178, in run
self.reactor.run()
File "/home/pi/klipper/klippy/reactor.py", line 251, in run
g_next.switch()
File "/home/pi/klipper/klippy/reactor.py", line 278, in _dispatch_loop
timeout = self._check_timers(eventtime)
File "/home/pi/klipper/klippy/reactor.py", line 136, in _check_timers
t.waketime = waketime = t.callback(eventtime)
File "/home/pi/klipper/klippy/reactor.py", line 48, in invoke
res = self.callback(eventtime)
File "/home/pi/klipper/klippy/extras/web_dwc2.py", line 1614, in update_printdata
if self.get_printer_status() in ['S', 'P', 'D']:
File "/home/pi/klipper/klippy/extras/web_dwc2.py", line 1359, in get_printer_status
self.pause_macro()
File "/home/pi/klipper/klippy/extras/web_dwc2.py", line 1226, in pause_macro
self.gcode_queue.append(parse_params('PAUSE_PRINT'))
NameError: global name 'parse_params' is not defined
~

@markwinger
Copy link
Author

I tried a different approach. I renamed pause_print, resume_print to my_pause_print and my_resume_print so they would not be executed but the pause/resume buttons.
I then created 2 dwc2 macros, pause.g and resume.g. I tried clicking the pause button and it worked. So I clicked the resume button and it resumed immediately, but did not wait for nozzle temp to reach target, but it did start heating back up to the target temp. Since I did not wait very long before resuming, the temp had not dropped much so extrusion temp was still above minimum. So I repeated the test this time waiting for the temp to get well below minimum temp.
This time when I resumed, the buttons immediately changed to grayed pause and a start again button and showed print 100% done. But the macro was running, because a the temperature target was reset, nozzle started to heat. When target was reached I got a popup saying the idle timeout had been reset to 600(Last thing in the resume macro).

At this point printer showed print 100% complete with hotend and bed at target temperatures. I waited 10 minutes to confirm idle timeout turned off heaters. That worked.

So I repeated the process using the my_pause_printer and my_resume_print macros to see if they work correctly. But got the error about white space in the json file again.

Rebooted, ran some macros ok, so tried again. While printing, all macros report the white space error.

So the problem now appears to be macros work, but not while printing.

I attached my printer.cfg file.
config.txt

@markwinger
Copy link
Author

I tried my filament runout renabling octoprint and it fails to start correctly that way as well. How do I disable dwc2 to insure it is not interfering with octoprint?

@pluuuk
Copy link

pluuuk commented May 13, 2020 via email

@pluuuk
Copy link

pluuuk commented May 13, 2020

PAUSE_PRINT
@markwinger , I have pushed a fix to the issue in this comment, it was a typo in the pause gcode execution. It should work as nominal now.
Rename your macros to how you had them setup originally, don't list them as uppercase.

@pluuuk
Copy link

pluuuk commented May 13, 2020

@markwinger , can you please run

cd ~/dwc2-for-klipper/
git pull

And retest?

@markwinger
Copy link
Author

I have not tried your change yet. But I have a new piece of info. I did a pause, which saves the temp. I did a resume which resets the temp with an M109. The print resumed immediately but the temp target did not change. I waited a minute or two and did a pause again. At this point the M109 must have been issued because the target changed back to the original temp. When the target temp was reached, the resume took place. This is really interesting. Here is the resume macro.
[gcode_macro RESUME_PRINT]
gcode:
reset_temp
SET_IDLE_TIMEOUT timeout=600
resume

Notice the reset_temp is the first thing done. Which should wait for target temperature before continuing. But I see the SET_IDLE_TIMEOUT when the resume was done as if it skipped the reset_temp. But then the reset_temp appears to run later when I run the pause. Seems like we have an sequencing issues here.

I cant do the pull right now but hopefully I can in an hour or 2.

@markwinger
Copy link
Author

markwinger commented May 14, 2020

I did your pull. Although I don't know how your code works, it appears that the macros are forked or run in a different thread so the job will continue to run even though the macro is waiting. This clear when I do a resume, the print starts immediately, not waiting for the macro to complete. I arrive at this conclusion because when I do resume and pause again before the m109 of the previous macro is complete, the next macro does not start until the m109 is done. i.e it keeps printing until the target temp is reached, then it pauses. I also see the message saying the idle_timeout has changed reinforcing this conclusion.

A different issue, if I pause the job 3 time is goes to done. There must be some pause_resume limit imposed somewhere.

Also, I see popups occasionally saying something like "response too long. See console" But the console doesn't show it.

@pluuuk
Copy link

pluuuk commented May 14, 2020

@markwinger , do the macros work when you run octoprint? I'm not familiar with the macro syntax, but why do you specify "reset_temp" and "resume" are those variables you have defined?

@markwinger
Copy link
Author

Yes, the macros work in octoprint.
As the macros are current setup, I have a macro call PAUSE_PRINT, which is called by the filament runout code. It is named this way so when I press the "Pause" in dwc2, it will be called. The macro contains a call to another macro called my_temps. That macro gets the current hotend target temp and stores in it in a macro variable called nozzle_temp, sets the hotend temp to 0, then sets the idle_timeout very long(so the hotbed does not get turned of an loose adhesion). After return from my_temps, the PAUSE_PRINT does retraction, and moves the print head to 0,0. Klipper then pauses.

Then I have RESUME_PRINT which is called by a menu selection. Also because of the name it is called by dwc2 when the "Resume" button is clicked. This macro calls macro reset_temps, which simply sends an M109 with the nozzle target temp saved by my_temps. The M109 is supposed to pause until target temp is reached. When reset_temps returns to RESUME_PRINT, the idle_timeout is set back to 600 and resume is called telling klipper to resume.

The M109 not causing the print to wait, but another macro to pause is where my problem seems to be originating.

@markwinger
Copy link
Author

One more issue I noticed. After this testing I end up with the job done/cancelled/??? but the bed and nozzle heaters are still on. So I tried going to tools->control-all-> everything off. I get an error:

G10 P0 R-273.15 S-273.15 M140 P0 S-273.15
Error: Requested temperature (-273.1) out of range (0.0:265.0)
Error: Requested temperature (-273.1) out of range (0.0:130.0)

Wow, absolute 0. That's cool. Cooler that the climate here in Minnesota.
But if I set the temps to 0, it works correctly.

@changedsoul
Copy link

changedsoul commented May 14, 2020

I must be missing something. I cannot get this to work for the life of me. There seems to be multiple commands that claim to work and nothing works for me.
The only thing that gets me close is from here: https://klipper.info/klipper-+-dwc2-1/installing-dwc2
Yet I still get the "try_load_module" error.
I found the suggestion to rename that in one of the previous posts, and this got me to see the web interface, yet I was still unable to connect.
When I perform a "FIRMWARE_RESTART" I get the following error: Error: 'dict' object has no attribute 'get_commandline'

Any idea whats wrong?
This is all that is in /tmp/klipper.log after I issue the command:

"FIRMWARE_RESTART
DWC2:24782.43 - 10.0.0.44 - GET - /rr_gcode?gcode=FIRMWARE_RESTART
FIRMWARE_RESTART
failed: FIRMWARE_RESTART'dict' object has no attribute 'get_commandline'
"

@markwinger
Copy link
Author

I think I know what my main problem is. When you click the resume button, the printer is resumed then the macro is run. In octoprint, the macro is run first. So I tried creating resume.g macro, and renamed the macro RESUME_PRINT to MY_RESUME_PRINT so dwc2 does not run it. I then created a dwc2 macro called my_resume_print, and ran it directly with out clicking the resume button.

The macro runs properly, but dwc2 continues to stay paused. Temp goes up correctly, idle_timeout get set when temp hits target, but dwc2 does not resume. Clipper however is in a different state. The logs show:
DWC2:68106.65 - 192.168.1.118 - GET - /rr_config
passed: RESET_TEMP
idle_timeout: Timeout set to 600.00 s
passed: SET_IDLE_TIMEOUT
Print is not paused, resume aborted
passed: RESUME

So my macro worked, klipper is ready to go, but dwc2 is not resumed.

So I have 2 problems, and they may not be solvable
1-dwc2 appears to run the macro after resuming print. So I cannot use the resume button.
2-resume in a macro only resumes klipper and dwc2 does not seem to know we have resumed. So unless we have a way to tell dwc2 to resume from a macro, this may just be impossible.

@markwinger
Copy link
Author

I'm switching back to octoprint now. The number of issues I've seen is way too high right now, and I have barely even used it. I'll be happy to test fixes for you but for now, using dwc2 for everyday printing is just not worth it.

@Stephan3
Copy link
Owner

TLDR
-> fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants