Programmatically Opening and Closing Data Connections

Use the DataSocket Open and DataSocket Close functions to open and close data connections programmatically.

Complete the following steps to open and close a data connection programmatically.

  1. Add the DataSocket Open function to the block diagram.

     Add  Find
  2. Wire a psp URL to the URL input or wire a shared variable control to the URL input.
  3. Right-click the mode input and select Create»Constant from the shortcut menu.
  4. Click the mode constant and select Read (0), Write (1), ReadWrite (2), BufferedRead (3), or BufferedReadWrite (4). You also can use the DataSocket:Mode property to set the data connection mode programmatically.
  5. Add one of the following functions to the block diagram and create controls or constants for the appropriate inputs:
  6. Wire the connection id output of the DataSocket Open function to the connection in input of the DataSocket Read or DataSocket Write function.
  7. Add a DataSocket Close function to the block diagram.

     Add  Find
  8. Wire the connection out output of the DataSocket Read or DataSocket Write function to the connection id input of the DataSocket Close function to close the data connection. The connection also closes when the VI stops.
  9. Wire all error in and error out terminals on the block diagram.