The .net API samples and helper classes do not expose an easy way to retrieve events. That can be done via the Web API or if the Canary Events configuration is changed to log to MSSQL. Then watch that table for new events and make calls to get the associated tag data.
To point the Event service to a SQL server instance, first stop the Canary Events service from the Canary Admin client. In the “C:\Program Files\Canary Labs\Canary Admin” folder or the install location of the Admin client, add a file named CanaryEventService.exe.admin, and place the following XML into it. A sql server user account with enough privileges to create the CanaryEvents Database, and store the credentials in the file will need created. After the first time the service runs and creates the db, it’s privileges can be downgraded if needed or we can provide the sql statements to create the schema. Adjust these settings to provide access to your SQL Server instance:
<Settings>
<SQLServer>.</SQLServer>
<Database>CanaryEvents</Database>
<User>CanaryEventsUser</User>
<PWD>CanaryEventsUserPassword</PWD>
</Settings>
Save the file and restart the Canary Events service. The SQL server database should get generated.
There are 2 tables to be concerned with, Events and AssociatedTags. AssociatedTags has a tab delimited list of tags associated to the event. Events has a field named AssetBasePath. To properly reference the tag, split the tab delimited list of tags and append each one to the AssetBasePath with a period between them. In essence something like string tagPath = event.AssetBasePath + “.” + tag[i]; should be what is used to identify the tag when retrieving it’s values.
Here is some sample SQL for the fields needed for the tag calls (add some filtering to reduce the size of the recordset): select e.EventTypeName, e.StartsAt, e.EndsAt, e.assetbasepath, a.tags from [Events] e, AssociatedTags a where e.EventTypeName = a.EventType
If using the .NET API, their is sample code in the link below. It is not necessary to follow the example explicitly, just create a connection and use the GetRawData or GetProcessedData functions for the associated tag(s). Alternatively, it is possible to connect via the Web API and use the /getTagData endpoint.
Comments
0 comments
Article is closed for comments.