com.langner.jmatic2
Class SxPLC

java.lang.Object
  extended bycom.langner.jmatic2.SxPLC

public class SxPLC
extends java.lang.Object

This class is used for communication with SIMATIC S5® and S7® PLCs utilizing the S7Functions or the FETCH/WRITE protocol over a TCP or ISO-On-TCP connection. The behaviour of this class is to simplify the access to the data of a PLC. SxPLC is a high-level counterpart to S7Functions of FetchWrite. Data is accessed only through PLCAlias objects rather than binary buffers. These PLCAlias objects are proxies for the real-world process variables.

To use this class, you have to do just a few simple steps:

1. Create an instance of a SxPLC class.

2. Create aconnection to be used by the SxPLC class. If utilizing the S7Functions use the CreateConnection with an instance of a S7FunctionsSettings object. If utilizing a TCP connection use the CreateConnection with an instance of a FetchWriteTCPSettings object. If utilizing a ISO-On-TCP connection use the CreateConnection with an instance of a FetchWriteRFC1006Settings object.

3. Register one or more PLCAlias objects to this instance.

4. Register a SxPLCListener implementation to be informed about value changes.

4. Call the method start to roll the dices. At this point, the SxPLC object will connect to the PLC and call your listener for all variables that have changed since last read. At startup, all values will be initialized. SxPLC reads the data from the PLC in the interval specified with the pollrate and takes care about changes of the values read. If the connection is lost or dropped, the SxPLC object will try to reconnect to the PLC.

5. To write a variable on the PLC, just use the method setValue.

Version:
2.0
Author:
Langner Communications AG
Copyright:
Langner (c) 2001-2005

Constructor Summary
SxPLC()
          Creates a new instance of SxPLC
 
Method Summary
 void addListener(SxPLCListener listener)
          Adds a listener.
 void CreateConnection(FetchWriteRFC1006Settings settings, PLCModel model)
          Creats a connection using FetchWrite over ISO-on-TCP.
 void CreateConnection(FetchWriteTCPSettings settings, PLCModel model)
          Creats a connection using FetchWrite over TCP.
 void CreateConnection(S7FunctionsSettings settings)
          Creats a connection using S7Functions.
 PLCAlias getAlias(java.lang.String aliasName)
          Get a previously registered PLCAlias object by name.
 PLCAlias[] getAliases()
          Get all registered PLCAlias objects.
 long getPollrate()
          Retrieves the pollrate of this SxPLC object.
 IPLCValue getValue(java.lang.String aliasName)
          Gets the current value of an PLCAlias object.
 void registerAlias(PLCAlias alias)
          Register a new PLCAlias object.
 void registerFromFile(java.lang.String filename)
          RegisterFromFile uses an Excel CSV file to specify the PLC memory layout.
 void removeListener(SxPLCListener listener)
          Remove a previously added Listener.
 void setPollrate(long ms)
          Sets the pollrate for this SxPLC object.
 void setValue(java.lang.String aliasName, byte[] value)
          Sets a value into a PLCAlias object.
 void setValue(java.lang.String aliasName, java.lang.Object value)
          Sets a value into a PLCAlias object.
 void start()
          This method starts the communication with the PLC.
 void stop()
          This method stops the communication with the PLC.
 void unregisterAlias(java.lang.String aliasName)
          Unregister a previous registered PLCAlias.
 void unregisterAllAliases()
          Unregisters all previous registered PLCAliases.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SxPLC

public SxPLC()
Creates a new instance of SxPLC

Method Detail

CreateConnection

public void CreateConnection(S7FunctionsSettings settings)
                      throws JMaticException
Creats a connection using S7Functions. This constructor initializes the properties with the supplied values.

Parameters:
settings - Object with the connection settings
Throws:
JMaticException

CreateConnection

public void CreateConnection(FetchWriteTCPSettings settings,
                             PLCModel model)
                      throws JMaticException
Creats a connection using FetchWrite over TCP. This constructor initializes the properties with the supplied values.

Parameters:
settings - Object with the connection settings
model - Specifies the model of the PLC to be connected to.
Throws:
JMaticException

CreateConnection

public void CreateConnection(FetchWriteRFC1006Settings settings,
                             PLCModel model)
                      throws JMaticException
Creats a connection using FetchWrite over ISO-on-TCP. This constructor initializes the properties with the supplied values.

Parameters:
settings - Object with the connection settings
model - Specifies the model of the PLC to be connected to.
Throws:
JMaticException

addListener

public void addListener(SxPLCListener listener)
Adds a listener.

Parameters:
listener - The listener to be added.

removeListener

public void removeListener(SxPLCListener listener)
Remove a previously added Listener.

Parameters:
listener - The listener to be removed.

setPollrate

