How to prompt a user for input to set a variable
24 Mar 2015 21:40 - 24 Mar 2015 21:42 #57149
by dgarrett
Replied by dgarrett on topic How to prompt a user for input to set a variable
An example script for a user M code to prompt user for input:
A demonstration gcode program using the script with name M131
#!/usr/bin/tclsh
# EDIT here to set ::the_pin_name as required:
set ::the_pin_name motion.analog-in-00
set ::default_value 0
# 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]
set ::value $::default_value
package require Hal
package require Tk
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
A demonstration gcode program using the script with name M131
%
; demonstrate user prompt using m131
g0 x0
f100 g1 x1
m66 e0 l0 ; read motion.analog-in-00 pin
(debug, before=#5399)
m131 ; prompt user for input to motion.analog-in-00 pin
m66 e0 l0 ; read motion.analog-in-00 pin
(debug, after=#5399)
g1 x0 ; continue program
%
Last edit: 24 Mar 2015 21:42 by dgarrett.
The following user(s) said Thank You: Treetop
Please Log in or Create an account to join the conversation.
26 Mar 2015 03:09 #57190
by Treetop
Replied by Treetop on topic How to prompt a user for input to set a variable
Many thanks for the input.
I will have a go at getting my head around TCL.
Jeff
I will have a go at getting my head around TCL.
Jeff
Please Log in or Create an account to join the conversation.
Time to create page: 0.074 seconds