hi,
I want to write a plugin to mimic sd card functions for prusa printers via prusaLink. The prusaLink part isn't hard.
I already have code to catch e.g. M20 (via queuing hook). What's missing for my first results is how to put my results in the received queue.
For me and the Bambu plugin I'm able to do it through the serial factory I've added to the plugin to handle all serial communication back and forth. If you're not doing it all and just intercepting the M20 command you would have to call the internal comm layer received command I suspect. Something that uses the comm_instance parameter of the gcode queing callback, which is an instance of the MachineCom class. Seems like it might be difficult to do.
The other option, which I don't know if Prusa supports, is the use of M118 command, which basically tells the printer to send me back this line. So your hook captures queuing, grabs the file list, and then expands the command being sent to include a bunch of M118 commands with the file data lines appended.
M118 seams to work. nice idea! I want to replace the other not/not well supported SD commands.
I see I can control octoprint with that: "M118 A1 action:cancel" fancy
I looked already in the comm module and also find it hard to use for my purpose.
Cool, so yeah that should work. In your gcode queueing hook, instead of returning line, you would return a list of M118 commands. Simple example (untested)...
def prusa_list(self, comm_instance, phase, cmd, cmd_type, gcode, subcode=None, tags=None *args, **kwargs):
if gcode != "M20":
return
# code to get list of files and generate return data, ie dosname, date, size, unix timestamp, long filename
file_list_commands = ["Begin file list"]
for file in files:
# dosname size timestamp "filename"
file_list_commands .append(f"M118 {dosname } {size} {timestamp} \"{filename}\"")
file_list_commands.append("End file list")
return file_list_commands
__plugin_hooks__ = {
"octoprint.comm.protocol.gcode.queuing": prusa_list
}
you may also have to use the received phase gcode hook to manipulate how the printer sends the information (ie, remove "echo: " from the string possibly)
a meta-comment just to say "thanks". I'm not in this topic, but want to say in general that the world is a better place because of folks who help each other. I think you know that, and I don't think you are doing this just so that you get these "thanks", But it is important, so : kudos....
That is all
Hi, @jneilliii thx for the answer. Main difference as I understand is that you have a complete printer plugin and I only a plugin that tries to modify the standard printer behaviour throug hooks and tricks.
This is my first plugin in octoprint and I'm feeling not ready for making a complete new printer class, albeit it might be better in the end.
My plugin shows files on sd card with long filenames and times (currently not the size of a file). I can load the file (with no analyze of the file) and delete a file. Also sd upload is possible.
I wasn't able to set capabilities, because i can't hook in the capability readout (with complete printer plugin as yours this is easy).
Currently I work on starting the print from sd card.
Any clue how I can hook in the analyze stuff so I can provide more informations of the file?