-
Notifications
You must be signed in to change notification settings - Fork 0
/
dmxftdi.py
48 lines (42 loc) · 1.47 KB
/
dmxftdi.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
from pyftdi import ftdi
#FTDI device info
vendor=0x0403
product=0x6001
#####################
# DMX USB controller
#####################
class OpenDmxUsb():
def __init__(self):
self.baud_rate = 250000
self.data_bits = 8
self.stop_bits = 2
self.parity = 'N'
self.flow_ctrl = ''
self.rts_state = 0
self._init_dmx()
#Initialize the controller
def _init_dmx(self):
self.ftdi=ftdi.Ftdi()
# self.ftdi.open(vendor,product,0)
self.ftdi.open_from_url('ftdi:///1')
self.ftdi.set_baudrate(self.baud_rate)
self.ftdi.set_line_property(self.data_bits,self.stop_bits,self.parity,break_=0)
self.ftdi.set_flowctrl(self.flow_ctrl)
self.ftdi.purge_rx_buffer()
self.ftdi.purge_tx_buffer()
self.ftdi.set_rts(self.rts_state)
#Send DMX data
def send_dmx(self,channelVals):
self.ftdi.write_data(channelVals)
# Need to generate two bits for break
self.ftdi.set_line_property(self.data_bits,self.stop_bits,self.parity,break_=1)
self.ftdi.set_line_property(self.data_bits,self.stop_bits,self.parity,break_=1)
self.ftdi.set_line_property(self.data_bits,self.stop_bits,self.parity,break_=0)
if __name__=="__main__":
dmxUsb=OpenDmxUsb()
channelVals=bytearray([0]*513)
channelVals[0]=0 # dummy channel 0
for i in range(512):
channelVals[i]=255
print('sending ', channelVals)
dmxUsb.send_dmx(channelVals)