Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed dmx-plugin enttec driver to match python-3 serial requirements. #179

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions plugins/dmx/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ def __init__(self, smarthome, tty, interface='nanodmx'):
logger.warning("Could not communicate with dmx adapter.")
self._is_connected = False
elif interface == 'enttec':
self._enttec_data = [chr(0)] * 513
self._enttec_data = bytearray(512)
self.send = self.send_enttec
self._send_enttec(chr(0o3) + chr(0o2) + chr(0) + chr(0) + chr(0))
self._send_enttec(chr(10) + chr(0o2) + chr(0) + chr(0) + chr(0))
else:
logger.error("Unknown interface: {0}".format(interface))

Expand All @@ -76,7 +74,7 @@ def _send_enttec(self, data):
if not self._is_connected:
return False
self._lock.acquire()
self._port.write((chr(126) + data + chr(231)).encode())
self._port.write(data)
self._lock.release()
return True

Expand All @@ -91,8 +89,32 @@ def send_nanodmx(self, channel, value):
self._send_nanodmx("C{0:03d}L{1:03d}".format(int(channel), int(value)))

def send_enttec(self, channel, value):
self._enttec_data[channel] = chr(value)
self._send_enttec(chr(6) + chr(1) + chr(2) + ''.join(self._enttec_data))
START_VAL = 0x7E
END_VAL = 0xE7

LABELS = {
'GET_WIDGET_PARAMETERS' :3, #unused
'SET_WIDGET_PARAMETERS' :4, #unused
'RX_DMX_PACKET' :5, #unused
'TX_DMX_PACKET' :6,
'TX_RDM_PACKET_REQUEST' :7, #unused
'RX_DMX_ON_CHANGE' :8, #unused
}

START_DATA = 0x00

self._enttec_data[channel] = int(value);

packet = bytearray()
packet.append(START_VAL)
packet.append(LABELS['TX_DMX_PACKET'])
packet.append(len(self._enttec_data) & 0xFF)
packet.append((len(self._enttec_data) >> 8) & 0xFF)
packet.append(START_DATA)
packet.extend(self._enttec_data)
packet.append(END_VAL)

self._send_enttec(packet)

def parse_item(self, item):
if 'dmx_ch' in item.conf:
Expand Down