www.rkjava.de

de.rkjava.serial.rk512
Class Rk512toPLC

java.lang.Object
  extended byde.rkjava.serial.rk512.Rk512toPLC
All Implemented Interfaces:
EventListener, J3964RNextInDataListener

public class Rk512toPLC
extends Object
implements J3964RNextInDataListener

This is the class to communicate with RK512-protocol (even MPI-protocol by using for example Helmholz-Adapter SSW7-RK512) via serial interface with a PLC (S7, S5, ... ) using the de.rkjava.serial.j3964r-package. Look at this simple example:

 import de.rkjava.serial.rk512.Rk512toPLC;
 import de.rkjava.serial.rk512.DefaultS7Model;
 //
 public class SimpleRk512Example {
  //
  // 
  // The example fetchs data from datablock No 10 and sends it to datablock No 100.
  //
  public static void main(String args[]) {
    //
    long   timeout = 1000;
    String serialInterface = "/dev/ttyS1";//"COM1";
    //
    Rk512toPLC.trace = true;
    Rk512toPLC.open(serialInterface);
    Rk512toPLC.setMPI(serialInterface, true);  //for MPI via Rk512-MPI-adapter
    //
    //
    // fetch Data from datablock No.10
    //
    int cpuNo        =   2; //MPI-CPU-No
    int dbNo         =  10;
    int firstWordNo  =   0;
    int ammountWords =  10;
    //
    DefaultS7Model dBTen = new DefaultS7Model(cpuNo, dbNo, firstWordNo, ammountWords);
    //
    Rk512toPLC s7DBTen = new Rk512toPLC(dBTen,serialInterface);
    //
    s7DBTen.fetch(timeout);
    //
    //
    // send Data to datablock No.100
    //
    cpuNo        =   2; //MPI-CPU-No
    dbNo         = 100;
    firstWordNo  =   0;
    ammountWords =  10;
    //
    DefaultS7Model dB100 = new DefaultS7Model(cpuNo, dbNo, firstWordNo, ammountWords);
    dB100.setBytes(dBTen.getBytes());  //put DB10-Data into DB100-Model
    //
    Rk512toPLC s7DB100 = new Rk512toPLC(dB100,serialInterface);
    //
    s7DB100.send(timeout); //send DB100 to PLC
    //
    //
    // Close serialInterface
    //
    Rk512toPLC.close(serialInterface);
  }
 }
 

Author:
Gerd Limbeck, www.rkjava.de

Field Summary
static int BYTES_ERROR
          -10000
static int FETCH_ACKNOWLEDGE_ERROR
          -10003
static int SEND_ACKNOWLEDGE_ERROR
          -10002
static int TIMEOUT
          -10001
static boolean trace
          Defaultvalue: false
 
Constructor Summary
Rk512toPLC(S5Model s5Model, String portName)
          Creates an instance of Rk512toPLC
Rk512toPLC(S5Model s5Model, String portName, byte koordinierungsmerkerByte, byte koordinierungsmerkerBit)
          Creates an instance of Rk512toPLC
Rk512toPLC(S7Model s7Model, String portName)
          Creates an instance of Rk512toPLC
Rk512toPLC(S7Model s7Model, String portName, byte koordinierungsmerkerByte, byte koordinierungsmerkerBit)
          Creates an instance of Rk512toPLC
 
Method Summary
static void close(String portName)
          Closed the serial interface portName.
static void closeAll()
          Closed all serial interfaces.
 int fetch(long timeout)
          This method fetchs the data from the PLC and puts it into your S5Model/S7Model.
static String getErrorMessage(int errorNo)
          If fetch or send returns a number not 0, this method tells you what kind of error you got.
static boolean getMPI(String portName)
          Returns the MPI-status for portName.
static int getSpeed(String portName)
          The current speed of serial interface portName
static boolean isPort(String portName)
          Tests whether portName exist or not.
static void open(String portName)
          Opens the serial interface portName.
 int send(long timeout)
          This method sends the data from your S5Model/S7Model and puts it into the PLC.
 void sendAcknowledge(J3964REvent e)
          This method must be implemted for J3964RNextInDataListener, do not call it!
static void setMPI(String portName, boolean mpi)
          Tells the package whether you are using an RK512-MPI-Adapter at portName, like Helmholz-Adapter SSW7-RK512) or not.
static void setSpeed(String portName, int baudrate)
          Sets the speed of your serial interface portName
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

trace

public static boolean trace
Defaultvalue: false


BYTES_ERROR

public static final int BYTES_ERROR
-10000

See Also:
Constant Field Values

TIMEOUT

public static final int TIMEOUT
-10001

See Also:
Constant Field Values

SEND_ACKNOWLEDGE_ERROR

public static final int SEND_ACKNOWLEDGE_ERROR
-10002

See Also:
Constant Field Values

FETCH_ACKNOWLEDGE_ERROR

public static final int FETCH_ACKNOWLEDGE_ERROR
-10003

See Also:
Constant Field Values
Constructor Detail

Rk512toPLC

public Rk512toPLC(S7Model s7Model,
                  String portName,
                  byte koordinierungsmerkerByte,
                  byte koordinierungsmerkerBit)
           throws NoSuchPortException,
                  PortInUseException
Creates an instance of Rk512toPLC

