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.
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.
- Add the JAR files of the projects
Ade.CommonRemoting
Ade.CommonRemotingImpl
Arp.System.Rsc
,Arp.System.Rsc.Services
SLF4J
andBouncyCastle
as project dependencies:
- 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; ...
- Define the connection properties.
NOTE: With default controller settings, the RSC service allows only secured connections, even if the application is executed on the device.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); } }
- 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'); } } }
-
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-10-30 ☀ Revision 074 •