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);
}
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);
}
}
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);
}
}
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);
}
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();
}
Aggregations