Changing component parameter via Glade
01 Apr 2021 03:30 #204355
by lrak
Changing component parameter via Glade was created by lrak
So this hal-file approach does not work:
The last line tries to connect a RW parameter to the output of mux2 and fails.. (mux2 works fine).
I can change the parameter live from bash via
So I'm rather new to glade - but have other bits working. Is there a way to run a simple bash command from glade?
I understand why encoder.n.scale is a parameter and not a pin - (I'm guessing halcmd setp stops and restarts the component?) - Seems like I should be able to run a halcmd via glade?
I think I should do something like this in python:
This should be rather simple - but I'm not finding a halcmd example from gvcp..
net gear-change gear.out hm2_7i93.0.encoder.04.scale
The last line tries to connect a RW parameter to the output of mux2 and fails.. (mux2 works fine).
I can change the parameter live from bash via
$ halcmd setp hm2_7i93.0.encoder.04.scale 22
So I'm rather new to glade - but have other bits working. Is there a way to run a simple bash command from glade?
I understand why encoder.n.scale is a parameter and not a pin - (I'm guessing halcmd setp stops and restarts the component?) - Seems like I should be able to run a halcmd via glade?
I think I should do something like this in python:
import subprocess
subprocess.call("halcmd setp hm2_7i93.0.encoder.04.scale 22")
This should be rather simple - but I'm not finding a halcmd example from gvcp..
Please Log in or Create an account to join the conversation.
01 Apr 2021 05:36 #204358
by phillc54
Replied by phillc54 on topic Changing component parameter via Glade
You could import the hal module:
linuxcnc.org/docs/devel/html/hal/halmodule.html#_set_p
I think it requires LinuxCNC 2.8 or later
import hal
hal.set_p('hm2_7i93.0.encoder.04.scale', '22')
linuxcnc.org/docs/devel/html/hal/halmodule.html#_set_p
I think it requires LinuxCNC 2.8 or later
The following user(s) said Thank You: lrak
Please Log in or Create an account to join the conversation.
01 Apr 2021 18:45 #204415
by lrak
Replied by lrak on topic Changing component parameter via Glade
Might work? Not clear how to call the script? (It is also often not clear what works with pins vs parameters.) If I can call python, I can get it to work. (Sure wish I could find a working example of gvcp changing a parameter )
But it is not clear what file to modify to get the script called- almost has to be in gvcp-panel.ui ??
A working example of calling python or a shell command from gvp-panel.ui would get me where I need to be.
I need to act when the button is pressed and know the state of the toggle - and run the script.. There is a signals tab - that is for doing something on a gtk event - the 'handler' provides a dropdown list - perhaps I need to type the name of the script there? Or edit the gvcp-panel.ui file directly?
But it is not clear what file to modify to get the script called- almost has to be in gvcp-panel.ui ??
A working example of calling python or a shell command from gvp-panel.ui would get me where I need to be.
I need to act when the button is pressed and know the state of the toggle - and run the script.. There is a signals tab - that is for doing something on a gtk event - the 'handler' provides a dropdown list - perhaps I need to type the name of the script there? Or edit the gvcp-panel.ui file directly?
Please Log in or Create an account to join the conversation.
01 Apr 2021 22:00 #204439
by cmorley
Replied by cmorley on topic Changing component parameter via Glade
You need to add a python handler file to work with the glade file.
linuxcnc.org/docs/2.8/html/gui/gladevcp....gladevcp:programming
there is a sim config axis/gladevcp that shows this technique
linuxcnc.org/docs/2.8/html/gui/gladevcp....gladevcp:programming
there is a sim config axis/gladevcp that shows this technique
The following user(s) said Thank You: lrak
Please Log in or Create an account to join the conversation.
02 Apr 2021 01:43 #204454
by lrak
Replied by lrak on topic Changing component parameter via Glade
The first code bit in the link has syntax errors -
linuxcnc.org/docs/devel/html/gui/gladevc..._callbacks_in_python
Looks like the -end of lines went missing..
Not sure who to tell this to so it can be corrected?
linuxcnc.org/docs/devel/html/gui/gladevc..._callbacks_in_python
Looks like the -end of lines went missing..
Not sure who to tell this to so it can be corrected?
Please Log in or Create an account to join the conversation.
02 Apr 2021 06:50 #204461
by cmorley
Replied by cmorley on topic Changing component parameter via Glade
ok done
Please Log in or Create an account to join the conversation.
02 Apr 2021 19:57 #204550
by lrak
Replied by lrak on topic Changing component parameter via Glade
I did get this working:
Might be other ways to do it - but this is fairly simple/concise and works. (Took me forever to find the method I needed gtkobj.hal_pin.get() .. )
(I realized that this post ended up in the wrong catagory - should be in "User Interfaces/GladeVCP" but I don't see any way to move it. )
nhits = 0
sterr = ""
def on_high_gear_button_pressed(gtkobj,data=None):
global nhits
import os
if gtkobj.hal_pin.get() :
cmd = "/usr/bin/halcmd setp hm2_7i93.0.encoder.04.scale 22"
sterr = os.system(cmd)
else:
cmd = "/usr/bin/halcmd setp hm2_7i93.0.encoder.04.scale 248.8571"
sterr = os.system(cmd)
Might be other ways to do it - but this is fairly simple/concise and works. (Took me forever to find the method I needed gtkobj.hal_pin.get() .. )
(I realized that this post ended up in the wrong catagory - should be in "User Interfaces/GladeVCP" but I don't see any way to move it. )
Please Log in or Create an account to join the conversation.
Time to create page: 0.078 seconds