WPC Python driver Logo
3.1.7

API REFERNECE

  • Products Feature
  • Products Usage

EXAMPLE CODES

  • Example Codes - Console (sync)
  • Example Codes - Console (async)
    • Device finder
      • Find all devices
      • Find network devices and blink
    • Drone
    • STEM
    • EDrive-ST
    • EMotion
    • Ethan-A
    • Ethan-A2
    • Ethan-D
    • Ethan-EX-D
    • Ethan-I
    • Ethan-IA
    • Ethan-L
    • Ethan-O
    • Ethan-P
    • Ethan-T
    • USB-DAQ-F1-AD
    • USB-DAQ-F1-AOD
    • USB-DAQ-F1-CD
    • USB-DAQ-F1-D
    • USB-DAQ-F1-D-SNK
    • USB-DAQ-F1-RD
    • USB-DAQ-F1-TD
    • Wifi-DAQ-E3-A
    • Wifi-DAQ-E3-AH
    • Wifi-DAQ-F4-A
    • Wifi-DAQ-E3-AOD
  • Example Codes - GUI (sync)

APPENDICES

  • I/O Port Function Table
  • I/O Channel Function Table
  • AI Max Sampling Rate Table
  • Error Code Table
  • Setting Table
WPC Python driver
  • Example Codes - Console (async)
  • Find network devices and blink

Find network devices and blink

 1'''
 2Find_devices - find_network_devices_blink.py with asynchronous mode.
 3
 4This example demonstrates how to find ethernet devices and blink.
 5
 6For other examples please check:
 7    https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
 8See README.md file to get detailed usage of this example.
 9
10Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
11'''
12
13## WPC
14from wpcsys import pywpc
15
16## Python
17import asyncio
18import sys
19sys.path.insert(0, 'src/')
20
21
22async def main():
23    ## Get Python driver version
24    print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
25
26    ## Create device handle
27    dev = pywpc.DeviceFinder()
28
29    ## Connect to device
30    dev.connect()
31
32    ## Perform network device information
33    print("Find all network devices....")
34    try:
35        dev_2d_list = await dev.Bcst_enumerateNetworkDevices_async()
36        for device_list in dev_2d_list:
37            print(device_list)
38            mac_num = device_list[2]
39
40            ## Check MAC and let LED blink
41            err = await dev.Bcst_checkMACAndRing_async(mac_num)
42            print(f"Bcst_checkMACAndRing_async, status: {err}")
43
44    except Exception as err:
45        pywpc.printGenericError(err)
46
47    finally:
48        ## Disconnect device
49        dev.disconnect()
50
51        ## Release device handle
52        dev.close()
53
54
55def main_for_spyder(*args):
56    if asyncio.get_event_loop().is_running():
57        return asyncio.create_task(main(*args)).result()
58    else:
59        return asyncio.run(main(*args))
60
61
62if __name__ == '__main__':
63    asyncio.run(main())  ## Use terminal
64    # await main()  ## Use Jupyter or IPython(>=7.0)
65    # main_for_spyder()  ## Use Spyder
Previous Next

© Copyright 2024, WPC Systems Ltd..

Built with Sphinx using a theme provided by Read the Docs.