Drive scan move

 1'''
 2Drive - Drive_scan_move.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## Python
18import time
19
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.EDriveST()
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        active_high = 1
41        en_forward = 1
42        en_reverse = 1
43        position_0 = 30000
44        position_1 = -30000
45        speed = 30000
46        acceleration = 10000
47        timeout = 3  ## [sec]
48
49        ## Get firmware model & version
50        driver_info = dev.Sys_getDriverInfo(timeout)
51        print(f"Model name: {driver_info[0]}, Firmware version: {driver_info[-1]} ")
52
53        ## Motion open
54        err = dev.Motion_open(port, timeout)
55        print(f"Motion_open, status: {err}")
56
57        ## Motion configure
58        err = dev.Motion_cfgLimit(port, en_forward, en_reverse, active_high, timeout)
59        print(f"Motion_cfgLimit, status: {err}")
60
61        ## Motion Servo on
62        err = dev.Motion_enableServoOn(port, timeout)
63        print(f"Motion_enableServoOn, status: {err}")
64
65        ## Motion start scanning
66        err = dev.Motion_startScanMove(port, position_0, position_1, speed, acceleration, timeout)
67        print(f"Motion_startScanMove, status: {err}")
68
69        ## Wait for seconds for moving
70        time.sleep(10)  ## delay [sec]
71    except Exception as err:
72        pywpc.printGenericError(err)
73    except KeyboardInterrupt:
74        print("Press keyboard")
75    finally:
76        ## Motion stop
77        err = dev.Motion_stopProcess(port, timeout)
78        print(f"Motion_stopProcess, status: {err}")
79
80        ## Motion Servo off
81        err = dev.Motion_enableServoOff(port, timeout)
82        print(f"Motion_enableServoOff, status: {err}")
83
84        ## Motion close
85        err = dev.Motion_close(port, timeout)
86        print(f"Motion_close, status: {err}")
87
88        ## Disconnect device
89        dev.disconnect()
90
91        ## Release device handle
92        dev.close()
93
94
95if __name__ == '__main__':
96    main()