Set LED status

 1'''
 2System_Wifi - set_LED_status.py with asynchronous mode.
 3
 4This example demonstrates how to set LED status from WifiDAQF4A.
 5
 6-------------------------------------------------------------------------------------
 7Please change correct serial number or IP and port number BEFORE you run example code.
 8
 9For other examples please check:
10    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
11See README.md file to get detailed usage of this example.
12
13Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
14'''
15
16## Python
17import asyncio
18
19## WPC
20
21from wpcsys import pywpc
22
23async def main():
24    ## Get Python driver version
25    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
26
27    ## Create device handle
28    dev = pywpc.WifiDAQF4A()
29
30    ## Connect to device
31    try:
32        dev.connect("192.168.5.38") ## Depend on your device
33    except Exception as err:
34        pywpc.printGenericError(err)
35        ## Release device handle
36        dev.close()
37        return
38
39    try:
40        ## Parameters setting
41        value = 1
42
43        ## Get firmware model & version
44        driver_info = await dev.Sys_getDriverInfo_async()
45        print("Model name: " + driver_info[0])
46        print("Firmware version: " + driver_info[-1])
47
48        for i in range(3):
49            ## Reset LED status
50            err = await dev.Wifi_resetLED_async()
51            print(f"Wifi_resetLED_async, status: {err}")
52
53            ## Set green LED status
54            err = await dev.Wifi_setGreenLED_async(value)
55            print(f"Wifi_setGreenLED_async, status: {err}")
56            await asyncio.sleep(1) ## delay [s]
57
58            ## Reset LED status
59            err = await dev.Wifi_resetLED_async()
60            print(f"Wifi_resetLED_async, status: {err}")
61
62            ## Set blue LED status
63            err = await dev.Wifi_setBlueLED_async(value)
64            print(f"Wifi_setBlueLED_async, status: {err}")
65            await asyncio.sleep(1) ## delay [s]
66
67            ## Reset LED status
68            err = await dev.Wifi_resetLED_async()
69            print(f"Wifi_resetLED_async, status: {err}")
70
71            ## Set red LED status
72            err = await dev.Wifi_setRedLED_async(value)
73            print(f"Wifi_setRedLED_async, status: {err}")
74            await asyncio.sleep(1) ## delay [s]
75
76            print("")
77    except Exception as err:
78        pywpc.printGenericError(err)
79
80    ## Disconnect network device
81    dev.disconnect()
82
83    ## Release device handle
84    dev.close()
85
86    return
87
88def main_for_spyder(*args):
89    if asyncio.get_event_loop().is_running():
90        return asyncio.create_task(main(*args)).result()
91    else:
92        return asyncio.run(main(*args))
93
94if __name__ == '__main__':
95    asyncio.run(main()) ## Use terminal
96    # await main() ## Use Jupyter or IPython(>=7.0)
97    # main_for_spyder() ## Use Spyder