HAL in Python getprefix() and setprefix() Usage?
the hal component for python states that any pins can be accessed, but it will not allow you to use an existing name for the hal.component and if you use an existing name for the pin you want to access, it says 'undefined.
From this behavior, I assume that the pin prefix and the hal.component names have to match.
There are commands (methods?) for getting and setting the prefix. They seem to work, but I cannot figure out how to use them. I've done numerous searches, but just keep coming up with the same document that mentions the commands, but gives no clue on how to use them.
Please Log in or Create an account to join the conversation.
..............the hal component for python states.............
You need to tell us exactly what you have been reading ( a link to it ) and as importantly, exactly what you are trying to do.
There are lots of orphaned wikis and old html pages out there, we can't guess what you have stumbled upon, or whether what you have read is relevant or applicable to what you are trying to do.
regards
Please Log in or Create an account to join the conversation.
This shows you how set_prefix works.
The component will be loaded by and called passthrough but
the pin names are pt.in and pt.out
The prefix change needs to be done before any pins are made.
!/usr/bin/python
import hal, time
h = hal.component("passthrough")
h.set_prefix('pt')
h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()
try:
while 1:
time.sleep(1)
h['out'] = h['in']
except KeyboardInterrupt:
raise SystemExit
Please Log in or Create an account to join the conversation.
Depending on the linuxcnc version there are other functions available:
FUNCTIONS
component_exists(...)
Return a TRUE value if the named component exists
component_is_ready(...)
Return a TRUE value if the named component is ready
connect(...)
connect pin to signal
get_msg_level(...)
Get the RTAPI message level
new_sig(...)
create a signal
pin_has_writer(...)
Return a FALSE value if a pin has no writers and TRUE if it does
set_msg_level(...)
Set the RTAPI message level
Please Log in or Create an account to join the conversation.
..............the hal component for python states.............
You need to tell us exactly what you have been reading ( a link to it ) and as importantly, exactly what you are trying to do.
There are lots of orphaned wikis and old html pages out there, we can't guess what you have stumbled upon, or whether what you have read is relevant or applicable to what you are trying to do.
regards
I am trying as best I can to explain the process, and I am very thankful for all of the time everyone is spending trying to help, but the solutions only address a specific pieces of the puzzle and not the overall task. So the instruction on how to create pins is great and the suggestion on how to net them is great and the suggestion of how to use Glade actions is great, but none of these will do the whole job, because none will create and net and read and write multiple pins.
In a nutshell, I want to be able to create, and then read and write ANY pin under program control using a language that can also do math, conditional statements and also (I never got this far before, but may as well throw it out there) the ability to manipulate disk files.
So far as I can determine at this point, all of that exists, but not in any one form. You need Python HAL to create pins, then another method to net the pins and the Python program that creates and manipulates the pins won't load automatically and has to load before the hal program that nets the pins, and so on. It's like you can't get there from here. I am hoping that I'm just being dense and not understanding something.
I do appreciate everyone being patient and trying to figure out what the heck I'm taking about
Please Log in or Create an account to join the conversation.
The docs may be stale a bit.
Depending on the linuxcnc version there are other functions available:
FUNCTIONS component_exists(...) Return a TRUE value if the named component exists component_is_ready(...) Return a TRUE value if the named component is ready connect(...) connect pin to signal get_msg_level(...) Get the RTAPI message level new_sig(...) create a signal pin_has_writer(...) Return a FALSE value if a pin has no writers and TRUE if it does set_msg_level(...) Set the RTAPI message level
The documents that I am using are on LinuxCNC.org
If this is the 'linuxCNC' library, then I think the docs are out of date as I don't recall seeing any functions having to do with pins at all . . and I looked for them.
Where can I find the current documentation on the LinuxCNC library for Python? If linking/netting has been added then the combination of the 'hal' and the 'LinuxCNC' would create the pins and then 'net' them. That's not the entire pie, but a lot more than I know about so far! And it's all Python, so trying to get the Python to run first and then another HAL file afterward would be eliminated.
The majority of the device communicates with LinuxCNC via a pair of macros. One macro covers all 48 Modbus coils and the other covers all 35 Modbus registers (a.k.a. 'holding'). These are written in BASH which has direct access to all of the pins, including the Modbus pins and also the specially prefixed pins created by PyVCP. This was uber easy to do and has me thinking that BASH may be the better solution.
There is also apparently a Python 'plug-in' that has yet another different set of capabilities which I have not looked at yet.
My suggestion, just based on what I can determine at this point would be to recruit the talent to add the pin access that bash has to the 'linuxCNC' library which has everything BUT access to the pins. It seems at least that some of that may have been done already. I need to get my hands on the current docs for the 'LinuxCNC' library.
Where can I find that?
Please Log in or Create an account to join the conversation.
The docs may be stale a bit.
Depending on the linuxcnc version there are other functions available:
FUNCTIONS component_exists(...) Return a TRUE value if the named component exists component_is_ready(...) Return a TRUE value if the named component is ready connect(...) connect pin to signal get_msg_level(...) Get the RTAPI message level new_sig(...) create a signal pin_has_writer(...) Return a FALSE value if a pin has no writers and TRUE if it does set_msg_level(...) Set the RTAPI message level
I thought these were new stuff added to the 'linuxcnc' library for python, bit it does not appear that's the case.
What library are these from?
Please Log in or Create an account to join the conversation.
So Just guessing what info you need.
This shows you how set_prefix works.
The component will be loaded by and called passthrough but
the pin names are pt.in and pt.out
The prefix change needs to be done before any pins are made.
!/usr/bin/python import hal, time h = hal.component("passthrough") h.set_prefix('pt') h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN) h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT) h.ready() try: while 1: time.sleep(1) h['out'] = h['in'] except KeyboardInterrupt: raise SystemExit
#!/usr/bin/python
import hal, time
h = hal.component("passthrough")
h.newpin("in", hal.HAL_FLOAT, hal.HAL_IN)
h.newpin("out", hal.HAL_FLOAT, hal.HAL_OUT)
h.ready()
try:
while 1:
time.sleep(1)
h = h
except KeyboardInterrupt:
raise SystemExit
Above is what is on LinuxCNC.org, so there must be more current stuff somewhere.
What is the best place to look for the most up-to-date documents?
As far as get/setprefix, given the way you describe the usage, it will not be useful in accessing existing pins, which was my hope.
Please Log in or Create an account to join the conversation.
The python bindings which constitute 'the library' as you call it are written in quasi C++
They are at
src/hal/halmodule.cc
src/emc/usr_intf/axis/extensions/emcmodule.cc
for the most part
These locations refer to the source code, which you will need to download
github.com/LinuxCNC/linuxcnc
The docs are mostly
linuxcnc.org/docs/2.6/html/common/python-interface.html
linuxcnc.org/docs/html/hal/halmodule.html
wiki.linuxcnc.org/cgi-bin/wiki.pl?Using_HAL_In_Python
The whole need / use for getprefix() and setprefix() is not clear to me in any case.
A pin prefix is always that of the owning component by default, if you want to interrogate values of existing pins etc that is completely different.
Look at find_item() to start with, in halmodule.cc
regards
Please Log in or Create an account to join the conversation.
I thought these were new stuff added to the 'linuxcnc' library for python, bit it does not appear that's the case.
What library are these from?
These are from the HAL python library. there are no docs on them aside from reading the python module.
I knew they were there because I added a couple of them and have read the source code.
They have been there a long time so if you are using 2.6 or better they will be there.
in a terminal type
python <return>
then type
import hal <return>
then type
help(hal) <return>
keep scrolling down with the cursor keys
pressing q will get you back
Chris M
Please Log in or Create an account to join the conversation.