For those who are unfamiliar with the details of the PLCnext architecture, the following diagram might proof helpful.
As you can see non real-time components can communicate with the PLCnext runtime via Remote Service Calls and Access to shared data with the GDS and the the Operating System APIs. There are services running on the PLC exposing a part of this functionality to the network and these are the service we are going to use to create a simple GUI-Application that will use some of the available services.
In the application we are going to use the new java library to communicate with this services and javafx to render the GUI. If you want to see the code behind this application you can find the code here on Github. First we are going to discuss the UI segmentation and the currently usable functionality, but we are going to come back to how the code works and how you can extend it.
The UI starts with a simple login screen as it is a prerequisite for all services to be connected to the PLC. To connect you have to enter the ip of your PLCNext Controller, the port the service is listening on (defaults to 41100), a existing linux user name and the corresponding password. To ease the login process, the information can be read from a config.txt file, in form of a coma separated list. It is obviously not recommended to safe a password in plain text for any PLC outside of testing and debugging uses.
After login the main screen is separated into tabs corresponding to the different services their content uses. The first tab, called the main tab shows the current State of the controller and allows you to manipulate that state by starting and stopping the program on the controller as well as restarting the controller itself. The last feature on this tab is starting a firmware update. This does only work if you have previously placed a new firmware on the controller in the /opt/PLCnext folder.
This can either be accomplished with an SFTP client or using the second tab of this application. It allows you to browse the filesystem, copy files and folders to and from the PLC, create new folders and remove existing files and folders.
The third tab can be used to monitor the state of Global Data Space variables. Just enter the uri into the text box above the subscribe button and if this uri is valid, the variable with its type and value will appear in the table on the left. To unsubscribe from a variable you can select a variable in the table and press unsubscribe. You can also write to a selected variable by entering a text representation of the value into the text box above the write button and hitting write. Currently this does only work for simple types like strings and numbers.
The new RSC library does all the heavy lifting in the background. This application is just a thin wrapper, adapting it´s functionality into GUI representable format. The services used within each tab are as follows.
- Main Tab
- IPlcMangerService2 Used to start and stop the currently running program on the PLC
- IDeviceControlService Used restart and start the firmware upgrade
- File Service Tab
- IDirectoryService Used to browse the filesystem and create new folders, as well as removing folders.
- IFileService Used to copy files to and from the PLC, as well as removing files.
- GDS Tab
- ISubscriptionService Retrieves local copy of the subscribed variable values that is automatically updated. Is used manage the subscribed variables and update their values periodically.
- IDataAccessService Gives one time read and write access to a variable. Used to write values back to the PLC.
Of course there are way more services that one could use, to add more capabilities to this or other applications. For instance there is a service to change user credentials, a service to read and change the Axioline configuration or to validate the identity of a PLC cryptographically.
Adapting this project
If you want to adapt this project for your own purposes, here is a brief description of the inner workings of this program. The main view, the screen displayed after login, is a TabPane with only the log Tab in it by default and a label at the bottom to display messages and errors. All other tabs are loaded, when the MainViewController is initialized. Each Tab consists of at least two parts. A fxml file and the controller linked to by the fxml. This controller has to implement the TabController interface for initialisation and clean up purposes. Shared communication infrastructure to notify other tabs about events and to display messages to the user are available in the CoreCommunication class, an instance of which is shared by all tabs. To separate the logic talking to the services and the UI, every TabView controller of this application delegates it´s logic to a Service in the RscController package. Accordingly this is were you should look if you want to see how the communication with the new library works.