-
Notifications
You must be signed in to change notification settings - Fork 0
/
DmxPy.py
executable file
·41 lines (34 loc) · 1.06 KB
/
DmxPy.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
import serial
import sys
###CODE IMPORTED FROM ##############
#https://github.com/davepaul0/DmxPy#
def hello():
print "Hello World!"
DMXOPEN = chr(126)
DMXCLOSE = chr(231)
DMXINTENSITY=chr(6)+chr(1)+chr(2)
DMXINIT1= chr(03)+chr(02)+chr(0)+chr(0)+chr(0)
DMXINIT2= chr(10)+chr(02)+chr(0)+chr(0)+chr(0)
class DmxPy:
def __init__(self, serialPort):
try:
self.serial=serial.Serial(serialPort, baudrate=57600)
except:
print "Error: could not open Serial Port "+serialPort
sys.exit(0)
self.serial.write( DMXOPEN+DMXINIT1+DMXCLOSE)
self.serial.write( DMXOPEN+DMXINIT2+DMXCLOSE)
self.dmxData=[chr(0)]*513 #128 plus "spacer".
def set(self, chan, intensity):
if chan > 512 : chan = 512
if chan < 1 : return
if intensity > 255 : intensity = 255
if intensity < 0 : intensity = 0
self.dmxData[chan] = chr(intensity)
def setall(self, val=255):
for i in xrange (1, 512, 1):
self.dmxData[i] = chr(val)
def render(self):
sdata=''.join(self.dmxData)
self.serial.write(DMXOPEN+DMXINTENSITY+sdata+DMXCLOSE)
######## END OF IMPORTED CODE #################