Reading data from var file using Python

More
1 year 1 month ago #335627 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!

Please Log in to join the conversation.

More
1 year 4 weeks ago #335665 by andypugh
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

Please Log in to join the conversation.

More
1 year 4 weeks ago #335684 by cmorley
try a mode change: mdi to manual back to mdi.
It forces the vars to be saved to file.

Please Log in to join the conversation.

More
1 year 4 weeks ago #335716 by Ahmed.emara
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 :)

Please Log in to join the conversation.

More
1 year 4 weeks ago #335732 by andypugh
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 )

Please Log in to join the conversation.

Time to create page: 0.086 seconds
Powered by Kunena Forum