Reading and Writing Data (WSN)
- Updated2023-02-21
- 3 minute(s) read
WSN VIs use Elemental I/O to read from and write to analog and digital channels. You use I/O variables to read data from and write data to the host. To transfer the value of a hardware channel to the host, wire the Elemental I/O item to its corresponding static I/O variable, as shown in the following block diagram.
You access data using static I/O variables from the project tree in the Project Explorer window or programmatically using supported Shared Variable functions with the following URL format:
ni.var.psp://gateway/node/channel
- gateway—The IP address of the WSN gateway. For NI 9792 WSN Real-Time Gateway targets, you can use localhost for local I/O variable access.
- node—The WSN node name. The default node name is Nodex in the project tree, where x is the ID assigned to the WSN node when you added it to the LabVIEW project. Node names become active after you deploy the project to the gateway.
- channel—The I/O variable name. Default I/O variable names depend on the WSN node type. I/O variable names become active after you deploy the project to the gateway.
The following block diagram demonstrates how to use the AI0 I/O variable to write data from AI0 on Node1.
![]() |
Note Use the supported Shared Variable functions if the data type of an I/O variable or user-defined I/O variable is a waveform. For I/O variables with other data types, use the static I/O variables for the project. |
Creating User-Defined I/O Variables
You can create user-defined I/O variables to send data from the WSN node to the host. You can create a maximum of eight user-defined I/O variables per WSN node.
Complete the following steps to create a user-defined I/O variable.
- Right-click the WSN node in the Project Explorer window and select New»User-Defined Variable.
- Select the data type for the I/O variable. The Length text box automatically displays the maximum size for the selected data type.
Note Some WSN nodes support only certain types of I/O variables.
You only can create user-defined I/O variables that send data from the WSN node to the WSN gateway. Sending data from the WSN gateway to the WSN node is unsupported.
The following LabVIEW project includes User0, a user-defined I/O variable.
The following block diagram demonstrates how to write the value of AI0 on Node1 to User0. User0 then sends that data to the WSN gateway.
Buffering Data
When you use I/O variables in a WSN VI, LabVIEW buffers the data in the I/O variable buffer, which is a first-in-first-out (FIFO) buffer. Buffering the data prevents data loss if the network connection fails.
You can use the Memory Configuration page to configure the size of the I/O variable buffer. When you increase the I/O variable buffer size, the amount of total RAM that the I/O variable buffer uses might increase significantly. If the network connection fails, the I/O variable buffer retains any data that LabVIEW wrote to the buffer.
You must enable buffering for each I/O variable to enable I/O variable buffering.