Skip to content

ftd2xx controller #57

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
63 changes: 63 additions & 0 deletions PyDMXControl/controllers/_FTD2XXController.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""
* PyDMXControl: A Python 3 module to control DMX using OpenDMX or uDMX.
* Featuring fixture profiles, built-in effects and a web control panel.
* <https://github.com/MattIPv4/PyDMXControl/>
* Copyright (C) 2022 Matt Cowley (MattIPv4) ([email protected])
"""

from time import sleep
from typing import List

from ._TransmittingController import TransmittingController

try:
import ftd2xx
except OSError as e:
print("ftd2xx binaries not present")

class FTD2XXController(TransmittingController):

def __init__(self, device_number, *args, **kwargs):
"""
FTD2CXX interface requires a device number to establish connection, e.g. 0

Parameters
----------
device_number: int
"""

# Store the device_number and device
self.__device_number = device_number
self.__device = None
super().__init__(*args, **kwargs)

def _connect(self):
# Try to close if exists
if self.__device is not None:
try:
self.__device.close()
except Exception:
pass

# Get new device
self.__device = ftd2xx.open(self.__device_number)
self.__device.resetDevice()
self.__device.setBaudRate(250000)
self.__device.setDataCharacteristics(8, 2, 0) # 8 bit word, 2 stop bit, no parity

def _close(self):
self.__device.close()
print("CLOSE: FTD2XX device connection closed")

def _transmit(self, frame: List[int], first: int):
# Convert to a bytearray and pad the start of the frame
# We're transmitting direct DMX data here, so a frame must start at channel 1, but can end early
data = bytearray(([0] * (first - 1)) + frame)

# The first byte in the type, and is `0` for normal DMX data
data.insert(0, 0)

# Write
self.__device.setBreakOn()
self.__device.setBreakOff()
self.__device.write(bytes(data))
1 change: 1 addition & 0 deletions PyDMXControl/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
from ._uDMXController import uDMXController
from ._OpenDMXController import OpenDMXController
from ._SerialController import SerialController
from ._FTD2XXController import FTD2XXController
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@ pyftdi>=0.54.0,<=0.55.0
pyserial>=3.5,<4.0

# Web
Flask>=2.3,<3.0
Flask>=2.3,<3.0

#FTD2XX
ftd2xx>=1.3.6