Hi,
I got a problem when I try to subscribe to OPC tag data using the OpcDaCom driver.
at the moment my test program is headless i.e. no form, running version 3.99x of the aHMI package
This is the simple test code in c#:
using AdvancedHMIDrivers;
using MfgControl.AdvancedHMI.Drivers.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace opcTest
{
class Tester
{
const string serverProgID = "RSLinx Remote OPC Server";
const string topic = "PLC001";
const string itemA = "Tag001.child001";
const string itemB = "Tag001.child002";
private OpcDaCom opcClient;
public void Work()
{
opcClient = new OpcDaCom()
{
OPCServer = serverProgID,
OPCTopic = topic
};
string[] opcValue = opcClient.Read(itemA, 1);
Console.WriteLine("Tag: {0}, Value: {1} ", itemA, opcValue[0]);
int itemAID = opcClient.Subscribe(itemA, 1, 500, opcClient_DataChange);
Console.WriteLine("hit <return> to close...");
Console.ReadLine();
}
private void opcClient_DataChange(object sender, PlcComEventArgs e)
{
try
{
Console.WriteLine(e.Values[0]);
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
}
static void Main(string[] args)
{
Tester tst = new Tester();
tst.Work();
}
}
}
the error I'm getting is System.NullReferenceException occurred
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=AdvancedHMIDrivers
StackTrace:
at AdvancedHMIDrivers.OpcDaCom.DataChangedCallBack(Object clientHandle, Object requestHandle, ItemValueResult[] values) in D:\AdvancedHMIv399x\AdvancedHMIDrivers\OpcDaCom.vb:line 561
at OpcCom.Da.Subscription.Callback.OnDataChange(Int32 dwTransid, Int32 hGroup, Int32 hrMasterquality, Int32 hrMastererror, Int32 dwCount, Int32[] phClientItems, Object[] pvValues, Int16[] pwQualities, FILETIME[] pftTimeStamps, Int32[] pErrors)
when debugging I can see 'm_SynchronizingObject' in Sub 'DataChangedCallBack' is Nothing i.e. 'Object reference not set to an instance of an object.'
So this mush be user error and I'm not setting up the OpcDaCom object correctly, can anyone see what I'm doing wrong?
Thanks.