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-2024 WPC Systems Ltd. All rights reserved.
12'''
13
14## Python
15import asyncio
16
17## WPC
18
19from wpcsys import pywpc
20
21async def main():
22 ## Get Python driver version
23 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
24
25 ## Create device handle
26 dev = pywpc.EMotion()
27
28 ## Connect to device
29 try:
30 dev.connect("192.168.1.110") ## Depend on your device
31 except Exception as err:
32 pywpc.printGenericError(err)
33 ## Release device handle
34 dev.close()
35 return
36
37 try:
38 ## Parameters setting
39 port = 0 ## Depend on your device
40 stop_decel = 0
41
42 ## Linear interpolation parameters
43 axis1 = 0
44 dest_posi1 = 2000
45 axis2 = 1
46 dest_posi2 = 2000
47 axis3 = 2
48 dest_posi3 = 2000
49
50 ## Get firmware model & version
51 driver_info = await dev.Sys_getDriverInfo_async()
52 print("Model name: " + driver_info[0])
53 print("Firmware version: " + driver_info[-1])
54
55 ## Motion open
56 err = await dev.Motion_open_async(port)
57 print(f"open_async in port {port}, status: {err}")
58
59 ## Motion open configuration file
60 err = await dev.Motion_openCfgFile_async('C:/Users/user/Desktop/3AxisStage_2P.ini')
61 print(f"openCfgFile_async, status: {err}")
62
63 ## Motion load configuration file
64 err = await dev.Motion_loadCfgFile_async()
65 print(f"loadCfgFile_async, status: {err}")
66
67 ## Motion configure
68 err = await dev.Motion_cfg3AxisLinearInterpo_async(port, axis1, dest_posi1, axis2, dest_posi2, axis3, dest_posi3, speed=2000, accel=100000, decel=100000)
69 print(f"cfg3AxisLinearInterpo_async in port {port}, status: {err}")
70
71 ## Motion start
72 err = await dev.Motion_startLinearInterpo_async(port)
73 print(f"startLinearInterpo_async in port {port}, status: {err}")
74
75 move_status = 0
76 while move_status == 0:
77 axis1_move_status = await dev.Motion_getMoveStatus_async(port, axis1)
78 axis2_move_status = await dev.Motion_getMoveStatus_async(port, axis2)
79 axis3_move_status = await dev.Motion_getMoveStatus_async(port, axis3)
80 move_status = axis1_move_status & axis2_move_status & axis3_move_status
81 if move_status == 0:
82 print("Moving......")
83 else:
84 print("Move completed")
85
86 ## Motion stop
87 for i in [axis1, axis2, axis3]:
88 err = await dev.Motion_stop_async(port, i, stop_decel)
89 print(f"stop_async axis{i} in port {port}, 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 ## Disconnect device
98 dev.disconnect()
99
100 ## Release device handle
101 dev.close()
102
103 return
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
111if __name__ == '__main__':
112 asyncio.run(main()) ## Use terminal
113 # await main() ## Use Jupyter or IPython(>=7.0)
114 # main_for_spyder() ## Use Spyder