1'''
2Relay - Relay_set_channel.py with synchronous mode.
3
4This example demonstrates how to write channel from EthanL.
5
6-------------------------------------------------------------------------------------
7Please change correct serial number or IP and port number BEFORE you run example code.
8
9For other examples please check:
10 https://github.com/WPC-Systems-Ltd/WPC_Python_driver_release/tree/main/examples
11See README.md file to get detailed usage of this example.
12
13Copyright (c) 2022-2024 WPC Systems Ltd. All rights reserved.
14'''
15
16## Python
17import time
18
19## WPC
20
21from wpcsys import pywpc
22
23def main():
24 ## Get Python driver version
25 print(f'{pywpc.PKG_FULL_NAME} - Version {pywpc.__version__}')
26
27 ## Create device handle
28 dev = pywpc.EthanL()
29
30 ## Connect to device
31 try:
32 dev.connect("192.168.1.110") ## Depend on your device
33 except Exception as err:
34 pywpc.printGenericError(err)
35 ## Release device handle
36 dev.close()
37 return
38
39 try:
40 ## Parameters setting
41 port = 0 ## Depend on your device
42 DO_port = 0
43 timeout = 3 ## second
44
45 ## Get firmware model & version
46 driver_info = dev.Sys_getDriverInfo(timeout)
47 print("Model name: " + driver_info[0])
48 print("Firmware version: " + driver_info[-1])
49
50 ## Relay open
51 err = dev.Relay_open(port, timeout)
52 print(f"Relay_open in port {port}, status: {err}")
53
54 ## Toggle digital state for 10 times. Each times delay for 0.5 second
55 for i in range(10):
56 if i%2 == 0:
57 value = [0, 0, 0, 0, 0, 0]
58 else:
59 value = [1, 1, 1, 1, 1, 1]
60
61 dev.DO_writePort(DO_port, value, timeout)
62 print(f'Port: {DO_port}, digital state= {value}')
63
64 ## Wait
65 time.sleep(0.5) ## delay [s]
66
67 ## Relay close
68 err = dev.Relay_close(port, timeout)
69 print(f"Relay_close in port {port}, status: {err}")
70 except Exception as err:
71 pywpc.printGenericError(err)
72
73 ## Disconnect device
74 dev.disconnect()
75
76 ## Release device handle
77 dev.close()
78
79 return
80
81if __name__ == '__main__':
82 main()