ALP4lib is a Python module to control Vialux DMDs based on ALP4.X API. This is not an independant open source module, it uses the .ddl files provided by Vialux. This software is experimental, use it at your own risk.
This module wraps the basic function of the Vialux dlls to control a digitial micro-mirror device with a Vialux board. Vialux provides dlls and also modules for Matlab and Labview but not for Python. This code is tested with a device using the 4.3 version of the ALP API, other versions may have issues. LED control related functions are not implemented. Please read the ALP API description provided with the Vialux ALP installation.
If the code was helpful to your work, please consider citing it:
Just copy the ALP4.py file in the working directory.
To automatically download and copy the module in the python directory (so it can be available from anywhere), run the command:
pip install ALP4lib
or
easy_install ALP4lib
To install the latest version from Github, clone the repository, and install the package with the the following command.
python setup.py install
Instead of the normal installation, if you want to install ALP4lib in development mode, use:
python setup.py develop
The win32 ALPX.dll files should be directly in the working directory and the win64 dll with the same name in a /x64 subfolder. Alternatively, a different dll directory can be set at the initialization of the DMD handler object. The dlls have the following names respectively for the 4.1, 4.2 and 4.3 versions of the ALP API: 'alp41.dll', 'alp42.dll' and 'alp4395.dll'.
import numpy as np
from ALP4 import *
import time
# Load the Vialux .dll
DMD = ALP4(version = '4.3')
# Initialize the device
DMD.Initialize()
# Binary amplitude image (0 or 1)
bitDepth = 1
imgBlack = np.zeros([DMD.nSizeY,DMD.nSizeX])
imgWhite = np.ones([DMD.nSizeY,DMD.nSizeX])*(2**8-1)
imgSeq = np.concatenate([imgBlack.ravel(),imgWhite.ravel()])
# Allocate the onboard memory for the image sequence
DMD.SeqAlloc(nbImg = 2, bitDepth = bitDepth)
# Send the image sequence as a 1D list/array/numpy array
DMD.SeqPut(imgData = imgSeq)
# Set image rate to 50 Hz
DMD.SetTiming(pictureTime = 20000)
# Run the sequence in an infinite loop
DMD.Run()
time.sleep(10)
# Stop the sequence display
DMD.Halt()
# Free the sequence from the onboard memory
DMD.FreeSeq()
# De-allocate the device
DMD.Free()
The DMD can be also triggered with an external trigger cable. The following code initializes the DMD to do so:
from ALP4 import *
dmd = ALP4(version = '4.3')
# Initialize the device
dmd.Initialize()
# grayscale imagee
imgBlack = np.zeros([DMD.nSizeY,DMD.nSizeX])
imgWhite = np.ones([DMD.nSizeY,DMD.nSizeX])*(2**8-1)
imgSeq = np.concatenate([imgBlack.ravel(),imgWhite.ravel()])
dmd.SeqAlloc(nbImg = imgSeq.shape[0], bitDepth = 8)
# Send the image sequence as a 1D list/array/numpy array
dmd.SeqPut(imgData = imgSeq)
# set to 50Hz
# subtract 10µs because if the pictureTime is roughly the same time
# as the time between two triggers, sometime some triggers are missed
dmd.SetTiming(pictureTime = round(0.05*1_000_000) - 10)
# DMD listens to trigger
dmd.ProjControl(ALP_PROJ_MODE, ALP_SLAVE)
dmd.Run()
# best case start the triggers after, otherwise there might be a small delay