forked from danjperron/PIC_MULTI_10_IO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebRelais.py
More file actions
executable file
·59 lines (47 loc) · 1.3 KB
/
Copy pathWebRelais.py
File metadata and controls
executable file
·59 lines (47 loc) · 1.3 KB
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
#!/usr/bin/python3.2
import sys
import webiopi
sys.path.append("/home/pi")
import PicModule
import time
#import datetime
modules = PicModule.PicMbus(127,Device='/dev/ttyUSB0')
ModuleAddress = [11,12,13]
@webiopi.macro
def setPin(Module,Pin, Value):
modules.setAddress(ModuleAddress[int(Module)])
modules.writeIO(int(Pin),int(Value))
return(readPin(Module,Pin))
@webiopi.macro
def readPin(Module,Pin):
time.sleep(0.05)
modules.setAddress(ModuleAddress[int(Module)])
Value = modules.readIO(int(Pin))
return str(Value)
@webiopi.macro
def readAllPins(Module):
modules.setAddress(ModuleAddress[int(Module)])
Value = modules.readAllIO()
return str(Value)
@webiopi.macro
def setAllPins(Module,Value):
modules.setAddress(ModuleAddress[int(Module)])
modules.writeAllIO(int(Value))
@webiopi.macro
def togglePin(Module,Pin):
# read io sensor and inverse it
# not 0 = true not 1= false
# int(true)=1 int(false)=0
modules.setAddress(ModuleAddress[int(Module)])
Value = int( not modules.readIO(int(Pin)))
modules.writeIO(int(Pin),Value)
return(readPin(Module,Pin))
#@webiopi.macro
#def allOFF(Module):
# modules.setAddress(ModuleAddress[int(Module)])
# for i in range(8):
# modules.writeIO(i,0)
@webiopi.macro
def allOFF(Module):
modules.setAddress(0)
modules.writeAllIO(0)