LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to re-open an OPC-connection with after the server was restartet

Hi all,
my software needs to exchange data via an opc-connection. There are about 8 clients. When i restart the opc-server all clients don't communicate via opc anymore. Each DS_Update takes about 1 second. The communication does not reactivate itself.
My code in pseudo code so far:

Init:
for each socket()
{
    DS_Open();
}

Polling the receive-data:
for each socket()
{
    DS_Update();
    DS_GetDataType();
    DS_GetDataValue();
}

Termination:
for each socket()
{
    DS_DiscardObjHandle();
}


I tried to call DS_DiscardObjHandle() for all sockets and the reopen them again with DS_Open() but all sockets remain in the unconnected state and i don't receive any data anymore.

The code looks a follows:

Init:
for each socket()
{
    DS_Open(); // for each socket
}

Polling the receive-data:
for each socket()
{
    DS_Update();
    DS_GetDataType();
    DS_GetDataValue();
}

ReConnect:
for each socket()
{
    DS_DiscardObjHandle();
    DS_Open();
}

Termination:
for each socket()
{
    DS_DiscardObjHandle();
}

How can i revive an OPC connection after the Server was restarted without restarting all clients.

Greetings, Urs

0 Kudos
Message 1 of 2
(3,124 Views)
Hi Urs,

i guess it is a problem concerning discarding objects.

So first of all, you should use DS_OpenEx() instead of DS_OPEN(). This is recommend by CVI. For the diffrence of these two command please consult the CVI help files.

Here is a small suggestion for a structur of a Data Reader:
1. Open a connection and get a handle to the data source using DS-OpenEx. You must specify whethter to configure the DataSocket object manual or automatic updating.

2. Read the data from the source using DS_GetDataValue. If you configure the DataSocket object for automatic updating, the callback function is called when the data changes on the data source. You then must call DS_GetDataValue t read the data. If you configure the DataSocket object for manual updating, there is no callback function. Instead, you must call DS_Update before reading the data with DS_GetDataValue.

3. Process the data according to your requirements

4. Close the connection and discard the handle using DS_DiscardObjHandle.

So you should use DS_DiscardObjHandle after having received your Data.

I hope this helps

For further investigation, I should know what system you use for your OPC server as well as which version of LabWindows/CVI you use.

Regards
Kilian
0 Kudos
Message 2 of 2
(3,096 Views)