Ways to get an user M code return value

More
07 Nov 2023 07:56 #284750 by jogger
Hi!

I have read some statements that there is currently no direct way to get a return value of my user defined M function back to the G code. My questions:

1.) Is there a way to set parameters (like #4999) directly in the M code?

2.) One working way is to set HAL pins/parameters via "halcmd" and then read them out in the G code.
Is there a (very simple) hal module which only offers some parameters to be used as a "clipboard" between M code and G code?
As I understood HAL there is no function needed for updating something because there are no inputs and outputs needed, just parameters. Before I write such a module - has it already been written?

Best regards,
Chris

Please Log in or Create an account to join the conversation.

More
07 Nov 2023 17:07 #284799 by Aciera
I would use a python remap.
Create a file 'remap.py':
def m444(self, **words):
    c = self.blocks[self.remap_level]
    # parse the i-argument
    i = c.i_number if c.i_flag else 0
    self.params[4999]=i

mark the file as executable and place it in a folder 'python' in your machine config

then add this to the [RS274NGC] section in your ini file:
SUBROUTINE_PATH = ./remap_subs
          REMAP = M444  modalgroup=10  argspec=i python=m444

In your gcode you should then be able to do something like:
m444 i4
g0 x#4999

which should move the x axis to 4



 
The following user(s) said Thank You: jogger

Please Log in or Create an account to join the conversation.

More
08 Nov 2023 11:13 #284855 by jogger
Ahh, perfect :-)

Thank you very much!

Please Log in or Create an account to join the conversation.

More
09 Nov 2023 19:26 #284960 by Joco
I would be interested to know experiences here in WHEN the remapped m word is executed.  I did this (M259) to run some halcmd lines to set pins in hal and found that this was being executed as soon as the programe was parsed and then again when it was run.  But NOT when the line was encountered in the correct order in the program.  I could solve for preventing the parsing issue but could not find a way to get things to only happen at the correct point in the program run.

The only way I could solve this was to use the M100-M199 range of pre configured user available words.  These behave correctly in that sense. i.e. trigger only when encountered in the program execution.   I can't remember if they also prevent parsing execution, I already had the code to prevent that baked in.

So ... interested in your findings.

Cheers - J.

NB: using 2.9 debian install of linuxcnc.

Please Log in or Create an account to join the conversation.

Time to create page: 0.092 seconds
Powered by Kunena Forum