AO write one channel

  1'''
  2AO - AO_write_one_channel.py with synchronous mode.
  3
  4This example demonstrates the process of writing AO signal of STEM.
  5To begin with, it demonstrates the steps to open AO.
  6Next, it outlines the procedure for writing digital signals with channel to the AO pins.
  7Finally, it concludes by explaining how to close AO.
  8
  9If your product is "STEM", please invoke the function `Sys_setAIOMode`.
 10
 11-------------------------------------------------------------------------------------
 12Please change correct serial number or IP and port number BEFORE you run example code.
 13
 14For other examples please check:
 15    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
 16See README.md file to get detailed usage of this example.
 17
 18Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
 19'''
 20
 21## Python
 22import time
 23
 24## WPC
 25
 26from wpcsys import pywpc
 27
 28
 29def main():
 30    ## Get Python driver version
 31    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
 32
 33    ## Create device handle
 34    dev = pywpc.STEM()
 35
 36    ## Connect to device
 37    try:
 38        dev.connect("192.168.1.110") ## Depend on your device
 39    except Exception as err:
 40        pywpc.printGenericError(err)
 41        ## Release device handle
 42        dev.close()
 43        return
 44
 45    try:
 46        ## Parameters setting
 47        slot = 1 ## Connect AIO module to slot
 48        ao_value_list = [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5]
 49        timeout = 3 ## second
 50
 51        ## Get firmware model & version
 52        driver_info = dev.Sys_getDriverInfo(timeout)
 53        print("Model name: " + driver_info[0])
 54        print("Firmware version: " + driver_info[-1])
 55
 56        ## Get slot mode
 57        slot_mode = dev.Sys_getMode(slot, timeout)
 58        print("Slot mode:", slot_mode)
 59
 60        ## If the slot mode is not set to "AIO", set the slot mode to "AIO"
 61        if slot_mode != "AIO":
 62            err = dev.Sys_setAIOMode(slot, timeout)
 63            print(f"Sys_setAIOMode in slot {slot}, status: {err}")
 64
 65        ## Get slot mode
 66        slot_mode = dev.Sys_getMode(slot, timeout)
 67        print("Slot mode:", slot_mode)
 68
 69        ## Open AO
 70        err = dev.AO_open(slot, timeout)
 71        print(f"AO_open in slot {slot}, status: {err}")
 72
 73        ## Write AO vaule in channel 0
 74        err = dev.AO_writeOneChannel(slot, 0, ao_value_list[0], timeout)
 75        print(f"In slot {slot} channel 0, the AO value is {ao_value_list[0]}, status: {err}")
 76
 77        ## Write AO vaule in channel 1
 78        err = dev.AO_writeOneChannel(slot, 1, ao_value_list[1], timeout)
 79        print(f"In slot {slot} channel 1, the AO value is {ao_value_list[1]}, status: {err}")
 80
 81        ## Write AO vaule in channel 2
 82        err = dev.AO_writeOneChannel(slot, 2, ao_value_list[2], timeout)
 83        print(f"In slot {slot} channel 2, the AO value is {ao_value_list[2]}, status: {err}")
 84
 85        ## Write AO vaule in channel 3
 86        err = dev.AO_writeOneChannel(slot, 3, ao_value_list[3], timeout)
 87        print(f"In slot {slot} channel 3, the AO value is {ao_value_list[3]}, status: {err}")
 88
 89        ## Close AO
 90        err = dev.AO_close(slot)
 91        print(f"AO_close in slot {slot}, status: {err}")
 92    except Exception as err:
 93        pywpc.printGenericError(err)
 94
 95    ## Disconnect device
 96    dev.disconnect()
 97
 98    ## Release device handle
 99    dev.close()
100
101    return
102
103if __name__ == '__main__':
104    main()