OPCDAAuto.dll OPCGroup dataChange not work invoke after work a period time|Classic OPC: DA, A&E, HDA, XML-DA, etc.|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
OPCDAAuto.dll OPCGroup dataChange not work invoke after work a period time
Avatar
jian xin
Member
Members
Forum Posts: 7
Member Since:
11/25/2022
sp_UserOfflineSmall Offline
1
03/16/2023 - 00:13
sp_Permalink sp_Print

I use OPCDAAuto.dll to connect OPC Server.Everything work normally,but after work about half an hour,dataChange event never work.

But i print check group status,like isActive/IsSubscribe…,every thing is ok.

Could anyone give me one hand? 

Avatar
Randy Armstrong
Admin
Forum Posts: 1578
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
2
03/16/2023 - 05:11
sp_Permalink sp_Print

Check your threading. A deadlock somewhere could explain the symptoms.

Avatar
jian xin
Member
Members
Forum Posts: 7
Member Since:
11/25/2022
sp_UserOfflineSmall Offline
3
03/21/2023 - 01:39
sp_Permalink sp_Print

Randy Armstrong said
Check your threading. A deadlock somewhere could explain the symptoms.

  

Thanks for your response.Sorry for reply so late.I am trying to find problem by following your guidance,but I have not been successful.

I am running some other libraries like GodSharp.Automation and ThingsGateway(using opc net api) to find possible reason.

But i have not get my conclusion.

ing…

Avatar
Randy Armstrong
Admin
Forum Posts: 1578
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
4
03/21/2023 - 02:51
sp_Permalink sp_Print

Could be a server issue.

Also if the VB client is releasing the connection point because of some timeout/clean up code that would stop updates.

Do async reads work after datachanges stop?

Avatar
jian xin
Member
Members
Forum Posts: 7
Member Since:
11/25/2022
sp_UserOfflineSmall Offline
5
03/22/2023 - 17:50
sp_Permalink sp_Print

Randy Armstrong said
Could be a server issue.

Also if the VB client is releasing the connection point because of some timeout/clean up code that would stop updates.

Do async reads work after datachanges stop?

  

I am in .net 6 and just run in console.

I can read and write subcribed tags after dataChanges stop.I only use sync method.

I find that the exe with console print run longer than the exe with log output,keep confused.

Maybe sdk or OPCDAAuto.dll has problem.I’ll test that.

First,i plan to use .net framwork to try run and check the situation.

Second,i plan to view the implementation of GodSharp.Opc.Da.OpcAutomation.it seems work normally,but i need to run more times.

Avatar
Randy Armstrong
Admin
Forum Posts: 1578
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
6
03/24/2023 - 03:37
sp_Permalink sp_Print

You need to try async reads. That would confirm that it is connection point issue.

Avatar
jian xin
Member
Members
Forum Posts: 7
Member Since:
11/25/2022
sp_UserOfflineSmall Offline
7
03/25/2023 - 17:43
sp_Permalink sp_Print

Randy Armstrong said
You need to try async reads. That would confirm that it is connection point issue.

  

Wow,when i used async read,there was no asyncReadCompleted invoke.

But i used readSync at the same time,it worked normally and got real-time data continuously.

Can such suitation expose some problems?

I’m confusedConfused,could you tell more about it ?

Thanks!

Avatar
Randy Armstrong
Admin
Forum Posts: 1578
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
8
03/26/2023 - 09:10
sp_Permalink sp_Print

To get callbacks the automation wrapper registers a connection point with DCOM.

This connection point can get messed up which appears to be the source of the issue.

It is difficult to debug further if you do not have access to error codes.

Can you create a simple test program that subscribes to the same data?

This would allow you know if it there is something going on inside your client application that is triggering the issue.

Avatar
jian xin
Member
Members
Forum Posts: 7
Member Since:
11/25/2022
sp_UserOfflineSmall Offline
9
03/29/2023 - 19:36
sp_Permalink sp_Print

Randy Armstrong said
To get callbacks the automation wrapper registers a connection point with DCOM.

This connection point can get messed up which appears to be the source of the issue.

It is difficult to debug further if you do not have access to error codes.

Can you create a simple test program that subscribes to the same data?

This would allow you know if it there is something going on inside your client application that is triggering the issue.

  

After this Monday i saw your reply,i tried to create a simple test problem and wanted to re-show the problem.But it worked normally for long time.So i can’t reply you immediately.

