Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

multiple data sockets / VB

I have an application where LabView acquires data through 5 channels and writes them to data sockets which are then accessed through VB MS. I am currently writing the data from each channed to a different data socket (say, dstp://localhost/test1, ... dstp://localhost/test5). In VB, I have placed a separate DS connection for each channel on the User Control panel and for each DS, I have the following routine for accessing the data written to the DS:

For DS 1:

Private Sub CWDataSocket1_OnDataUpdated(ByVal Data As CWDSLib.CWData)
If IsArray(Data.Value) Then
CWGraph1.PlotY Data.Value
End If
End Sub

For DS2:

Private Sub CWDataSocket2_OnDataUpdated(ByVal Data As CWDSLib.CWData)
If IsArray(Data.Value) Then
CWGraph2.PlotY Data.Value
End If
End Sub

.... etc.

So, basically I am trying to plot the data from each channel's DS connection on a different CWGraph. The source for each DS connection is also specified, and I have the connection procedure for each DS coded as follows:

Private Sub ConnectButton_Click()
CWDataSocket1.ConnectTo Text1.Text, cwdsReadAutoUpdate
CWDataSocket2.ConnectTo Text2.Text, cwdsReadAutoUpdate
........
End Sub

So, on the mouse click on the connect button on the web page I generated using the application setup wizard, the individual data sockets connect to the data specified by the path Text(n).Text and plot them on different graphs.

However, when I run the program, even though the status for each DS is displayed as "connected", the CWGraphs are not updated with the data. Exactly the same code, but with just one channel works fine, with the graph being updated with the data written on the Data Socket.

So, I am wondering whether the approach I am using is wrong. i.e. should I not use individual data sockets for each channel of data? Can I write data from all channels on the same DS connection and then somehow retrieve them separately in VB? Or is the problem I am having due to my code in VB (I am only a beginner) and if so, what would you suggest (currently I have separate procedures for each DS connection - may be i should have them all within one)

thanks!
0 Kudos
Message 1 of 4
(3,436 Views)
I'm not sure why you're seeing these problems. Do you have a small test project that reproduces the problem that you could post?

Another approach that you could take would be to create a 2D array out of the data you acquire from the channels and write the 2D array to DataSocket. On the client, you could take the array and just pass it to the PlotY method. The graph will take each row (or column, depending on how you configure the graph) and plot it on a separate plot. Alternatively, you could configure a binding from the graph to the DataSocket item and you shouldn't have to write much code at all.

- Elton
0 Kudos
Message 2 of 4
(3,436 Views)
Elton, thanks for the answer. I am attaching a very simple test program that reproduces the problem I am having. The VB part for this is pasted below:

Private Sub ConnectButton_Click()
CWDataSocket1.ConnectTo Text1.Text, cwdsReadAutoUpdate
CWDataSocket2.ConnectTo Text2.Text, cwdsReadAutoUpdate
End Sub

Private Sub CWDataSocket1_OnDataUpdated(ByVal Data As CWDSLib.CWData)
If IsArray(Data.Value) Then
CWGraph1.PlotY Data.Value
End If
End Sub

Private Sub CWDataSocket1_OnStatusUpdated(ByVal Status As Long, ByVal Error As Long, ByVal Message As String)
StatusLbl1.Caption = Message
End Sub

Private Sub CWDataSocket2_OnDataUpdated(ByVal Data As CWDSLib.CWData)
If IsArray(Data.Value) Then
CWGraph2.PlotY
Data.Value
End If
End Sub

Private Sub CWDataSocket2_OnStatusUpdated(ByVal Status As Long, ByVal Error As Long, ByVal Message As String)
StatusLbl2.Caption = Message
End Sub

Private Sub DisconnectButton_Click()
CWDataSocket1.Disconnect
CWDataSocket2.Disconnect
End Sub
0 Kudos
Message 3 of 4
(3,436 Views)
Thanks for the sample project - that makes it a lot easier to figure out what's going on. I see two things here:

1.) The vi is writing a single point at a time, not an array, so the If IsArray check in the DataUpdated event handlers fail.

2.) Since the vi is writing a single point at a time, it will be hard to see any data as the VB code is written because the plot will be cleared and a single point will be written every time the DataUpdated event fires. If you change this to ChartY, you will see something more like what you're seeing in your vi.

Try changing your two DataUpdated event handlers to this:

Private Sub CWDataSocket1_OnDataUpdated(ByVal Data As CWDSLib.CWData)
CWGraph1.ChartY Data.Value
End Sub

Private Sub CWDat
aSocket2_OnDataUpdated(ByVal Data As CWDSLib.CWData)
CWGraph2.ChartY Data.Value
End Sub

Hope this helps.

- Elton
0 Kudos
Message 4 of 4
(3,436 Views)