#!/bin/sh  
# \
exec oagtclsh "$0" "$@"


set auto_path [linsert $auto_path 0  /usr/local/oag/apps/lib/$env(HOST_ARCH)]
set auto_path [linsert $auto_path 0 /usr/local/oag/lib_patch/$env(HOST_ARCH)]

APSStandardSetup

set channel 3
set instName 164.54.1.68 
#set outPV L:LR:quantumEfficiencyM 
set outPV ""
set args $argv
APSParseArguments {channel instName outPV}

if [catch {exec sendHP9000ScopeCommand -instName $instName -command ":MEAS:VAMP CHAN$channel" } result] {
    puts stderr "Error1: $result"
    exit 1
}
if [string length $outPV] {
    if [pv linkw outVar $outPV] {
        puts stderr "Error link pv $outPV: $errorCode"
        exit 1
    }
    while {1} {
        if [catch {exec sendHP9000ScopeCommand -instName $instName -command ":MEAS:VAMP?" } result] {
            puts stderr "Error2: Error reading the amplitude: $result"
            exit 1
        }
        set outVar $result
        if [pv putw outVar] {
            puts stderr "Error setting pv $outPV to $outVar: $result"
            exit 1
        }
        after 1000
    }
} else {
    if [catch {exec sendHP9000ScopeCommand -instName $instName -command ":MEAS:VAMP?" } result] {
        puts stderr "Error2: Error reading the amplitude: $result"
        exit 1
    }
    puts $result
}
    
exit 0
