Read value or file in G-code
- Doc_emmet
- Offline
- New Member
-
Less
More
- Posts: 17
- Thank you received: 2
02 Jul 2025 18:58 - 02 Jul 2025 19:01 #331118
by Doc_emmet
Read value or file in G-code was created by Doc_emmet
Hello, I want to use QtDragon to determine the tool height using Utils - Workpiece and then save the result so that I can access the value in the G-code. My idea was to save the result to a file, which also works by slightly modifying the auto_height.py file. I added the following line:
def show_result(self, data):
diff = float(data) - float(data)
self.lineEdit_height.setText(format(diff, '.3f'))
# New line by me:
with open('/home/dg/linuxcnc/nc_files/probe_height.txt', 'w') as f: f.write(str(diff))
But how can I access the value stored in the probe_height file in a measurement routine.ngc, or can I save the measured value directly in
the G-coder as a variable, e.g., #5000
def show_result(self, data):
diff = float(data) - float(data)
self.lineEdit_height.setText(format(diff, '.3f'))
# New line by me:
with open('/home/dg/linuxcnc/nc_files/probe_height.txt', 'w') as f: f.write(str(diff))
But how can I access the value stored in the probe_height file in a measurement routine.ngc, or can I save the measured value directly in
the G-coder as a variable, e.g., #5000
Last edit: 02 Jul 2025 19:01 by Doc_emmet.
Please Log in or Create an account to join the conversation.
- andypugh
-
- Offline
- Moderator
-
Less
More
- Posts: 23395
- Thank you received: 4971
11 Jul 2025 20:10 #331712
by andypugh
Replied by andypugh on topic Read value or file in G-code
This isn't elegant, but if your python file imports "hal" then you can create a HAL pin, put the value on that, and then read that value in your G-code.
The most reliable way to do this is to "net" it to one of the G-code analogue inputs and read it with M66. But you can also use the #<hal[mymodule.pinname]> format in the G-code. Just be aware that the latter method will generally get the value that was on the pin when the G-code program starts and won't see any live updates.
linuxcnc.org/docs/html/gcode/overview.html#gcode:ini-hal-params
The most reliable way to do this is to "net" it to one of the G-code analogue inputs and read it with M66. But you can also use the #<hal[mymodule.pinname]> format in the G-code. Just be aware that the latter method will generally get the value that was on the pin when the G-code program starts and won't see any live updates.
linuxcnc.org/docs/html/gcode/overview.html#gcode:ini-hal-params
Please Log in or Create an account to join the conversation.
Time to create page: 0.057 seconds