com.langner.jmatic2
Class FetchWrite

java.lang.Object
  extended bycom.langner.jmatic2.FetchWrite
All Implemented Interfaces:
IConnection, IS7

public class FetchWrite
extends java.lang.Object
implements IS7, IConnection

This class is used for communication with SIMATIC S7® PLCs utilizing the FETCH/WRITE protocol over a TCP or a ISO-On-TCP connection. The plc has to be configured for a FetchWrite communication. It is important to have two communications configured, one for Fetch and one for Write. The Siemens S5 or S7 is not able to handle Fetch and Write on one connection.

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

Constructor Summary
FetchWrite(FetchWriteRFC1006Settings settings)
          Constructs an initialized object for a ISO-On-TCP connection.
FetchWrite(FetchWriteTCPSettings settings)
          Constructs an initialized object for a TCP connection.
 
Method Summary
 void connect()
          Establishes a connection to the S7 PLC.
 void disconnect()
          Disconnects from the S7 PLC.
 ErrorInfo getLastError()
          Returns the last error.
 boolean isConnected()
          Returns the connection status of the FetchWrite object.
 boolean isConnectedFetch()
          Returns the connection status of the FetchWrite object.
 boolean isConnectedWrite()
          Returns the connection status of the FetchWrite object.
 int readCounter(int address, byte[] data)
          Requests data of one PLC counter cell (synchronous).
 int readDB(int dbnumber, int offset, int length, byte[] data)
          Requests data from a specific PLC data block (synchronous).
 int readInput(int address, int length, byte[] data)
          Requests input data from a specific PLC address (synchronous).
 int readMemoryBytes(int address, int length, byte[] data)
          Requests PLC flag data (synchronous).
 int readOutput(int address, int length, byte[] data)
          Requests output data from a specific PLC address (synchronous).
 int readTimer(int address, byte[] data)
          Requests the data of one PLC timer cell (synchronous).
 int writeDB(int dbnumber, int offset, int length, byte[] data)
          Transmits data to a specific PLC data block (DB).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FetchWrite

public FetchWrite(FetchWriteTCPSettings settings)
           throws JMaticException
Constructs an initialized object for a TCP connection. This constructor initializes the properties with the supplied values. Note: You may use the Fetch/Write protocol for accessing either a Siemens S5 via the CP1430 or a Siemens S7 via the CP343/443. If you want read and write data from the plc please note that two connections must be configured in the Simatic manager (NetPro), one for the Fetch connection and one for the Write connection.

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

FetchWrite

public FetchWrite(FetchWriteRFC1006Settings settings)
           throws JMaticException
Constructs an initialized object for a ISO-On-TCP connection. This constructor initializes the properties with the supplied values. Note: You may use the Fetch/Write protocol for accessing either a Siemens S5 via the CP1430 or a Siemens S7 via the CP343/443. If you want read and write data from the plc please note that two connections must be configured in the Simatic manager (NetPro), one ISO-On-TCP connection for Fetch passive (read data from PLC) and one ISO-On-TCP connection for Write passive. For this kind of connection the JMatic ISO-On-TCP classes (RFC1006.class version 2.0 or later) are required.

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

isConnected

public boolean isConnected()
Returns the connection status of the FetchWrite object. Indicates whether a FETCH or WRITE connection is established.

Specified by:
isConnected in interface IConnection
Returns:
true if the object is connected, otherwise false.
See Also:
connect, disconnect

isConnectedFetch

public boolean isConnectedFetch()
Returns the connection status of the FetchWrite object. Indicates whether a FETCH connection is established.

Returns:
true if the object is connected, otherwise false.
See Also:
connect, disconnect

isConnectedWrite

public boolean isConnectedWrite()
Returns the connection status of the FetchWrite object. Indicates whether a WRITE connection is established.

Returns:
true if the object is connected, otherwise false.
See Also:
connect, disconnect

connect

public void connect()
             throws JMaticException
Establishes a connection to the S7 PLC. This function attempts to make a connection with the remote PLC specified by the remote IP and port. These parameters IP address and TCP/IP port must be specified before by initializing the FetchWrite object with the FetchWriteTCPSettings object. This function will pause until exception is thrown. If it returns normally, the connection has been established successfully.

Specified by:
connect in interface IConnection
Throws:
JMaticException - if the connect attempt fails
See Also:
isConnectedFetch, isConnectedWrite, disconnect

disconnect

