Cannot call Macro containing custom m-code before custom m-code
-
Apologies in advance if I've been missing something obvious, but I've been having problems getting custom m-codes working the way I'd like on the Duet 3, RRF ver 3.4.5
I've found that if I call a macro containing a custom m-code with M98 right before calling another custom m-code, the RPi-side code will freeze, and I can only continue after hitting the GUI's emergency stop button to restart the Duet. I'm able to get around this issue by removing the flush command, but then the custom m-code after the macro completes before the custom m-code within the macro. My test code is based almost entirely on the custom m-code example from the dsf-python repository:
dsf_server.py:
from dsf.connections import InterceptConnection,InterceptionMode,CommandConnection from dsf.commands.code import CodeType from dsf.object_model import MessageType import time if __name__=="__main__": filters = ["M1234","M1111"] intercept_connection = InterceptConnection(InterceptionMode.POST,filters=filters,debug=True) intercept_connection.connect() print("Connected and listening...") try: while True: cde = intercept_connection.receive_code() cde_str = str(cde.type)+str(cde.majorNumber) if cde_str in filters: intercept_connection.flush(cde.channel) print(cde_str) if cde.type==CodeType.MCode and cde.majorNumber==1234: #report time of execution time_executed = round(time.time(),2) msg_type = MessageType.Success msg = "Time completed: {}".format(time_executed) intercept_connection.resolve_code(msg_type,msg) elif cde.type==CodeType.MCode and cde.majorNumber==1111: #blank, filler m-code to fill the m queue intercept_connection.resolve_code() except Exception as e: print("Error") intercept_connection.close()
Test gcode that fails:
M98 P"/tests/Wrapper" M1234
Wrapper macro file:
M1111
Can we just not put custom m-code calls inside of macros that are used in other macros or gcode files? Or has anyone else run into any similar issues? Thanks so much for your time!
-
Have you tested on 3.5 beta yet?
-
@rymnd Thanks for reporting this problem, I could reproduce it. You have two options to work-around this problem:
- Change your G-code to
M98 P"/tests/Wrapper" if true M1234
This ensures that
M1234
is not sent to your script beforeM98
completes.- Use separate scripts/connections for
M1111
/M1234
The reason for this problem is that
M1234
waits for all other codes to complete while it is waiting for the followingM1111
to be handled by that very same script as well, which results in a deadlock. I'm going to add better error handling to the next DSF version and add a new option to the interceptor API to automatically flush the code channel internally (if desired) to avoid this problem altogether. -
@chrishamm Thanks so much for the fast reply! Regarding your #2 on separate scripts, you're referring to the dsf python code on the RPi side that intercepts the custom m-codes, correct?
I've also found that if both custom m-codes are wrapped in their own macro files and called via M98 on the same level, that works too
-
@rymnd Yes, that's right. I've got the corresponding changes ready for 3.5.0-rc.1 and potentially 3.4.7.