VISA Sockets vs. Other Sockets APIs

NI-VISA

VISA Sockets vs. Other Sockets APIs

For TCP/IP devices that you want to program directly (in the absence of a higher level protocol implementation), VISA provides a platform independent sockets API. VISA sockets are based on the UNIX sockets implementation in the Berkeley Software Distribution. A socket is a bi-directional communication endpoint, an object through which a VISA sockets application sends or receives packets of data across a network.

The VISA socket resource string format is "TCPIP::<hostname>::<port>::SOCKET". The SOCKET resource class informs VISA that you are communicating with an Ethernet device that does not support the LAN instrument or LXI protocol. By default, only the read and write operations are valid. If the device recognizes 488.2 commands such as "*TRG\n" and "*STB?\n", you can set the attribute VI_ATTR_IO_PROT to VI_PROT_4882_STRS (4) and then use the operations such as viAssertTrigger() and viReadSTB(). However, unlike LAN instruments, there is no way to support the service request event with the SOCKET resource class.

For users familiar with other platform independent sockets APIs, VISA does have some advantages. The VISA sockets API is simpler than the UNIX sockets API because viOpen() includes the functionality of socket(), bind(), and connect(). It is simpler and more portable than the Windows sockets API because it removes the need for calls to WSAStartup() and WSACleanup(). VISA uses platform independent VISA callbacks for asynchronous reads and writes so you do not need the platform specific knowledge of threading models and asynchronous completion services that other sockets APIs require. Finally, VISA is more powerful than that of many application development environments because it provides additional attributes for modifying the TCP/IP communication parameters.

The attribute VI_ATTR_TCPIP_KEEPALIVE defaults to false, but if enabled will use "keep-alive" packets to ensure that the connection has not been lost. The attribute VI_ATTR_TCPIP_NODELAY defaults to true, which enforces that VISA write operations get flushed immediately; this ensures consistency with other supported VISA interfaces. The default setting disables the Nagle algorithm, which typically improves network performance by buffering send data until a full-size packet can be sent. Disabling this attribute (setting it to false) may improve the performance of multiple back-to-back VISA write operations to a TCP/IP device.