VirtualBench

cancel
Showing results for 
Search instead for 
Did you mean: 

VirtualBench C API Getting started - Are there examples/documentation somewhere?

I am new to VirtualBench and I saw that there is a C API but cannot find much about it online or any documentation.  Maybe I am just looking in the wrong place.  I have the latest driver installed on my machine.  Is there an example program and documentation somewhere?  Thanks!

0 Kudos
Message 1 of 11
(10,551 Views)

Hi Ejo,

 

If you install ANSI C support during the NI-VirtualBench driver install, after the install completes you should find a VirtualBench C Reference Help.chm at C:\Users\Public\Documents\National Instruments\VirtualBench Documentation as well as example programs at C:\Users\Public\Documents\National Instruments\VirtualBench ANSI C Examples.

 

If you don't see these files currently, you can go to Control Panel >> Programs and Features >> National Instruments Software, find the VirtualBench ADE Support, and do a modify install.

 

Hope that helps!

Michael Keane
National Instruments
0 Kudos
Message 2 of 11
(10,522 Views)

Thank you, I found the examples, but I am having trouble getting them to compile.  Can you point me to the location of the nivirtualbench.h file?

0 Kudos
Message 3 of 11
(10,479 Views)

I have found the nivirtualbench.h file under C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C

But I still cannot get the example to compile, specifically, niVB_Dig_Example.c

 

I created a new project in eclipse, pointed it to the correct .h files now, but I am still getting this error:
relocation truncated to fit: R_X86_64_PC32 against undefined symbol `niVB_Dig_Close' niVB_Dig_Example line 0 C/C++ Problem

 

I also tried the niVB_Dig_Example_utf16.c, but I don't have the windows.h file for that example.

0 Kudos
Message 4 of 11
(10,476 Views)

You'll also need to link against the import library. I'm not an Eclipse user, so I don't know where specifically in the project options this needs to go (somewhere related to "linker options" probably?), but you'll need to add one of the following:

  • C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc\nivirtualbench.lib (for 32-bit applications)
  • C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc\nivirtualbench.lib (for 64-bit applications)

 

For the *_utf16.c examples, windows.h is part of the Windows SDK.

——
Brandon Streiff
ni.com/compactdaq · ni.com/daq
0 Kudos
Message 5 of 11
(10,470 Views)

I think I am linking the libs correctly, but I am still receiving those errors.  Below are the actual commands that are getting run from eclipse:

 

make all 
Building file: ../src/niVB_Dig_Example2.c
Invoking: Cross GCC Compiler
gcc -I"C:\cygwin64\usr\include" -I"C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\include" -O0 -g3 -Wall -c -fmessage-length=0 -mcmodel=medium -fPIC -MMD -MP -MF"src/niVB_Dig_Example2.d" -MT"src/niVB_Dig_Example2.o" -o "src/niVB_Dig_Example2.o" "../src/niVB_Dig_Example2.c"
../src/niVB_Dig_Example2.c:1:0: warning: -fPIC ignored for target (all code is position independent)
 /******************************************************************************
 ^
../src/niVB_Dig_Example2.c: In function 'main':
../src/niVB_Dig_Example2.c:98:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t {aka long unsigned int}' [-Wformat=]
          printf("Iteration %d:\n", i);
                 ^
../src/niVB_Dig_Example2.c:98:17: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t {aka long unsigned int}' [-Wformat=]
Finished building: ../src/niVB_Dig_Example2.c
 
Building target: niVB_Dig_Example2.exe
Invoking: Cross GCC Linker
gcc -L"C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc" -o "niVB_Dig_Example2.exe"  ./src/niVB_Dig_Example2.o   -lnisyscfg -lnivirtualbench
C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Initialize' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b)
C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Finalize' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b)
C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_GetExtendedErrorInformation' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b)
C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_GetErrorDescription' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b)
C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Dig_Initialize' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b)
C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Dig_Write' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b)
C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Dig_Read' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b)
C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b):(.text+0x2): relocation truncated to fit: R_X86_64_32 against symbol `__imp_niVB_Dig_Close' defined in .idata$5 section in C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc/nivirtualbench.lib(nilcicapi.dll.b)
collect2: error: ld returned 1 exit status
make: *** [makefile:32: niVB_Dig_Example2.exe] Error 1
0 Kudos
Message 6 of 11
(10,461 Views)

Sorry, those were not the same errors as before, these are new "relocation truncated to fit" errors, which I think indicates either a linking issue or trying to store some very large data in the program, or maybe something else.

0 Kudos
Message 7 of 11
(10,456 Views)

Is it possible for NI to provide a complete working Solution file (for visual studio), a Makefile, or even just the gcc commands used to compile and link the examples properly?  I am having a tough time getting this to work with our new VirtualBench.

0 Kudos
Message 8 of 11
(10,445 Views)

Apologies for the delay; I'd been tied up with NIWeek.

 

Attached is an example project I built with MSVC2017. I built this with the following steps:

  • New→Project..., starting from the C++ Empty Project template.
  • Project→Properties
    • Set Configuration: "All Configurations", Platform: "All Platforms":
      • Under "VC++ Directories", added "C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\include" to "Include Directories"
      • Under Linker→Input, added "nivirtualbench.lib" to "Additional Dependencies"
    • Set Configuration: "All Configurations", Platform: "Win32"
      • Under "VC++ Directories", added "C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib32\msvc" to "Library Directories"
    • Set Configuration: "All Configurations", Platform: "x64"
      • Under "VC++ Directories", added "C:\Program Files (x86)\National Instruments\Shared\ExternalCompilerSupport\C\lib64\msvc" to "Library Directories"
  • Project→Add Existing Item...
    • Added "C:\Users\Public\Documents\National Instruments\VirtualBench ANSI C Examples\niVB_DMM_Example.c"

I think these steps should be roughly the same for older versions of MSVC.

 

I also ran into the same format-string warnings you saw when building for 64-bit; when the examples were first made, the current version of MSVC didn't support format-string checking, so we missed that. I filed CAR 648920 for us to update the example to use the correct format string specifiers.

——
Brandon Streiff
ni.com/compactdaq · ni.com/daq
Message 9 of 11
(10,436 Views)

Thank you for the complete project, it worked right away and I see where I went wrong now. I was able to modify some of the examples to do what I need with the VB. I don't have much experience with Visual Studio or MSVC, so this was a big help.  I think it would be beneficial to others to have a sample project like that bundled with the API.

0 Kudos
Message 10 of 11
(10,421 Views)