-
Notifications
You must be signed in to change notification settings - Fork 1
/
relay_test.py
executable file
·69 lines (57 loc) · 1.21 KB
/
relay_test.py
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
#!/usr/bin/env python2
#
# This simple program reads one or more elevation sensors, made by
#
# Level Developments, Inc, UK
#
# They manifest as HID devices, we use the "hidapi" Python library to
# interact with the devices.
#
#
# It also drives a linear-actuator motor at a fixed rate either UP or
# DOWN to achieve a given dish position.
#
#
import os
import struct
import time
import math
import sys
from pylibftdi import BitBangDevice
import signal
bbd = None
def sighandle(num, stack):
global bbd
bbd.port = 0
print "Resetting relay board"
time.sleep(0.2)
print "Exiting"
sys.exit()
signal.signal(signal.SIGINT, sighandle)
signal.signal(signal.SIGHUP, sighandle)
signal.signal(signal.SIGQUIT, sighandle)
signal.signal(signal.SIGSEGV, sighandle)
signal.signal(signal.SIGBUS, sighandle)
#
# Create an FTDI BigBangDevice instance, based on serial number passed in
#
bbd = BitBangDevice(device_index=0)
#
# Set direction regiser
#
bbd.direction = 0xFF
bbd.port = 0
DOWN=0b00001101
UP=0b00001110
while True:
bbd.port = DOWN
time.sleep(1)
bbd.port = UP
time.sleep(1)
# We really want that motor to stop
#
bbd.port = 0
if (timeout == True):
sys.exit(3)
else:
sys.exit(0)