Focus HMI VNC Server

In this article , we will talk about screen shering with VNC server. In Focus HMI operator panels, vnc server connection is set as default open and without password. So you can connect VNc server without any configration.

We will connect Focus HMI via Vnc Viewer.

You can download Vnc Viewer from here.

After opening the Vnc Viewer program, instead of “Enter a VNC Server address” write Focus HMI Ip and port number “5900” as described in the image below.

Press continue on the windows.

And you are ready to use Vnc server.

If you want to use your VNC server with encryption, you can review our article “VNC Server Password Creation”.

VNC Whatcdog Script

You can add a script to your project that allows VNC to be restarted when there is a problem with the VNC connection.

import java.lang.reflect.Method;
import java.net.*;
import java.io.*;
public class NewScript{
	public static short VncState;
	
	public NewScript(Class Accessing){
		Thread newThread = new Thread(() -> { 
			try{
				if(VncState >= 2){
					VncState = 0;
					Runtime.getRuntime().exec("x11vnc -display :0 -shared -forever"); 
				}else{
					try (Socket socket = new Socket("192.168.0.11", 5900)) {
						VncState = 1;
		               } catch (UnknownHostException ex) {        
		               	VncState = 2; 
		               	Runtime.getRuntime().exec("x11vnc -R stop");                
		               } catch (IOException ex) {        
		               	VncState = 3;             
		               	Runtime.getRuntime().exec("x11vnc -R stop");
		               }  
				}    
				Method setValue = Accessing.getMethod("setValue", String.class, Object.class);		
				setValue.invoke(Accessing, "VncState", VncState);
			}catch(Exception exp){
				javax.swing.JOptionPane.showMessageDialog(null , exp.getMessage());
			}
        	});
        	newThread.start(); 		
	}
}

Create a new script and copy the above code.

Compile and save the script. I saved it as VncTest.

You can choose how it will work from the script section in the settings section.

Leave a Reply