How to read hal pin from embedded panel from an other component

More
16 Mar 2021 18:15 #202493 by newbynobi
This might be a very complex question or just a very simple one.

I want to build a universal debug panel as embedded tab. As the panel should be universal and should be able to show also hal pin from other components, I need to get the component hal pin.

If I do this code in the py file of the embedded tab called "debug_panel", embedded in gmoccapy:
print(hal.component_exists("gmoccapy"))
print("gmoccapy = ", hal_glib.GComponent("gmoccapy"))
print(hal.component_exists("debug_panel"))
print("timer = ", hal_glib.GComponent("debug_panel"))
print(hal.component_exists("abs"))
print("abs = ", hal_glib.GComponent("abs"))
print(hal.component_exists("motion"))
print("motion = ", hal_glib.GComponent("motion"))

I get True for gmoccapy, debug_panel, abs and False for motion.
The strange is, that I get for all components the same ID, something like this:
True
('gmoccapy = ', <hal_glib.GComponent instance at 0x7f07ac079200>)
True
('debug_panel = ', <hal_glib.GComponent instance at 0x7f07ac079200>)
True
('abs = ', <hal_glib.GComponent instance at 0x7f07ac079200>)
False
('motion = ', <hal_glib.GComponent instance at 0x7f07ac079200>)

If I try to read a PIN from gmoccapy as gmoccapy.blockheigt like this:
hal_glib.GComponent("gmoccapy")["blockheight"]
I get an error like:
Traceback (most recent call last):
  File "./timer.py", line 123, in _periodic2
    print("gmoccapy = ", hal_glib.GComponent("gmoccapy")["blockheight"])
  File "/home/norbert/linuxcnc-org/lib/python/hal_glib.py", line 77, in __getitem__
    def __getitem__(self, k): return self.comp[k]
TypeError: string indices must be integers, not str
If I try a integer, I just get the corresponding letter of the component name.

Is there a way to read a hal pin from an component outside the own component?
A signal would also be OK, but first I will need to get the "component address" and all my test have failed till now.

Appreciate your help.

Norbert

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

More
18 Mar 2021 01:29 #202695 by andypugh

newbynobi wrote: I get True for gmoccapy, debug_panel, abs and False for motion.


The component name for motion is "motmod"
halcmd: show comp
Loaded HAL Components:
ID      Type  Name                                            PID   State
    72  User  halcmd96007                                     96007 ready
...
    20  RT    __servo-thread                                        ready
    19  RT    motmod                                                ready
...

Is there a way to read a hal pin from an component outside the own component?

import hal
...
v = hal.get_value("motion.program-line")

I don't know if the hal python interface is documented anywhere but here:
linuxcnc.org/docs/2.8/html/hal/halmodule.html

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

Moderators: mhaberler
Time to create page: 0.097 seconds
Powered by Kunena Forum