I can not seem to make this work the way I wanted it to (with python directly accessing the parameter values)
But I was able to mostly accomplish what I wanted using a tclsh script posted here.
forum.linuxcnc.org/38-general-linuxcnc-q...-a-variable?start=10
It isn't as neat and tidy as I would like it to be, and requires me to do more in the g-code and use m66and m68 to get the values in and out of Linuxcnc. But at least it works.
The M-code
Code:
#!/usr/bin/tclsh
# EDIT here to set ::the_pin_name as required:
set ::the_pin_name motion.analog-in-00
# Note: This file must:
# have execute permissions (chmod +x this_file_name)
# be located according to rules for user M codes
# exist before starting LinuxCNC
#------------------------------------------------------------------
set ::prog [file tail $::argv0]
package require Hal
package require Tk
set ::default_value [hal getp motion.analog-out-00]
set ::value $::default_value
proc go {} {
if [catch {
puts "$::prog:$::the_pin_name before: [hal getp $::the_pin_name]"
hal setp $::the_pin_name $::value
puts "$::prog:$::the_pin_name after: [hal getp $::the_pin_name]"
} msg ] {
set ::value "FIXME"
popup "ERROR\n\n$msg"
} else {
exit 0
}
}
proc abort {} {
popup "Aborting Gcode program"
exit 1
}
proc err_exit {msg} {
popup $msg
exit 1
}
proc popup {msg} {
puts stderr "$::prog: $msg"
tk_messageBox \
-title "$::prog:$::the_pin_name" \
-type ok \
-message "$msg"
}
wm title . "$::prog pin: $::the_pin_name"
wm protocol . WM_DELETE_WINDOW {puts "$::prog: window close disallowed"}
pack [label .l -text "Enter Value:"] -side left
pack [entry .e -textvar ::value] -side left
bind .e <Return> go
pack [button .b -text Go -command go] -side left
pack [button .a -text Abort -command abort] -side left
And and this is the G-code that goes with it.
Code:
#<_change>=3.6
o10 if [EXISTS[#<_width>]]
(debug, _global exists and has the value #<_width>)
o10 else
(debug, _width does not exist set to default value)
#<_width>=3.6
o10 endif
m68 e0 q#<_width>
M100
m66 e0 l0
#<_width>=#5399
(debug,_width set to #<_width>)