11/25/2022
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…
11/25/2022
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.
11/25/2022
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 confused,could you tell more about it ?
Thanks!
05/30/2017
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.
11/25/2022
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:
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.
05/30/2017
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.
11/25/2022
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.
1 Guest(s)