├── DmxPy.py ├── LICENSE ├── README.md └── dmxtest.py /DmxPy.py: -------------------------------------------------------------------------------- 1 | import serial, sys, time 2 | 3 | 4 | DMXOPEN = bytes([126]) 5 | DMXCLOSE = bytes([231]) 6 | DMXINTENSITY = bytes([6]) + bytes([1]) + bytes([2]) 7 | DMXINIT1 = bytes([3]) + bytes([2]) + bytes([0]) + bytes([0]) + bytes([0]) 8 | DMXINIT2 = bytes([10]) + bytes([2]) + bytes([0]) + bytes([0]) + bytes([0]) 9 | 10 | 11 | class DmxPy: 12 | def __init__(self, serialPort): 13 | try: 14 | self.serial = serial.Serial(serialPort, baudrate=57600) 15 | except: 16 | print("Error: could not open Serial Port") 17 | sys.exit(0) 18 | self.serial.write(DMXOPEN + DMXINIT1 + DMXCLOSE) 19 | self.serial.write(DMXOPEN + DMXINIT2 + DMXCLOSE) 20 | 21 | self.dmxData = [bytes([0])] * 513 #128 plus "spacer". 22 | 23 | 24 | def setChannel(self, chan, intensity): 25 | if chan > 512: chan = 512 26 | if chan < 0: chan = 0 27 | if intensity > 255: intensity = 255 28 | if intensity < 0: intensity = 0 29 | self.dmxData[chan] = bytes([intensity]) 30 | 31 | 32 | def blackout(self): 33 | for i in range(1, 512, 1): 34 | self.dmxData[i] = bytes([0]) 35 | 36 | 37 | def render(self): 38 | sdata = b''.join(self.dmxData) 39 | self.serial.write(DMXOPEN + DMXINTENSITY + sdata + DMXCLOSE) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 L Trevor Davies 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## DmxPy - Python Controller for USB - DMX devices 2 | 3 | This is a Python 3 port of [DmxPy](https://github.com/davepaul0/DmxPy). 4 | 5 | DmxPy is a super-lightweight Python library for controlling any USB-DMX device that is compatible with Enttec's DMXUSB Pro. This includes all Dmxking ultraDMX devices. 6 | 7 | DmxPy requires PySerial to work - http://pyserial.sourceforge.net/ 8 | 9 | To import:
10 | from DmxPy import DmxPy 11 | 12 | To initialize:
13 | dmx = DmxPy('serial port') 14 | Where 'serial port' is where your device is located. 15 | 16 | To set a channel's value:
17 | dmx.setChannel(chan, value) 18 | Where 'chan' and 'value' are integers representing the respective DMX channels and values to set! 19 | 20 | To push dmx changes to device:
21 | dmx.render() 22 | You need to call this to update the device! 23 | 24 | -------------------------------------------------------------------------------- /dmxtest.py: -------------------------------------------------------------------------------- 1 | from DmxPy import DmxPy 2 | import time 3 | 4 | dmx = DmxPy('/dev/ttyUSB0') 5 | dmx.setChannel(1, 100) 6 | dmx.setChannel(2, 50) 7 | dmx.render() 8 | time.sleep(2) 9 | dmx.setChannel(3, 100) 10 | time.sleep(2) 11 | dmx.blackout() 12 | dmx.render() --------------------------------------------------------------------------------