Get the value of a HAL component in a python script

More
5 years 6 months ago #205522 by elisa
Hello everybody,

I write this post for those who are having trouble getting the value of a HAL component in a Python script.

1) For those who have the LinuxCNC version 2.8.x installed, you can use the command "hal.get_value (" your_component ")" and import the "import hal" library

2) For those who have installed LinuxCNC version 2.7.x, unfortunately the "hal.get_value" command will not work, but it is possible to use the "import linuxcnc" library and the commands in this order:

- s.linuxcnc_stat ()
- s.poll (): updates the current status of the machine
- s.your_command (): Look at the wiki to find the command you need ( linuxcnc.org/docs/2.6/html/common/python-interface.html )

Hope this post can help someone!

P.S. For older versions, I don't know if commands for the 2.7.x version will work, however, try it.

Please Log in to join the conversation.

More
5 years 6 months ago #205599 by Benb
In the past couple of days, I have been trying to understand how HAL communicates with GUI's. I found in the documentation so far three sections (there might be more) all related to HAL communication. I added links to the three sections below . I also added what I think each module does. It seems that Gstat module is the more efficient but the lists of communication messages/attributes (see docs for clarity) between these two modules are different however they complement each other (maybe).

Any clarification for when to use these modules is welcomed.

Python Interface (linuxcnc Module)
linuxcnc.org/docs/2.8/html/hal/halmodule.html
From the given examples in the docs: linuxcnc module periodically poll the data.

GStat Module
linuxcnc.org/docs/2.8/html/gui/GStat.html
Gstat is event driven instead which is more efficient then polling.

Creating Userspace Python Components
linuxcnc.org/docs/2.8/html/config/python-interface.html
This part uses Gstat module to read and write data into HAL through pins and parameters.

Please Log in to join the conversation.

More
5 years 6 months ago #205605 by elisa
Thank you very much Benb! I will try to use GStat module too and report it.

Any other suggestions and clarifications are welcome.

Please Log in to join the conversation.

Time to create page: 0.192 seconds
Powered by Kunena Forum