1'''
2Motion - Motion_1axis_move_with_inposition.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 two_pulse_mode = 1
39 rel_posi_mode = 1
40 stop_decel = 0
41 timeout = 3 ## [sec]
42
43 ## Axis and encoder parameters
44 axis_dir_cw = 0
45 encoder_dir_cw = 0
46
47 ## Polarity and enable parameters
48 active_low = 0
49 active_high = 1
50 forward_enable_true = 1
51 reverse_enable_true = 1
52 inposi_enable_false = 0
53
54 ## Get firmware model & version
55 driver_info = dev.Sys_getDriverInfo(timeout)
56 print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
57
58 ## Motion open
59 err = dev.Motion_open(port, timeout)
60 print(f"Motion_open in port {port}, status: {err}")
61
62
63 '''
64 ## Motion open configuration file
65 err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
66 print(f"openCfgFile, status: {err}")
67
68 ## Motion load configuration file
69 err = dev.Motion_loadCfgFile()
70 print(f"loadCfgFile, status: {err}")
71 '''
72
73 ## Motion configure
74 err = dev.Motion_cfgAxis(port, axis, two_pulse_mode, axis_dir_cw, encoder_dir_cw, active_low, timeout)
75 print(f"Motion_cfgAxis in axis{axis}, status: {err}")
76
77 err = dev.Motion_cfgLimit(port, axis, forward_enable_true, reverse_enable_true, active_low, timeout)
78 print(f"Motion_cfgLimit in axis{axis}, status: {err}")
79
80 err = dev.Motion_cfgInposi(port, axis, inposi_enable_false, active_low, timeout)
81 print(f"Motion_cfgInposi in axis{axis}, status: {err}")
82
83 err = dev.Motion_cfgAxisMove(port, axis, rel_posi_mode, target_posi=5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
84 print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
85
86 err = dev.Motion_rstEncoderPosi(port, axis, encoder_posi=0, timeout=timeout)
87 print(f"Motion_rstEncoderPosi in axis{axis}, status: {err}")
88
89 ## Servo on
90 err = dev.Motion_enableServoOn(port, axis, timeout)
91 print(f"Motion_enableServoOn in axis{axis}, status: {err}")
92
93 ## Motion start
94 err = dev.Motion_startSingleAxisMove(port, axis, timeout)
95 print(f"Motion_startSingleAxisMove in axis{axis}, status: {err}")
96
97 move_status = 0
98 while move_status == 0:
99 move_status = dev.Motion_getMoveStatus(port, axis, timeout)
100 print("Motion_getMoveStatus:", move_status)
101
102 ## Motion stop
103 err = dev.Motion_stop(port, axis, stop_decel, timeout)
104 print(f"Motion_stop in axis{axis}, status: {err}")
105
106 ## Servo off
107 err = dev.Motion_enableServoOff(port, axis, timeout)
108 print(f"Motion_enableServoOff in axis{axis}, status: {err}")
109
110 ## Motion close
111 err = dev.Motion_close(port, timeout)
112 print(f"Motion_close in port {port}, status: {err}")
113 except Exception as err:
114 pywpc.printGenericError(err)
115
116 finally:
117 ## Disconnect device
118 dev.disconnect()
119
120 ## Release device handle
121 dev.close()
122
123
124if __name__ == '__main__':
125 main()