Connect to Matrikon server with OPC UA Java Legacy - java

I am trying to connect to an OPC server of a Siemens S7 1200 PLC. For this I used the Matrikon application
That is configured on my local machine. With the JeasyOPC library I can make the connection, so it is like this:
JOpc jopc = new JOpc("localhost","Matrikon.OPC.SiemensPLC.1","JOPC1");
JOpc.coInitialize();
But this library can only be used in Windows and has problems when compiling binaries in 64.
So I have tried with OPC Foundation UA JAVA Legacy and I would like to make the same connection, however in the examples we ask for many more things:
String publicHostname = InetAddress.getLocalHost().getHostName();
String url = "opc.tcp://localhost:102/"; // ServerExample1
// String url = "Matrikon.OPC.SiemensPLC.1"; // This not work for me
EndpointDescription[] endpoints = myClient.discoverEndpoints(url);
I would like to emulate the operation of jeasyOPC as far as possible, in any case I can not find any example that works for me.
I would appreciate any example that would help me have a base client that would work with the Matrikon server
Thank you.

Okay. I answer to myself.
After many searches I have found my error:
There are two types of OPC: DA and UA.
The first of all (the DA) is to which I could connect with:
JOpc jopc = new JOpc ("localhost", "Matrikon.OPC.SiemensPLC.1", "JOPC1");
This version of the protocol is the one used historicaménte windows, uses COM libraries and can only be implemented under a Windows computer.
The second, the OPC UA, is the new implementation and connects like this:
String url = "opc.tcp: // localhost: 102 /"; // ServerExample1
This version is already compatible with Windows, Linux and any system that is capable of running the libria.
The problem was that, in my case, the S7 1200 only uses OPC DA, which made the UA option unfeasible for me if it did not use a compatible gateway.
I hope this information will help someone who is in my situation.
Greetings.

Related

How to connect opc kepware server through a Java program, without the username and the password?

I am trying to connect opc kepware server through a Java program, I want to know what jar files can be used to connect to KepwareserverEx.V5 and what is the code without the use of password and username.
I have referenced http://www.opcconnect.com/uakit.php, and https://github.com/digitalpetri/ua-server-sdk, but it doesn't have anything that doesn't connect without a username and a pawssword. I have a program in vb that connects to kepware using Interop.OPCAutomation.dll file and uses the code:
ConnectedOPCServer = New OPCAutomation.OPCServer
ConnectedOPCServer.Connect("Kepware.KEPServerEX.V5", "")
ConnectedGroup = ConnectedOPCServer.OPCGroups.Add("MPM Group")
ConnectedGroup.UpdateRate = 1000
ConnectedGroup.IsSubscribed = True
ConnectedGroup.IsActive = True
I want to write Java code in a similar way. Searched through the internet to see various examples, but none have the above connection without a username and password not being specified.
First of all, I assume that you have created an "anonymous" and "SecurityPolicy.None" endpoint on KepServerEX.
You refer to digitalpetri's old and server SDK. The new project is called "Milo". I can recommend you take a look at the Milo project's client SDK examples using this link. There is an application of anonymous identity and none security policy.
In terms of jar, you can either build your client-sdk (see example here) or directly download the client-sdk jar from Maven Central.
NB Milo is considered to be in incubation. That is to say, it is not mature yet. Be careful using it in production systems.
Yes that's right. The security policy is none on the KepwareServerEX. I made some permission changes on the server where Kepware exists, so that my localhost computer would be able to talk to the Kepware server host. Provided credentials for my localhost, and able to connect.

Configuration OPC UA Server (Milo)?