I tried to find the reason,and it seems that when i don’t have the reference to the OPCGroup and OPCItem,the problem occurs,like the program 2.

I can’t make sure if we need maintence the subscribed groups and items during our application-lifeTime. 

When such suitation occurs,output shows like the picture:

Image Enlarger

program 1 work normally:

public class Program5
{
private static bool bRun = true;
private static OPCAutomation.OPCServer server;

public static void Main()
{
var program = new Program5();
var progID = “Kepware.KEPServerEX.V6”;
var hostIP = “127.0.0.1”;
var groupName = “Device1”;
var tagName = “Channel1.Device1.Tag1”;
//var progID = “Intellution.IntellutionGatewayOPCServer”;
//var hostIP = “10.230.16.19”;
//var groupName = “WC26”;
//var tagName = “WC26.Device1.TotalNum”;
var testTagClientHandle = 2;

server = new OPCAutomation.OPCServer();

server.Connect(progID, hostIP);
Console.WriteLine(“Connected”);

server.OPCGroups.DefaultGroupIsActive = true;
server.OPCGroups.DefaultGroupDeadband = 0;
server.OPCGroups.DefaultGroupUpdateRate = 1000;
server.OPCGroups.DefaultGroupTimeBias = 0;
server.ServerShutDown += program.ServerShutdown;

var testGroup = server.OPCGroups.Add(groupName);
testGroup.IsActive = true;
testGroup.UpdateRate = server.OPCGroups.DefaultGroupUpdateRate;
testGroup.IsSubscribed = true;
testGroup.DataChange += program.TestGroup_DataChange;
testGroup.AsyncReadComplete += program.TestGroup_AsyncReadComplete;

var testTag = testGroup.OPCItems.AddItem(tagName, testTagClientHandle);
testTag.IsActive = true;
var testTagServerHandle = testTag.ServerHandle;

while (bRun)
{
program.ReadTagSync(groupName, tagName);
program.ReadTagAsync(groupName, testTagServerHandle);
Thread.Sleep(30000);
}

Console.WriteLine(“Completed”);
}

private void ReadTagSync(OPCItem item)
{
item.Read(1, out object itemValue, out object quality, out object timeStamp);
Console.WriteLine($”readSync – itemValue:{itemValue},quality:{quality},timeStamp:{timeStamp}”);
}

private void ReadTagSync(string groupName,string itemName)
{
var group = server.OPCGroups.Item(groupName);
var item = group.OPCItems.Item(itemName);
item.Read(1, out object itemValue, out object quality, out object timeStamp);
Console.WriteLine($”readSync – itemValue:{itemValue},quality:{quality},timeStamp:{timeStamp}”);
}

private void ReadTagAsync(OPCGroup group,int tagServerHandle)
{
Console.WriteLine(“ReadAsync exec”);
group.AsyncRead(1, new int[] { 0, tagServerHandle }, out Array errors, 1, out int cancelId);
}

private void ReadTagAsync(string groupName, int tagServerHandle)
{
Console.WriteLine(“ReadAsync exec”);
var group = server.OPCGroups.Item(groupName);
group.AsyncRead(1, new int[] { 0, tagServerHandle }, out Array errors, 1, out int cancelId);
}

private void TestGroup_AsyncReadComplete(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps, ref Array Errors)
{
var outputStr = new StringBuilder(” async read complete – errors:”);
foreach (var item in Errors)
{
outputStr.Append(item.ToString());
outputStr.Append(“, “);
}
outputStr.Append(“result : “);
for (int i = 0; i < NumItems; i++)
{
var value = ItemValues.GetValue(i + 1);
var quality = Qualities.GetValue(i + 1);
var time = Convert.ToDateTime(TimeStamps.GetValue(i + 1)).ToLocalTime();
outputStr.Append($”value:{value},quality:{quality},time:{time}”);
}

Console.WriteLine(outputStr.ToString());
}

private void TestGroup_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)
{
Console.WriteLine($”OpcGroup_DataChange,num:{NumItems},time:{DateTime.Now}”);
}

private void ServerShutdown(string reason)
{
Console.WriteLine($”reason:{reason}”);
}
}

 

Program 2 (occured twice):

