Get a #var to use in a Python script
02 Dec 2019 14:51 #151754
by Vmax549
Get a #var to use in a Python script was created by Vmax549
Anyone know how to get a # var into a python script such as:
X_Value = #5061
I do not see any function like GetVar() where it would be used like Test_Value = Getvar(5061)
(;-)TP
X_Value = #5061
I do not see any function like GetVar() where it would be used like Test_Value = Getvar(5061)
(;-)TP
Please Log in or Create an account to join the conversation.
02 Dec 2019 20:54 #151774
by smgvbest
Replied by smgvbest on topic Get a #var to use in a Python script
haven't tried it but does this help
github.com/LinuxCNC/linuxcnc/blob/master...athe-fanucy/remap.py
or a full writeup here
linuxcnc.org/docs/2.7/html/remap/remap.h...g_dealing_with_abort
github.com/LinuxCNC/linuxcnc/blob/master...athe-fanucy/remap.py
or a full writeup here
linuxcnc.org/docs/2.7/html/remap/remap.h...g_dealing_with_abort
Please Log in or Create an account to join the conversation.
02 Dec 2019 21:01 #151775
by Vmax549
Replied by Vmax549 on topic Get a #var to use in a Python script
Unfortunately no it does not help. I read that earlier in my search.
But thanks for the help, ( TP
But thanks for the help, ( TP
Please Log in or Create an account to join the conversation.
02 Dec 2019 21:17 #151776
by smgvbest
Replied by smgvbest on topic Get a #var to use in a Python script
Do you know how you use the debugger features of your python IDE?
I beelive in another thread a comment was made about 'above my paygrade' so i've not sure of your skillset. please do not take offense, trying to understand skill level.
So actually what are you using to code python?
I use WingIDE and pycharm
the reason I ask is you can with a python debugger you can browse thru what LinuxCNC is passing you back so you can find what your searching for.
I beelive in another thread a comment was made about 'above my paygrade' so i've not sure of your skillset. please do not take offense, trying to understand skill level.
So actually what are you using to code python?
I use WingIDE and pycharm
the reason I ask is you can with a python debugger you can browse thru what LinuxCNC is passing you back so you can find what your searching for.
Please Log in or Create an account to join the conversation.
02 Dec 2019 22:56 - 02 Dec 2019 23:00 #151780
by Vmax549
Replied by Vmax549 on topic Get a #var to use in a Python script
No offense taken ( I am not a programmer. I use Gedit to modify scripts. Then run PP and if I get an error I look in teh PathPilot.log to see what it was
From a python script:
check_x = str( 123.345) ## I need numeric value to be <_X>
Then I pass it off to a message to teh operator
BUT I get an error message
File "/home/operator/v2.3.6/python/ui_common.py", line 5291, in send_m1_alert
check_x = str( _x)
NameError: global name '_x' is not defined
AND the error makes sense as _x is a gcode variable and is not present in the Python side
It seems there is a void between Python and teh Gcode side of LinuxCNC where you cannot pass variables across OR at least not from what little I know of it.
( TP
From a python script:
check_x = str( 123.345) ## I need numeric value to be <_X>
Then I pass it off to a message to teh operator
BUT I get an error message
File "/home/operator/v2.3.6/python/ui_common.py", line 5291, in send_m1_alert
check_x = str( _x)
NameError: global name '_x' is not defined
AND the error makes sense as _x is a gcode variable and is not present in the Python side
It seems there is a void between Python and teh Gcode side of LinuxCNC where you cannot pass variables across OR at least not from what little I know of it.
( TP
Last edit: 02 Dec 2019 23:00 by Vmax549.
Please Log in or Create an account to join the conversation.
02 Dec 2019 23:25 #151783
by Vmax549
Replied by Vmax549 on topic Get a #var to use in a Python script
I had found this code example in a script " if self.params[5600] > 0.0: " and I thought it might be teh answer but it errored as well
check_x = self.params[5061] I used teh 5061 because I know what it is (
Attribute error: Mill instance has no attribute ' params '
( TP
check_x = self.params[5061] I used teh 5061 because I know what it is (
Attribute error: Mill instance has no attribute ' params '
( TP
Please Log in or Create an account to join the conversation.
03 Dec 2019 13:57 - 03 Dec 2019 13:57 #151862
by andypugh
Replied by andypugh on topic Get a #var to use in a Python script
self.params is available if your python imports canon. ieAs seen in stdglue.py
But, you can only import canon in remap python code.
If your script is not part of a G-code remap then would it make sense to re-cast it as one?
I am wondering if it is possible to send an MDI command via the python linuxcnc.command() interfaceAnd somehow parse the output. (which might, or might not, appear in the python interface to the error channel). Zero marks for elegance, even if it does work.
import emccanon
But, you can only import canon in remap python code.
If your script is not part of a G-code remap then would it make sense to re-cast it as one?
I am wondering if it is possible to send an MDI command via the python linuxcnc.command() interface
linuxcnc.command.mdi("(DEBUG, #5601)")
Last edit: 03 Dec 2019 13:57 by andypugh.
Please Log in or Create an account to join the conversation.
03 Dec 2019 16:30 #151888
by Vmax549
Replied by Vmax549 on topic Get a #var to use in a Python script
It is ODD that as long as EMC has been around that there is NO link between teh 2 sections Python/Gcode to share variables or parameters. I can do half teh function from Gcode but cannot notify teh operator. I can do teh notify operator from teh Python side but cannot pass variable data to them.
I wonder WHY you cannot import emccanon from Python script. Python has no idea what emccanon is.
Catch22 , Close but no Cigar , ( TP
I wonder WHY you cannot import emccanon from Python script. Python has no idea what emccanon is.
Catch22 , Close but no Cigar , ( TP
Please Log in or Create an account to join the conversation.
03 Dec 2019 16:57 #151890
by andypugh
Replied by andypugh on topic Get a #var to use in a Python script
I think it is because there are two halves of linuxCNC, and they don't always agree.
There is the interpreter, running in user-space, then there is the realtime code which controls the machine.
Often the interpreter has finished queuing several hours worth of cutting path into the motion controller before the tool even touches the work.
At that point there are two different opinions on the value of the parameters. The interpreter will hold the final value, and the realtime code the initial value.
And there is nothing sending currrent parameter values back to user-space from realtime. In fact I don't think the realtime code even knows what parameters are, it just sees numbers.
There is the interpreter, running in user-space, then there is the realtime code which controls the machine.
Often the interpreter has finished queuing several hours worth of cutting path into the motion controller before the tool even touches the work.
At that point there are two different opinions on the value of the parameters. The interpreter will hold the final value, and the realtime code the initial value.
And there is nothing sending currrent parameter values back to user-space from realtime. In fact I don't think the realtime code even knows what parameters are, it just sees numbers.
Please Log in or Create an account to join the conversation.
03 Dec 2019 19:07 #151893
by Vmax549
Replied by Vmax549 on topic Get a #var to use in a Python script
I think I may be able to use remap. I am testing now.
Please Log in or Create an account to join the conversation.
Moderators: cncbasher
Time to create page: 0.113 seconds