1 / 32

Graphical Programming Lecture 9 - Networking in LabVIEW

Graphical Programming Lecture 9 - Networking in LabVIEW. Witold Nocoń, Ph.D. http://terminator.ia.polsl.gliwice.pl/~virtual alias: http://www.virtual.w.pl. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Introduction.

luna
Télécharger la présentation

Graphical Programming Lecture 9 - Networking in LabVIEW

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Graphical ProgrammingLecture 9 - Networking in LabVIEW Witold Nocoń, Ph.D http://terminator.ia.polsl.gliwice.pl/~virtual alias: http://www.virtual.w.pl

  2. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Introduction In this lecture, the following networking technologies will be discussed: • DataSocket technology • UDP • TCP Obviously, those are not the only networking technologies...

  3. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket DataSocket is a technology to share live data with other VIs and other applications, such as National Instruments ComponentWorks, on the Web, or on your local computer. DataSocket technology provides access to several input and output mechanisms from the front panel through the DataSocket Connection dialog box.

  4. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket Suppose you want to share the measurements with several machines. A typical scenario is a college lab where one machine controls the experiment while several students do their own real-time analysis from individual workstations. Historically, to do this you would have turned to the TCP library to distribute the data. While these libraries can solve the problem, there are several steps to complete: • Pick a TCP/IP port number (and hope it is not in use by any other apps on the system) • Define the protocol (e.g. what gets sent when) • Configure the Server to listens on selected port and create connection when client initiates request. • Configure the Server to flatten the data and writes to all connections. • Manage any errors • Configure the Client applications to connect to the selected port, unflatten the data, and display it.

  5. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket This is only an overview, but already you find several details that most developers would rather not have to deal with. Of course, when you make changes to the server, such as adding a new data item, you have to fix all the clients as well. With enough work, you can make a very robust implementation, but you have added a lot of code to your simple program. To perform the same task using the DataSocket technology you perform two basics steps: • Open a DataSocket connection using a name you choose to identify the data. • Write data to that connection as you compute new results In this case, the low-level TCP/IP programming has been done for you.

  6. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket - Specifying a URL URLs use communication protocols, such as dstp, ftp, and file, to transfer data. The protocol you use in a URL depends on the type of data you want to publish and how you configure your network. You can use the following protocols when you publish or subscribe to data using DataSocket: • DataSocket Transport Protocol (dstp) The native protocol for DataSocket connections. 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 DataSocket 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 Control (opc)—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.

  7. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket -Specifying a URL • (Windows) logos—An internal National Instruments technology for transmitting data between the network and your local computer. •File Transfer Protocol (ftp)—You can use this protocol to specify a file from which to read data. • file—You can use this protocol to provide a link to a local or network file that contains data.

  8. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket - Data Formats Supported by DataSocket Use DataSocket to publish and subscribe to 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 publish data in arrays. LabVIEW interprets tabbed text as an array of data. • wav data—Use .wav data to publish a sound to a VI or function. • Variant data—Use variant data to subscribe to data from another application, such as a ComponentWorks control.

  9. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket - using it on the Front Panel The simplest way to connect between applications (to send data from one application to another) is by publishing or subscribing to a front panel object. When you share the data of a front panel object with other users, you publish data. When users retrieve the published data and view it on their front panel, users subscribe to the data. Note: DataSocket Server should be run before using DataSocket networking. Use: Start - Programs - National Instruments - DataSocket - DataSocker Server, or the DataSocket Server may be launched programmatically.

  10. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket - using it on the Front Panel To publish data from a particular control or indicator, right-click on it and select Data Operations - Data Socket Connection... ...specify the URL for this particular data (dstp://address/DataName), and select Publish (form Connection Type) To subscribe to data (so that the value of the indicator will be taken from DataSocket, select Subscribe (form Connection Type)

  11. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket - using it on the Front Panel Once, an object is “connected” to DataSocket, a small indicator appears (connection status: - green - OK, red - error) Example (gp9_1.vi).

  12. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket - reading and writing live data through the Block Diagram DataSocket Write Writes data to the connection specified in URL. The connector pane displays the default data types for this polymorphic function. data is the data written to the DataSocket connection. data can be in any format or LabVIEW data type.

  13. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket - reading and writing live data through the Block Diagram DataSocket Read Reads the data from the connection specified in URL and returns the data, which you can publish to another front panel object or pass to another function. The connector pane displays the default data types for this polymorphic function. type (Variant) specifies the type of data to be read and defines the type of thedata output terminal. The default type is a Variant, which can be any type. ms timeout specifies how long to wait for a value update. This time is ignored if wait for updated value is false and an initial value has arrived. The default is 10 seconds. Example (gp9_2.vi).

  14. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket and Variant Data In some cases, the VI or other application that programmatically reads the data cannot convert the data back into its original data type, such as when you subscribe to data from another application. Also, you might want to add an attribute to the data, such as a timestamp or warning, which the data types do not permit.

  15. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. DataSocket and Variant Data

  16. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are available on all platforms LabVIEW supports. What about IP? IP performs the low-level service of moving data between computers. IP packages data into components called datagrams. A datagram contains, among other things, the data and a header that indicates the source and destination addresses. IP determines the correct path for the datagram to take across the network or internet and sends the data to the specified destination. IP cannot guarantee delivery. In fact, IP may deliver a single datagram more than once if the datagram is duplicated in transmission. Programs rarely use IP because they use TCP or UDP instead.

  17. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) are available on all platforms LabVIEW supports. TCP is a reliable, connection-based protocol. It provides error detection and ensures that data arrive in order and without duplication. For these reasons, TCP is usually the best choice for network applications. Although UDP can give higher performance than TCP and does not require a connection, it does not guarantee delivery. Typically, use UDP in applications in which guaranteed delivery is not critical. For example, an application might transmit data to a destination frequently enough that a few lost segments of data are not problematic.

  18. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - UDP (User Datagram Protocol) UDP provides simple, low-level communication between processes on computers. Processes communicate by sending datagrams to a destination computer or port. A port is the location where you send data. IP handles the computer-to-computer delivery. Once the datagram reaches the destination computer, UDP moves the datagram to its destination port. If the destination port is not open, UDP discards the datagram. UDP shares all the delivery problems of IP. Use UDP in applications where reliability is not critical. For example, an application might transmit informative data to a destination frequently enough that a few lost segments of data are not problematic. Using UDP Because UDP is not a connection-based protocol as TCP is, you do not need to establish a connection with a destination before you send or receive data. Instead, you specify the destination for the data when you send each datagram. Operating systems do not report transmission errors.

  19. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - UDP (User Datagram Protocol) Use the UDP Open function to open a port. The number of simultaneously open UDP ports depends on the operating system. UDP Open returns a UDP Network Connection refnum, which is an opaque token used in all subsequent operations that pertain to that port. UDP Open connection ID is a network connection refnum that uniquely identifies the UDP socket. Use this value to refer to this socket in subsequent VI calls.

  20. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - UDP (User Datagram Protocol) Use the UDP Write function to send data to a destination and use the UDP Read function to read that data. Each write operation requires a destination address and port. Each read operation contains the source address and port. UDP preserves the datagram bytes that you specified for each command you send. UDP Write port is the port of the address to which you want to send a datagram. address is the address of the computer where you want to send a datagram connection ID is a network connection refnum that uniquely identifies the UDP socket. Use this value to refer to this socket in subsequent VI calls.

  21. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - UDP (User Datagram Protocol) UDP Read max size is the maximum number of bytes to read. The default is 548. timeout ms is in milliseconds. If the connection is not established in the specified time, the VI completes and returns an error. The default is –1, which indicates to wait indefinitely. port is the port of the UDP socket that sent the datagram. address is the address of the computer where a datagram originates

  22. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - UDP (User Datagram Protocol) UDP Close connection ID is a network connection refnum that uniquely identifies the UDP socket you want to close. Example (gp9_3.vi).

  23. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) TCP ensures reliable transmission across networks, delivering data in sequencewithout errors, loss, or duplication. TCP will retransmit the datagram until it receives an acknowledgement. TCP is a connection-based protocol, which means that sites must establish a connection before transferring data. TCP permits multiple, simultaneous connections. You initiate a connection either by waiting for an incoming connection or by actively seeking a connection with a specified address. In establishing TCP connections, you have to specify the address and a port at that address. A number between 0 and 65,535 represents a port. UNIX reserves port numbers less than 1,024 for privileged applications. Different ports at a given address identify different services at that address.

  24. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) TCP Open Connection Opens a TCP network connection with the address and port. address is the address with which you want to establish a TCP connection. This address can be in IP dot notation or it can be a hostname. remote port is the port of the address with which you want to establish a TCP connection. timeout ms is in milliseconds. If the connection is not established in the specifiedtime, the VI completes and returns an error. The default is 60,000 ms (1 minute). A value of –1 indicates to wait indefinitely. local port is the local TCP connection port. Some servers only allow connections to clients that use port numbers within a specific range that is dependent on the server. If the value is 0, the operating system selects an unused port. connection ID is a network connection refnum that uniquely identifies the TCP connection. Use this value to refer to this connection in subsequent VI calls.

  25. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) TCP Listen Creates a listener and waits for an accepted TCP network connection at the specified port. port is the port number on which you want to listen for a connection. timeout ms is in milliseconds. If the connection is not established in the specified time, the VI completes and returns an error. The default is –1, which indicates towait indefinitely. connection ID is a network connection refnum that uniquely identifies the TCP connection. Use this value to refer to this connection in subsequent VI calls. remote address is the address of the remote machine associated with the TCP connection. This address is in IP dot notation format. remote port is the port the remote system uses for the TCP connection.

  26. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) TCP Write Writes data to a TCP network connection. connection ID is a network connection refnum that uniquely identifies the TCP connection you want to close. data in contains the data to write to the TCP connection. timeout ms is in milliseconds. If the connection is not established in the specifiedtime, the VI completes and returns an error. The default is –1, which indicates to wait indefinitely. bytes written is the number of bytes to write to the TCP connection.

  27. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) TCP Read Reads a number of bytes from a TCP network connection, returning the results indata out. mode indicates the behavior of the read operation. 1 Standard (default)—Waits until all bytes requested have arrived or until the time runs out. Returns the number of bytes that have been received so far. If less than therequested number of bytes arrives, reports a timeout error. 2 Buffered—Waits until all bytes requested have arrived or until the time runs out. Returns the number of bytes requested or none. If less than the requested number of bytes arrive, reports a timeout error.

  28. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) TCP Read Reads a number of bytes from a TCP network connection, returning the results indata out. mode indicates the behavior of the read operation. 3 CRLF—Waits until a CR (carriage return) followed by a LF (line feed) are received within the number of bytes requested or until the time runs out. Returns the bytes received up to and including the CR and LF or none. If a CR and LF are not found, reports a timeout error. 4 Immediate—Waits until any bytes are received. Waits the full timeout only if no bytes have been received. Returns the number of bytes received so far. Reports a timeout error if no bytes have been received.

  29. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) TCP Read Reads a number of bytes from a TCP network connection, returning the results indata out. connection ID is a network connection refnum that uniquely identifies the TCP connection you want to close. bytes to read is the number of bytes to read. timeout ms is in milliseconds. If the connection is not established in the specified time, the VI completes and returns an error. The default is –1, which indicates to wait indefinitely. data out contains the data read from the TCP connection.

  30. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) A number of other functions are used when implementing TCP communication:

  31. Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) A number of other functions are used when implementing TCP communication: Type cast Casts x to the data type, type. The connector pane displays the default data typesfor this polymorphic function. type is the data type to which you want to convert the data. x is the data you want to convert to type. x can be any data type. *(type *) &xis the value provided in x and converted to the same data typeas type. This function converts a 1D array of flat data to a string or a string to a 1D array of flat data. Flat data is defined recursively as a numeric scalar, a Boolean scalar, or a cluster of flat data. Casting data to a string converts it into machine-independent, big endian form. That is, the function puts the most significant byte or word first and the least significant byte or word last, removes alignment, and converts extended-precision numbers to 16 bytes. Casting a string to a 1D array converts the string from machine-independent form to the native form for that platform.

  32. Unflatten from String Graphical Programming Lecture 9- Networking in LabVIEW presented by Witold Nocoń Ph.D. Low-level communication - TCP (Transmission Control Protocol) A number of other functions are used when implementing TCP communication: Flatten to String Converts anything to a string of binary values. type string is a type descriptor that describes the data type of anything. data string is the flattened form of anything. Converts binary string to the type wired to type. binary string should contain flattened data of the type wired to type. Example (gp9_5.vi).

More Related