diff --git a/mount_tnc/raspberry/astro_resources.tcl b/mount_tnc/raspberry/astro_resources.tcl new file mode 100644 index 0000000..5220032 --- /dev/null +++ b/mount_tnc/raspberry/astro_resources.tcl @@ -0,0 +1,124 @@ +# source C:/d/rapido/rapido2/actions_incitatives_2019/orientalmotor/test3.tcl + +# source C:/d/rapido/rapido2/actions_incitatives_2019/orientalmotor/test3.tcl +# set f [az_open] +# set cmd ":e1" +# puts -nonewline $f "${cmd}\r" +# flush $f + +# ==================================== +# === Tools : Open/close communication +# ==================================== + +proc az_close { } { + global audace + if {[info exists audace(orientalmotor,fid)]==0} { + error "Communication not previously opened" + } + set f $audace(orientalmotor,fid) + close $f + unset audace(orientalmotor,fid) +} + +proc az_open { {port //./COM6} } { + global audace + if {[info exists audace(orientalmotor,fid)]==1} { + error "Port $port ever opened" + } + set err [catch { + set f [open $port w+] + fconfigure $f -mode 115200,n,8,1 -buffering none -blocking 0 + after 2000 + } msg] + if {$err==1} { + error $msg + } + set audace(orientalmotor,fid) $f + az_delay 200 + return $f +} + +proc az_open_if_needed { } { + global audace + if {[info exists audace(orientalmotor,fid)]==0} { + az_open + } +} + +# ==================================== +# === Tools : Put/Get messages +# ==================================== + +proc az_delay { {delay ""} } { + global audace + if {$delay==""} { + set delay $audace(orientalmotor,delay) + } else { + set audace(orientalmotor,delay) $delay + } + after $delay +} + +proc az_put { cmd } { + global audace + az_open_if_needed + set f $audace(orientalmotor,fid) + puts -nonewline $f "${cmd}\r" + flush $f + az_delay +} + +proc az_read { } { + global audace + az_open_if_needed + set f $audace(orientalmotor,fid) + set result "" + set t0 [clock milliseconds] + set sortie 0 + while {$sortie==0} { + set res [read -nonewline $f] + if {$res==""} { + set sortie 1 + break + } + append result $res + set dt [expr [clock milliseconds]-$t0] + if {$dt>1000} { + set sortie 2 + break + } + after 100 + } + return $result +} + +proc az_putread { cmd } { + global audace + az_read + az_put $cmd + set res [az_read] + #return $res + # --- search for the echo of the command name + set k [string last ${cmd} $res] + if {$k<0} { + error "No response" + } + set res [string range $res $k end] + # --- search for the = symbol to isolate the value + set k [string first = $res] + if {$k>=0} { + set res [string range $res [expr 1+$k] end] + # --- take only the first element of the response as value + set res [split $res \n] + set value [lindex $res 0] + } else { + # --- take only the second element of the response as value + set res [split $res \n] + set value [lindex $res 1] + } + return $value +} + +# ==================================== +# === Tools : high level functions +# ==================================== -- libgit2 0.21.2