PublishModule module increments or decrements a value cyclicallyEventModule module allows to click on a toggle to set if the first module should increment or decrement the value, and shows the valuePublishModule in the Groovy scripting language.
PublishModule which:EventModule which:
PublishModule in Groovy:
applications.xml XML file has to be modified to switch from a Java module implementation to a Groovy module implementation.
applications.xml XML file, by modifying the PublishModule configuration:<application name="publishAppli" id="2"> <modules> <groovyModule name="PublishModule" id="1" > <groovyImplementation path="publish.groovy" > <defaultSendEntryPoint method="publish" /> </groovyImplementation> <interfaces> <eventReceived service="event"/> <cyclic service="published" frequency="200ms" attach="attach"/> </interfaces> </groovyModule> </modules> </application>As you can see, we specified that the implementation of the
PublishModule is in the publish.groovy file, in the same directory as the application.xml file. We also specified that a publish method in the Groovy script will be called each time the published Service is cyclically invoked.
published service to be invoked cyclically every 200 milliseconds in the module XML specification:<cyclic service="published" frequency="200ms" attach="attach"/>The
publish.groovy script will implement the behavior of this Module:subscribe method will be notified of the event Service. Depending on the value of the event data, a step variable will have a 1 or -1 valuepublish method will be invoked cyclically for the published Service. The current value will be incremented or decremented, and the Service will be notified with this current valueint step = 1; int count = 1; public void subscribe(ServiceInstance service) { boolean evt = service.getData("event").getValueAsBoolean(); if (evt) { step = -1; } else { step = 1; } } public void publish(ServiceInstance service) { service.setDataIntValue("value", count); count += step; service.invoke(); }
Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence