Java RSC API ‒ Getting started

The following steps describe the basic project setup for using the former Java RSC API.

Note:
The Java RSC API will soon be replaced by a better solution. Therefore the support for this tool is already discontinued. If you decide to use the Java RSC API anyway you'll be on your own.
  1. Add the JAR files of the projects
    1. Ade.CommonRemoting
    2. Ade.CommonRemotingImpl
    3. Arp.System.Rsc,
    4. Arp.System.Rsc.Services
    5. SLF4J and
    6. BouncyCastle
      as project dependencies:
  2. If you are using Java™ 9 with the module system, add the module entries in the module-info.java file:
    ...
    requires com.phoenixcontact.arp.system.rsc;
    requires com.phoenixcontact.arp.system.rsc.services;
    ...
  3. Define the connection properties.
    import com.phoenixcontact.arp.system.rsc.ConnectionInfo;
    import com.phoenixcontact.arp.system.rsc.SecurityInfo;
    public class Example {
        public static void main(String[] args) throws Exception {
            // connection properties
            String hostname = "192.168.1.10"; // your controller IP
            int port = 41100; // The default port for RSC communication is 41100
            int connectTimeout = 10000;
            int readTimeout = 10000;
            ConnectionInfo connectionInfo = new ConnectionInfo(hostname, port, connectTimeout, readTimeout;
            String username = "admin";
            char[] password = new char[] { '1', '2', '3', '4' };
            SecurityInfo securityInfo = new SecurityInfo(username, password);
        }
    }
    NOTE: With default controller settings, the RSC service allows only secured connections, even if the application is executed on the device.
  4. Now create a new ServiceManager instance and execute the connect method.
    // import for connection properties
    import com.phoenixcontact.arp.system.rsc.ConnectionInfo;
    import com.phoenixcontact.arp.system.rsc.SecurityInfo;
    // import for service manager
    import com.phoenixcontact.arp.system.rsc.ServiceManager;
    import java.util.Arrays;
    public class Example {
      public static void main(String[] args) throws Exception {
        // connection properties
        String hostname = "192.168.1.10";
        int port = 41100;
        int connectTimeout = 10000;
        int readTimeout = 10000;
        ConnectionInfo connectionInfo = new ConnectionInfo(hostname, port, connectTimeout, readTimeout);
        String username = "admin";
        char[] password = new char[] { '1', '2', '3', '4' };
        SecurityInfo securityInfo = new SecurityInfo(username, password);
        // service manager
        try (ServiceManager serviceManager = new ServiceManager()) {
          serviceManager.connect(connectionInfo, securityInfo);
        } finally {
          Arrays.fill(password, '\0');
        }
      }
    }
    
  5. Request and create a RSC service instance. Access a RSC service and execute a service method. If the requested service does not exist, the return value of getService(…) will be zero.

    // import for connection properties
    import com.phoenixcontact.arp.system.rsc.ConnectionInfo;
    import com.phoenixcontact.arp.system.rsc.SecurityInfo;
    // import for service manager
    import com.phoenixcontact.arp.system.rsc.ServiceManager;
    import java.util.Arrays;
    // import for RSC service instance
    import com.phoenixcontact.arp.plc.domain.services.IPlcManagerService2;
    import com.phoenixcontact.arp.plc.domain.services.PlcStates;
    public class Example {
      public static void main(String[] args) throws Exception {
        // connection properties
        String hostname = "192.168.1.10";
        int port = 41100;
        int connectTimeout = 10000;
        int readTimeout = 10000;
        ConnectionInfo connectionInfo = new ConnectionInfo(hostname, port, connectTimeout, readTimeout);
        String username = "admin";
        char[] password = new char[] { '1', '2', '3', '4' };
        SecurityInfo securityInfo = new SecurityInfo(username, password);
        // service manager
        try (ServiceManager serviceManager = new ServiceManager()) {
            serviceManager.connect(connectionInfo, securityInfo);
            // create a RSC service instance
            IPlcManagerService2 service = serviceManager.getService(IPlcManagerService2.class);
            PlcStates state = service.getPlcState();
            System.out.println(state.getFlags());
        } finally {
          Arrays.fill(password, '\0');
        }
      }
    }

 

 

 


• Published/reviewed: 2024-05-06   ★  Revision 068 •