AI on demand once

 1'''
 2AI24Bit - AI_on_demand_once.py with synchronous mode.
 3
 4This example demonstrates the process of obtaining AI data in on demand mode.
 5Additionally, it retrieve AI data from EthanI.
 6
 7-------------------------------------------------------------------------------------
 8Please change correct serial number or IP and port number BEFORE you run example code.
 9
10For other examples please check:
11    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
12See README.md file to get detailed usage of this example.
13
14Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
15'''
16
17## Python
18import time
19
20## WPC
21
22from wpcsys import pywpc
23
24def main():
25    ## Get Python driver version
26    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
27
28    ## Create device handle
29    dev = pywpc.EthanI()
30
31    ## Connect to device
32    try:
33        dev.connect("192.168.1.110") ## Depend on your device
34    except Exception as err:
35        pywpc.printGenericError(err)
36        ## Release device handle
37        dev.close()
38        return
39
40    try:
41        ## Parameters setting
42        port = 0 ## Depend on your device
43        timeout = 3 ## second
44
45        ## Get firmware model & version
46        driver_info = dev.Sys_getDriverInfo(timeout)
47        print("Model name: " + driver_info[0])
48        print("Firmware version: " + driver_info[-1])
49
50        ## Open AI
51        err = dev.AI_open(port, timeout)
52        print(f"AI_open in port {port}, status: {err}")
53
54        ## Read data acquisition
55        data =  dev.AI_readOnDemand(port, timeout)
56        print(f"data in port {port}: ")
57        print(f"{data}")
58
59        ## Close AI
60        err = dev.AI_close(port, timeout)
61        print(f"AI_close in port {port}, status: {err}")
62    except Exception as err:
63        pywpc.printGenericError(err)
64
65    ## Disconnect device
66    dev.disconnect()
67
68    ## Release device handle
69    dev.close()
70
71    return
72if __name__ == '__main__':
73    main()