This code is specifically tailored to the 24-relay card, but it would be easy to modify for another one.
It requires the Data Acquisition Toolbox.
The code manually compensates for the bug reported here: http://www.mathworks.com/support/bugreports/details.html?rp=498986 . If you perform this workaround, or if this problem is fixed in a future release, then this code will need updating.
The code is written in MATLAB's old OOP style, so it will work on pre-2008 releases.