TINE console client applications play an important role in middle-layer servers, automatic servers, scripts, diagnostic checks, etc. Client applications requiring a user interface are best written as GUI applications.
The example below is a simple java client code module which obtains the sine curve from the simple console server example, and illustrates both synchronous and asynchronous calls. It makes use of the acop java bean for graphical display of the sine wave.
Create a new java project and make sure that tine.jar and acop.jar are included in the library list on otherwise on the class path. In this example, we'll assume this is a java project in Eclipse called "SINE-gui", where a package "tineSineClientGUIExample" has been created with a class called "SineClient". In Eclipse make sure the class is added as a 'visual' class.
Assuming that the top level visual container is a Swing JFrame, you should put a JPanel in the center position, go to the properties of the Jpanel and set the layout manager to 'null'. If you like layout manager and know what you're doing then you can ignore these suggestions. However for the sake of presenting a simple (Visual Basic - like) example we'll turn it off.
If the acop bean does not show up in the bean list, then select "Choose Bean" and type "acop" and select the Acop bean from the list. Now drag this over the JPanel and place and size it however you like it.
At this stage, the generated code should look something like the following:
and your visual editor should show something like:
Note that in this example we have made no attempt to name the acop instance anything other than the suggestiong 'acop'. You could give it the name 'sinewave' or something more meaningful if you like.
In the main() method add
so that the application will display itself when it is being run. underneath the package declaration.
Add the int variable 'size' to the class, initializing it to 1024. Now add the float arrays sdat and refdat, dimensioned to size;
Set the acop properties 'AccessProtocol' to "TINE", 'AccessMode' to "POLL", 'DeviceContext' to "TEXT", 'DeviceGroup' to "SINEWAVE", 'DeviceName' to "#0", 'DeviceProperty' to "SINE". Generated code frequently places these property settings in the instantiation routine of the acop.
In the visual editor, right click on the acop and select 'Add Events', and choose 'Acop' -> 'Acop.receive'.
The generated code will add an 'AcopListener' and an AcopReceive() event stub which prints out "AcopReceive()" on the standard output.
Your SineClient.java code should now look like the following:
Create a simple callback method called cbSineClient() and inside this method, issue an acop.ClearScreen and an acop.Draw so that the sine wave display is updated every time the receive event is fired.
Inside the initialize method you can set the 'max' and 'min' display properties for the acop display. For this simple example, we'll just set them with a priori knowledge as the range of values.
You can also obtain a 'reference' display with a synchronous 'Execute()' call inside the initialization routine, but remember to set the AccessMode to "READ" prior to the call and to set it back to "POLL" prior to making a call to 'AttachLink()', which you should also do in this routine.
The code in your SineClient.java module should now look something like:
When you run the application, make sure the the virtual machine definition -Dtine.home is set (e.g -Dtine.home=L:\database or -Dtine.home=/usr/etc/tine). You should see a display something like the following:
To run the java application stand-alone instead of inside a development environment such as Eclipse, you should export the project as an external .jar file, for example mySineClient.jar.
In Windows, you can start the application at the command prompt by typing:
javaw -cp mySineClient.jar;tine.jar;acop.jar; -Dtine.home="L:\\database" tineSineClientGUIExample.SineClient
If the tine.home property is contained in a properties file called tine.properties and this file is in the same directory where tine.jar is located, then you can also start the application by typing:
javaw -cp mySineClient.jar;tine.jar;acop.jar; tineSineClientGUIExample.SineClient
We called the .jar file mySineClient.jar and it needs tine.jar and acop.jar on the classpath in order to start. Finally, the package name 'tineClientGUIExample' and the class containing the 'main' method that we want to start needs to be the last entry on the command line. If the package name uses long url names (in order to avoid name collisions) this all needs to be specified (i.e. your package name is de.desy.mcs.tineSineClientGUIExample for instance).
It is frequently a good idea to place system jar files together in a repository and to make use of the java.ext.dirs property switch to point to this repository. For instance, if an enviroment variable JARPATH is set to point to this repository, e.g.
set JARPATH=L:\java
then applying the property definition -Djava.ext.dirs=JARPATH% will eliminate the need for placing all necessary jar files on the classpath.
If the application jar file has a manifest which identifies the main routine to start execution, then the application can be started by typing
javaw -Djava.ext.dirs=JARPATH% -jar tineSineClientGUIExample.SineClient
If you place this command line inside a batch file, remember to use 'start' so as to avoid an open cmd window.
In UNIX you can type:
java -cp mySineClient.jar:tine.jar:acop.jar: -Dtine.home=/usr/etc/tine tineSineClientGUIExample.SineClient
Or if you use a JARPATH location such as
export JARPATH=/usr/jars
java -Djava.ext.dirs=$JARPATH -jar tineSineClientGUIExample.SineClient