net.wimpi.modbus.net
Class UDPSlaveTerminal

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

 class UDPSlaveTerminal
extends Object
implements UDPTerminal

Class implementing a UDPSlaveTerminal.

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

Nested Class Summary
(package private)  class UDPSlaveTerminal.PacketReceiver
           
(package private)  class UDPSlaveTerminal.PacketSender
           
 
Field Summary
private  boolean m_Active
           
protected  InetAddress m_LocalAddress
           
private  int m_LocalPort
           
protected  ModbusUDPTransport m_ModbusTransport
           
private  UDPSlaveTerminal.PacketReceiver m_PacketReceiver
           
private  UDPSlaveTerminal.PacketSender m_PacketSender
           
private  LinkedQueue m_ReceiveQueue
           
private  Thread m_Receiver
           
protected  Hashtable m_Requests
           
private  int m_Retries
           
private  Thread m_Sender
           
private  LinkedQueue m_SendQueue
           
private  DatagramSocket m_Socket
           
private  int m_Timeout
           
 
Constructor Summary
protected UDPSlaveTerminal()
           
protected UDPSlaveTerminal(InetAddress localaddress)
           
 
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.
 DatagramSocket getSocket()
          Returns the socket of this UDPSlaveTerminal.
protected  boolean hasResponse()
           
 boolean isActive()
          Tests if this UDPSlaveTerminal is active.
 byte[] receiveMessage()
          Receives and returns a message.
 void sendMessage(byte[] msg)
          Sends the given message.
protected  void setLocalPort(int port)
           
protected  void setSocket(DatagramSocket sock)
          Sets the socket of this UDPTerminal.
 
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_LocalPort

private int m_LocalPort

m_ModbusTransport

protected ModbusUDPTransport m_ModbusTransport

m_Retries

private int m_Retries

m_SendQueue

private LinkedQueue m_SendQueue

m_ReceiveQueue

private LinkedQueue m_ReceiveQueue

m_PacketSender

private UDPSlaveTerminal.PacketSender m_PacketSender

m_PacketReceiver

private UDPSlaveTerminal.PacketReceiver m_PacketReceiver

m_Receiver

private Thread m_Receiver

m_Sender

private Thread m_Sender

m_Requests

protected Hashtable m_Requests
Constructor Detail

UDPSlaveTerminal

protected UDPSlaveTerminal()

UDPSlaveTerminal

protected UDPSlaveTerminal(InetAddress localaddress)
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.

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)

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.

hasResponse

protected boolean hasResponse()

getSocket

public DatagramSocket getSocket()
Returns the socket of this UDPSlaveTerminal.

Returns:
the socket as DatagramSocket.

setSocket

protected void setSocket(DatagramSocket sock)
Sets the socket of this UDPTerminal.

Parameters:
sock - the DatagramSocket for this terminal.

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.


Copyright © 2012. All Rights Reserved.