Reading data from var file using Python
- Ahmed.emara
- Offline
- New Member
-
Less
More
- Posts: 19
- Thank you received: 0
30 Sep 2025 15:41 - 02 Oct 2025 13:09 #335627
by Ahmed.emara
Reading data from var file using Python was created by Ahmed.emara
SOLVED!
Hello everyone, In my machine setup I probe some points and store them in the var file. The probing is done through a custom M-code, and the probed coordinates are saved into parameters (variables). After that, I want to read these parameters from a Python script. I managed to do it, but I found that the Python script only sees the updated values if I restart LinuxCNC.
After digging I found out that parameters are saved in internal memory and, while shutting down, they get copied into the var file.That's why when I restart, my Python script works fine.My question is:Is there a way to access the internal memory directly and read the arameters with a Python script so that I don't need to restart the machine? Or if not, is there another way to access the probed points live without restarting?Thanks in advance!
Hello everyone, In my machine setup I probe some points and store them in the var file. The probing is done through a custom M-code, and the probed coordinates are saved into parameters (variables). After that, I want to read these parameters from a Python script. I managed to do it, but I found that the Python script only sees the updated values if I restart LinuxCNC.
After digging I found out that parameters are saved in internal memory and, while shutting down, they get copied into the var file.That's why when I restart, my Python script works fine.My question is:Is there a way to access the internal memory directly and read the arameters with a Python script so that I don't need to restart the machine? Or if not, is there another way to access the probed points live without restarting?Thanks in advance!
Last edit: 02 Oct 2025 13:09 by Ahmed.emara.
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
Less
More
- Posts: 22933
- Thank you received: 4945
01 Oct 2025 14:56 #335665
by andypugh
Replied by andypugh on topic Reading data from var file using Python
I have looked into this in the past, and concluded that it's not particularly easy.
forum.linuxcnc.org/pathpilot/45260-passi...ode-to-python#236301
In your case the answer probably is to send the probed points out of G-code on HAL pins into a python routine that is monitoring them.
For a small set of values you could use one pin per value, for a larger number maybe one pin to send the value and another to indicate which parameter it corresponds to.
linuxcnc.org/docs/stable/html/gcode/m-code.html#mcode:m68
forum.linuxcnc.org/pathpilot/45260-passi...ode-to-python#236301
In your case the answer probably is to send the probed points out of G-code on HAL pins into a python routine that is monitoring them.
For a small set of values you could use one pin per value, for a larger number maybe one pin to send the value and another to indicate which parameter it corresponds to.
linuxcnc.org/docs/stable/html/gcode/m-code.html#mcode:m68
The following user(s) said Thank You: Ahmed.emara
Please Log in or Create an account to join the conversation.
- cmorley
- Away
- Moderator
-
Less
More
- Posts: 7896
- Thank you received: 2165
02 Oct 2025 01:23 #335684
by cmorley
Replied by cmorley on topic Reading data from var file using Python
try a mode change: mdi to manual back to mdi.
It forces the vars to be saved to file.
It forces the vars to be saved to file.
The following user(s) said Thank You: tommylight, Ahmed.emara
Please Log in or Create an account to join the conversation.
- Ahmed.emara
- Offline
- New Member
-
Less
More
- Posts: 19
- Thank you received: 0
02 Oct 2025 13:08 #335716
by Ahmed.emara
Replied by Ahmed.emara on topic Reading data from var file using Python
thank you andy for this idea
i tried to make python script that reads the 2 hal pins but the problem is that due to the higher speed of changing the values in the hal pins the python script wasnt able to read all the values correctly there are some data missing and i tried cmorley idea to switch manual with simple python script and it did work
i tried to make python script that reads the 2 hal pins but the problem is that due to the higher speed of changing the values in the hal pins the python script wasnt able to read all the values correctly there are some data missing and i tried cmorley idea to switch manual with simple python script and it did work

Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
Less
More
- Posts: 22933
- Thank you received: 4945
02 Oct 2025 16:50 #335732
by andypugh
Replied by andypugh on topic Reading data from var file using Python
Yes, to make my idea work you would need to either have pause commands in the G-code to give the Python time to see the new value, or implement some sort of flow control where the G-code sends a pair of values then waits for a rising edge on a third HAL pin pointing the other way.
(See M66 linuxcnc.org/docs/html/gcode/m-code.html#mcode:m66 )
(See M66 linuxcnc.org/docs/html/gcode/m-code.html#mcode:m66 )
Please Log in or Create an account to join the conversation.
Time to create page: 0.068 seconds