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