I've just checked out the Eclipse Milo Project (https://projects.eclipse.org/proposals/milo), which seems to be a great project for an "open" OPC UA Client/Server even with the implemented OPC Stack. The project on github (https://github.com/eclipse/milo) contains a Hello World example, where an OPC Server is started and an example node is sent and received from the client. Everything works fine!
But in my next step, I wanted to check if the server is configured correctly. Therefore I've installed Matrikon Explorer, but the Explorer is stating out "No OPC servers installed on this machine" right after start (while the hello world example with a running OPC Server is running of course).
Also checked, if SAP Plant Connectivity is recognizing the OPC Server (which is the goal of my project) -> "Found no OPC Server on your system/localhost"
Where is my problem, what do I have to do, to install and configure the Server correctly?
Here's the Hello World Example:
public static void main(String[] args) throws Exception {
// Start server
int port = 12686;
String serverName = "test-server";
OpcUaServerConfig serverConfig = OpcUaServerConfig.builder()
.setBindPort(port)
.setCertificateManager(new DefaultCertificateManager())
.setCertificateValidator(new DefaultCertificateValidator(createTempDir()))
.setServerName(serverName)
.setUserTokenPolicies(singletonList(USER_TOKEN_POLICY_ANONYMOUS))
.build();
OpcUaServer server = new OpcUaServer(serverConfig);
server.getNamespaceManager().registerAndAdd(
"urn:eclipse:milo:opcua:test-namespace",
idx -> new HelloNamespace());
server.startup();
while(true){
System.out.println("server running");
}
}
Matrikon Explorer is an OPC-COM/DA client, and is probably interrogating the OPC Enum service in order to find registered COM clients.
OPC-UA is an entirely different, platform independent, technology. The concept of registration still exists, but it's not forced by default.
Try using an OPC-UA client like UaExpert to connect. Given the configuration you've copied, you'll want to point UaExpert at the endpoint URL opc.tcp://localhost:12686/test-server
I'm guessing there will be an issue once you connect with the partially implemented "hello world" namespace. I'll make sure we get a fully usable namespace example committed this week.
You can also look at the OpcUaClientIT integration test class for various client functionality and another example of setting up a server.

JAVA vs Python Socket defaults

