Please ensure Javascript is enabled for purposes of website accessibility
Powered by Zoomin Software. For more details please contactZoomin

AVEVA™ Batch Management

Example: Subscribe to "Batch Done" and "Custom RecipeMessage" Events

Example: Subscribe to "Batch Done" and "Custom RecipeMessage" Events

  • Last UpdatedNov 03, 2021
  • 3 minute read

The following example shows the ArchestrA Script code to subscribe to a few different EventTypes with one subscription (using an OR filter), but also to further filter the data within each EventType (using AND filters).

The subscription watches for "Batch Done" events and schedules/initializes/starts a new batch using most of the Context Properties from the finished batch.

It also watches for Custom RecipeMessage events. These events are fired if a recipe has a SendCustomEvent() expression function with an EventName of "RecipeMessage." If this message is received, it can be displayed for an operator. The purpose for this example is to tell the operator that the batch is ending.

For this example to work, do the following:

  1. Define the following UDAs on your event monitor ApplicationObject:

    • BatchHost - [string] set value to the AVEVA Batch Management Server host name

    • EventSvcPort - [integer] set value to the Event Service port (default=3575)

    • RecipeMessage - [string] set to the message from the recipe

    • ConnId - [integer] holds the unique Id for this subscription

    • EventsStarted – [bool] is set to true after the events start successfully

  2. Schedule a batch. The BatchId should just be an integer value. It will be incremented to schedule the new batch.

  3. Add the following scripts to the event monitor ApplicationObject. The GetEvents script should have a "Trigger Type" of "Periodic (2 seconds)" and it should be an Asynchronous script.

OnScan Script

dim id as integer;

ME.EventsStarted = false;

ME.ConnId = 0;

'Specify Batch Server Event Service connection info.

'Starts building an event subscription.

'ConnId returned is unique Id for this subscription

'and used for all subsequent calls

ME.ConnId = ArchestrA.Events.Scripting.MonitorEvents.ConnectToEventService(

ME.BatchHost, ME.EventSvcPort, 1);

'Request Batch EventType events where EventCodeName is for Batch Done

id = ArchestrA.Events.Scripting.MonitorEvents.AddEventFilter(

ME.ConnId, "EventType", "eq", "Batch");

ArchestrA.Events.Scripting.MonitorEvents.NarrowEventFilter(

ME.ConnId, id, "EventCodeName", "eq", "Done");

'Request Custom EventType events where EventName is for RecipeMessage

id = ArchestrA.Events.Scripting.MonitorEvents.AddEventFilter(

ME.ConnId, "EventType", "eq", "Custom" );

ArchestrA.Events.Scripting.MonitorEvents.NarrowEventFilter(

ME.ConnId, id, "EventName", "eq", "RecipeMessage");

'Tell system to start monitoring events for this subscription

ME.EventsStarted =

ArchestrA.Events.Scripting.MonitorEvents.StartRequestingEvents( ME.ConnId);

LogMessage("Event Subscription Initialized");

GetEvents Script

dim batchId as integer;

dim batchIdStr as string;

dim e as ArchestrA.Events.Scripting.Event;

'We need to keep trying this method until successful.

'Once successful we’ll start getting events

if ( ME.EventsStarted == 0 ) then

ME.EventsStarted =

ArchestrA.Events.Scripting.MonitorEvents.StartRequestingEvents( ME.ConnId);

endif;

'Get first available event

e = ArchestrA.Events.Scripting.MonitorEvents.GetNextEvent( ME.ConnId );

while ( ME.EventsStarted AND e <> null )

'Process Batch EventType events

if e.EventType == "Batch" then

batchIdStr = e.GetProperty("BatchId");

batchId = StringToIntg( batchIdStr );

batchId = batchId + 1;

'Use Stateless API to add/initialize/start a new batch.

'Delete the one that completed

InBatch.API.Schedule.AddScheduleEntry( me.BatchHost,

e.GetProperty("CampaignId"), e.GetProperty("LotId"),

e.GetProperty("BatchId"),

e.GetProperty("CampaignId"), e.GetProperty("LotId"), batchId,

e.GetProperty("RecipeId"), e.GetProperty("Train"),

e.GetProperty("BatchSize"), InBatchCommon.BatchModeType.Automatic,

"", "", "", "" );

InBatch.API.Schedule.InitializeScheduleEntry( me.BatchHost,

e.GetProperty("CampaignId"), e.GetProperty("LotId"), batchId,

"", "", "", "" );

InBatch.API.Batch.StartBatch( me.BatchHost,

e.GetProperty("CampaignId"), e.GetProperty("LotId"), batchId,

"", "", "", "" );

InBatch.API.Schedule.DeleteScheduleEntry( me.BatchHost,

e.GetProperty("CampaignId"), e.GetProperty("LotId"),

e.GetProperty("BatchId"), "", "", "", "");

LogMessage("Scheduled and started new batch: " +

e.GetProperty("CampaignId") + "/" + e.GetProperty("LotId") +

"/" + batchId);

endif;

'Process Custom EventType events - store the message in a UDA

if e.EventType == "Custom" then

ME.RecipeMessage = "Message from batch: " +

e.GetProperty("CampaignId") + "/" +

e.GetProperty("LotId") + "/" +

e.GetProperty("BatchId") + " --> " +

e.GetProperty("UserData");

endif;

'Get Next Event if one is queued

e = ArchestrA.Events.Scripting.MonitorEvents.GetNextEvent( ME.ConnId );

endwhile;

OffScan Script

'Terminate our subscription

ArchestrA.Events.Scripting.MonitorEvents.DisconnectFromEventService(

ME.ConnId );

ME.ConnId = 0;

LogMessage("Event Subscription Terminated");

In This Topic
TitleResults for “How to create a CRG?”Also Available in