NI 6008 digital output

7 visualizaciones (últimos 30 días)
mulham
mulham el 22 de Mayo de 2013
Respondida: Hari el 11 de Jun. de 2025
Hello all :) I have a National Instruments NI-DAQ USB 6008. I have the data acquisition toolbox, and I've used this device to capture and analyze analog inputs. Now, I would like to use it for digital outputs. In the simplest terms, I'm just writing a function that will set one of its digital outputs to high or low. Can somebody please explain to me the functions/code that I need to accomplish this? I'm having trouble finding the information.
Thanks! plz post the whole code :) Mulham

Respuestas (1)

Hari
Hari el 11 de Jun. de 2025
Hi,
I understand that you’re trying to use your NI USB-6008 device with MATLAB to perform simple digital output operations, such as setting a pin to high or low, using the Data Acquisition Toolbox.
I assume that you've already installed the necessary NI-DAQmx drivers and that your NI USB-6008 is detected in MATLAB when you run daq.getDevices.
In order to write a digital output (set a line to high or low), you can follow the below steps:
Step 1: Create a DataAcquisition object
You first create a daq session (or DataAcquisition object if using newer MATLAB versions).
Step 2: Add a digital output line
Add the line (e.g., port0/line0) as a digital output to your session.
Step 3: Write a logical value to the line
You use the write function to set the line to true (1) for high or false (0) for low.
Step 4: Full Example Code
Here is the complete code to set port0/line0 high, then low after 1 second:
% Step 1: Create DAQ session
dq = daq("ni");
% Step 2: Add digital output channel (use correct device ID, e.g., "Dev1")
dq.addoutput("Dev1", "port0/line0", "Digital");
% Step 3: Set line HIGH
write(dq, true); % or write(dq, 1);
pause(1); % wait for 1 second
% Step 4: Set line LOW
write(dq, false); % or write(dq, 0);
You can repeat the write command any number of times to toggle the pin.
References:
Hope this helps!

Categorías

Más información sobre Data Acquisition Toolbox Supported Hardware en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by