Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

NI-DAQmx/NI-syscfg crashes on 64bit library

So, using the text based environment I am trying to create an application that uses both nidaqmx and nisyscfg libraries. I am using the c language with the provided headers and libraries, and the latest version available of both. For reference, following is a screenshot from ni-package mangager:

thumbnail_Outlook-wqrt4ec3.png

 

Playing with the examples provided I found out that I had to have set the includes path and the libraries path to, respectively:

Include path is set to: "C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\include"
Libraries path is set to: "C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc"

 

These are snippets of the programs that I am compiling with msvc (Visual Studio 2022 Developer Command Prompt v17.7.6)

#pragma comment(lib, "NIDAQmx.lib")
#include <NIDAQmx.h>
#include <stdio.h>

#define DAQmxErrChk(functionCall) if(DAQmxFailed(error=(functionCall)) ) goto Error; else

int main(void) {
int32 error = 0;
char buffer[2048];
DAQmxErrChk(DAQmxGetSysDevNames(buffer, sizeof(buffer)));
printf("DEVICES (max chars %u): %s\n", sizeof(buffer), buffer);
Error:
return 0;
}

 

And another one:

#include <string.h>
#include <stdio.h>
#include "nisyscfg.h"
#pragma comment(lib, "nisyscfg.lib")

int main(void) {
      NISysCfgStatus status = NISysCfg_OK;
      NISysCfgSessionHandle session = NULL;
      NISysCfgEnumResourceHandle resourcesHandle = NULL;
      NISysCfgResourceHandle resource = NULL;
      NISysCfgFilterHandle filter = NULL;
      char expertName[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
      char resourceName[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
      char alias[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
      char productName[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
      char serialNumber[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
      char systemState[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
      char target[NISYSCFG_SIMPLE_STRING_LENGTH] = "";
      char* detailedDescription = NULL;
      char networkShow = 'y';

      //    Initialize System Configuration session and find all hardware on the target
      printf("\nInitializing session and finding hardware... \n");
      if (NISysCfg_Succeeded(status = NISysCfgInitializeSession("localhost", 0, 0, NISysCfgLocaleDefault, NISysCfgBoolTrue, 10000, 0, &session)))
{
            if (NISysCfg_Succeeded(status = NISysCfgCreateFilter(session, &filter)))
            {
                  NISysCfgSetFilterProperty(filter, NISysCfgFilterPropertyIsDevice, NISysCfgBoolTrue);
                  NISysCfgSetFilterProperty(filter, NISysCfgFilterPropertyIsPresent, NISysCfgIsPresentTypePresent);
                  NISysCfgSetFilterProperty(filter, NISysCfgResourcePropertyIsNIProduct, NISysCfgBoolTrue);
                  NISysCfgGetSystemProperty(session, NISysCfgSystemPropertySystemState, systemState);
                  printf("System state : %i\n\n\n", systemState);
                  if (NISysCfg_Succeeded(status = NISysCfgFindHardware(session, NISysCfgFilterModeAll, filter, NULL, &resourcesHandle)))
                  {
                        //    Iterate through all found resources and obtain properties
                        while (NISysCfg_Succeeded(status) && (status = NISysCfgNextResource(session, resourcesHandle, &resource)) == NISysCfg_OK)
                        {
                              NISysCfgGetResourceIndexedProperty(resource, NISysCfgIndexedPropertyExpertName, 0, expertName);
                              if ((strcmp(expertName, "network") != 0) || (networkShow == 'y' || networkShow == 'Y'))
                              {
                                    NISysCfgGetResourceIndexedProperty(resource, NISysCfgIndexedPropertyExpertResourceName, 0, resourceName);
                                    NISysCfgGetResourceIndexedProperty(resource, NISysCfgIndexedPropertyExpertUserAlias, 0, alias);

                                    //    Print the Device Alias if it exists (e.g. Dev1, PXI1Slot2, etc), otherwise print the Resource Name
                                    if (strlen(alias))
                                          printf("Device Alias : %s\n", alias);
                                    else
                                          printf("Resource Name : %s\n", resourceName);

                                    int led_state;
                                    NISysCfgGetResourceIndexedProperty(resource, NISysCfgIndexedPropertyUserLedState, 0, &led_state);
                                    printf("LED Satae : %i\n", led_state);

                                    NISysCfgGetResourceProperty(resource, NISysCfgResourcePropertyProductName, productName);
                                    printf("Product Name : %s\n", productName);

                                    NISysCfgGetResourceProperty(resource, NISysCfgResourcePropertySerialNumber, serialNumber);
                                    printf("Serial Number : %s\n", serialNumber);

                                    int adapter;
                                    NISysCfgGetResourceProperty(resource, NISysCfgResourcePropertyAdapterMode, &adapter);
                                    printf("Network adaptr: %i\n\n", adapter);

                                    status = NISysCfgCloseHandle(resource);
                              }
                        }
                  }
            }
}

      if (NISysCfg_Failed(status))
      {
            NISysCfgGetStatusDescription(session, status, &detailedDescription);
            printf("Error: %s\n", detailedDescription);

            NISysCfgFreeDetailedString(detailedDescription);
      }

      printf("Press Enter to close session and exit\n");
      fflush(stdin);
      getchar();
      status = NISysCfgCloseHandle(filter);
      status = NISysCfgCloseHandle(resourcesHandle);
      status = NISysCfgCloseHandle(session);
      return 0;
}

 

And sure enough everything works out as expected.

But the problem arises when I try to switch to compiling for x64. I change the includes and libraries path to the following:

Include path is set to: "C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\include"
Libraries path is set to: "C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc"

 

And compile. Everything compiles just fine, but when I try to run both programs they both crash with an access violation error as soon as control reaches one of the functions provided by the ni libraries:

thumbnail_Outlook-jbn0eznr.png

Outlook-zn03u0kz.png

 

I tried a couple of previous versions of both ni packages, but with the same exact results both times. I also tried uninstalling everything and then reinstalling the packages. I need the 64 bit version to work, to be able to integrate ni-stuff into a software we have, so I can't use the 32 bit version.

 

Does using 64bit version have something different, like some function or macro that I need to set or something like that or is it the library or something else? If anybody could give me a hand I'd be thankful!

0 Kudos
Message 1 of 3
(547 Views)

I have only tried to build a 64-bit EXE using CMake in VS Code. Perhaps you can use the attached file as a reference.

-------------------------------------------------------
Applications Engineer | TME Systems
https://tmesystems.net/
0 Kudos
Message 2 of 3
(509 Views)

Hmm, sadly even this problem occurs even with your provided configuration. Oddly enough, while trying to lauch the program without the debugger (thus launching directly the exe from file explorer) everything seems to behave, which is an improvement I guess, but I kind of need the debugger ;). Trying again with the debugger though, and the access violation pops up as soon as a function from the library gets called, in your example on the first DAQmxCreateTask("", &taskHandle) call; which is quite weird. I've also tried another debugger that's not visual studio, but the same thing happens there too.

image.png

0 Kudos
Message 3 of 3
(480 Views)