com.langner.jmatic2
Class RK512

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

public class RK512
extends java.lang.Object

This class is used for communication with SIMATIC S5® or S7® PLCs utilizing the RK512 protocol via the Langner 3964NET gateway. 3964NET is a gateway for connecting serial devices using the 3964R protocol to a TCP/IP network. Scheme:

|PLC|<-- serial RK512 over 3964R -->|3964NET|<-- RK512 over TCP/IP -->|JMatic application|

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

Constructor Summary
RK512(RK512NETSettings settings)
          Constructs an initialized object.
 
Method Summary
 void addListener(RK512Listener listener)
          Registers an event listener (required only when using the asynchronous RK512 methods such as readDB).
 void connect()
          Establishes a connection to the 3964NET gateway.
 void disconnect()
          Disconnects from the 3964NET gateway.
 java.lang.String getLastError()
          Returns the last error.
 boolean isConnected()
          Returns the connection status.
 void readCounter(int address)
          Requests data of one PLC counter cell (asynchronous).
 int readCounterWait(int address, byte[] data)
          Requests data of one PLC counter cell (synchronous).
 void readDB(int dbnumber, int offset, int length)
          Requests data from a specific PLC data block (asynchronous).
 int readDBWait(int dbnumber, int offset, int length, byte[] data)
          Requests data from a specific PLC data block (synchronous).
 void readInput(int address, int length)
          Requests input data from a specific PLC address (asynchronous).
 int readInputWait(int address, int length, byte[] data)
          Requests input data from a specific PLC address (synchronous).
 void readMemoryBytes(int address, int length)
          Requests PLC flag data (asynchronous).
 int readMemoryBytesWait(int address, int length, byte[] data)
          Requests PLC flag data (synchronous).
 void readOutput(int address, int length)
          Requests output data from a specific PLC address (asynchronous).
 int readOutputWait(int address, int length, byte[] data)
          Requests output data from a specific PLC address (synchronous).
 void readTimer(int address)
          Requests the data of one PLC timer cell (asynchronous).
 int readTimerWait(int address, byte[] data)
          Requests the data of one PLC timer cell (synchronous).
 void removeListener(RK512Listener listener)
          Removes an event listener.
 void writeDB(int dbnumber, int offset, int length, byte[] data)
          Transmits data to a specific PLC data block (asynchronous).
 int writeDBWait(int dbnumber, int offset, int length, byte[] data)
          Transmits data to a specific PLC data block (synchronous).
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RK512

public RK512(RK512NETSettings settings)
      throws JMaticException
Constructs an initialized object. This constructor initializes the properties with the supplied values.

Parameters:
settings - Object with the connection settings
Method Detail

isConnected

public boolean isConnected()
Returns the connection status. Indicates whether an TCP connection is established with the 3964NET gateway.

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

connect

public void connect()
             throws JMaticException
Establishes a connection to the 3964NET gateway. This function attempts to make a connection with the remote 3964NET gateway specified by the remote IP and 3964NET port. These parameters IP address and TCP/IP port must be specified before by initializing the RK512 object with the RK512NETSettings object.

Throws:
JMaticException - if the connect attempt fails
See Also:
isConnected, disconnect

disconnect

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

Throws:
JMaticException - if the disconnect fails
See Also:
isConnected, connect

writeDBWait

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

Parameters:
dbnumber - Target data block (DB). Possible values: 0..255.
offset - Target word offset address in DB.
data - Array of transmit data
length - The number of bytes of the array data that are to be sent (Possible values: 2..65534).. NOTE: The length parameter must be an even number, because data blocks (DB) are working with word length.
Returns:
The length of the written data when the method returned successful, otherwise 0.
Throws:
JMaticException - if the RK512 object is not connected or the parameters are out of range

writeDB

public void writeDB(int dbnumber,
                    int offset,
                    int length,
                    byte[] data)
             throws JMaticException
Transmits data to a specific PLC data block (asynchronous). The methods of the RK512Listener will inform your application about the success of this action. Other RK512 methods cannot be called until the action was confirmed with the dataSent or an error was signaled.

