1'''
2Drive - Drive_scan_move.py with asynchronous mode.
3
4-------------------------------------------------------------------------------------
5Please change correct serial number or IP and port number BEFORE you run example code.
6
7For other examples please check:
8 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
9See README.md file to get detailed usage of this example.
10
11Copyright (c) 2022-2025 WPC Systems Ltd. All rights reserved.
12'''
13
14## WPC
15from wpcsys import pywpc
16
17## Python
18import asyncio
19import sys
20sys.path.insert(0, 'src/')
21
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.EDriveST()
29
30 ## Connect to device
31 try:
32 dev.connect("192.168.1.110") ## 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 port = 0 ## Depend on your device
42 active_high = 1
43 en_forward = 1
44 en_reverse = 1
45 position_0 = 30000
46 position_1 = -30000
47 speed = 30000
48 acceleration = 10000
49
50 ## Get firmware model & version
51 driver_info = await dev.Sys_getDriverInfo_async()
52 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
53
54 ## Motion open
55 err = await dev.Motion_open_async(port)
56 print(f"Motion_open, status: {err}")
57
58 ## Motion configure
59 err = await dev.Motion_cfgLimit_async(port, en_forward, en_reverse, active_high)
60 print(f"Motion_cfgLimit, status: {err}")
61
62 ## Motion Servo on
63 err = await dev.Motion_enableServoOn_async(port)
64 print(f"Motion_enableServoOn, status: {err}")
65
66 ## Motion start
67 err = await dev.Motion_startScanMove_async(port, position_0, position_1, speed, acceleration)
68 print(f"Motion_startScanMove, status: {err}")
69
70 ## Wait for seconds for moving
71 await asyncio.sleep(10) ## delay [sec]
72 except Exception as err:
73 pywpc.printGenericError(err)
74 except KeyboardInterrupt:
75 print("Press keyboard")
76 finally:
77 ## Motion stop
78 err = await dev.Motion_stopProcess_async(port)
79 print(f"Motion_stopProcess, status: {err}")
80
81 ## Motion Servo off
82 err = await dev.Motion_enableServoOff_async(port)
83 print(f"Motion_enableServoOff, status: {err}")
84
85 ## Motion close
86 err = await dev.Motion_close_async(port)
87 print(f"Motion_close, status: {err}")
88
89 ## Disconnect device
90 dev.disconnect()
91
92 ## Release device handle
93 dev.close()
94
95
96def main_for_spyder(*args):
97 if asyncio.get_event_loop().is_running():
98 return asyncio.create_task(main(*args)).result()
99 else:
100 return asyncio.run(main(*args))
101
102
103if __name__ == '__main__':
104 asyncio.run(main()) ## Use terminal
105 # await main() ## Use Jupyter or IPython(>=7.0)
106 # main_for_spyder() ## Use Spyder