Access Modbus pins directly with Python - doable?

  • jepler
  • Administrator
  • Administrator
More
10 years 9 months ago #67731 by jepler
No, in a quick survey of the UIs that implement POSTGUI_HALFILE, only one is supported.

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

More
10 years 9 months ago - 10 years 9 months ago #67732 by dgarrett
You can start another application using the ini setting:
Code:
[APPLICATIONS] APP=name_of_app_in_the_PATH

A DELAY can be specified or the program can check to see if required precursors (like
hal pins) exist.

For example, sim configs in configs/sim/axis/xhc-hb04/*.ini
start programs named 'xhc-hb04-accels' and 'monitor-xhc-hb04'
that use this facility.

The xhc-hb04-accels script waits to make sure a predefined
hal testpin is available.

Ref:
linuxcnc.org/docs/2.7/html/config/ini-co...applications_section
Last edit: 10 years 9 months ago by dgarrett.

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

More
10 years 9 months ago #67750 by Simpson36
dgarret,

Thanks for the tip. I could not get it to work, unfortunately :(

This seems like it would be a common thing to do, but apparently not.

The documentation says that the python hal ("import hal") can read any pin, but I cannot get that to work either. If I try to set and existing pin group name to hal.component, it says 'duplicate' and it won't take any text as a pin name.

putting the python program in [APPLICATIONS] stops LinuxCNC from starting, whether the program name is used or if it is called by a hal file.

So, with LinuxCNC, there is no way for a python program to read/write existing pins and no way to load a python program at startup?

That's just crazy time :ohmy:

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

More
10 years 9 months ago - 10 years 9 months ago #67751 by dgarrett
Another alternative is haltcl. The commands are almost identical to
halcmd commands and all functionality is available.

linuxcnc.org/docs/2.7/html/hal/haltcl.html

Example (linuxcnc running in a separate shell):
Code:
$ haltcl haltcl: loadrt flipflop names=ff Component 'flipflop' ready Program '/data/s/linuxcnc-dev/bin/rtapi_app' started Realtime module 'flipflop' loaded haltcl: haltcl: show pin ff Component Pins: Owner Type Dir Value Name 80 bit IN FALSE ff.clk 80 bit IN FALSE ff.data 80 bit I/O FALSE ff.out 80 bit IN FALSE ff.reset 80 bit IN FALSE ff.set 80 s32 OUT 0 ff.time haltcl: haltcl: setp ff.data 1 setting parameter 'ff.data' to '1' Pin 'ff.data' set to 1 haltcl: haltcl: show pin ff Component Pins: Owner Type Dir Value Name 80 bit IN FALSE ff.clk 80 bit IN TRUE ff.data 80 bit I/O FALSE ff.out 80 bit IN FALSE ff.reset 80 bit IN FALSE ff.set 80 s32 OUT 0 ff.time haltcl:
Last edit: 10 years 9 months ago by dgarrett.
The following user(s) said Thank You: Simpson36

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

More
10 years 9 months ago - 10 years 9 months ago #67754 by newbynobi
Hallo Simpson36,

if you add a embedded tab in your ini with a command like:
Code:
gladevcp -x {XID} -u plasma.py -H plasma.hal plasma.glade

it will load first the glade panel, than excecute the hal file and include the python file as a handler file. so you can make what ever u want.

You can look at sim / gmoccapy / gmoccapy_plasma for an example, as it do handle it your way.

In your handler file, you add two own hal pin with your component name one in and one out,
and connect the in change signal to your own handler.
In the hal file connect whatever pin you want to your component in hal pin.
The handler can now change the out pin to any value.
The out pin is again connected in your hal file to any other pin.

So where is the problem?

Please give a detailed example.

Norbert
Last edit: 10 years 9 months ago by newbynobi.

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

More
10 years 9 months ago - 10 years 9 months ago #67755 by Simpson36
Norbert,

Thanks for the info. I know and understand what you said, but as I mentioned earlier, the problem with the python handlers is that there is no way to access any pin outside the def for each pin, so the glade stuff, while great for hooking up single signals to single screen controls (apparently what it is designed to do), but it is extremely awkward to get data from one pin to another using the handlers. I was able to get it done using a bunch of variables to transfer the data from one handler to another, but that would be something of a nightmare because it is critical to know if the data is current at all times.

It does not seem to me like what I want to do is at all unusual and the project is to port devices over from MACH3/MACH4, both of which have scripting that has access to the Modbus and is part of the programs.

The be specific, I need to get data off multiple Modbus registers, manipulate that data with calculations, conditional statements, etc and put it back on the Modbus. This is very simple stuff and so far here seems no way to do it in LinuxCNC.

The Hal component for Python is useable and I have that working to do these tasks, but now I cannot get it to load in LinuxCNC at startup. If I make the program executable, it runs fine, creates the pins and stays resident doing the communications (command/ acknowledge loops). The HAL comp seems to have no way to 'net' the pins, so I have to then make a separate .hal file that has to run after the python code to net the pins.

Awkward as heck, but at least it is all working. I could live with this if there is a way to get the stuff to load when LinuxCNC starts up, but so far there is no solution.

Any ideas would be most welcome!


Should I be looking at Bash instead of Python?
Last edit: 10 years 9 months ago by Simpson36.

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

Time to create page: 0.064 seconds
Powered by Kunena Forum