How to ensure that a MATLAB executable can communicate with NI Data Acquisition Cards

Dear community,
I want to create a small Matlab GUI which can handle NI DAQ devices. Later, I want to compile my application to an executable (.exe), such that the non Matlab user can do some easy measurements on the fly.
I know that I need to install the NI DAQmx support package from the addon installer to make it possible to work with the DAQs in Matlab, but how can I provide that package in such a way that the user can use my executable (of course together with the respective Matlab Runtime). Is it possible, that the user installs the NI DAQmx driver externally, such that the executable can use it? Which NI DAQmx version does it have to be? Is the base variant already enough for that purpose?
best regards
Jonas

5 Comments

Hey Jonas,
I can partly help with this as I have a similar idea about making a small MATLAB version of DAQ Assistant (if you are familiar with it from LabVIEW). Maybe we can collaborate if you are willing to make it open source and post it publicly, otherwise I can help a bit.
As far as I learned, most of the devices work on the latest DAQMX driver, while others are supported up to a particular driver, i.e. check USB NI-9233 and NI-9234. First one is supports up to R2018b, and DAQMX driver up to 17.5 IIRC, the latter one works up to latest MATLAB release. You can probably assume similar for the other NI devices.
Difference between writing the code for those two are in the functions used in the MATLAB DAQ toolbox, see the commented commands for the older version equivalent.
%% Checking connection with DAQ device and transducers
installedDrivers = daqvendorlist; % daq.getVendors;
if isempty(installedDrivers)
WriteToCmdWindow(app, "Error! DAQmx drivers have not been detected or installed.");
% Warn user to install DAQmx drivers
else
WriteToCmdWindow(app, "Detected drivers are listed below:")
detectedDriversTable = table2cell(head(installedDrivers));
detectedDriversCell = {join([detectedDriversTable{:}])};
WriteToCmdWindow(app, detectedDriversCell);
end
devices = daqlist; % daq.getDevices;
if isempty(devices)
WriteToCmdWindow(app, 'Error! No DAQ devices detected.');
app.DAQdevicesreadyLamp.Color = 'red';
else
WriteToCmdWindow(app, sprintf('Number of devices detected: %d\n', size(devices, 1)));
WriteToCmdWindow(app, sprintf('Devices detected: %s\n', devices.VendorID));
app.DAQdevicesreadyLamp.Color = 'green';
end
%% Configuration
% DAQ device config
numDevices = size(devices, 1);
for i = 1 : numDevices
app.MeasurementSetup(i).Device = daq(devices.VendorID(i)); % daq.createSession(devices.VendorID(i));
end
Additionally, only one DAQMX driver may be present on the PC.
dear Mario, thanks for your comment. INstalling the driver externally just seems to work. Unfortunately, having to install the whole daqmx package makes this task not lightweight at all. combined with the fact, that we also have t provide the Matlab runtime engine, we have to carry multiple GB of data to be able to make the tool work on any new computer.
beside that, there are already some nice looking apps provided on Matlab FEX. E.g. DataAcquisitionLive has laready a nice look. Recording/displaying mutiple channels would be nice, but extending it would not need much effort i guess...
Runtime and DAQmx package could all be downloaded through internet (unless the computers do not have internet). Nowadays, it's faster to download the file rather than to transfer it.
The code which uses that package uses the functions which are not recommended anymore. In the meantime, I am making the app and will post it on FEX/Git when MVP is done.
i know the internet ;-) but no nice solution for spontaneous application on any offline computer. Too heavy for a usb stick

Sign in to comment.

Answers (1)

Hi Jonas,
To create a small Matlab GUI that can handle NI DAQ devices, you will need to use the Data Acquisition Toolbox and the NI-DAQmx support package. You can create a standalone executable of your Matlab application by using the MATLAB Compiler.
To deploy your application to a non-Matlab user, you will need to provide them with the compiled executable and the respective Matlab Runtime that your application was built on. You can package these files together into a single installer file using the MATLAB Compiler.
As for the NI-DAQmx driver, you have a few options. You can include the NI-DAQmx driver installer with your application installer and ask the user to install it before running your application. Alternatively, you can include the driver files directly in your application installer and install them automatically during the installation process.
The version of the NI-DAQmx driver you will need depends on the version of the NI-DAQmx support package you are using in Matlab. You can find this information in the release notes of the support package. The base version of the NI-DAQmx driver may be sufficient for your application, but it's best to check the compatibility requirements of your version of the support package to be sure.

1 Comment

"Alternatively, you can include the driver files directly in your application installer and install them automatically during the installation process."
How do you enable this? I added ni-daqmx_21.3_online.exe in the "Files installed for your end user" section of the deploy tool, but all that does is add it to the install folder. I could detect that the driver isn't installed on the first run of the app and trigger the install from there, but I'd rather it happen on app install.

Sign in to comment.

Categories

Products

Release

R2022a

Tags

Asked:

on 1 Feb 2023

Commented:

on 12 Jul 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!