Example Programs

cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatically Finding Device in System

 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

  • LabVIEW 2012 or compatible
  • NI-DAQmx 9.5.5 or compatible

Hardware

  • NI Multifunction DAQ Device

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

 

搜狗截图17年01月07日1554_5.png

**This document has been updated to meet the current required format for the NI Code Exchange.**

 

Comments
Todd S.
NI Employee

Thanks for posting!  Do you mind renaming your attachment to include the LabVIEW version?  Something like "_lvXX.vi" would be great.

Todd S.
LabVIEW Community Manager
National Instruments
Member metoo
Member

How would you do this with GPIB devices

Member jim_monte
Member

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 */

Member Лехтин_АВ
Member
ok. This is informative C - example. Thanks! But anybody knows how detect IP address cDAQ shassi using NIDAQmx.lib ? Any opinions and an experience are welcome...