Last active
March 2, 2016 14:49
-
-
Save magno32/8701890 to your computer and use it in GitHub Desktop.
Groovy sample for getting tags from a sample matrikon OPC server using Apache Camel.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* camel-opc Matrikon Example | |
* | |
* Copyright (C) 2013 - 2014 Summit Management Systems, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
@GrabResolver(name='central-snapshots', root='https://oss.sonatype.org/content/repositories/snapshots/') | |
@Grab('org.apache.camel:camel-core:2.12.0') | |
@Grab(group='com.summitsystemsinc.camel.opc', module='camel-opc_da2',version='1.0-SNAPSHOT',type='jar') | |
@Grab('org.slf4j:slf4j-simple:1.6.6') | |
import org.apache.camel.* | |
import org.apache.camel.impl.* | |
import org.apache.camel.builder.* | |
def camelContext = new DefaultCamelContext() | |
def host = 'host'; | |
//CLSID of your OPC Server | |
def clsid = 'f8582cf2-88fb-11d0-b850-00c0f0104305'; | |
def user = 'username'; | |
def password = 'password'; | |
//Use something other than "localhost" if your user us a domain account | |
def domain = 'localhost'; | |
def delay = 5000; | |
//Path to the tags to subscribe to. | |
//If its a group tag, it will get all sub-tags | |
//If this is a tag, it will only subscribe to the tag. | |
def path = '/Simulation Items/Random' | |
//Setting this flag will force the component to only report changes | |
def diffOnly = false | |
//Turn down the jinterop logging, it is pretty verbose. | |
org.jinterop.dcom.common.JISystem.getLogger().setLevel(java.util.logging.Level.WARNING); | |
//Groovy will populate this string with the variables above | |
String uriString = "opcda2:opcdaTest${path}?delay=${delay}&host=${host}&clsId=${clsid}&username=${user}&password=${password}&domain=${domain}&diffOnly=${diffOnly}"; | |
//A simple route that will log all data. It is polled at an interval of ${delay} | |
camelContext.addRoutes(new RouteBuilder() { | |
def void configure() { | |
from(uriString) | |
.to("log://camelLogger?level=INFO") | |
} | |
}) | |
camelContext.start() | |
addShutdownHook{ camelContext.stop() } | |
synchronized(this){ this.wait() } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment