Search in sources :

Example 21 with PlcDriverManager

use of org.apache.plc4x.java.PlcDriverManager in project plc4x by apache.

the class Plc4xReadClient method main.

public static void main(String[] args) throws Exception {
    try (final PlcConnection connection = new PlcDriverManager().getConnection("plc4x://localhost?remote-connection-string=simulated%3A%2F%2Flocalhost")) {
        final PlcReadRequest.Builder requestBuilder = connection.readRequestBuilder();
        requestBuilder.addItem("test-BOOL", "RANDOM/foo:BOOL");
        requestBuilder.addItem("test-BYTE", "RANDOM/foo:BYTE");
        requestBuilder.addItem("test-WORD", "RANDOM/foo:WORD");
        requestBuilder.addItem("test-DWORD", "RANDOM/foo:DWORD");
        requestBuilder.addItem("test-USINT", "RANDOM/foo:USINT");
        requestBuilder.addItem("test-UINT", "RANDOM/foo:UINT");
        requestBuilder.addItem("test-UDINT", "RANDOM/foo:UDINT");
        requestBuilder.addItem("test-ULINT", "RANDOM/foo:ULINT");
        requestBuilder.addItem("test-SINT", "RANDOM/foo:SINT");
        requestBuilder.addItem("test-INT", "RANDOM/foo:INT");
        requestBuilder.addItem("test-DINT", "RANDOM/foo:DINT");
        requestBuilder.addItem("test-LINT", "RANDOM/foo:LINT");
        requestBuilder.addItem("test-REAL", "RANDOM/foo:REAL");
        requestBuilder.addItem("test-LREAL", "RANDOM/foo:LREAL");
        requestBuilder.addItem("test-CHAR", "RANDOM/foo:CHAR");
        requestBuilder.addItem("test-WCHAR", "RANDOM/foo:WCHAR");
        final PlcReadRequest readRequest = requestBuilder.build();
        final PlcReadResponse readResponse = readRequest.execute().get();
        System.out.println(readResponse);
    }
}
Also used : PlcReadResponse(org.apache.plc4x.java.api.messages.PlcReadResponse) PlcReadRequest(org.apache.plc4x.java.api.messages.PlcReadRequest) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) PlcConnection(org.apache.plc4x.java.api.PlcConnection)

Example 22 with PlcDriverManager

use of org.apache.plc4x.java.PlcDriverManager in project plc4x by apache.

the class Plc4xWriteClient method main.

public static void main(String[] args) throws Exception {
    try (final PlcConnection connection = new PlcDriverManager().getConnection("plc4x://localhost?remote-connection-string=simulated%3A%2F%2Flocalhost")) {
        final PlcWriteRequest.Builder requestBuilder = connection.writeRequestBuilder();
        requestBuilder.addItem("test-BOOL", "STDOUT/foo:BOOL", true);
        requestBuilder.addItem("test-BYTE", "STDOUT/foo:BYTE", new boolean[] { true, true, false, true, false, true, false, true });
        requestBuilder.addItem("test-WORD", "STDOUT/foo:WORD", new boolean[] { true, true, false, true, false, true, false, true, false, false, false, false, true, true, true, true });
        requestBuilder.addItem("test-DWORD", "STDOUT/foo:DWORD", new boolean[] { true, true, false, true, false, true, false, true, false, false, false, false, true, true, true, true, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false });
        requestBuilder.addItem("test-USINT", "STDOUT/foo:USINT", 12);
        requestBuilder.addItem("test-UINT", "STDOUT/foo:UINT", 12345);
        requestBuilder.addItem("test-UDINT", "STDOUT/foo:UDINT", 1234567890);
        requestBuilder.addItem("test-ULINT", "STDOUT/foo:ULINT", new BigInteger("12345678901234567"));
        requestBuilder.addItem("test-SINT", "STDOUT/foo:SINT", -12);
        requestBuilder.addItem("test-INT", "STDOUT/foo:INT", -12345);
        requestBuilder.addItem("test-DINT", "STDOUT/foo:DINT", -1234567890);
        requestBuilder.addItem("test-LINT", "STDOUT/foo:LINT", new BigInteger("-12345678901234567"));
        requestBuilder.addItem("test-REAL", "STDOUT/foo:REAL", 3.14159f);
        requestBuilder.addItem("test-LREAL", "STDOUT/foo:LREAL", 2.71828182845904523536028747135d);
        requestBuilder.addItem("test-CHAR", "STDOUT/foo:CHAR", "P");
        requestBuilder.addItem("test-WCHAR", "STDOUT/foo:WCHAR", "Ϡ");
        final PlcWriteRequest writeRequest = requestBuilder.build();
        final PlcWriteResponse writeResponse = writeRequest.execute().get();
        System.out.println(writeResponse);
    }
}
Also used : PlcWriteRequest(org.apache.plc4x.java.api.messages.PlcWriteRequest) BigInteger(java.math.BigInteger) PlcWriteResponse(org.apache.plc4x.java.api.messages.PlcWriteResponse) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) PlcConnection(org.apache.plc4x.java.api.PlcConnection)

Example 23 with PlcDriverManager

use of org.apache.plc4x.java.PlcDriverManager in project plc4x by apache.

the class ManualProfinetIoTest method main.

