1'''
2System_ETH - get_network_info.py with asynchronous mode.
3
4This example demonstrates how to get hardware & network information from EthanI.
5
6First, get hardware information such as firmware model & version.
7Last, get network information such as IP & submask & MAC.
8
9-------------------------------------------------------------------------------------
10Please change correct serial number or IP and port number BEFORE you run example code.
11
12For other examples please check:
13 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
14See README.md file to get detailed usage of this example.
15
16Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
17'''
18
19## Python
20import asyncio
21
22## WPC
23
24from wpcsys import pywpc
25
26async def main():
27 ## Get Python driver version
28 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
29
30 ## Create device handle
31 dev = pywpc.EthanI()
32
33 ## Connect to device
34 try:
35 dev.connect("192.168.1.110") ## Depend on your device
36 except Exception as err:
37 pywpc.printGenericError(err)
38 ## Release device handle
39 dev.close()
40 return
41
42 try:
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 ## Get IP & submask
49 ip_addr, submask = await dev.Net_getIPAddrAndSubmask_async()
50 print(f"IP: {ip_addr}")
51 print(f"Submask: {submask}")
52
53 ## Get MAC
54 mac = await dev.Net_getMACAddr_async()
55 print(f"MAC: {mac}")
56 except Exception as err:
57 pywpc.printGenericError(err)
58
59 ## Disconnect network device
60 dev.disconnect()
61
62 ## Release device handle
63 dev.close()
64
65 return
66
67def main_for_spyder(*args):
68 if asyncio.get_event_loop().is_running():
69 return asyncio.create_task(main(*args)).result()
70 else:
71 return asyncio.run(main(*args))
72
73if __name__ == '__main__':
74 asyncio.run(main()) ## Use terminal
75 # await main() ## Use Jupyter or IPython(>=7.0)
76 # main_for_spyder() ## Use Spyder