Package: electronsourcecontroller2-tspspi
Custom electron gun slow control Python communication library and GUI utlityWork in progressCommunication libraryThe communication library fromeguncom.pyimplements most of the
communication protocol with the electron beam slow-control system.class ElectronGunControlTheElectronGunControlclass implements asynchronous and synchronous
communication with the serially / USB attached control system. The port file
is passed to the constructorctrl = ElectronGunNotConnected(portFile = '/dev/...')When no port file is passed it defaults to/dev/ttyU0.The exposed public methods are:MethodDescriptionSynchronousAsynchronous callbackid()Queries the current versionwith sync = TruecbIdentify(controller, versionDate, versionRevision)getPSUVoltage(channel)Queries the current voltage on the given channelwith sync = TruecbVoltage(controller, channel, voltageVolts)getPSUCurrent(channel)Queries the current current on the given channelwith sync = TruecbCurrent(controller, channel, currentMicroamps)getPSUModes()Checks if PSUs are off, in voltage limited or current limited modewith sync = TruecbPSUMode(controller, states)getFilamentCurrent()Queries the filament currentwith sync = TruecbFilamentCurrent(controller, current)off()Disabled all high voltage and filament currentssetPSUPolarity(channel, polarity)Sets polarity to POLARITY_POS or POLARITY_NEGsetPSUEnable(channel)Enables the given PSU channelsetPSUDisable(channel)Disables the given PSU channelsetPSUVoltage(channel, voltage)Sets the given channel to the given voltagesetFilamentCurrent(currentMa)Sets the filament current or target current to the specified milliampssetFilamentOn()Enabled the filament supplysetFilamentOff()Disabled the filament supplyrunInsulationTest()Runs an insulation test with low current limitswith sync = TruecbInsulation(isOk, listOfShorts)beamOn()Runs the slow beam on sequence (slowly heating filament to previously set setFilamentCurrent, ramping up voltages)with sync = TruecbBeamon()Usage exampleSynchronous sample (USB / serial)Example to perform asynchronous:Insulation checkStartup for 100 mA beam currentLooping through focus voltagesShutting downwith ElectronGunControl() as ctrl:
    # Currently a hack to wait for the control system to reset when using the
    # primary port

    time.sleep(5)

    # We want to see the voltages reported by the system so we
    # define a lambda that just prints the voltages while ramping up
    # during insulation test and beam on sequence

    ctrl.cbVoltage = lambda c,chan,v : print("Voltage for channel {} is {} V".format(chan, v))

    # Query it's identity
    ret = ctrl.id(sync = True)
    print("ID call returned {}".format(ret))

    # Run insulation test
    print("Running insulation test")
    ret = ctrl.runInsulationTest(sync = True)
    print("Insulation test returned: {}".format(ret))

    # Run beam on sequence ...
    ret = ctrl.beamOn(sync = True)
    print("Beam on successfully returned: {}".format(ret))

    print("Sweeping focus voltage")
    for focusVoltage in range(1750,1950):
        print("New focus voltage {}".format(focusVoltage))
        ctrl.setPSUVoltage(3, focusVoltage)
        time.sleep(1)

    ctrl.off()
    print("Off, done ...")