JavaFX – Saia Web server.

Each SAIA PCD has the integrated Web server allows the user to create an own control and monitoring function with help of JavaFX applets in HTML pages.

Saia Web server used CGI (Common Gateway Interface). The task of a Web server is to respond to requests for web pages issued by clients (usually browsers) by analyzing the content of the request (which is mostly in its URL), determining an appropriate document to send in response, and returning it to the client. CGI scripts are usually written in the scripting language and saved in Web server directory “/ cgi-bin” of PLC.

There two ways to exchange data of PLC controller to PC with a Saia Web server:

  1. HTML page must be stored in the “/ cgi-bin” directory of the PLC. Web server update variables in the page with stored tags.
  2. To use Saia CGI and Java asynchronous Http requests. Applet in the browser will send the request to the Web server. The answer will be sent back to the request originator on the same way.

1. Exchange PLC data  via HTML –> JavaScript–>JavaFX.

In first case Web server update tags in the html page and browser must reload page to update values  on client side.

This will be better way to use more than one page. One page will be displayed to the user, but in the background another page that will update values from PLC. This is need because the value in the PCD is changing, and the only way to have an updated value is to upload the page again and can have undesired side effect with large pages html. At least ‘update’ page must be stored in the “/ cgi-bin” directory of the Web server.

Values of the variables of the tags can be refreshed in ‘update’ HTML as show below. In this example, will be updates values of flag 115 and registers  219-221 of the PLC:

var F115=%%PDP,,F115,b%
var R219=%%PDP,,R219,d%
var R220=%%PDP,,R220,d%
var R221=%%PDP,,R221,d%
function update()
  //for IE
  if (parent.display.document.readyState == "complete")
  setTimeout("window.location.reload()", 500);
body onload="update()"

Now tags in the HTML page have new values, then they must be updated in JavaFX applet. JavaScript code on the web page can access the JavaFX Script applet and perform many operations, such as calling JavaFX Script functions,  setting variables, passing data from JavaScript to JavaFX Script.

JavaScript methods are invoked from Java or JavaFX using netscape.javascript.JSObject. An instance of JSObject can be obtained using static method JSObject.getWindow(< applet >) by passing the current applet instance as argument.

Applet instance can be obtained from JavaScript in display HTML.

<script language="JavaScript">

function updated()

  function MyJSFunction(){
    var app = document.getElementById("myApplet");
    app.script.MyAppletFunction(var1, var2,...);


Provide an applet name for javaFX application in “myApplet_browser.jnlp”.

name: “myApplet”,
id: “app”

Example: “Skid –> HTML –> JavaScript –> JavaFX v.1.3 applet”


2. Exchange PLC data with JavaFX applet. HttpRequest method.

This method makes asynchronous HTTP request to a remote server that supports the HTTP protocol.  Create the HTTP request with a location (URL)  and method(GET)and define our callback function (onInput), which is called when the HTTP request starts connecting with the function start.

try {
  var request = RequestHandler {
    location: location
    method: HttpRequest.GET
} catch (e: Exception) {
  println("WARNING: {e}");
  alert("Error", "Could not ... Please try again later.");

Callback function onInput.

public override var onInput = function(is: {
  try {
    var result: StringBuffer = new StringBuffer();
    var reader: BufferedReader  = new BufferedReader(new InputStreamReader(is, "UTF-8"));
    var temp: String;
    while ((temp = reader.readLine()) != null) {
    response = result.toString();<br />    reader.close();
  } finally {
    is.close();<br />  }

A location variable is URL of the HTTP request contains CGI functions. A response variable is response of the CGI function in Callback function onInput.

CGI (Common Gateway Interface) of the Web server.

In the Web server there are already 4 CGIs (executable) implemented.

* readval.exe
  read value function is used to read a single PCD media.
  The syntax is: Pref + readVal.exe?TAG

* writeval.exe
  write value function is used to write a single PCD
  media. The syntax is: Pref + writeval.exe?TAG+xxx.

* ordervalues.exe
  order values function is used when access to
  more than one PCD media is needed in the same time.
  The syntax is: Pref + OrderValues.exe?listname+dummy+ssss+TAG1+TAG2+ TAG3+T….
  http://pc_name/station_name/cgi-bin/OrderValues.exe?listname+dummy+ssss+TAG1+TAG2+ TAG3+T

* readfile.exe
  read file function is used to read the media values that
  have been predefined in the list with the “ordervalue” function.
  The function will return the list of the tags with their value.
  The syntax is: Pref + ReadFile.exe?listname.

* Pref = http:

* pc_name:
  the PC where the Web-Connect is running.

* Station_name:
  the name assigned to a PCD, corresponding to his communi
  cation settings.

* /cgi-bin/readVal.exe:
  the CGI.

* ? :
  separation between the CGI and the parameters.

* TAG :
  media tag, which has to be read.

* xxx:
  the value to be written, the format of the value was specified
  in the tag itself .

* Listname:
  list (or file) name of the media list that have been ordered
  before with „ordervalue”.

Java_launch Java_launch

Example: JavaFX v1.3 HttpRequest  and Web server Saia PLC. In this examples Control Panel applet communicate with Skid applet via PLC is physically located in Murten (Switzerland). At the bar below you can see URL and CGI for each operation. Control panel applet writes data to controller by using write.exe CGI functions and Skid applet reads data and updates it on the screen by using readfile.exe CGI function named “sim”, as a set of data.

Start two applets. Try to change variables with the control panel  in the Skid applets through PLC in Switzerland. If it does not work, check or PLC in Switzerland online. Starting third applets and push button “file”

Java_launch Java_source

Availability of  Saia-Siemens PLC.

Because not everyone has access to a PLC with a Web server, you can Step ® 7 compatible PLC type PCD3.M5547 access via the Internet, this PLC is physically located in Murten (Switzerland). You can control with approach.

Java_launch Java_source

NetBeans (JavaFX v1.3) example:  Saia-Siemens CGI test using HTTP request and all CGI functions.


NetBeans (JavaFX v1.3) example: Tanks.


5 Responses to “JavaFX – Saia Web server.”

  1. Thomas Ng Says:

    There’s a problem in the applet page, e.g:

    It reference to JavaFX 1.1:

    But the applet is actually compiled with JavaFX 1.2. In it’s JNLP file, it has:

    You should modify html page to reference the 1.2 dtfx.js also:

  2. Nicolas Lorain Says:

    Hi Alex

    I’m in charge of JavaFX Product Management at Oracle, and I also head the JavaFX Partner Program, which aims at making 3rd parties who develop applications in JavaFX more successful.

    Would you be available for a phone call to see if there’s an opportunity for us to work together? I must say your blog post is not only interesting because of the natur of the application you have written, but also because you have developed the same application using Silverlight.

    Let me know what date/time would work best for you, I can make myself available between 8am-10am Pacific Time most work days, which is 17h00- 19h00 CEST

  3. Kenan SATIR Says:

    Perfect work & sharing. Thanks a lot.

  4. Robin Says:

    Hi! Nice work. It seems that the examples doesnt work anymore.
    Is it possible to get more information about this?

    Thank you for sharing.

Comments are closed.

%d bloggers like this: