net.wimpi.modbus.net
Class UDPMasterTerminal

java.lang.Object
  extended by net.wimpi.modbus.net.UDPMasterTerminal
All Implemented Interfaces:
UDPTerminal

 class UDPMasterTerminal
extends Object
implements UDPTerminal

Class implementing a UDPMasterTerminal.

Version:
1.2 (@date@)
Author:
Dieter Wimberger

Field Summary
private  boolean m_Active
           
protected  InetAddress m_LocalAddress
           
private  int m_LocalPort
           
protected  ModbusUDPTransport m_ModbusTransport
           
protected  InetAddress m_RemoteAddress
           
private  int m_RemotePort
           
private  DatagramSocket m_Socket
           
private  int m_Timeout
           
 
Constructor Summary
  UDPMasterTerminal()
           
protected UDPMasterTerminal(InetAddress addr)
           
 
Method Summary
 void activate()
          Activate this UDPTerminal.
 void deactivate()
          Deactivates this UDPSlaveTerminal.
 InetAddress getLocalAddress()
          Returns the local address of this UDPTerminal.
 int getLocalPort()
          Returns the local port of this UDPTerminal.
 ModbusUDPTransport getModbusTransport()
          Returns the ModbusTransport associated with this TCPMasterConnection.
 InetAddress getRemoteAddress()
          Returns the destination InetAddress of this UDPSlaveTerminal.
 int getRemotePort()
          Returns the destination port of this UDPSlaveTerminal.
 int getTimeout()
          Returns the timeout for this UDPMasterTerminal.
 boolean isActive()
          Tests if this UDPSlaveTerminal is active.
 byte[] receiveMessage()
          Receives and returns a message.
 void receiveMessage(byte[] buffer)
           
 void sendMessage(byte[] msg)
          Sends the given message.
 void setLocalAddress(InetAddress addr)
           
protected  void setLocalPort(int port)
           
 void setRemoteAddress(InetAddress adr)
          Sets the destination InetAddress of this UDPSlaveTerminal.
 void setRemotePort(int port)
          Sets the destination port of this UDPSlaveTerminal.
 void setTimeout(int timeout)
          Sets the timeout for this UDPMasterTerminal.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_Socket

private DatagramSocket m_Socket

m_Timeout

private int m_Timeout

m_Active

private boolean m_Active

m_LocalAddress

protected InetAddress m_LocalAddress

m_RemoteAddress

protected InetAddress m_RemoteAddress

m_RemotePort

private int m_RemotePort

m_LocalPort

private int m_LocalPort

m_ModbusTransport

protected ModbusUDPTransport m_ModbusTransport
Constructor Detail

UDPMasterTerminal

public UDPMasterTerminal()

UDPMasterTerminal

protected UDPMasterTerminal(InetAddress addr)
Method Detail

getLocalAddress

public InetAddress getLocalAddress()
Description copied from interface: UDPTerminal
Returns the local address of this UDPTerminal.

Specified by:
getLocalAddress in interface UDPTerminal
Returns:
an InetAddress instance.

setLocalAddress

public void setLocalAddress(InetAddress addr)

getLocalPort

public int getLocalPort()
Description copied from interface: UDPTerminal
Returns the local port of this UDPTerminal.

Specified by:
getLocalPort in interface UDPTerminal
Returns:
the local port as int.

setLocalPort

protected void setLocalPort(int port)

getRemotePort

public int getRemotePort()
Returns the destination port of this UDPSlaveTerminal.

Returns:
the port number as int.

setRemotePort

public void setRemotePort(int port)
Sets the destination port of this UDPSlaveTerminal. The default is defined as Modbus.DEFAULT_PORT.

Parameters:
port - the port number as int.

getRemoteAddress

public InetAddress getRemoteAddress()
Returns the destination InetAddress of this UDPSlaveTerminal.

Returns:
the destination address as InetAddress.

setRemoteAddress

public void setRemoteAddress(InetAddress adr)
Sets the destination InetAddress of this UDPSlaveTerminal.

Parameters:
adr - the destination address as InetAddress.

isActive

public boolean isActive()
Tests if this UDPSlaveTerminal is active.

Specified by:
isActive in interface UDPTerminal
Returns:
true if active, false otherwise.

activate

public void activate()
              throws Exception
Activate this UDPTerminal.

Specified by:
activate in interface UDPTerminal
Throws:
Exception - if there is a network failure.

deactivate

public void deactivate()
Deactivates this UDPSlaveTerminal.

Specified by:
deactivate in interface UDPTerminal

getModbusTransport

public ModbusUDPTransport getModbusTransport()
Returns the ModbusTransport associated with this TCPMasterConnection.

Specified by:
getModbusTransport in interface UDPTerminal
Returns:
the connection's ModbusTransport.

getTimeout

public int getTimeout()
Returns the timeout for this UDPMasterTerminal.

Returns:
the timeout as int.

setTimeout

public void setTimeout(int timeout)
Sets the timeout for this UDPMasterTerminal.

Parameters:
timeout - the timeout as int.

sendMessage

public void sendMessage(byte[] msg)
                 throws Exception
Description copied from interface: UDPTerminal
Sends the given message.

Specified by:
sendMessage in interface UDPTerminal
Parameters:
msg - the message as byte[].
Throws:
Exception - if sending the message fails.

receiveMessage

public byte[] receiveMessage()
                      throws Exception
Description copied from interface: UDPTerminal
Receives and returns a message.

Specified by:
receiveMessage in interface UDPTerminal
Returns:
the message as a newly allocated byte[].
Throws:
Exception - if receiving a message fails.

receiveMessage

public void receiveMessage(byte[] buffer)
                    throws Exception
Throws:
Exception


Copyright © 2012. All Rights Reserved.