1'''
2Motion - Motion_2axis_linear_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 stop_decel = 0
43
44 ## Linear interpolation parameters
45 axis1 = 0
46 dest_posi1 = 2000
47 axis2 = 1
48 dest_posi2 = 2000
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"open_async in port {port}, status: {err}")
57
58 ## Motion open configuration file
59 err = await dev.Motion_openCfgFile_async('C:/Users/user/Desktop/3AxisStage_2P.ini')
60 print(f"openCfgFile_async, status: {err}")
61
62 ## Motion load configuration file
63 err = await dev.Motion_loadCfgFile_async()
64 print(f"loadCfgFile_async, status: {err}")
65
66 ## Motion configure
67 err = await dev.Motion_cfg2AxisLinearInterpo_async(port, axis1, dest_posi1, axis2, dest_posi2, speed=2000, accel=100000, decel=100000)
68 print(f"cfg2AxisLinearInterpo_async in axis{axis1} and {axis2}, status: {err}")
69
70 ## Motion start
71 err = await dev.Motion_startLinearInterpo_async(port)
72 print(f"startLinearInterpo_async in port {port}, status: {err}")
73
74 move_status = 0
75 while move_status == 0:
76 axis1_move_status = await dev.Motion_getMoveStatus_async(port, axis1)
77 axis2_move_status = await dev.Motion_getMoveStatus_async(port, axis2)
78 move_status = axis1_move_status & axis2_move_status
79 if move_status == 0:
80 print("Moving......")
81 else:
82 print("Move completed")
83
84 ## Motion stop
85 for i in [axis1, axis2]:
86 err = await dev.Motion_stop_async(port, i, stop_decel)
87 print(f"stop_async axis{i}, status: {err}")
88
89 ## Motion close
90 err = await dev.Motion_close_async(port)
91 print(f"close_async in port {port}, status: {err}")
92 except Exception as err:
93 pywpc.printGenericError(err)
94
95 finally:
96 ## Disconnect device
97 dev.disconnect()
98
99 ## Release device handle
100 dev.close()
101
102
103def main_for_spyder(*args):
104 if asyncio.get_event_loop().is_running():
105 return asyncio.create_task(main(*args)).result()
106 else:
107 return asyncio.run(main(*args))
108
109
110if __name__ == '__main__':
111 asyncio.run(main()) ## Use terminal
112 # await main() ## Use Jupyter or IPython(>=7.0)
113 # main_for_spyder() ## Use Spyder