Tips for Using the Network Variable Library
- Updated2023-02-21
- 3 minute(s) read
Consider the following items as you create applications using the Network Variable Library.
Discarding and Cleaning up Global Resources
You must call the CNVFinish function after your program is done using the Network Variable Library to discard and clean up global resources. If you do not call this function after calling other functions in the Network Variable Library, your program might hang or crash when it closes and LabWindows/CVI might not be able to report the leaked resources in your program. You must not call this function in DllMain, atexit handlers, and Network Variable Library callback functions—doing so may cause your application to deadlock and stop responding.
Sharing Resources
The system shares resources like sockets and data buffers among connections that refer to the same network variable in one program. Sharing can result in program behavior that is different from having a single connection per variable, especially in buffering.
Configuring Firewalls and NAT Routers
You must configure firewalls and Network Address Translating (NAT) routers if you want to access network variables through firewalls or routers.
Specifying a Timeout Period
As you debug, network variable connections may disconnect, depending on how long your program is suspended. If a network variable gets disconnected because the program is suspended longer than allowed, the library automatically tries to reconnect when the program resumes. The default timeout for this is 10 seconds on Windows and 12 seconds on real-time (RT) systems. You can change the timeout by creating an INI file:
Create a file named logosxt.ini in C:\ProgramData\National Instruments\Logos XT on Windows or in /usr/local/natinst/share/etc on Linux. Add the following lines to logosxt.ini:
[logosXT]
Heartbeat_SendTimeoutSecs=n
Heartbeat_AbsenceDetectCount=n
The Network Variable Library determines the timeout period by calculating Heartbeat_SendTimeoutSecs × Heartbeat_AbsenceDetectCount.
![]() |
Note For RT systems, add the Heartbeat_SendTimeoutSecs and Heartbeat_AbsenceDetectCount items to the ni-rt.ini file to specify a timeout period. |
If you are using the Logos protocol, create a file named logos.ini in your Windows folder (\windows or \winnt) with the following lines:
[LogosSockets]
DisconnectTimeoutSeconds=n
You must restart your computer after creating or changing the logosxt.ini or logos.ini file. Setting the DisconnectTimeoutSeconds item to 0 prevents network variables from disconnecting when the program suspends. National Instruments recommends that you change or disable this setting only while debugging, and afterwards delete the INI file and restart your computer to use the default value. You also can see this behavior if you run the Network Variable Library function panels or call the Network Variable Library functions in the Interactive Execution Window.
Receiving Data on Reader Connections
In some cases, reader connections might receive data or data notifications even when new data has not been written to the server. This issue typically occurs for network variables with the single-writer restriction when an existing writer disconnects or a new writer connects. Data is sent again because the write-access attribute changes on the server.
You can avoid this behavior if your system has only one writer connection and the lifetime of the reader connection is bound by the lifetime of the writer connection. You also can avoid this behavior if you use explicitly created network variables, which do not have the single-writer restriction.