Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

DataSocketSource OPC object bugs?

I'm using the DataSocketSource object to create multiple dynamic OPC connections whose URL's may differ between connection attempts.

If I successfully establish a connection to an OPC source, it would appear the connection is somehow 'cached', or some object instances are not being cleaned up. In my code, between connection attempts, I currently completely dispose of the DataSocketSource I used to make the connection and create a new object (ie: new DataSocketSoure()) for reconnecting. If I, however, change the connection string (to another source or intentionally break it), the DataSocketSource still reconnects to the previously successfully connected source. Stepping through the code reveals the tags for the connections I am making are definately using the updated URL. The lastMessage and LastError properties for the tag bindings also say that the connection is active and OK - which doesn't compute!

I am currently using Measurement Studio .NET 7.1 (eval) but we have just purchased a full version (on order). Is this a known issue or am I doing something wrong here?

Generally, I initialise the connection as follows (aSocketInstance is of type DataSocketSource):

((System.ComponentModel.ISupportInitialize)(aSocketInstance)).BeginInit();
aSocketInstance = BindLowLevelData(aNetworkInstance, aSocketInstance, aInstancePanel);   //this procedure binds two tags
((System.ComponentModel.ISupportInitialize)(aSocketInstance)).EndInit();

aSocketInstance.Connect();

Between calls to the above code, I create and delete the aSocketInstance object when I connect and disconnect respectively. I also clear all the bindings from the labels, etc being used (as well as from the aSocketInstance, just for safety).

Any ideas or feedback?

0 Kudos
Message 1 of 6
(4,020 Views)
Hi Alex:
 
Have you had a chance to look at our data socket example programs that ship with measurement studio.  They can be located at C:\Program Files\National Instruments\MeasurementStudioVS2003\DotNET\Examples\DataSocket. 
 
Thank you
Nandini
 
0 Kudos
Message 2 of 6
(4,007 Views)
Yes I have. How different is the DataSocket object to the DataSocketSource object?

The biggest problem I have is that because I have so many dynamic fields/objects to update, it would be impractical to update the form objects through the update eventHandler. Therefore, I am using bindings on the objects using the DataSocketSource object, which does seem to behave somewhat differently to the DataSocket object.

I've tried simply disconnecting and reconnecting my DataSocketSource object like in the DataSocket example, but that leads to more issues (doesn't reconnect and other funny things). Therefore, my reasoning was to freshly recreate the DataSocketObject when reconnecting to try and eliminate the problems I've described, without success.
0 Kudos
Message 3 of 6
(4,004 Views)

CNiDataSocket encapsulates the NI-DataSocket interface. You can use CNiDataSocket objects in your applications to transfer live measurement data over the Internet or between applications on the same computer.

DataSocketSource binds DataSocket data sources or targets to a Windows Forms control.   Because the DataSocketSource object does not have a user interface, it is added to the component tray below the form. bind DataSocket data sources or targets to a Windows Forms control.   From the Toolbox, drag a DataSocketSource object onto a designer, such as the Windows Forms Designer. Because the DataSocketSource object does not have a user interface, it is added to the component tray below the form.

You must call Dispose when you finish using a DataSocketSource object. If you add this object to a Windows form with the Windows Forms Designer, the form calls Dispose automatically.

 

Nandini

0 Kudos
Message 4 of 6
(3,989 Views)
Ok, after taking a slight different approach, the connecting to localhost is now working.

However, remote machine connections are causing nids.dll (datasocket dll?) to throw an exception.

I've tried to connect to numerous OPC servers that are not on my machine (which works fine), and retrieve two tags. If I purposefully incorrectly specify the connection string, then the connection simply fails. However, if the connection string is correct, the program crashes with an exception (see attached image).

The connection string is of the usual format: eg: "opc://apollo/test/segmentName" and the exception at the end init line:

((System.ComponentModel.ISupportInitialize)(aSocketInstance)).EndInit();

Any ideas?
               
0 Kudos
Message 5 of 6
(3,980 Views)
I forgot to mention that I can connect to all the OPC servers using a 3rd party OPC client without any issues
0 Kudos
Message 6 of 6
(3,978 Views)