/EasyOPC

OPC Foundation UA .NET Wrapper

Primary LanguageC#MIT LicenseMIT

Easy OPC

Eeasy OPC is a .NET wrapper over the OPC Foundation UA .NET library and can be used for OPC Server tags/singals retrieval,monitoring and updating in real time.

Prerequisite

How to use it

  • Create an instance of MonitoringManager class:
IMonitoringManager manager =  new MonitoringManager();
  • Initialize the instance with data about he monitored OPC server:
IResult result = manager.Init(ipAddress,iPort,OPCServerInstanceName,CertificateName);

or you can use the Settings class :

ISettings settings =  new Settings(ipAddress,iPort,OPCServerInstanceName,CertificateName);

manager.Init(settings);
  • Retrieve the tags from the OPC Server:
List<Tag> tags = manager.AvailableTags;	
  • Subscribe to tags changes :
manager.SuSubscribeToChangeEvents((changedTag)=>{
	Console.WriteLine(String.Format("Tag {0} has a new value of {1} ",changedTag.DisplayName,changedTag.Value.ToString()));
});
  • Start the OPC server monitoring process.
IResult result = manager.StartMonitoring();

if(!result.Success)
{ 
 	throw result.Exception;
}

The above code monitors all the available tags for changes.

To monitor just for a certain tag or tags changes you can use the StartMonitoring() method overload:

List<Tag> selectedTags = manager.AvailableTags.Where(tag=> ... some condition here ..);
manager.StartMonitoring(selectedTags);
  • To retrieve the monitored tags (the tags passed to the StartMonitoring() method) can be used the MonitoredTags property :
var monitoredTags = manager.MonitoredTags;
  • Force a tag refresh. The value and the quelity of the tag will be reloaded from the OPC Server and will update the given tag.
manager.RefreshTag(tagID);
  • Write a tag value, for a writable tag.
manager.WriteTagValue(tagID,tagValue);
  • Stop the monitoring process
manager.StopMonitoring()