-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyap-serial
executable file
·105 lines (80 loc) · 2.34 KB
/
pyap-serial
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python3
#
#
# Used to control serial electric I/O to send notification by serial port
# FIXME: don't know yet how to manage PIN3.
#
import os
import sys
import time
pathname, scriptname = os.path.split(sys.argv[0])
sys.path.append(os.path.join(pathname, '..'))
from db9 import Db9
GREEN_LED = Db9.PIN4
RED_LED = Db9.PIN7
# I"m using a bi-color led.
ORANGE_LED = GREEN_LED | RED_LED
def usage():
print ("usage: %s <tty>\n\n", sys.argv[0].split('/')[-1])
def switchon(pin, all_state):
print (f"[+] - switch on pin {pin}")
return all_state | pin
def switchoff(pin, all_state):
print (f"[+] - switch off pin {pin}")
return all_state & ~pin
def main(tty):
out = Db9(tty)
out.connect()
print ("[+] - Checking leds")
out.switch_off(Db9.ALL_OUTPUT)
for i in xrange(6):
time.sleep(0.1)
out.switch_on(GREEN_LED)
time.sleep(0.1)
out.switch_off(GREEN_LED)
out.switch_on(ORANGE_LED)
time.sleep(0.1)
out.switch_off(ORANGE_LED)
out.switch_on(RED_LED)
time.sleep(0.1)
out.switch_off(RED_LED)
time.sleep(0.1)
out.switch_off(ORANGE_LED)
time.sleep(0.1)
out.switch_off(GREEN_LED)
time.sleep(0.1)
time.sleep(1)
print ("[+] - set all entries down")
out.switch_off(Db9.ALL_OUTPUT)
print ("[+] - is GREEN_LED on ?")
if out.is_on(GREEN_LED):
print (" [!] - yes ??? GREEN_LED should be off !")
else:
print (" [+] - no ... OK, that's fine")
print ("[+] - sleeping during 5 sec")
time.sleep(5)
print ("[+] - switch on GREEN_LED")
out.switch_on(GREEN_LED)
print ("[+] - is GREEN_LED really on ?")
if out.is_on(GREEN_LED):
print (" [+] - yes ... OK, that's fine")
else:
print (" [!] - no ??? GREEN_LED should be on !")
print ("[+] - sleeping during 5 sec")
time.sleep(5)
print ("[+] - set orange led")
out.switch_on(ORANGE_LED)
print ("[+] - sleeping during 5 sec")
time.sleep(5)
print ("[+] - set red led")
out.switch_off(GREEN_LED)
out.switch_on(RED_LED)
print ("[+] - sleeping during 5 sec")
time.sleep(5)
out.disconnect()
if __name__ == '__main__':
try:
main(sys.argv[1])
except IndexError:
usage()
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4