OnDataUpdated Event

NI DataSocket

OnDataUpdated Event


Sub ControlName_OnDataUpdated( Data As CWData)

Applies To



Generates when the CWDataSocket value is updated.


CWDataSocket sets the DataUpdated property to True immediately before this event is generated.

The OnDataUpdated event is generated when CWDataSocket receives new data. The event passes a reference to the DataSocket CWData object so that you can easily process the new data from the event procedure:

Sub CWDataSocket1_OnDataUpdated(ByVal Data As CWData)

'Plot new data

CWGraph1.PlotY Data.Value

End Sub

You can use the DataSocket.Data property to access the currently stored value. The Data property returns a reference to the same CWData object that is passed to the event. From the CWData object, you can get the value or attributes associated with the current data, as in the following example:

x = CWDataSocket1.Data.Value

The data value is returned as a variant (the specific type of variant depends on the source to which the DataSocket is connected).

Rather than waiting for this event, you might find it more convenient to check for new data. To determine if data has been updated since it was last read, query the value of the DataUpdated property. When a new value is loaded, DataUpdated is set to True. After the DataUpdated property is queried, DataUpdated reverts to False.

Use the DataUpdated property to check for updates along with another periodic operation, such as an operation initiated by a timer event:

Sub Timer1_OnTimer()

'DataUpdated is true only if the data

'has been reloaded

If DataSocket1.DataUpdated Then

' Reading the data property resets the

' DataUpdated property

MySub DataSocket1.Data

End If

'Other timer event code

End Sub


Data As CWData

Data read from DataSocket.


Private Sub CWDataSocket1_OnDataUpdated(Data as CWData)
    'Graph the new data
    CWGraph1.PlotY Data.Value
End Sub

See Also