Search in sources :

Example 6 with PooledPlcDriverManager

use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project plc4x by apache.

the class Plc4xNamespace method onDataItemsCreated.

@Override
public void onDataItemsCreated(List<DataItem> dataItems) {
    for (DataItem item : dataItems) {
        plc4xServer.addField(item);
        if (plc4xServer.getDriverManager() == null) {
            plc4xServer.removeField(item);
            plc4xServer.setDriverManager(new PooledPlcDriverManager());
        }
    }
    subscriptionModel.onDataItemsCreated(dataItems);
}
Also used : DataItem(org.eclipse.milo.opcua.sdk.server.api.DataItem) PooledPlcDriverManager(org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager)

Example 7 with PooledPlcDriverManager

use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project incubator-streampipes by apache.

the class Plc4xS7Adapter method before.

/**
 * This method is executed when the adapter is started. A connection to the PLC is initialized
 * @throws AdapterException
 */
@Override
protected void before() throws AdapterException {
    // Extract user input
    getConfigurations(adapterDescription);
    this.driverManager = new PooledPlcDriverManager();
    try (PlcConnection plcConnection = this.driverManager.getConnection("s7://" + this.ip)) {
        if (!plcConnection.getMetadata().canRead()) {
            this.LOG.error("The S7 on IP: " + this.ip + " does not support reading data");
        }
    } catch (PlcConnectionException e) {
        this.LOG.error("Could not establish connection to S7 with ip " + this.ip, e);
    } catch (Exception e) {
        this.LOG.error("Could not close connection to S7 with ip " + this.ip, e);
    }
}
Also used : PlcConnectionException(org.apache.plc4x.java.api.exceptions.PlcConnectionException) PlcConnection(org.apache.plc4x.java.api.PlcConnection) PlcConnectionException(org.apache.plc4x.java.api.exceptions.PlcConnectionException) AdapterException(org.apache.streampipes.connect.api.exception.AdapterException) ExecutionException(java.util.concurrent.ExecutionException) PooledPlcDriverManager(org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager)

Example 8 with PooledPlcDriverManager

use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project plc4x by apache.

the class Plc4XEndpoint method setTrigger.

public void setTrigger(String trigger) {
    this.trigger = trigger;
    plcDriverManager = new PooledPlcDriverManager();
    String plc4xURI = uri.replaceFirst("plc4x:/?/?", "");
    // TODO: is this mutation really intentional
    uri = plc4xURI;
    try {
        connection = plcDriverManager.getConnection(plc4xURI);
    } catch (PlcConnectionException e) {
        throw new PlcRuntimeException(e);
    }
}
Also used : PlcRuntimeException(org.apache.plc4x.java.api.exceptions.PlcRuntimeException) PlcConnectionException(org.apache.plc4x.java.api.exceptions.PlcConnectionException) PooledPlcDriverManager(org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager)

Example 9 with PooledPlcDriverManager

use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project plc4x by apache.

the class ManualS7PlcDriverMT method scheduledLoop.

@ParameterizedTest
@ValueSource(ints = { 1, 5, 10, 20 })
public void scheduledLoop(int period) throws InterruptedException {
    PlcDriverManager plcDriverManager = new PooledPlcDriverManager();
    ScheduledExecutorService executorService = Executors.newScheduledThreadPool(10);
    DescriptiveStatistics statistics = new DescriptiveStatistics();
    int numberOfRuns = 1000;
    AtomicInteger counter = new AtomicInteger(0);
    executorService.scheduleAtFixedRate(() -> {
        // System.out.println("Run: " + counter.get());
        double timeNs = runSingleRequest(plcDriverManager);
        statistics.addValue(timeNs);
        if (counter.getAndIncrement() >= numberOfRuns) {
            executorService.shutdown();
            printStatistics(statistics);
        }
    }, 0, period, TimeUnit.MILLISECONDS);
    executorService.awaitTermination(100, TimeUnit.SECONDS);
}
Also used : DescriptiveStatistics(org.apache.commons.math3.stat.descriptive.DescriptiveStatistics) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) PooledPlcDriverManager(org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager) PooledPlcDriverManager(org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with PooledPlcDriverManager

use of org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager in project plc4x by apache.

the class TriggeredScraperRunner method main.

/**
 * testing of TriggeredScraper vs real device
 */
public static void main(String[] args) throws IOException, ScraperException {
    ScraperConfiguration configuration = ScraperConfiguration.fromFile("plc4j/utils/scraper/src/test/resources/example_triggered_scraper.yml", ScraperConfigurationTriggeredImpl.class);
    PlcDriverManager plcDriverManager = new PooledPlcDriverManager();
    TriggerCollector triggerCollector = new TriggerCollectorImpl(plcDriverManager);
    TriggeredScraperImpl scraper = new TriggeredScraperImpl(configuration, (j, a, m) -> LOGGER.info("Results from {}/{}: {}", j, a, m), triggerCollector);
    scraper.start();
    triggerCollector.start();
}
Also used : ScraperConfiguration(org.apache.plc4x.java.scraper.config.ScraperConfiguration) TriggeredScraperImpl(org.apache.plc4x.java.scraper.triggeredscraper.TriggeredScraperImpl) TriggerCollector(org.apache.plc4x.java.scraper.triggeredscraper.triggerhandler.collector.TriggerCollector) TriggerCollectorImpl(org.apache.plc4x.java.scraper.triggeredscraper.triggerhandler.collector.TriggerCollectorImpl) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) PooledPlcDriverManager(org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager) PooledPlcDriverManager(org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager)

Aggregations

PooledPlcDriverManager (org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager)10 PlcDriverManager (org.apache.plc4x.java.PlcDriverManager)7 DescriptiveStatistics (org.apache.commons.math3.stat.descriptive.DescriptiveStatistics)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Test (org.junit.jupiter.api.Test)3 PlcConnection (org.apache.plc4x.java.api.PlcConnection)2 PlcConnectionException (org.apache.plc4x.java.api.exceptions.PlcConnectionException)2 ScraperConfiguration (org.apache.plc4x.java.scraper.config.ScraperConfiguration)2 TriggeredScraperImpl (org.apache.plc4x.java.scraper.triggeredscraper.TriggeredScraperImpl)2 TriggerCollectorImpl (org.apache.plc4x.java.scraper.triggeredscraper.triggerhandler.collector.TriggerCollectorImpl)2 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 GenericKeyedObjectPool (org.apache.commons.pool2.impl.GenericKeyedObjectPool)1 GenericKeyedObjectPoolConfig (org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig)1 PlcRuntimeException (org.apache.plc4x.java.api.exceptions.PlcRuntimeException)1 TriggerCollector (org.apache.plc4x.java.scraper.triggeredscraper.triggerhandler.collector.TriggerCollector)1 AdapterException (org.apache.streampipes.connect.api.exception.AdapterException)1 DataItem (org.eclipse.milo.opcua.sdk.server.api.DataItem)1