1'''
2Motion - Motion_save_configuration_file.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-2024 WPC Systems Ltd. All rights reserved.
12'''
13
14## Python
15import time
16
17## WPC
18
19from wpcsys import pywpc
20
21def 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 axis = 0
41 two_pulse_mode = 1
42 rel_posi_mode = 1
43 timeout = 3 ## second
44
45 ## Axis and encoder parameters
46 axis_dir_cw = 0
47 encoder_dir_cw = 0
48
49 ## Polarity and enable parameters
50 active_low = 0
51 active_high = 1
52
53 ## Get firmware model & version
54 driver_info = dev.Sys_getDriverInfo(timeout)
55 print("Model name: " + driver_info[0])
56 print("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 ## Motion open configuration file
63 err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
64 print(f"Motion_openCfgFile, status: {err}")
65
66 ## Motion configure
67 err = dev.Motion_cfgAxis(port, axis, two_pulse_mode, axis_dir_cw, encoder_dir_cw, active_low, timeout)
68 print(f"Motion_cfgAxis in axis{axis}, status: {err}")
69
70 err = dev.Motion_cfgAxisMove(port, axis, rel_posi_mode, target_posi=5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
71 print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
72
73 ## Motion save configuration file
74 err = dev.Motion_saveCfgFile(timeout)
75 print(f"Motion_saveCfgFile, status: {err}")
76
77 ## Motion close
78 err = dev.Motion_close(port, timeout)
79 print(f"Motion_close in port {port}, status: {err}")
80 except Exception as err:
81 pywpc.printGenericError(err)
82
83 ## Disconnect device
84 dev.disconnect()
85
86 ## Release device handle
87 dev.close()
88
89 return
90
91if __name__ == '__main__':
92 main()