Parameters:
s7Model - a S7Model
portName - the serial interface for the communication, e.g. "COM1"
koordinierungsmerkerByte - some PLC's needs this parameter
koordinierungsmerkerBit - some PLC's needs this parameter
Throws:
NoSuchPortException - if portName is not valid
PortInUseException - if portName is in use from an other programm.

Rk512toPLC

public Rk512toPLC(S7Model s7Model,
                  String portName)
           throws NoSuchPortException,
                  PortInUseException
Creates an instance of Rk512toPLC

Parameters:
s7Model - a S7Model
portName - the serial interface for the communication, e.g. "COM1"
Throws:
NoSuchPortException - if portName is not valid
PortInUseException - if portName is in use from an other programm.

Rk512toPLC

public Rk512toPLC(S5Model s5Model,
                  String portName,
                  byte koordinierungsmerkerByte,
                  byte koordinierungsmerkerBit)
           throws NoSuchPortException,
                  PortInUseException
Creates an instance of Rk512toPLC

Parameters:
s5Model - a S5Model
portName - the serial interface for the communication, e.g. "COM1"
koordinierungsmerkerByte - some PLC's needs this parameter
koordinierungsmerkerBit - some PLC's needs this parameter
Throws:
NoSuchPortException - if portName is not valid
PortInUseException - if portName is in use from an other programm.

Rk512toPLC

public Rk512toPLC(S5Model s5Model,
                  String portName)
           throws NoSuchPortException,
                  PortInUseException
Creates an instance of Rk512toPLC

Parameters:
s5Model - a S5Model
portName - the serial interface for the communication, e.g. "COM1"
Throws:
NoSuchPortException - if portName is not valid
PortInUseException - if portName is in use from an other programm.
Method Detail

open

public static void open(String portName)
                 throws NoSuchPortException,
                        PortInUseException
Opens the serial interface portName.

Parameters:
portName - The OS-name for the serial interface. E.g. "COM1" for Windows or "/dev/ttyS0" for Linux.
Throws:
NoSuchPortException - if portName does not exist.
PortInUseException - if portName is locked by an other process.

close

public static void close(String portName)
Closed the serial interface portName.

Parameters:
portName - The OS-name for the serial interface. E.g. "COM1" for Windows or "/dev/ttyS0" for Linux.

closeAll

public static void closeAll()
Closed all serial interfaces.


setMPI

public static void setMPI(String portName,
                          boolean mpi)
                   throws NoSuchPortException,
                          PortInUseException
Tells the package whether you are using an RK512-MPI-Adapter at portName, like Helmholz-Adapter SSW7-RK512) or not.

Parameters:
portName - The OS-name for the serial interface. E.g. "COM1" for Windows or "/dev/ttyS0" for Linux.
mpi - False, if you communicate directly via rk512. True, if you are using MPI (via RK512-MPI-Adapter).
Throws:
NoSuchPortException - if portName does not exist.
PortInUseException - if portName is locked by an other process.

getMPI

public static boolean getMPI(String portName)
                      throws NoSuchPortException,
                             PortInUseException
Returns the MPI-status for portName.

Parameters:
portName - The OS-name for the serial interface. E.g. "COM1" for Windows or "/dev/ttyS0" for Linux.
Returns:
True if MPI. Otherwise False.
Throws:
NoSuchPortException - if portName does not exist.
PortInUseException - if portName is locked by an other process.

setSpeed

public static void setSpeed(String portName,
                            int baudrate)
                     throws UnsupportedCommOperationException,
                            NoSuchPortException,
                            PortInUseException
Sets the speed of your serial interface portName

Parameters:
portName - The OS-name for the serial interface. E.g. "COM1" for Windows or "/dev/ttyS0" for Linux.
baudrate - the speed
Throws:
UnsupportedCommOperationException - if the speed is not supported by your serial interface portName
NoSuchPortException - if portName does not exist.
PortInUseException - if portName is locked by an other process.

getSpeed

public static int getSpeed(String portName)
                    throws NoSuchPortException,
                           PortInUseException
The current speed of serial interface portName

Parameters:
portName - The OS-name for the serial interface. E.g. "COM1" for Windows or "/dev/ttyS0" for Linux.
Returns:
the current speed
Throws:
NoSuchPortException - if portName does not exist.
PortInUseException - if portName is locked by an other process.

getErrorMessage

public static String getErrorMessage(int errorNo)
If fetch or send returns a number not 0, this method tells you what kind of error you got.

Parameters:
errorNo - the returned number from fetch or send
Returns:
kind of error

isPort

public static boolean isPort(String portName)
Tests whether portName exist or not.

Parameters:
portName - The OS-name for the serial interface. E.g. "COM1" for Windows or "/dev/ttyS0" for Linux.
Returns:
True, if portName exist. Ohterwise False.

fetch

public int fetch(long timeout)
This method fetchs the data from the PLC and puts it into your S5Model/S7Model.

Parameters:
timeout - time for timeout
Returns:
0, if no error. Otherwise an error-No.

send

public int send(long timeout)
This method sends the data from your S5Model/S7Model and puts it into the PLC.

Parameters:
timeout - time for timeout
Returns:
0, if no error. Otherwise an error-No.

sendAcknowledge

public void sendAcknowledge(J3964REvent e)
This method must be implemted for J3964RNextInDataListener, do not call it!

Specified by:
sendAcknowledge in interface J3964RNextInDataListener
Parameters:
e - a parameter
See Also:
J3964R.sendData(Byte[],J3964RNextInDataListener)

www.rkjava.de