Add HAL Pins to GUI

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
06 Feb 2024 13:26 - 06 Feb 2024 13:29 #292645 by JT
Add HAL Pins to GUI was created by JT
I have a simple GUI and I'm trying to add a HAL pin.


def setup_hal(parent):
    c = hal.component("buttons")
    c.newpin('out', hal.HAL_BIT, hal.HAL_OUT)
    c.ready()

But after running this and opening up showhal I don't see the pin... what am I missing?

I've grepped all the linuxcnc code and searched the forum for a clue but come up empty handed...

JT
Last edit: 06 Feb 2024 13:29 by JT.

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

More
06 Feb 2024 13:37 #292646 by cmorley
Replied by cmorley on topic Add HAL Pins to GUI
Are you sure the function is being called?

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

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
06 Feb 2024 13:43 #292647 by JT
Replied by JT on topic Add HAL Pins to GUI
Thanks for replying Chris.

If I add a print function like this:
def setup_hal(parent):
	print('here')
	c = hal.component("buttons")
	c.newpin('out', hal.HAL_BIT, hal.HAL_OUT)
	c.ready()
it prints to the terminal.

JT

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

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
06 Feb 2024 13:43 #292648 by JT
Replied by JT on topic Add HAL Pins to GUI
There is an odd component I think showing up in halshow.
 

JT
Attachments:

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

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
06 Feb 2024 13:45 #292649 by JT
Replied by JT on topic Add HAL Pins to GUI
Hmm it shows up even if I don't run that function so I assume it's part of Lcnc.

JT

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

More
06 Feb 2024 13:54 - 06 Feb 2024 13:55 #292654 by cmorley
Replied by cmorley on topic Add HAL Pins to GUI
I wonder if it's because c is a local variable and is garbage collected. try:
c= None
def setup_hal(parent):
    print('here')
    global c
    c = hal.component("buttons")
    c.newpin('out', hal.HAL_BIT, hal.HAL_OUT)
    c.ready()

 
Last edit: 06 Feb 2024 13:55 by cmorley.
The following user(s) said Thank You: JT

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

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
06 Feb 2024 13:55 #292655 by JT
Replied by JT on topic Add HAL Pins to GUI
If I add a test to see if the component exists it returns True
def setup_hal(parent):
	c = hal.component("buttons")
	c.newpin('out', hal.HAL_BIT, hal.HAL_OUT)
	c.ready()
	print(hal.component_exists("buttons"))

JT

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

  • JT
  • JT's Avatar Topic Author
  • Away
  • Administrator
  • Administrator
More
06 Feb 2024 13:58 #292657 by JT
Replied by JT on topic Add HAL Pins to GUI
Chris, thanks so much. You nailed it, c was garbage collected!

JT
The following user(s) said Thank You: cmorley

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

Time to create page: 0.097 seconds
Powered by Kunena Forum