Você está na página 1de 41

New Features and Best Practices for Network Data Exchange

Jason Reding Senior Software Engineer LabVIEW Software

Agenda
Challenges of Network Communication Common Communication Paradigms
Network Shared Variable
New Features in LV 2010

Network Streams

Questions

Challenges of Network Communication


Connection Management
Ordering requirements Disconnections due to unreliable networks
Difficult to tell if data in flight was lost

Transferring data in a generic way


Serialize to and from binary stream Often have to develop your own protocol for identifying data

Different communication patterns lend themselves to different implementations

Communication Paradigm 1
Latest Value or N Values
Only care about the most recent data Data loss is acceptable Relatively low throughput and latency requirements Typically 1 writer and 1:N readers

Logging

Update HMI

Update HMI

Network Shared Variables

What is a Shared Variable?


Similar to a local or global variable except it has network scope Supports most LV data types
Vision Image Data Type

Built on a client/server architecture


Server controls lifetime of the variable Clients can subscribe at any time to receive updates and publish updates

Client/Server Architecture
Machine 1
Client Readers Var 1 Var 2 Client Writers Var 1

Machine 2
Server
Var 1 Var 2

Machine 3
Client Readers Var 1

Client Writers Var 2

Client/Server Architecture
Machine 1
Server
Var 1

Machine 1
Server
Var 1

Machine 2
Client Readers Var 1

Client Readers
Var 1

Client Writers
Var 1

Client Writers Var 1

Shared Variable APIs

10

Creating and Deploying Variables


Interactively
Right click option on project library Running a VI in a project containing a static Variable Node (doesnt undeploy when done) Distributed System Manager

Runtime / Programmatic
Build Specs (Windows) Deploy/Undeploy Library VI server methods ( Windows, remote RT and local Windows targets) DSC Module (Windows)

11

Connection Management
Client reconnections are performed automatically by the communications protocol Errors and warnings generated when reading/writing:
Variable hasnt been deployed to the server Client attempts to read a Variable that has never been written to since it has been deployed to the server Client connection hasnt yet been established or has become disconnected

Client reader receives latest value written to the server upon connection (if any)

12

Connection Management
Machine 1
Client Writers Var 1
6 5 4 3 2

Machine 2
Server
Var 1
6 2 1

Machine 3
Client Readers Var 1

13

Connection Management
Static Variable Node
Each instance of the node on the diagram establishes a separate client connection Client connections are established before diagram execution begins

Dynamic API
Each Open Node creates a unique client connection
Connection can be performed synchronously or asynchronously

Reads and Writes using a reference not generated through an Open Node share the same connection

14

Which API to Use?


Static API
Small number of variables (20 or less) Slightly better runtime performance and code maintenance Ease of use (happy with default connection management)

Dynamic API
Need to scale to large number of variables More explicit management over connections Decouple system configuration from runtime code

15

2010 Editor Enhancements


Replace with Programmatic Access

16

2010 Editor Enhancements


Support for linking to a typedef

17

2010 Editor Enhancements


Batch updating of static nodes

18

Communication Paradigm 2
Data Streaming
Potentially large data sets Data loss isnt acceptable Typically 1 writer and 1 reader Throughput is more important than latency
`

19

Buffered Network Variables

20

Buffered Network Variables


Server buffer size controlled by value in property dialog Client side buffer
Static API size controlled by value in property dialog Dynamic API size controlled by Open Node Machine 1
Server
Var 1

Machine 2
Client Readers Var 1

Client Writers Var 1

21

Pitfalls of Streaming with Variables


Lack of flow control can result in data loss Data may be lost if the TCP/IP connection is dropped
Machine 1
Server
Var 1
5 6 7 1 2 3 4

Machine 2
Client Readers
Var 1
4 5 6 7 1 2 3 4

Client Writers Var 1


5 6 7 1 2 3 4

22

Pitfalls of Streaming with Variables


Buffering across connections may not behave as expected
Machine 1
Server
Var 1
3 4 1 2

Machine 2
Client Readers Var 1
3 4 1 2

Client Writers Var 1


1 2

Var 1
3 4 1 2

Var 1
3 4

23

Pitfalls of Streaming with Variables


Buffering across connections may not behave as expected
Machine 1
Server
Var 1

Machine 2
Client Readers Var 1

Client Writers Var 1

24

Network Streams

What is a Network Stream?


Similar in concept to a queue or RT FIFO except it has network scope Supports same data types as Network Variable Point to point architecture
Lossless, unidirectional data transfer Stream lifetime determined by read and write endpoints No deployment required to run No persistence of stream once VI finishes executing

26

Point to Point Architecture


Machine 1
Writer Endpoints
Endpt 1 Endpt 2

Machine 2
Reader Endpoints
Endpt 1 Endpt 4

Reader Endpoints
Bill

Writer Endpoints
Ted

27

Connection Management
Connections are established once compatible reader and writer endpoints are created Order of creating endpoints isnt important
Creating endpoints acts like a network rendezvous

Must create at least one active endpoint


28

Connection Management
Reconnections
Performed automatically by the protocol in the background (will retry forever) Preserve lossless nature of data stream Will error if endpoints cant resynchronize Active endpoint initiates reconnection upon a disconnect

29

Reading and Writing Data


Can read/write single or multiple elements at a time Data is never overwritten or regenerated No partial data transfers
Read/Write will either succeed or time out Maximum read/write size is limited by the endpoint buffer size
30

Network Streams in Action


Machine 1
Writer Endpoint
9 3 2 1 8 5 4 7 6 5 4 3 2 1 9 8 5 4 7 6 Acknowledge (2) Flow Control (3) (2)

Machine 2
Reader Endpoint
5 4 3 2 1 5 4 3

31

Shutting Down a Stream


Use Flush Stream to ensure all data has been transferred from the write endpoint Writes will error immediately if the reader endpoint is destroyed Reads will error if the writer endpoint has been destroyed and the read buffer is empty
Final read request that empties buffer may return fewer elements than requested

32

Shutting Down a Stream


Machine 1
Writer Endpoint
3 2 1

Machine 2
Reader Endpoint

3 2 1

33

Shutting Down a Stream


Machine 1
Writer Endpoint
3 2 1

Machine 2
Reader Endpoint
3 2 1

3 2 1

34

Buffer Management
Each endpoint buffer can be independently sized Buffers are allocated when the endpoint is created Non-scalar elements are allocated as needed through read and write calls (arrays, clusters, and strings)
Buffer of Scalar Elements Buffer of NonScalar Elements

1 2 3

35

Communication Paradigm 3
Commands
Small data sets Data loss isnt acceptable Typically 1 writer and 1:N reader Latency is more important than throughput
Configure Start Stop
`

Configure Start Stop

Done Stop

Done Stop

36

Network Variables for Commands


Can lose commands (even with buffering) Reread the same command unless you use blocking read New connections receive the latest value upon connecting Work best for latched commands

37

Network Streams for Commands


Guaranteed not to lose data Use Flush with zero timeout to minimize latency Works best for 1:N communication where N is known ahead of time For an arbitrary number of clients, consider using TCP to establish stream connections

38

Summary of Recommendations
Latest Value
Network Variable

Data Streaming
Network Streams Buffered Network Variable
Distributed streaming to numerous clients Can tolerate losing data during bad network conditions

Commands
Network Streams TCP Palette Network Variable
Can tolerate losing the occasional command Latched commands

39

Questions?

41

Você também pode gostar