Using .set with HAL_GLIB outside of INIT

More
02 Jul 2023 21:38 - 02 Jul 2023 21:41 #274665 by BrandonS
I'm really sorry to bug others with this, but I'm at a complete loss.  I've been working on trying to sort out HAL and Python the past few days and I've been stuck on this part all day long. 

I can get my new HAL pin connected and I can link it in HAL to other pins as long as I set the value in the def __init__.  Once I try and use the same syntax in another function, the value will no longer change.  

What I'm trying to do below is that when the tool number changes it runs _update_tool_info and inside that function it sets the HAL signal, ToolFluteCount to 4.  What's happening is, during __init__ it creates the signal, sets the value to 3, but then in update_tool_info it runs all the other code successfully, but the ToolFluteCount.set never changes the value of the signal, it remains three.

Consequently, how do you debug this?  I've been just making changes, opening Axis (reading a crash log if it doesn't run), and then looking at HAL pins, but I don't know where warnings and such get posted.
class PanelTestClass:
    def _update_tool_info(self,hal_pin,data=None):
        ToolFluteCount.set("4")
        self.toolflutes.set_label("%.0f" % (toolflutes))

    def __init__(self, halcomp,builder,useropts):
        ToolFluteCount = hal_glib.GPin(self.hal.newpin('ToolFluteCount', hal.HAL_FLOAT, hal.HAL_IN))
        ToolFluteCount.set("3")
       
        ToolChange = hal_glib.GPin(self.hal.newpin('ToolNum',hal.HAL_U32, hal.HAL_IN))
        ToolChange.connect('value_changed', self._update_tool_info)
       
def get_handlers(halcomp,builder,useropts):
    return [ProbePanelClass(halcomp,builder,useropts)]


 
Last edit: 02 Jul 2023 21:41 by BrandonS.

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

More
03 Jul 2023 17:03 #274700 by cmorley
ToolFluteCount is a local-to-the-function reference. Outside the function it is defined in, it is just another local-to-that-function reference.

To have a local-to-the-class reference make all 'ToolFluteCount' into 'self.ToolFluteCount' Now anywhere in the class it will reference the same variable.

also in the function _update_tool_info(self,hal_pin, data=None):
hal_pin is the calling function's pin  (the halpin you need reference to)
So you can use it in the function like this:
    def _update_tool_info(self,hal_pin,data=None):
        hal_pin.set("4") # hal_pin is a reference to  the calling function's pin object
        self.toolflutes.set_label("%.0f" % (toolflutes)) # <- not sure what toolflutes is a reference to so this will cause an error

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

More
12 Jul 2023 09:55 #275268 by BrandonS
Thank you for the explanation. That explanation is crystal clear. I'm not a programmer past easy if/then and bash scripts. This is my first attempt with Python and Glade. I have no idea why I wasn't seeing these for what they are; normal function and passing values.

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

Moderators: mhaberlerHansU
Time to create page: 0.140 seconds
Powered by Kunena Forum