1'''
2Motion - Motion_3axis_helical_interpolation.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.EMotion()
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 axis = 0
43 stop_decel = 0
44
45 ## Helical parameters
46 center_x = 0
47 center_y = 0
48 finish_x = 100
49 finish_y = 100
50 pitch_axis3 = 0
51 pitch_axis4 = 0
52 rotation_num = 0
53 speed = 0
54 cal_timeout = 1000
55 helical_dir_cw = 0
56
57 ## Get firmware model & version
58 driver_info = await dev.Sys_getDriverInfo_async()
59 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
60
61 ## Motion open
62 err = await dev.Motion_open_async(port)
63 print(f"open_async in port {port}, status: {err}")
64
65 ## Motion open configuration file
66 err = await dev.Motion_openCfgFile_async('C:/Users/user/Desktop/3AxisStage_2P.ini')
67 print(f"openCfgFile_async, status: {err}")
68
69 ## Motion load configuration file
70 err = await dev.Motion_loadCfgFile_async()
71 print(f"loadCfgFile_async, status: {err}")
72
73 ## Motion configure
74 err = await dev.Motion_cfgHelicalInterpo_async(port, center_x, center_y, finish_x, finish_y, int(False), pitch_axis3, int(False), pitch_axis4, rotation_num,
75 speed, helical_dir_cw, cal_timeout)
76 print(f"cfgHelicalInterpo_async in axis{axis}, status: {err}")
77
78 ## Motion start
79 err = await dev.Motion_startHelicalInterpo_async(port)
80 print(f"startHelicalInterpo_async in axis{axis}, status: {err}")
81
82 move_status = 0
83 while move_status == 0:
84 move_status = await dev.Motion_getMoveStatus_async(port, axis)
85 print(f"getMoveStatus_async in axis{axis}: {move_status}")
86
87 ## Motion stop
88 err = await dev.Motion_stop_async(port, axis, stop_decel)
89 print(f"stop_async in axis{axis}, status: {err}")
90
91 ## Motion close
92 err = await dev.Motion_close_async(port)
93 print(f"close_async in port {port}, status: {err}")
94 except Exception as err:
95 pywpc.printGenericError(err)
96
97 finally:
98 ## Disconnect device
99 dev.disconnect()
100
101 ## Release device handle
102 dev.close()
103
104
105def main_for_spyder(*args):
106 if asyncio.get_event_loop().is_running():
107 return asyncio.create_task(main(*args)).result()
108 else:
109 return asyncio.run(main(*args))
110
111
112if __name__ == '__main__':
113 asyncio.run(main()) ## Use terminal
114 # await main() ## Use Jupyter or IPython(>=7.0)
115 # main_for_spyder() ## Use Spyder