Ejemplo n.º 1
0

def pressureTask(pressureIndex, period):
    """Set the selected pressure channel to a random value every [period] seconds"""
    minPressure, maxPressure = fgt_get_pressureRange(pressureIndex)
    while not cancellationToken:
        pressureOrder = random.random() * maxPressure
        fgt_set_pressure(pressureIndex, pressureOrder)
        print("task {}: New pressure order: {:.2f} mbar".format(
            pressureIndex, pressureOrder))
        time.sleep(period)


## Initialize the session
# This step is mandatory before starting threads at the same time
fgt_init()

## Create the threads
# Thread 1: drives the first pressure channel (index 0) every 2 seconds
thread1 = Thread(target=pressureTask, args=(0, 2))
# Thread 2: drives the second pressure channel (index 1) every 5 seconds
thread2 = Thread(target=pressureTask, args=(1, 5))

try:
    # Start the threads
    thread1.start()
    thread2.start()
    # Wait 10 seconds
    time.sleep(10)
finally:
    # Stop the threads
# Detect all controllers
SNs, types = fgt_detect()
controllerCount = len(SNs)
print('Number of controllers detected: {}'.format(controllerCount))

# List all found controllers' serial number and type
for i, sn in enumerate(SNs):
    print('Detected instrument at index: {}, ControllerSN: {}, type: {}'\
          .format(i, sn, str(types[i])))

## Initialize specific instruments
# Initialize only specific instrument controllers here If you do not want
# a controller in the list or if you want a specific order (e.g. LineUP
# before MFCS instruments), rearrange parsed SN table
fgt_init(SNs)

# Get total number of initialized pressure channels
print('Total number of pressure channels: {}'.format(fgt_get_pressureChannelCount()))

## Get detailed information about all controllers

controllerInfoArray = fgt_get_controllersInfo()
for i, controllerInfo in enumerate(controllerInfoArray):
    print('Controller info at index: {}'.format(i))
    print(controllerInfo)

## Get detailed information about all pressure channels

pressureInfoArray = fgt_get_pressureChannelsInfo()
for i, pressureInfo in enumerate(pressureInfoArray):