Changing component parameter via Glade

More
5 years 6 months ago #204355 by lrak
So this hal-file approach does not work:
Code:
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
Code:
$ 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:
Code:
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 to join the conversation.

More
5 years 6 months ago #204358 by phillc54
You could import the hal module:
Code:
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

Please Log in to join the conversation.

More
5 years 6 months ago #204415 by lrak
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?

Please Log in to join the conversation.

More
5 years 6 months ago #204439 by cmorley
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

Please Log in to join the conversation.

More
5 years 6 months ago #204454 by lrak
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?

Please Log in to join the conversation.

More
5 years 6 months ago #204461 by cmorley
ok done

Please Log in to join the conversation.

More
5 years 6 months ago #204550 by lrak
I did get this working:
Code:
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 to join the conversation.

Time to create page: 0.164 seconds
Powered by Kunena Forum