1'''
2Motion - Motion_1axis_move_with_capture.py with synchronous 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
18def main():
19 ## Get Python driver version
20 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
21
22 ## Create device handle
23 dev = pywpc.EMotion()
24
25 ## Connect to device
26 try:
27 dev.connect("192.168.1.110") ## Depend on your device
28 except Exception as err:
29 pywpc.printGenericError(err)
30 ## Release device handle
31 dev.close()
32 return
33
34 try:
35 ## Parameters setting
36 port = 0 ## Depend on your device
37 axis = 0
38 rel_posi_mode = 1
39 stop_decel = 0
40 timeout = 3 ## [sec]
41
42 ## Get firmware model & version
43 driver_info = dev.Sys_getDriverInfo(timeout)
44 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
45
46 ## Capture parameters setting
47 rising_edge = 0
48 capture_logical_position = 0
49
50 ## Motion open
51 err = dev.Motion_open(port, timeout)
52 print(f"Motion_open in port {port}, status: {err}")
53
54 ## Motion open configuration file
55 err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
56 print(f"Motion_openCfgFile, status: {err}")
57
58 ## Motion load configuration file
59 err = dev.Motion_loadCfgFile(timeout)
60 print(f"Motion_loadCfgFile, status: {err}")
61
62 ## Motion configure
63 err = dev.Motion_cfgCapture(port, axis, rising_edge, capture_logical_position, timeout)
64 print(f"Motion_cfgCapture in axis{axis}, status: {err}")
65
66 err = dev.Motion_enableCapture(port, axis, int(True), timeout)
67 print(f"Motion_enableCapture in axis{axis}, status: {err}")
68
69 err = dev.Motion_cfgAxisMove(port, axis, rel_posi_mode, target_posi=5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
70 print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
71
72 err = dev.Motion_rstEncoderPosi(port, axis, encoder_posi=0, timeout=timeout)
73 print(f"Motion_rstEncoderPosi in axis{axis}, status: {err}")
74
75 ## Servo on
76 err = dev.Motion_enableServoOn(port, axis, timeout)
77 print(f"Motion_enableServoOn in axis{axis}, status: {err}")
78
79 ## Motion start
80 err = dev.Motion_startSingleAxisMove(port, axis, timeout)
81 print(f"Motion_startSingleAxisMove in axis{axis}, status: {err}")
82
83 move_status = 0
84 while move_status == 0:
85 move_status = dev.Motion_getMoveStatus(port, axis, timeout)
86 print(f"Motion_getMoveStatus in axis{axis}: {move_status}")
87
88 capture_points = dev.Motion_readCapturePoint(port, axis, timeout)
89 print(f"Motion_readCapturePoint in axis{axis}: {capture_points}")
90
91 ## Motion stop
92 err = dev.Motion_stop(port, axis, stop_decel, timeout)
93 print(f"Motion_stop in axis{axis}, status: {err}")
94
95 ## Servo off
96 err = dev.Motion_enableServoOff(port, axis, timeout)
97 print(f"Motion_enableServoOff in axis{axis}, status: {err}")
98
99 ## Motion close
100 err = dev.Motion_close(port, timeout)
101 print(f"Motion_close in port {port}, status: {err}")
102 except Exception as err:
103 pywpc.printGenericError(err)
104
105 finally:
106 ## Disconnect device
107 dev.disconnect()
108
109 ## Release device handle
110 dev.close()
111
112
113if __name__ == '__main__':
114 main()