Sharing Live Data Programmatically

You can use the DataSocket VI and functions to programmatically configure, read, or write live data.

(Real-Time, Windows) National Instruments recommends that you wire a Shared Variable node into VIs and functions to share live data programmatically.

Note You can create, configure, and host shared variables only on Windows or RT targets with the LabVIEW Real Time Module. Use the DataSocket VI and functions to read or write shared variables from other platforms.

Using Shared Variables

Use shared variables to share data among VIs or between locations on the block diagram that you cannot connect with wires. You can share data using shared variables with little or no block diagram programming.

For the DataSocket VI and functions, you read or write data by specifying a URL in much the same way you specify URLs in a Web browser.

Specifying a URL

URLs use communication protocols, such as opc, ftp, and http on Windows, and psp, dstp, and file on all LabVIEW-supported platforms, to transfer data. The protocol you use in a URL depends on the type of data you want to write and how you configure your network.

You can use the following protocols when you read or write data using the DataSocket VI and functions or when you enable a connection for a control :

  • NI Publish-Subscribe Protocol psp —National Instruments technology for transmitting data between the network and your local computer. When you use this protocol, the VI communicates with the Shared Variable Engine (SVE). Use the psp protocol to connect to shared variables and server or device data items. You must provide a name for the data item, which is appended to the URL. The data connection uses that name to address a particular data item in the SVE. You also can use this protocol when using front panel data binding. You can use the fieldpoint protocol as an alias for NI Publish-Subscribe Protocol (NI-PSP).
  • DataSocket Transport Protocol dstp —When you use this protocol, the VI communicates with the DataSocket Server. You must provide a named tag for the data, which is appended to the URL. The data connection uses the named tag to address a particular data item on a DataSocket Server. To use this protocol, you must run a DataSocket Server.
  • (Windows) OLE for Process Controlopc —Designed specifically for sharing real-time production data, such as data generated by industrial automation operations. To use this protocol, you must run an OPC server.
  • (Windows) File Transfer Protocolftp —You can use this protocol to specify a file from which to read data from an FTP server.
    Note To read a text file from an FTP site using DataSocket functions, add [text] to the end of the URL.
  • file —You can use this protocol to provide a link to a local or network file that contains data.
  • (Windows) http —You can use this protocol to provide a link to a Web page that contains data.
    Note To read a text file via the http protocol using DataSocket functions, add [text] to the end of the URL.

The following table shows examples of each protocol URL.

URL Example

psp

For shared variables:

psp://computer/library/shared_variable

For NI-PSP data items, such as server and device data items:

psp://computer/process/data_item

fieldpoint://host/FP/module/channel

dstp

dstp://servername.com/numeric, where numeric is the named tag for the data

opc

opc:\National Instruments.OPCTest\item1

opc:\computer\National Instruments.OPCModbus\Modbus Demo Box.4:0

opc:\computer\National Instruments.OPCModbus\Modbus Demo Box.4:0?updaterate=100&deadband=0.7

ftp

ftp://ftp.ni.com/datasocket/ping.wav

ftp://ftp.ni.com/support/00README.txt[text]

file

file:ping.wav

file:c:\mydata\ping.wav

file:\computer\mydata\ping.wav

http

http://ni.com

Use the psp, dstp, and opc URLs to share live data because these protocols can update remote and local controls and indicators. Use the ftp and file URLs to read data from files because these protocols cannot update remote and local controls and indicators.

Data Formats Supported by the DataSocket VI and Functions

You can pass data of any LabVIEW data type using the DataSocket VI and functions. You also can use the DataSocket VI and functions to read and write the following data:

  • Raw text —Use raw text to deliver a string to a string indicator.
  • Tabbed text —Use tabbed text, as in a spreadsheet, to write data in arrays. LabVIEW interprets tabbed text as an array of data.
  • .wav data —Use .wav data to write a sound to a VI or function.
  • Variant data —Use variant data to read data from another application, such as a National Instruments Measurement Studio ActiveX control.