public void setPollrate(long ms)
Sets the pollrate for this SxPLC object.

Parameters:
ms - The pollrate in milliseconds.

getPollrate

public long getPollrate()
Retrieves the pollrate of this SxPLC object.

Returns:
The pollrate in milliseconds.

start

public void start()
           throws JMaticException
This method starts the communication with the PLC.

Throws:
JMaticException - in case of an unrecoverable error.

stop

public void stop()
          throws JMaticException
This method stops the communication with the PLC.

Throws:
JMaticException - in case of an unrecoverable error.

getAlias

public PLCAlias getAlias(java.lang.String aliasName)
Get a previously registered PLCAlias object by name.

Parameters:
aliasName - The alias name of the object. See registerAlias
Returns:
The PLCAlias object or null if not found.

getAliases

public PLCAlias[] getAliases()
Get all registered PLCAlias objects.

Returns:
Array of all registered PLCAlias objects.

registerFromFile

public void registerFromFile(java.lang.String filename)
                      throws JMaticException
RegisterFromFile uses an Excel CSV file to specify the PLC memory layout.
Every line specifies one plc variable (operand). Syntax is

# Comment
Operand.Offset.[Count.]Data_type, Variable_name



Operand types
Operand Meaning
DBn Data block. "n" is the DB number
O Output
I Input
M Memory Byte
C Counter
T Timer

Data types
Data type Meaning Possible operands
BOOL0-BOOL7 Boolean with offset X.0-X.7 (X represents the byte offset) DB, O, I
BYTE Byte DB, O, I
CHAR ASCII character DB, O, I
INT Signed integer DB, O, I
DINT Signed long integer DB, O, I
WORD Unsigned short DB, O, I
DWORD Unsigned long integer DB, O, I
REAL Float DB, O, I
S7STRING String (only S7 plc) DB
STRING String DB
DATE IEC Date DB
DATE_AND_TIME Date and Time (8 Byte) DB
TIME IEC Time DB
S5TIME Time type of S5 plc DB
TIME_OF_DAY Daytime DB

Creating a configuration file
There are three ways to create the configuration file.
  1. Using the Langner tool S7-Projectimport which is part of the JMatic distribution. This is the easiest and most relieable way because it eliminates errors. In order to use the Step7 project import, you must have access to the Step7 files as created with SIMATIC manager. In this project you must open the S7 project file "*.s7p".
  2. Create the file with MS Excel.
  3. Create the file in a simple text editor.

Created with text editor Created with Excel

#Var address, var name
DB1.O0.BOOL0, boolVar_0
DB1.O0.BOOL1, boolVar_1
DB1.O0.BOOL2, boolVar_2
DB1.O10.L96.S7STRING, errormessage
DB2.O0.INT, Pump_1
DB3.O0.INT, Pump_2
DB12.O2.INT, Yield
DB12.O4.INT, TargetQuantity
I.O8.WORD, InputWord 8
O.O8.WORD, OutputWord 8
M.O1.BYTE, MB_1
C.O2.WORD, counter_1
T.O2.WORD, timer_2

Parameters:
filename - The path and name of the csv file to be used as input.
Throws:
JMaticException

registerAlias

public void registerAlias(PLCAlias alias)
                   throws JMaticException
Register a new PLCAlias object. If a PLCAlias object with the same name is already registered, it will be overwritten.

Parameters:
alias - The PLCAlias object to register.
Throws:
JMaticException - in case of an unrecoverable error.

unregisterAlias

public void unregisterAlias(java.lang.String aliasName)
                     throws JMaticException
Unregister a previous registered PLCAlias.

Parameters:
aliasName - The name of the PLCAlias.
Throws:
JMaticException

unregisterAllAliases

public void unregisterAllAliases()
                          throws JMaticException
Unregisters all previous registered PLCAliases.

Throws:
JMaticException

getValue

public IPLCValue getValue(java.lang.String aliasName)
Gets the current value of an PLCAlias object. It's a shortcut for getAlias().getValue().

Parameters:
aliasName - The name of the PLCAlias.
Returns:
IPLCValue object that contain the value or null if not found.

setValue

public void setValue(java.lang.String aliasName,
                     byte[] value)
              throws JMaticException
Sets a value into a PLCAlias object. This function must be used only to a PLCAlias object of type PLC_BINARY.

Parameters:
aliasName - The name of the PLCAlias object.
value - The value to set/write.
Throws:
JMaticException - in case of an error.

setValue

public void setValue(java.lang.String aliasName,
                     java.lang.Object value)
              throws JMaticException
Sets a value into a PLCAlias object.

Parameters:
aliasName - The name of the PLCAlias object.
value - The value to set/write.
Throws:
JMaticException - in case of an error.


Copyright © 2001-2005 Langner Communications AG. All Rights Reserved.