Class PLCmon.ConnectTLServer
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class PLCmon.ConnectTLServer

Object
   |
   +----PLCmon.ConnectTLServer

public class ConnectTLServer
extends Object
This class allows you to log on to a remote TLServer on the Internet by providing the IP address, username and password. It also provides methods for communicating with any of the 256 possible PLCs that are connected to the TLServer without learning about the host link commands. You just have to create the "Action" object with all the relevant parameters and then call the "commAction()" method to read data from the PLC or write data into the PLC


Variable Index

 o zeroOffset

Constructor Index

 o PLCmon.ConnectTLServer(Applet, String, String)
Use This Constructor when writing a Java Applet.
 o PLCmon.ConnectTLServer(String, String, String)
Use This Constructor when writing a Java Application (not Applet)

Method Index

 o appendID(String, int)
The method prefixes the provided "command" string with the "
 o atoh2(String)
 o atoh4(String)
 o atoh8(String)
 o commAction(Action[], int)
Provides an extremely easy way of interacting with the PLC using the "Action" object.
 o compute_FCS(String)
Compute the Frame Check sequence of a command string.
 o getErrorString()
return the error message that has been thrown by CommException
 o isOnline()
Check whether the TLServer has been log In.
 o logIn()
Establish contact with the TLServer and negotiate for entry using the "username" and "password" variable of this object.
 o logOut()
Explicitly log out of the TLServer and close any communication streams.
 o removeID(String)
Strip off the "
 o sendCommand(int, String)
Allows you to directly send a host link command to a PLC connected to the Internet via the TLServer without using the commAction method.
 o setDebug(boolean)
Determine whether to output verbose messages to aid troubleshooting.
 o setHttpTunnel(boolean, String)
If you access the Internet behind some kind of firewall, your network administrator may not allow your PC to establish direct socket connection with the TLServer that are located outside the firewall.

Variables

 o zeroOffset
public int zeroOffset

Constructors

 o ConnectTLServer
public ConnectTLServer(Applet applet,
                       String username,
                       String password)
Use This Constructor when writing a Java Applet.

Parameters:
applet - -- the applet itself who need declare a ConnectTLServer object.

username - - - the "username" of the user that is defined in the TLServer.

password - - - the "password" of the user that is defined in the TLServer.
 o ConnectTLServer
public ConnectTLServer(String URLstring,
                       String username,
                       String password)
Use This Constructor when writing a Java Application (not Applet)

Parameters:
URLstring - - - e.g. "127.0.0.1:9080" or "localhost:9080". Do not prefix with "http://"

username - - - the "username" of the user that is defined in the TLServer.

password - - - the "password" of the user that is defined in the TLServer.

Methods

 o appendID
public java.lang.String appendID(String command,
                                 int ID)
The method prefixes the provided "command" string with the "@nn", where "nn" is the ID number of the PLC, as well as appends the two bytes FCS string to the end of the command string. This routine is used internally by the sendCommand method, but is made available for users who wish to construct their own mutli-point commands.

Parameters:
command - - - The command string in "point-to-point" format.
ID - - - The PLC's ID, which should be 00 to FF hex or 0 to 255 decimal.
Returns:
An 8-bit integer number which is the numeric form of the computed FCS.
 o atoh2
public int atoh2(String numstr)
 o atoh4
public int atoh4(String numstr)
 o atoh8
public int atoh8(String numstr)
 o commAction
public synchronized boolean commAction(Action[] action,
                                       int count) throws CommException
Provides an extremely easy way of interacting with the PLC using the "Action" object. It accepts an array of "Action" objects (maximum = 20) so that multiple commands can be sent in a single TCP/IP packet. This very effectively reduces the round trip delay caused by the Internet traffic, which will be very noticeable if commands are sent one at a time. Note that since each element of the action[] array may contain a different PLC's ID, it means that you can interact with multiple PLCs (connected by RS485 to the same TLServer) in a single call of the commAction method.

Parameters:
action[] - - - An array of "Action" objects that contain instruction/data.
count - - - The number of "actions" to carry out. It should be from 1 to maximum length of action[] array.

Returns:
"true" if communication session is successful, and it throws a commException if it fails to connect to TLServer or to the PLC or if it receives a null Action object.
 o compute_FCS
public int compute_FCS(String string)
Compute the Frame Check sequence of a command string. This routine is used internally by the sendCommand method to compute the FCS of a given string. This is made available for user who wish to construct their own mutli-point commands.

Parameters:
string - - - The string whose FCS is required.
Returns:
An 8-bit integer number which is the numeric form of the computed FCS.
 o getErrorString
public java.lang.String getErrorString()
return the error message that has been thrown by CommException

 o isOnline
public boolean isOnline()
Check whether the TLServer has been log In.

Returns:
"true" if successfully log-On. "false" if fails.
 o logIn
public boolean logIn()
Establish contact with the TLServer and negotiate for entry using the "username" and "password" variable of this object. This method is automatically called by commAction and sendCommand methods if the caller attempts to communicate without first logging On.

Returns:
"true" if LogIn is successful. "false" if fail.
 o logOut
public void logOut()
Explicitly log out of the TLServer and close any communication streams. It is always a good practice to close unused streams instead of leaving them to occupy memory space.

 o removeID
public java.lang.String removeID(String response)
Strip off the "@nn" header and the two-byte "FCS" characters from a multi-point host link command or response. This routine is used internally by the sendCommand method, but is made available for user who wish to construct their own mutli-point commands.

Parameters:
response - - - The response string in "multi-point" format.
Returns:
- - The end result of the string without the "@nn" header and FCS characters.
 o sendCommand
public synchronized java.lang.String sendCommand(int PLCID,
                                                 String command) throws CommException
Allows you to directly send a host link command to a PLC connected to the Internet via the TLServer without using the commAction method. This method automatically appends the "@nn" ID header and the FCS to the "command" string in point-to-point format.

Parameters:
PLCID - - - The ID of the PLC, should be from 00 to FF hex or 0 to 255 decimal.

command - - - The hostlink command in "point-to-point" format.
Returns:
- - The response string from the PLC. The ID header and FCS will be stripped off, leaving only the point-to-point response string format for easy analysis
 o setDebug
public void setDebug(boolean s)
Determine whether to output verbose messages to aid troubleshooting. If debug mode is set to "true", the command and response messages as well as explanation of most of the failures or exceptions will be sent to the Java console. When your program is working well and you do not want to receive verbose messages during communication with the PLC, then setDug to "false". .

Parameters:
s - - - "true" to see verbose messages for each comm action. "false" for silent operation.
 o setHttpTunnel
public void setHttpTunnel(boolean httpTunnel,
                          String httpProxy)
If you access the Internet behind some kind of firewall, your network administrator may not allow your PC to establish direct socket connection with the TLServer that are located outside the firewall. Direct socket connection provides faster message transmission and is always prefered. However, if you could not convince your network administrator to allow you to establish direct connection, then you may have to use the HTTP-tunneling techique which camouflage the communication messages as if they are http requests and responses in order route them through the network server. If your LAN make use of a proxy server to handle internet traffic you will also have to supply the URL or IP address of the proxy server Please contact your network administrator for more details. Otherwise input it as a blank string "".

Parameters:
httpTunnel - - - "true" to use HTTP tunneling. "false" to use direct socket connection (default is "false").

httpProxy - - - URL string or IP address string of the proxy server, if any.

All Packages  Class Hierarchy  This Package  Previous  Next  Index