proc RFGUN_Switch_OnlyInfo {args} {
    return "This switches the rf gun and turns off the modulators but does not start the other gun. That is left to the user. The new gun's power supplies are turned on if there were off and set to 0.\n\nIf the gun is powered by K1 the PEM will cause K3 to go through a timing mode switch."
}

#Need a fake SCRFile

proc RFGUN_Switch_Only {args} {
    APSMpStep init -promptDialog "APSMpPromptInitDialog"

    #Hard coding the SCR file. This is just a place holder.
    set SCRFile /home/helios/oagData/SCR/snapshots/LPL/LPL-SysRef_PAR_RF1_T2_RF12_T2.gz

    if [catch {APSLinkToLINACPVs} result] {
        return -code error "RFGUN_Switch_Only: $result"
    }
   #RG1
    if {[catch {APSRFGUN_DetectSelectedGun} gun]} {
        APSMpReturn error "RFGUN_Switch_Only: $gun"
    }
    if {$gun == "RG2"} {
        set deviceList "L1:RG1:H1 L1:RG1:V1 L1:RG1:H2 L1:RG1:V2 L1:RG1:H3 L1:RG1:V3 L1:RG1:Q1 L1:RG1:Q2 L1:RG1:Q3 L1:RG1:Q4 L1:H1 L1:V1 L1:H2 L1:V2 L1:Q1 L1:Q2"
    } elseif {$gun == "RG1"} {
        set deviceList "L1:RG2:V1 L1:RG2:H2 L1:RG2:V2 L1:RG2:H3 L1:RG2:V3 L1:RG2:Q1 L1:RG2:Q2 L1:RG2:Q3 L1:RG2:Q4 L1:H1 L1:V1 L1:H2 L1:V2 L1:Q1 L1:Q2"
    } else {
        APSMpReturn error "RFGUN_Switch_Only: Unable to detect selected gun"
    }
    if [catch {APSDevSend -releaseLinks 1 -group LinacPS -operation QueryOff -deviceList $deviceList} offList] {
        APSMpReturn error "RFGUN_Switch_Only: $offList"
    }
    foreach device $deviceList off $offList {
        if {$off} {
            if [catch {APSDevSend -releaseLinks 1 -group LinacPS -operation SetCurrent -deviceList $device -valueList 0} result] {
                APSMpReturn error "RFGUN_Switch_Only: $result"
            } 
        }
    }
    APSWaitWithUpdate -waitSeconds 1
    foreach device $deviceList off $offList {
        if {$off} {
            if [catch {APSDevSend -releaseLinks 1 -group LinacPS -operation TurnOn -deviceList $device} result] {
                APSMpReturn error "RFGUN_Switch_Only: $result"
            } 
        }
    }
     
    if {[catch {LPL_Configure -Modulators 0 -PowerSupplies 0 -examineSCRFile 0 -RFGUN 1 -startupLTP 0 -startupPAR 0 -startupPTB 0 -startupPARBypass 0 -SCRFile $SCRFile -forceChangeGunOnly 1} result]} {
        APSMpReturn error "RFGUN_Switch_for_Only: $result"
    }
    APSMpReturn ok
}

