
proc APSSRStartStandardCorrection {args} {
    APSMpReturn error "APSSRStartStandardCorrection: This procedure no longer available."
}

proc APSStartSROrbitControllaw {args} {
    APSMpReturn error "APSSRStartSROrbitControllaw: This procedure no longer available."
}

proc APSAbortControllaw {args} {
    set runControlPV ""
    set clear 0
    set statusCallback ""
    set timeout 100
    set sourceID controllawAudit
    APSStrictParseArguments {runControlPV clear statusCallback sourceID timeout}
    
    if ![string length $runControlPV] {
        APSMpReturn error "AbortControllaw: No runControlPV supplied."
    }
    # Don't need to abort if not running.
    if ![exec cavget -list=${runControlPV}.RUN -numerical] {
        APSMpReturn ok 0
    }
    if [string length $statusCallback] {
        eval $statusCallback {"Aborting $runControlPV..."}
    }
    if [string length $sourceID] {
        if [ catch {exec logMessage  -sourceId=$sourceID \
                      -tag=Instance $runControlPV -tag=Action Abort \
                  } result ] {
            APSAlertBox .alert -errorMessage "error with logMessage: $result"
        }
    }
    if [ catch {exec cavput -list=${runControlPV}.ABRT=1 -pend=30} result ] {
        APSMpReturn error "APSAbortControllaw: $result"
    }
    after 2000
    if $clear {
        if [string length $statusCallback] {
            eval $statusCallback {"Waiting for $runControlPV to clear..."}
        }
        if [catch {exec cawait -waitfor=$runControlPV.RUN,equal=0 -timeLimit=$timeout} result] {
            APSMpReturn error "Problem aborting $runControlPV: $result"
        }
        if [catch {exec cavput -list=$runControlPV.CLR=1 -pend=30} result] {
            APSMpReturn error "Problem clearing $runControlPV: $result"
        }
    }
    if [string length $statusCallback] {
        eval $statusCallback {"$runControlPV is aborted."}
    }
    APSMpReturn ok 0
}

proc APSSuspendControllaw {args} {
    set runControlPV ""
    APSStrictParseArguments {runControlPV}

    if ![string length $runControlPV] {
        APSMpReturn error "AbortControllaw: No runControlPV supplied."
    }
    if [ catch {exec logMessage  -sourceId=controllawAudit\
                  -tag=Instance $runControlPV -tag=Action Suspend \
              } result ] {
        APSAlertBox .alert -errorMessage "error with logMessage: $result"
    }
    if [ catch {exec caput $runControlPV.SUSP 1} result ] {
        APSMpReturn error "APSAbortControllaw: $result"
    }
    APSMpReturn ok 0
}

proc APSResumeControllaw {args} {
    set runControlPV ""
    APSStrictParseArguments {runControlPV}

    if ![string length $runControlPV] {
        APSMpReturn error "AbortControllaw: No runControlPV supplied."
    }
    if [ catch {exec logMessage  -sourceId=controllawAudit\
                  -tag=Instance $runControlPV -tag=Action Resume \
              } result ] {
        APSAlertBox .alert -errorMessage "error with logMessage: $result"
    }
    if [ catch {exec caput $runControlPV.SUSP 0} result ] {
        APSMpReturn error "APSAbortControllaw: $result"
    }
    APSMpReturn ok 0
}

