Passing #parameter from Gcode to python .

More
03 Mar 2022 23:38 #236293 by Vmax549
Hi Guys is it possible to pass a Gcode # parameter to the python side ??

ngc     #3000 =1

python      if  #3000  ==  1 :
                      do this

(;-) TP

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

More
04 Mar 2022 00:31 #236301 by andypugh
Yes.

One way is to send the value on the "G-code analogue outputs"
linuxcnc.org/docs/2.8/html/gcode/m-code.html#mcode:m67

That requires that your Python module imports the "hal" library so that it can make a HAL pin to receive the value.

There are several other ways that might suit in particular situations. For example you could create a remapped (or new) G-code that calls a Python routine.

It is actualluy possible to do exactly what your example shows, but only in a remap, as far as I know.
For example: github.com/LinuxCNC/linuxcnc/blob/master...glue/stdglue.py#L171 uses "self.params" to access arbitrary G-code parameters. But I have never managed to get access to that params structure outside of a remap routine.

If you want to get really crazy you can try something undocumented that I found recently, I think that a magic comment in the G-code can execute a Python script:
(pyrun, somefile.py)

I have no idea if this really works, or where it looks for the python file.


A python file can get a lot of info via the stat structure:
linuxcnc.org/docs/2.8/html/config/python...ding_linuxcnc_status
But I don't think that it gets access to the parameters.

M100-M199 can be any executable program, so you could call a small Python routine that way. In theory this small script could "import" your main script and call code inside it.

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

More
04 Mar 2022 02:06 #236307 by Vmax549
Hi Andy, What I am doing is setting up an error message system similar to teh #3000 error codes in Haas or Fanuc. You set the #3000 paramater to a nunmber that represents the error message you want displayed. I store the error _msg in the INI file where there is easy access to add more entries.

Everything works GREAT except I cannot pass the #3000 value to python. It turned into one of those CLOSE but NO cigar functions.

IF it worked the self.params() function would be great perfect. But I have not been able to get it to work. I even tried to import the files that I thought the function cam from but it will NOT let me import them. EMCCANON and INTERPETOR. I do not know where they reside so I can't set a path statement to include them.

So far I have never worked with a controller that you could not easily pass #var values back and forth between the NGC side and the support programming language..

OH WELL I guess I mark this off as another " close but no cigar"

(;-) TP

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

More
04 Mar 2022 04:35 #236311 by cmorley
The python interpreter instance in linuxcnc's interpreter is not accessible from another python instance.
This is a known and common limitation with python.

Linuxcnc wasn't designed with external var access in mind it seems.

Linuxcnc's error system kinda sucks too :)

Both I'm sure are improvable but would require some smart guy with a plan to program.

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

More
04 Mar 2022 10:22 #236328 by andypugh

Hi Andy, What I am doing is setting up an error message system similar to teh #3000 error codes in Haas or Fanuc.

There are other ways to report errors which might do what you want, but they are different. 

You can code messages, errors and aborts directly in the G-code:
linuxcnc.org/docs/2.8/html/gcode/overview.html#gcode:comments
Also (ABORT, ...) Which is touched on here: linuxcnc.org/docs/2.8/html/remap/remap.h...g_dealing_with_abort [1]

There is also the HAL "message" component that can be driven with G-code digital outputs: linuxcnc.org/docs/2.8/html/man/man9/message.9.html

But, I agree. It would be really handy to be able to access the parameter space, ideally with the emc.stat structure. 

[1] We should collect together all the "magic comments" somewhere in the docs. Here is the source:
github.com/LinuxCNC/linuxcnc/blob/master...erp_convert.cc#L1437

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

More
04 Mar 2022 12:49 #236337 by Vmax549
Hi Andy, The problem in PathPilot is all of the Gcode side error msg function send the msg to stderr or in the case of pathpilot it goes to the status page. There is even a Mo1(message) function BUT that M01(msg) function ONLY works if you can see the M00/M01 from the Gcode treeview. IF the M01 resides in an outside sub then it does not work.

I had looked at doing a (debug,1,error message text) function where when PP reads the debug line the 1 after the first comma would pipe the results to the message_line which is on the run page at the bottom of the toolpath display. PERFECT I thought. But how in the world can I pull that off ????

IF ONLY the self.params() worked a lot of things in Linuxcnc / PathPilot would be easier to make work.

It is what is is though , (;-) TP

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

More
04 Mar 2022 16:05 #236357 by andypugh

It is what is is though , (;-) TP

Ah, but, the beauty of open-source is that it doesn't have to be. 

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

More
04 Mar 2022 17:04 #236364 by Vmax549
HIYA Andy Open Source ??? It is great as long as it stays open source. Things can change (;-)

It would be NICE if an OEM would take up the cause and support an open source PP . But Tormach might not like the idea (;-)

AND no that would not be me. I am not a programmer by any sense of teh word. I am just an old chip slinger that likes to have CNC functions based on the real world ways and am willing to work for it. (;-) You know things like G31 skip for probing NOT G38, or G68/69 for coordinate rotation NOT g10 l ???? or G15/16 for polar not ^xxnn. And I do have those remapped in PP for my useage and being able to use old gcode programs.

I guess it would nice to have an online PP toolbox setup to share code but lets see how the PP software useage for nontormach machine plays out. IF PP goes private it changes a lot of things dealling with PP useage on non Tormach machines.

(;-) TP

(;-) TP

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

Moderators: cncbasher
Time to create page: 0.072 seconds
Powered by Kunena Forum