Reading and writing to Parameter Variables?

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Away
  • Platinum Member
  • Platinum Member
More
18 Jun 2026 09:44 #347145 by Todd Zuercher
Reading and writing to Parameter Variables? was created by Todd Zuercher
I would like to set up a GladeVCP tab (in Axis) that displays and can set the values for a range G-code numbered parameter variables, similar to how most industrial control interfaces have.  I tried to use AI to write the handler file, but that is failing for me.  I used Glade to make the tab screen and that looks good and opens in the tab, it just doesn't do anything yet.  When running Linuxcnc from the terminal I'm not seeing any messages that are helping me see what is wrong.  Here are the glade and py files I have so far.

 

File Attachment:

File Name: variables.py
File Size:1 KB

 

File Attachment:

File Name: variables.glade
File Size:32 KB
Attachments:

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

More
18 Jun 2026 12:41 - 18 Jun 2026 13:22 #347147 by Aciera
Replied by Aciera on topic Reading and writing to Parameter Variables?
1. Are you sure you are actually loading 'variables.py' along with the 'variables.glade' in the ini file entry?

2. This method of reading the initial parameter values is nonsense as there is no access to the parameter values from the status channel:

# Set initial value from LinuxCNC parameters
self.s.poll()
spin.set_value(self.s.settings)

see linuxcnc.org/docs/html/config/python-interface.html for information on the 'settings' attribute.

Some thoughts on this:
a. The parameter range you are trying to read is volatile so they will all be Zero on start up. See linuxcnc.org/docs/stable/html/gcode/over...:overview-parameters
b. The only way to get the current value of any parameter is to read the value through an MDI command and grab the response.
c. Because of (b) there is no way I know of to actually query the state of a parameter while a gcode program is executing. Which implies that you would need to have something like a 'Refresh' button to read the current values of those parameters if they were changed by the execution of a gcode program.
Last edit: 18 Jun 2026 13:22 by Aciera.

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

More
18 Jun 2026 14:14 - 18 Jun 2026 14:16 #347150 by Aciera
Replied by Aciera on topic Reading and writing to Parameter Variables?
This example code will read parameters 5200..5299 and write the values to a file 'log.txt', in a next step you would read the file and extract the values to initialize the spin boxes:

import linuxcnc

c = linuxcnc.command()
c.mode(linuxcnc.MODE_MDI)
c.wait_complete()
# write parameter values to log.txt
# file will be in the same dir as the ini
c.mdi('(LOGOPEN,log.txt)')
c.wait_complete()
for p in range(5200,5300):
cmd = f"(LOG,{p},#{p})"
c.mdi(cmd)
c.mdi('(LOGCLOSE)')
Last edit: 18 Jun 2026 14:16 by Aciera.
The following user(s) said Thank You: NWE

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

Moderators: HansU
Time to create page: 0.209 seconds
Powered by Kunena Forum