public static void main(String[] args) throws Exception {
    final PlcConnection connection = new PlcDriverManager().getConnection("profinet://192.168.24.31");
    final PlcReadRequest readRequest = connection.readRequestBuilder().addItem("test", "").build();
    final PlcReadResponse plcReadResponse = readRequest.execute().get();
    System.out.println(plcReadResponse);
}
Also used : PlcReadResponse(org.apache.plc4x.java.api.messages.PlcReadResponse) PlcReadRequest(org.apache.plc4x.java.api.messages.PlcReadRequest) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) PlcConnection(org.apache.plc4x.java.api.PlcConnection)

Example 24 with PlcDriverManager

use of org.apache.plc4x.java.PlcDriverManager in project plc4x by apache.

the class TriggeredScraperImplTest method setUp.

@BeforeEach
public void setUp() throws Exception {
    driverManager = new PlcDriverManager();
    MockConnection mock1Connection = ((MockConnection) driverManager.getConnection("mock:1"));
    MockConnection mock2Connection = ((MockConnection) driverManager.getConnection("mock:2"));
    // Create Mocks
    mockDevice1 = Mockito.mock(MockDevice.class);
    mockDevice2 = Mockito.mock(MockDevice.class);
    // Assign to Connections
    mock1Connection.setDevice(mockDevice1);
    mock2Connection.setDevice(mockDevice2);
}
Also used : MockDevice(org.apache.plc4x.java.mock.connection.MockDevice) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) MockConnection(org.apache.plc4x.java.mock.connection.MockConnection) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 25 with PlcDriverManager

use of org.apache.plc4x.java.PlcDriverManager in project plc4x by apache.

the class HelloWebservice method run.

public void run() throws Exception {
    // Establish a connection to the plc.
    try (PlcConnection plcConnection = new PlcDriverManager().getConnection(options.getConnectionString())) {
        // Check if this connection support subscriptions.
        if (!plcConnection.getMetadata().canSubscribe()) {
            logger.error("This connection doesn't support subscriptions.");
            return;
        }
        // Create a new read request:
        // - Give the single item requested the alias name "value"
        final PlcSubscriptionRequest.Builder builder = plcConnection.subscriptionRequestBuilder();
        for (int i = 0; i < options.getFieldAddress().length; i++) {
            builder.addChangeOfStateField("value-" + i, options.getFieldAddress()[i]);
        }
        PlcSubscriptionRequest subscriptionRequest = builder.build();
        // Execute the subscription response.
        final PlcSubscriptionResponse subscriptionResponse = subscriptionRequest.execute().get();
        // Attach handlers for the incoming data.
        for (String subscriptionName : subscriptionResponse.getFieldNames()) {
            final PlcSubscriptionHandle subscriptionHandle = subscriptionResponse.getSubscriptionHandle(subscriptionName);
            subscriptionHandle.register(new ValueChangeHandler(options.getWebserviceUrl()));
        }
        // Wait for the user to press "Enter" to abort the program.
        Scanner scanner = new Scanner(System.in);
        try {
            logger.info("Please press Enter to exit program.");
            scanner.nextLine();
            logger.info("Finishing");
        } catch (IllegalStateException e) {
            // System.in has been closed
            logger.error("System.in was closed; exiting");
        }
    }
}
Also used : Scanner(java.util.Scanner) PlcSubscriptionRequest(org.apache.plc4x.java.api.messages.PlcSubscriptionRequest) PlcSubscriptionResponse(org.apache.plc4x.java.api.messages.PlcSubscriptionResponse) PlcSubscriptionHandle(org.apache.plc4x.java.api.model.PlcSubscriptionHandle) PlcDriverManager(org.apache.plc4x.java.PlcDriverManager) PlcConnection(org.apache.plc4x.java.api.PlcConnection)

Aggregations

PlcDriverManager (org.apache.plc4x.java.PlcDriverManager)54 PlcConnection (org.apache.plc4x.java.api.PlcConnection)35 PlcConnectionException (org.apache.plc4x.java.api.exceptions.PlcConnectionException)13 PlcReadRequest (org.apache.plc4x.java.api.messages.PlcReadRequest)13 PlcReadResponse (org.apache.plc4x.java.api.messages.PlcReadResponse)13 Test (org.junit.jupiter.api.Test)12 PooledPlcDriverManager (org.apache.plc4x.java.utils.connectionpool.PooledPlcDriverManager)10 BigInteger (java.math.BigInteger)8 ExecutionException (java.util.concurrent.ExecutionException)8 TimeUnit (java.util.concurrent.TimeUnit)5 Condition (org.assertj.core.api.Condition)5 BigDecimal (java.math.BigDecimal)4 LocalDate (java.time.LocalDate)4 Map (java.util.Map)4 PlcRuntimeException (org.apache.plc4x.java.api.exceptions.PlcRuntimeException)4 PlcSubscriptionRequest (org.apache.plc4x.java.api.messages.PlcSubscriptionRequest)4 PlcSubscriptionResponse (org.apache.plc4x.java.api.messages.PlcSubscriptionResponse)4 PlcSubscriptionHandle (org.apache.plc4x.java.api.model.PlcSubscriptionHandle)4 Disabled (org.junit.jupiter.api.Disabled)4 LocalDateTime (java.time.LocalDateTime)3