Read value or file in G-code

More
1 year 3 months ago #331118 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
 

Please Log in to join the conversation.

More
1 year 3 months ago #331712 by andypugh
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

Please Log in to join the conversation.

Time to create page: 0.072 seconds
Powered by Kunena Forum