To download NI software, including the products shown below, visit ni.com/downloads.
Overview
This VI demonstrates how to use property nodes to poll your system for a particular device, so that you can programmatically choose the Physical Channel input for DAQmx Create Channel.vi.
Description
This programmatically inputs the device name into the DAQmx Create Channel "physical channel" sink. It queries the system for available device and finds the device name based on matching the device product type to the device you specify. Loop through the array of DevNames in the System until the device you are looking for (A) matches the ProductType output (B). Concatenate a string: device name + "/" + channel. This string can be used as input into the "Physical Channel" input for the Create Channel.vi.
Requirements
Software
Hardware
Steps to Implement or Execute Code
1. Design a file path
2.Use the create virtual channel drop down box to select the log channel and window channel by control clicking the two.
3. Run the VI
4.Observe the results in the text file after stopping it.
Additional Information or References
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Thanks for posting! Do you mind renaming your attachment to include the LabVIEW version? Something like "_lvXX.vi" would be great.
How would you do this with GPIB devices
Assuming it pastes properly, below is an ANSI C version. As is too often the case, the NI documentation is incomplete, so I had to guess about what might work -- an unfortunate situation for a commercial product. Based on my testing, the code below works using NI DAQmx 15.1
--------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include "NIDAQmx.h"
static void ni_error(void);
int main(void)
{
int xrc = 0;
char *p_buf = (char *) NULL; /* buffer to receive names */
int rc;
/* Find the required buffer size. This feature appears to be undocumented
* but setting the buffer to NULL and the size to 0 returns the required
* buffer size. It is unknown what other combinations would return this
* information. The size returned includes space for a terminating '\0' */
if (DAQmxFailed(rc = DAQmxGetSysDevNames(NULL, 0))) {
(void) fprintf(stderr, "Error getting size "
"system device names. "
"NI returned %d.\n");
ni_error();
xrc = -1;
goto EXITPOINT;
}
/* Allocate buffer to receive names of devices */
if ((p_buf = (char *) malloc(rc)) == (char *) NULL) {
(void) fprintf(stderr, "Unable to allocate buffer "
"to receive names of devices.\n");
xrc = -1;
goto EXITPOINT;
}
/* Call again with a properly sized buffer. On successful return the
* names are given as a comma-separated list with one space after the
* comma. Again these details are not specived in the documentation but
* appear to be what is done. */
if (DAQmxFailed(rc = DAQmxGetSysDevNames(p_buf, rc))) {
(void) fprintf(stderr, "Error getting system device names. "
"NI returned %d.\n");
ni_error();
xrc = -1;
goto EXITPOINT;
}
/* Output results */
if (fprintf(stdout, "Installed devices: %s.\n",
p_buf) < 0) {
(void) fprintf(stderr, "Unable to output device names.\n");
xrc = -1;
goto EXITPOINT;
}
EXITPOINT:
/* Free buffer used to get names of devices */
if (p_buf != (char *) NULL) {
free((void *) p_buf);
}
return xrc;
} /* end of function main */
/* Unsure about length, but 2048 used in samples */
#define N_BYTE_ERROR_STRING 2048
/* This function gets the NI error details and outputs them to stderr.
* It should be called before any other NI calls are made to preserve
* the error */
static void ni_error(void)
{
char p_buf[N_BYTE_ERROR_STRING];
/* Get details */
DAQmxGetExtendedErrorInfo(p_buf, sizeof p_buf);
/* Output details */
(void) fprintf(stderr, "NI details: %s.\n",
p_buf);
return;
} /* end of function ni_error */