Parameters:
dbnumber - Target data block (DB). Possible values are 1..255.
offset - Traget word offset address in the DB.
data - Array of transmit data
length - The number of bytes of the array data that are to be sent (Possible values: 2..4096). NOTE: The length parameter must be an even number, because data blocks (DB) are working with word length.
Throws:
JMaticException - if the RK512 object is not connected or the parameters are out of range

readDBWait

public int readDBWait(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.

Parameters:
dbnumber - Target data block (DB). Possible values: 0..255.
offset - Target word offset address in DB.
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 RK512 object is not connected or the parameters are out of range

readDB

public void readDB(int dbnumber,
                   int offset,
                   int length)
            throws JMaticException
Requests data from a specific PLC data block (asynchronous). Received data will be signaled by calling the RK512Listener method dataReceived. Other RK512 methods cannot be called until the requested data was received or an error was signaled.

Parameters:
dbnumber - Target data block (DB).
offset - Target word offset in DB.
length - The number of requested bytes (Possible values: 2..4096).
Throws:
JMaticException - if the RK512 object is not connected or the parameters are out of range

readOutputWait

public int readOutputWait(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..

Parameters:
address - Target Output byte 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 RK512 object is not connected or the parameters are out of range

readOutput

public void readOutput(int address,
                       int length)
                throws JMaticException
Requests output data from a specific PLC address (asynchronous). Received data will be signaled by calling the RK512Listener method dataReceived. Other RK512 methods cannot be called until the requested data was received or an error was signaled.

Parameters:
address - Target Output byte address.
length - The number of requested bytes.
Throws:
JMaticException - if the RK512 object is not connected or the parameters are out of range

readInputWait

public int readInputWait(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.

Parameters:
address - Target Input byte address.
data - Array for the requested data.
length - The number of requested bytes.
Throws:
JMaticException - if the RK512 object is not connected or the parameters are out of range

readInput

public void readInput(int address,
                      int length)
               throws JMaticException
Requests input data from a specific PLC address (asynchronous). Received data will be signaled by calling the RK512Listener method dataReceived. Other RK512 methods cannot be called until the requested data was received or an error was signaled.

Parameters:
address - Target Input byte address.
length - The number of requested bytes.
Throws:
JMaticException - if the RK512 object is not connected or the parameters are out of range

readMemoryBytesWait

public int readMemoryBytesWait(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.

Parameters:
address - Target Memory byte 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 RK512 object is not connected or the parameters are out of range

readMemoryBytes

public void readMemoryBytes(int address,
                            int length)
                     throws JMaticException
Requests PLC flag data (asynchronous). Received data will be signaled by calling the RK512Listener method dataReceived. Other RK512 methods cannot be called until the requested data was received or an error was signaled.

Parameters:
address - Target Memory byte address.
length - The number of requested bytes.
Throws:
JMaticException - if the RK512 object is not connected or the parameters are out of range

readCounterWait

public int readCounterWait(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.

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

readCounter

public void readCounter(int address)
                 throws JMaticException
Requests data of one PLC counter cell (asynchronous). Received data will be signaled by calling the RK512Listener method dataReceived. Other RK512 methods cannot be called until the requested data was received or an error was signaled.

Parameters:
address - Counter number.
Throws:
JMaticException - if the RK512 object is not connected or the parameters are out of range

readTimerWait

public int readTimerWait(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.

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

readTimer

public void readTimer(int address)
               throws JMaticException
Requests the data of one PLC timer cell (asynchronous). Received data will be signaled by calling the RK512Listener method dataReceived. Other RK512 methods cannot be called until the requested data was received or an error was signaled.

Parameters:
address - Timer number.
Throws:
JMaticException - if the RK512 object is not connected or the parameters are out of range

addListener

public void addListener(RK512Listener listener)
Registers an event listener (required only when using the asynchronous RK512 methods such as readDB). Adds an event listener to the internal list.

Parameters:
listener - The object that shall be informed about incoming data and errors. If it is already in the list, it will not be added a second time.

removeListener

public void removeListener(RK512Listener listener)
Removes an event listener. Removes an event listener from the internal list.

Parameters:
listener - The object that shall be removed. If it is not in the list, this function does nothing.

getLastError

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

Returns:
The last error message.


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