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