public class Program6
{
public static void Main()
{
Console.WriteLine(“Program6”);

var progID = “Kepware.KEPServerEX.V6”;
var hostIP = “127.0.0.1”;
var groupName = “Device1”;
var tagName = “Channel1.Device1.Tag1”;
var testTagClientHandle = 2;

var client = new OpcClient();
client.Connect(progID, hostIP);
client.Subcribe(groupName, tagName, testTagClientHandle);

while (true)
{
client.ReadTagSync(groupName,tagName);
client.ReadTagAsync(groupName);
Thread.Sleep(30000);
}

Console.ReadLine();
}
}

public class OpcClient
{
OPCAutomation.OPCServer server = new OPCAutomation.OPCServer();
int itemServerHandle;

public void Connect(string progId,string hostIP)
{
server.Connect(progId, hostIP);
Console.WriteLine(“Connected”);

server.OPCGroups.DefaultGroupIsActive = true;
server.OPCGroups.DefaultGroupDeadband = 0;
server.OPCGroups.DefaultGroupUpdateRate = 1000;
server.OPCGroups.DefaultGroupTimeBias = 0;
server.ServerShutDown += ServerShutdown;
}

public void Subcribe(string groupName,string tagName,int tagClientHandle)
{
var group = server.OPCGroups.Add(groupName);
group.IsActive = true;
group.UpdateRate = server.OPCGroups.DefaultGroupUpdateRate;
group.IsSubscribed = true;
group.DataChange += GroupDataChange;
group.AsyncReadComplete += GroupAsyncReadComplete;

var item = group.OPCItems.AddItem(tagName, tagClientHandle);
item.IsActive = true;
itemServerHandle = item.ServerHandle;
}

public void ReadTagSync(string groupName,string itemName)
{
var group = server.OPCGroups.Item(groupName);
var item = group.OPCItems.Item(itemName);
item.Read(1, out object itemValue, out object quality, out object timeStamp);
Console.WriteLine($”readSync – itemValue:{itemValue},quality:{quality},timeStamp:{timeStamp}”);
}

public void ReadTagAsync(string groupName)
{
Console.WriteLine(“ReadAsync exec”);
var group = server.OPCGroups.Item(groupName);
group.AsyncRead(1, new int[] { 0, itemServerHandle }, out Array errors, 1, out int cancelId);
}

private void GroupAsyncReadComplete(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps, ref Array Errors)
{
var outputStr = new StringBuilder(” async read complete – errors:”);
foreach (var item in Errors)
{
outputStr.Append(item.ToString());
outputStr.Append(“, “);
}
outputStr.Append(“result : “);
for (int i = 0; i < NumItems; i++)
{
var value = ItemValues.GetValue(i + 1);
var quality = Qualities.GetValue(i + 1);
var time = Convert.ToDateTime(TimeStamps.GetValue(i + 1)).ToLocalTime();
outputStr.Append($”value:{value},quality:{quality},time:{time}”);
}

Console.WriteLine(outputStr.ToString());
}

private void GroupDataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps)
{
Console.WriteLine($”OpcGroup_DataChange,num:{NumItems},time:{DateTime.Now}”);
}

private void ServerShutdown(string reason)
{
Console.WriteLine($”reason:{reason}”);
}
}

 

Content is too many,sorry about that.

Avatar
Randy Armstrong
Admin
Forum Posts: 1578
Member Since:
05/30/2017
sp_UserOfflineSmall Offline
10
03/30/2023 - 19:00
sp_Permalink sp_Print sp_EditHistory

I tried to find the reason,and it seems that when i don’t have the reference to the OPCGroup and OPCItem,the problem occurs,like the program 2.

.NET will recycle unreferenced objects. If you lost the references to the objects containing the callback you could see the problem. That said, it is not clear why the Client object does not keep a reference to the Groups. That may be an automation wrapper issue.

If you have a program that works, model your program on it.

Avatar
jian xin
Member
Members
Forum Posts: 7
Member Since:
11/25/2022
sp_UserOfflineSmall Offline
11
03/30/2023 - 19:19
sp_Permalink sp_Print

Randy Armstrong said

I tried to find the reason,and it seems that when i don’t have the reference to the OPCGroup and OPCItem,the problem occurs,like the program 2.

.NET will recycle unreferenced objects. If you lost the references to the objects containing the callback you could see the problem. That said, it is not clear why the Client object does not keep a reference to the Groups. That may be an automation wrapper issue.

If you have a program that works, model your program on it.

  

Program 2 has worked normally one whole day,it seems true reason.I’ll take more time to run and test.

Your guidance lead me to process this problem.

Thank you very much.Cool

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 13
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1444
Posts: 4887