Reading and writing to Parameter Variables?

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • 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.

  • Aciera
  • Aciera's Avatar
  • Away
  • Administrator
  • Administrator
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.
The following user(s) said Thank You: Todd Zuercher

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

  • Aciera
  • Aciera's Avatar
  • Away
  • Administrator
  • Administrator
More
18 Jun 2026 14:14 - 18 Jun 2026 17:14 #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 17:14 by Aciera.
The following user(s) said Thank You: Todd Zuercher, NWE

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

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
18 Jun 2026 18:03 #347152 by Todd Zuercher
Replied by Todd Zuercher on topic Reading and writing to Parameter Variables?
I'm a little disappointed that there is no way to read/monitor them directly, but I was coming to that conclusion. Now to figure out the best work aroud. I'll probably end up trying to do what you suggest. Thanks for your help.

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

  • Todd Zuercher
  • Todd Zuercher's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
18 Jun 2026 21:04 #347155 by Todd Zuercher
Replied by Todd Zuercher on topic Reading and writing to Parameter Variables?
Would there be a way for the python handler for the vcp, to call or reference to python remap script that can access the interpreter variables?  With as little python programming skill as i have this seems like it could be possible, I wouldn't know if that is completely impossible, or not any better than writing to an intermediary file.

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

  • Aciera
  • Aciera's Avatar
  • Away
  • Administrator
  • Administrator
More
19 Jun 2026 05:53 - 22 Jun 2026 18:40 #347159 by Aciera
Replied by Aciera on topic Reading and writing to Parameter Variables?
The example code can be used inside a python remap and the handler could read the file with the parameter values but the remap itself would have to be called from inside the gcode program which is currently executing.
So if you wanted your parameter page to reflect changes coming from the gcode program you would need to insert the remap after every parameter assignment in the gcode.

Another way to expose parameter values is to send them to a hal pin:

'M68 E0 Q#500' will expose parameter value 500 to the hal pin 'motion.analog-out-00' which you can then connect to your gladevcp display.
Note that the M68 code would need to be called every time after the #500 parameter is changed in the gcode and every parameter will need its own analog pin.

You could create a custom G- or M-Code to handle assigning and exposing parameter values in a single line and/or use a filter script to search for parameter assignments and add the appropriate M68 code to expose it.
Last edit: 22 Jun 2026 18:40 by Aciera. Reason: Add M68 alternative

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

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