Prusa link sd card emulation

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.

Any idea how to do that?

I saw this Handle M20 - List SD Card for printers don't support M20 but it misses some details for me, so I open a new thread...

thx in advance!

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.

1 Like

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 :slight_smile:
I looked already in the comm module and also find it hard to use for my purpose.

thx :slight_smile: :grinning:

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)

Exactly what I did. Currently working on getting the M20 L to work for more then msdos filenames.

besides of the gcode commands I have the problem that file manager don't show my file list. I think I have to manipulate the printer capabilities.

Yeah, I enabled long file name support and long file name writing, since I also am using the sd card upload hook.

Oh more pointers on the dosname and timestamp. For timestamp I'm using OctoPrint's conversion from unix timestamp.

and for dosname I'm using OctoPrint's get_dos_filename

1 Like

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?

Unfortunately analysis doesn't work on SD card files, I have the same problem with full virtual printer.

my plan is to have a custom GcodeAnalysisQueue that download the file and analyse it.

I look in plugin "prusa mini eta" there is a good example.