Relay Knowledge:
Relays have three terminals: normally open (NO), normally closed (NC), Grounded (C)
If the connection takes a long time and occasionally requires a power outage, then NC and C are connected so that the relay set on is powered off. In addition, the relays can also control the keys, as well as the long press.
The relay lights up when the relay is switched on. The ZZR08 has 8 relays that represent their overall state in a single byte, with a bit height per bit (bit high) representing the status of the corresponding relay. For example: the first relay set on is 00000001,set off when the bit is 0, the second set on is 00000010 (2), and set off when the bit is 0. And so on.
How to use relays:
1. Command "ls/dev/tty*", you can find like this
/dev/tty Relaycard
Before the access relay run "ls/dev/tty*", after the access to run again, the more out is the identity of the relay.
2. Check the file /etc/udev/rules.d/acs.rules. In this file, there has a code like
This
subsystems=="usb", attrs{idvendor}=="10c4", attrs{ idproduct}=="ea60", SYMLINK+ ="ttyrelaycard" , mode="0666", owner="buildbot "
If there don ' t has this code, please add it by manual. And then re-plugin the
Relay card ' s USB cable.
Check to see if there is a/etc/udev/rules.d/acs.rules, and if it does not exist, create the file: Touch acs.rules, the file contents as above.
3. View permissions: Ls-l/dev/ttyrelaycard, result crw-rw----1 root dialout.
You can change the relay permissions: chmod a+rw/dev/ttyrelaycard. The downside is that each plug-in relay has to be changed.
The user of the relay is root and group is dialout. You can make the current user subordinate to the Dialout user group. To view user groups: Groups users. Change the user's secondary user group List:sudo usermod-g dialout,adm,...
4. Python Script
Import Serialimport sys, time ' ser = serial. Serial (Port=none, # Number of device, numbering starts at# zero. If everything fails, the user# can specify a Device string, note# that this isn ' t portable anymore# if No. port is specified a unconfigured# an closed serial port obj ECT is createdbaudrate=9600, # baud ratebytesize=eightbits, # Number of Databitsparity=parity_none, # ENA ble parity Checkingstopbits=stopbits_one, # Number of Stopbitstimeout=none, # Set a timeout value, None for Wai Ting Foreverxonxoff=0, # Enable software flow controlrtscts=0, # Enable rts/cts flow Controlint Erchartimeout=none # inter-character Timeout, None to disable) ' device = sys.argv[1] #/dev/ttyrelaycardser = serial. Serial (device, 19200, Serial. Eightbits, serial. Parity_none, serial. Stopbits_two, None) W = 0.05def get_version (): cmd = print "Get the Relay software version" Ser.write (Chr (cmd)) Time.sleep (W) A = Ser.read (1) Print Ord (a) b = ser.read (1) Print ord (b) Time.sleep (1) def set_relay_on (i): "Relay No is from 1 to 8" cmd = + i print "Set relay%d on"% (i) ser.write (Chr (cmd)) time.sleep (W) Ser.write (CHR) # get RelA Y states A = Ser.read (1) Print ord (a) Time.sleep (W) def set_relay_off (i): ' Relay No ' from 1 to 8 ' cmd = + I print "Set relay%d off"% (i) ser.write (Chr (cmd)) time.sleep (W) ser.write (chr) A = Ser.read (1 ) Print Ord (a) time.sleep (W) Set_relay_off (1) # set_relay_on (1)
Appendix
ZZR08 Command Table
Command |
Action |
Character |
DEC |
HEX |
|
|
90 |
5 A |
Get software version-returns 2 bytes, the first being the module ID which is 8, followed by the software version |
|
91 |
5B |
Get relay States-sends A single byte back to the controller, bit high meaning the corresponding relay is powered |
|
92 |
5C |
Set relay States-the next single byte would set all relays states = 255 (11111111), all off = 0 |
D |
100 |
64 |
All relays on |
E |
101 |
65 |
Turn Relay 1 on |
F |
102 |
66 |
Turn Relay 2 on |
G |
103 |
67 |
Turn Relay 3 on |
H |
104 |
68 |
Turn Relay 4 on |
I |
105 |
69 |
Turn Relay 5 on |
J |
106 |
6A |
Turn Relay 6 on |
K |
107 |
6B |
Turn Relay 7 on |
L |
108 |
6C |
Turn Relay 8 on |
N |
110 |
6E |
All Relays off |
O |
111 |
6F |
Turn Relay 1 off |
P |
112 |
70 |
Turn Relay 2 off |
Q |
113 |
71 |
Turn Relay 3 off |
R |
114 |
72 |
Turn Relay 4 off |
S |
115 |
73 |
Turn Relay 5 off |
T |
116 |
74 |
Turn Relay 6 off |
U |
117 |
75 |
Turn Relay 7 off |
V |
118 |
76 |
Turn Relay 8 off |
Relay Relay:zzr08