Using the PLC Java Comm Library "PLCmon.jar"

1.     Installing the Library File "PLCmon.jar"

There is only one library file: "PLCmon.jar" which  needs to be included into the Java compiler classpath if you are using the JDK to develop your Java program (see JDK documentations for details). For Visual Cafe version 3 and version 4 users, please  click on  "Tools ->  Environment Options -> Internal VM" and click on the "New" button, then browse to the path where you keep a copy of "PLCmon.jar" file and click the "Open" button to add it's path to the VisualCafe library. You will have to restart the Visual Cafe program in order to use the library.

2.    Using the API Library

  1. To make use of the API, you need to include it into your project using the "import PLCmon.*" keyword.
  2. You will then create a "ConnectTLServer" object using one of the two default constructors:
public ConnectTLServer(Applet applet,
                       String username,
                       String password)

public ConnectTLServer(String URLstring,
                       String username,
                       String password)
E.g. ConnectTLServer ctlsvr = new ConnectTLServer("127.0.0.1:9080", "samples", "1234")
The first form is used when writing an applet while the second form is used for writing an application. 

Note: Due to Java-imposed security policy, an unsigned applet will not be able open a network socket to any IP address other than the one that it has been loaded from. Hence if you use the second form of constructor to create an unsigned applet the program may compile OK but will not work properly. Only an "application" has the ability to open connection to any TLServer by supplying the URL address in the "URLString" variable.

  1. The ConnectTLServer object has a  "commAction" method which is the main method used to communicate with the PLC via the TLServer. However, in order to call the commAction method you have to pass to it an array of "actions" that you wish to perform. You define each of your desired action by constructing an "Action" object using one of the constructors:
public Action(int ID,int actionType,int varType,int index,int value,String s,int DM,int dmCount)
public Action(int ID,int actionType,int varType,int index,int value)
public Action(int ID,int actionType,int varType,int index,int dmCount,int DM)
public Action(int ID,int actionType,int varType,int index,String stringValue)

The Action object basically comprises the value or reference of the parameters to be sent to or received from the PLC. The first form is the most complete form. Other simplified forms can be used if the action does not involve the unused parameters. See the documentation on "PLCmon.Action" for more detailed descriptions of each parameter. Note that the "actionType" is an integer which define one of the four actions and varType define the variable type (e.g. INPUT[], RELAY[], A$-Z$, DM etc) that are involved. A list of static constants defining the actionType and varType are defined in the "PLCmon.ActionConstant" class. 

  1. You can define a series of actions to be performed by constructing an array of "Action" objects. For examples,

Action monAction = new Action[10]
monAction[0] = new Action(1,ActionConstant.READSINGLE,ActionConstant.INPUT,1,0);     // Read INPUT[1]
monAction[1] = new Action(1,ActionConstant.READDM, ActionConstant.DM,10, 5, DM);     // Read DM[10] toDM[14]

Then use the method commAction(monAction, 2) in the "ConnectTLServer" object to execute these two defined actions. The first action is READSINGLE variable and the value read from the PLC is stored in the variable monAction[0].value. The second action require you to first declare a integer array DM[4000] and pass it as a parameter to   monAction[1]. The commAction method will execute the required action, which is to read 5 counts of DM from DM[10] onwards, and the value read from the PLC are stored in the variable position monAction[1].DM[10] to monAction[1].DM[14].

That's it! The "commAction" method allows you to do almost anything you want with the PLC via the TLServer very easily without the need to learn any thing about network programming or the PLC host link commands. However, other useful methods are available for more adventurous programmers who are familiar with the M-series PLC's host link commands,  such as using the method:

sendCommand(int PLCID, String command)

to send a single host link command to the selected PLC (with ID = PLCID). To support direct communication via the hostlink commands, the package also include methods for bit manipulation and computation of FCS etc. Please see the documentation in the "PLCmon.connectTLServer.htm" for more details.

3.    Creating Your Own GUI !

You can now start to create your own GUI applet to control/monitor your PLCs via the Internet! The two supplied sample files: "TestProgram.java" and "TestApplet.java" are good place to start. First, compile and execute the "TestProgram.java" unmodified to ensure that it works as intended:

demo.gif (2873 bytes)

You can then modify the program by adding more elements such as more text boxes, scroll bar, push buttons etc, essentially following the construct in the sample program to process the data to/from the PLC. You can also use other "Java beans" such as those enhanced AWT supplied by Visual Cafe or or purchase from third party supplier.  

To test and deploy the applet version of the "TestApplet.java", please follow the comments stated in the "TestApplet.java" file to ensure that you understand the requirement regarding Applet communication.  Specifically, you need to understand that a Java Applet can only open a network connection with a TLServer from which it is loaded. Hence the applet can only be deployed from the same folder as the TLServer. You also must create a standalone archive so that all the library files in the PLCmon.jar can be pulled out and be included in a single ".jar" file for deployment purpose. Otherwise browsers which do not know of the existence of "PLCmon.jar" will report a "Class not found" error when loading the applet.