I'm pretty sure that my root problem is the antivirus app managed by our network, but my a basic socket client I wrote in Python that worked up until a short time ago is now giving me "socket error 10013". I also have the SocketTest app in JAVA. SocketTest works, but I have been unsuccessful in getting Python to connect.
The WIN 7 PC has two network cards, not bridged. I have switched the firewall on and off. If I disable the connection to the corporate LAN then the Python client is happy. Just to reiterate, this configuration worked for several months.
I cannot find the difference. Here is the sample code:
Python
MY_IP = '192.168.100.2'
MY_PORT = 62828
ROBOT_IP = "192.168.100.10"
ROBOT_SOCK = 29999
robotSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
robotSocket.bind((MY_IP, MY_PORT)) # Tried without binding
robotSocket.connect((ROBOT_IP, ROBOT_SOCK))
Result "socket error 10013"
JAVA:
socket = new Socket(ROBOT_IP, ROBOT_SOCK);
is = socket.getInputStream();
in = new BufferedInputStream(is);
while (!desonnected)
{
try
{
String got = readInputStream(in); // in.readLine();
This works fine, but I cannot find the difference to adjust my Python code. I'm sure it is the OfficeScan, but....
Edit
I ran WireShark as suggested. With both network cards enabled the Python connection request is not sent.
After disabling the corporate LAN, I compared the Connection requests between the JAVA client and the Python client and they contained the same data except for the local port of course.
I have recently struggled a lot with socket binding and multiple NICs on Windows 7.
I'm normally a unix guy, but I had to do some C#.Net for a friend as a favor..
MY problem was that I couldn't bind a socket to a specific port and ip on the client side. The solution was to increase the "binding priority" of the NIC I wanted to bind to. I don't know much about Windows, so I can't really elaborate more. Read this article for some info, it helped me: Network adapter card priority binding order in windows 7
Not sure if you're experiencing the same problem, as a socket error 10013 seems to be permission related. Google gives me this: dealing with socket error 10013

Java RMI - Remote Deployment

I have a locally working JAVA RMI Applicaton(Server & Client).
I have used Eclipse & a plugin(Genady) to write & run these applications.
There are three parts in my project:
1. Server
2. Interface(Common for both client & server)
3. Client
Local deployment, using Eclipse(+plugin), works perfectly. The client uses the common interface(added to the "Build Path") to communicate(to n fro) with the server(which also has the common interface added to its Build Path in eclipse).
And now, I'm planning to test the same system in two different computers, both having Internet connection.
What do I do now?
Should I be installing Apache on one computer(Server) & put the Server+Interface files(class-files) into the web-accessible directory? & then run the Client-files(having both client & interface class files) from another computer(Client)??
Can someone help me configure this? I mean, a step-by-step guide as to what I should be doing in order for the remote deployment to work?
Is using Apache(or any web server application) compulsory?? Any other alternative for my application to work without using a web server(I mean, like direct connection or something?)?
(I feel I've given all the info that is required. But if any more info is needed, please ask.)
This is my final year project & my final demo is coming up soon!
Thank you, in advance!
I don't know what Genady does since I rarely use Eclipse.
Developing RMI applications is very easy anyway.
Pack the server code and run it on the remote machine (the R in RMI)(a.k.a. server host), it should register itself with the Registry which by default uses port 1099 but you can create a registry in any port you like:
MyRemoteInterface stub = (MyRemoteInterface) UnicastRemoteObject.exportObject(server, 0); //I don't know if this is needed anymore, or you could make the "server" extend UnicastRemoteObject
int thePortUsedInTheServer = 1099; //default
Registry registry = Registry.createRegistry(thePortUsedInTheServer);
registry.rebind("Server", stub));
Pack the client code and run it on the client(s) (the M+I in RMI), it should locate the Registry in the remote machine (host+port):
String host = ...; //the host where the server is
int port = ...; //the port used in the server
Registry registry = LocateRegistry.getRegistry(host, port);
MyRemoteInterface stub = (MyRemoteInterface)registry.lookup("Server");
stub.myRemoteMethod(); //call your remote methods
The javadoc should help you out. Nothing else is required, no Apache, etc. Watch out for aggresive anti-virus software, firewalls, and the like. Those are the only real issues after you get the gist of it.

RMI calls not working when firewall present on the WindowsXP client, but fine on Windows 7 client

I am using the basic RMI-based client/server app shown in Java Tutorials. I am running the server and client on different machines. I also export the remote objects for both the server and client, and make them available to each other.
However, there is a firewall turned on the client side and so the RMI calls fail (from client to server or server back to client). Also, when the machine has Windows 7 instead of WindowsXP, just allowing the popup message from firewall makes everything run fine. Somehow, the same does not happen on WindowsXP.
I have looked at http://download.oracle.com/javase/6/docs/technotes/guides/rmi/faq.html#firewall mentioned in other similar questions and I am trying the fixed port approach (where in remote object listens on a fixed port).
The code is something like this:
Server
Compute engine = new ComputeEngine();
Compute stub = (Compute) UnicastRemoteObject.exportObject(engine,1299);
Registry registry = LocateRegistry.createRegistry(1299);
registry.rebind("Compute", stub);
Client
String host = "192.168.x.y";
Registry registry = LocateRegistry.getRegistry(host, 1299);
Compute comp = (Compute) registry.lookup("Compute");
Pi task = new Pi(Integer.parseInt(args[0]));
BigDecimal pi = comp.executeTask(task);
Please let me know if you have faced similar problem or if you can point out where I am going wrong.
Thanks,
Abhinav.
first try comment out this line:
Registry registry = LocateRegistry.createRegistry(1299);
and check do you have security.policy file if not then create that
then try this code in that:
grant {
permission java.security.AllPermission "", "";
};
and might be you are not setting security manager:
set that like this in your main method:
System.setSecurityManager(new RMISecurityManager());

Categories

Resources