public void disconnect()
                throws JMaticException
Disconnects from the S7 PLC. This function shuts down the connection, closing the underlying sockets. The function blocks until the connection has been successfully terminated. disconnect must always be called on any TCP object before program termination in order to clean up the underlying TCP socket and the background thread properly.

Specified by:
disconnect in interface IConnection
Throws:
JMaticException - if the disconnect fails
See Also:
isConnectedFetch, isConnectedWrite, connect

getLastError

public ErrorInfo getLastError()
Returns the last error. This method can be used to get the last error.

Specified by:
getLastError in interface IS7
Returns:
The ErrorInfo object containing the last error message.

writeDB

public int writeDB(int dbnumber,
                   int offset,
                   int length,
                   byte[] data)
            throws JMaticException
Transmits data to a specific PLC data block (DB). This method is synchronous and returns, when the data was written or an exception was thrown.

Specified by:
writeDB in interface IS7
Parameters:
dbnumber - Target data block. Possible range: 1..255.
offset - Target memory address in byte. Allowed values are 0..4094.
length - The number of bytes of the array data that are to be sent. Allowed values are 2..4096.
data - Array of transmit data
Returns:
The length of the written data when the method was successful, otherwise 0. NOTE: The length parameter must be an even number, because data blocks (DB) are working with word length.
Throws:
JMaticException - if the FetchWrite object is not connected or the parameters are out of range

readDB

public int readDB(int dbnumber,
                  int offset,
                  int length,
                  byte[] data)
           throws JMaticException
Requests data from a specific PLC data block (synchronous). This method returns, when the requested data was received or an exception was thrown.

Specified by:
readDB in interface IS7
Parameters:
dbnumber - Target data block. Possible values are 1..255.
offset - Target memory byte address. Allowed values are 0..4094.
data - Array for the requested data.
length - The number of requested bytes. Possible values: 2..4096. NOTE: The length parameter must be an even number, because data blocks (DB) are working with word length.
Returns:
The length in bytes of the received data when the method returned successful, otherwise 0.
Throws:
JMaticException - if the object is not connected or the parameters are out of range

readInput

public int readInput(int address,
                     int length,
                     byte[] data)
              throws JMaticException
Requests input data from a specific PLC address (synchronous). This method returns, when the requested data was received or an exception was thrown.

Specified by:
readInput in interface IS7
Parameters:
address - Target address.
data - Array for the requested data.
length - The number of requested bytes.
Returns:
The length of the received data when the method was successful, otherwise 0.
Throws:
JMaticException - if the object is not connected or the parameters are out of range

readMemoryBytes

public int readMemoryBytes(int address,
                           int length,
                           byte[] data)
                    throws JMaticException
Requests PLC flag data (synchronous). This method returns, when the requested data was received or an exception was thrown.

Specified by:
readMemoryBytes in interface IS7
Parameters:
address - Target address.
data - Array for the requested data.
length - The number of requested bytes.
Returns:
The length of the received data when the method was successful, otherwise 0.
Throws:
JMaticException - if the object is not connected or the parameters are out of range

readOutput

public int readOutput(int address,
                      int length,
                      byte[] data)
               throws JMaticException
Requests output data from a specific PLC address (synchronous). This method returns, when the requested data was received or an exception was thrown..

Specified by:
readOutput in interface IS7
Parameters:
address - Target address.
data - Array for the requested data.
length - The number of requested bytes.
Returns:
The length of the received data when the method was successful, otherwise 0.
Throws:
JMaticException - if the object is not connected or the parameters are out of range

readTimer

public int readTimer(int address,
                     byte[] data)
              throws JMaticException
Requests the data of one PLC timer cell (synchronous). This method returns, when the requested data was received or an exception was thrown.

Specified by:
readTimer in interface IS7
Parameters:
address - Timer address.
data - Array for the requested data.
Returns:
The length of the received data when the method was successful, otherwise 0.
Throws:
JMaticException - if the object is not connected or the parameters are out of range

readCounter

public int readCounter(int address,
                       byte[] data)
                throws JMaticException
Requests data of one PLC counter cell (synchronous). This method returns, when the requested data was received or an exception was thrown.

Specified by:
readCounter in interface IS7
Parameters:
address - Counter address.
data - Array for the requested data.
Returns:
The length of the received data when the method was successful, otherwise 0.
Throws:
JMaticException - if the object is not connected or the parameters are out of range


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