Motion save config file

 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-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        timeout = 3  ## [sec]
41
42        ## Axis and encoder parameters
43        axis_dir_cw = 0
44        encoder_dir_cw = 0
45
46        ## Polarity and enable parameters
47        active_low = 0
48        active_high = 1
49
50        ## Get firmware model & version
51        driver_info = dev.Sys_getDriverInfo(timeout)
52        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
53
54        ## Motion open
55        err = dev.Motion_open(port, timeout)
56        print(f"Motion_open in port {port}, status: {err}")
57
58        ## Motion open configuration file
59        err = dev.Motion_openCfgFile('C:/Users/user/Desktop/3AxisStage_2P.ini')
60        print(f"Motion_openCfgFile, status: {err}")
61
62        ## Motion configure
63        err = dev.Motion_cfgAxis(port, axis, two_pulse_mode, axis_dir_cw, encoder_dir_cw, active_low, timeout)
64        print(f"Motion_cfgAxis in axis{axis}, status: {err}")
65
66        err = dev.Motion_cfgAxisMove(port, axis, rel_posi_mode, target_posi=5000, velo=10000, accel=100000, decel=100000, timeout=timeout)
67        print(f"Motion_cfgAxisMove in axis{axis}, status: {err}")
68
69        ## Motion save configuration file
70        err = dev.Motion_saveCfgFile(timeout)
71        print(f"Motion_saveCfgFile, status: {err}")
72
73        ## Motion close
74        err = dev.Motion_close(port, timeout)
75        print(f"Motion_close in port {port}, status: {err}")
76    except Exception as err:
77        pywpc.printGenericError(err)
78
79    finally:
80        ## Disconnect device
81        dev.disconnect()
82
83        ## Release device handle
84        dev.close()
85
86
87if __name__ == '__main__':
88    main()