jamod at SF

net.wimpi.modbus.facade
Class ModbusUDPMaster

java.lang.Object
  extended bynet.wimpi.modbus.facade.ModbusUDPMaster

public class ModbusUDPMaster
extends java.lang.Object

Modbus/UDP Master facade.

Version:
1.2rc1 (09/11/2004)
Author:
Dieter Wimberger

Constructor Summary
ModbusUDPMaster(java.lang.String addr)
          Constructs a new master facade instance for communication with a given slave.
ModbusUDPMaster(java.lang.String addr, int port)
          Constructs a new master facade instance for communication with a given slave.
 
Method Summary
 void connect()
          Connects this ModbusUDPMaster with the slave.
 void disconnect()
          Disconnects this ModbusTCPMaster from the slave.
 BitVector readCoils(int ref, int count)
          Reads a given number of coil states from the slave.
 BitVector readInputDiscretes(int ref, int count)
          Reads a given number of input discrete states from the slave.
 InputRegister[] readInputRegisters(int ref, int count)
          Reads a given number of input registers from the slave.
 Register[] readMultipleRegisters(int ref, int count)
          Reads a given number of registers from the slave.
 boolean writeCoil(int unitid, int ref, boolean state)
          Writes a coil state to the slave.
 void writeMultipleCoils(int ref, BitVector coils)
          Writes a given number of coil states to the slave.
 void writeMultipleRegisters(int ref, Register[] registers)
          Writes a number of registers to the slave.
 void writeSingleRegister(int ref, Register register)
          Writes a single register to the slave.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModbusUDPMaster

public ModbusUDPMaster(java.lang.String addr)
Constructs a new master facade instance for communication with a given slave.

Parameters:
addr - an internet address as resolvable IP name or IP number, specifying the slave to communicate with.

ModbusUDPMaster

public ModbusUDPMaster(java.lang.String addr,
                       int port)
Constructs a new master facade instance for communication with a given slave.

Parameters:
addr - an internet address as resolvable IP name or IP number, specifying the slave to communicate with.
port - the port the slave is listening to.
Method Detail

connect

public void connect()
             throws java.lang.Exception
Connects this ModbusUDPMaster with the slave.

Throws:
java.lang.Exception - if the connection cannot be established.

disconnect

public void disconnect()
Disconnects this ModbusTCPMaster from the slave.


readCoils

public BitVector readCoils(int ref,
                           int count)
                    throws ModbusException
Reads a given number of coil states from the slave.

Note that the number of bits in the bit vector will be forced to the number originally requested.

Parameters:
ref - the offset of the coil to start reading from.
count - the number of coil states to be read.
Returns:
a BitVector instance holding the received coil states.
Throws:
ModbusException - if an I/O error, a slave exception or a transaction error occurs.

writeCoil

public boolean writeCoil(int unitid,
                         int ref,
                         boolean state)
                  throws ModbusException
Writes a coil state to the slave.

Parameters:
unitid - the slave unit id.
ref - the offset of the coil to be written.
state - the coil state to be written.
Returns:
the state of the coil as returned from the slave.
Throws:
ModbusException - if an I/O error, a slave exception or a transaction error occurs.

writeMultipleCoils

public void writeMultipleCoils(int ref,
                               BitVector coils)
                        throws ModbusException
Writes a given number of coil states to the slave.

Note that the number of coils to be written is given implicitly, through BitVector.size().

Parameters:
ref - the offset of the coil to start writing to.
coils - a BitVector which holds the coil states to be written.
Throws:
ModbusException - if an I/O error, a slave exception or a transaction error occurs.

readInputDiscretes

public BitVector readInputDiscretes(int ref,
                                    int count)
                             throws ModbusException
Reads a given number of input discrete states from the slave.

Note that the number of bits in the bit vector will be forced to the number originally requested.

Parameters:
ref - the offset of the input discrete to start reading from.
count - the number of input discrete states to be read.
Returns:
a BitVector instance holding the received input discrete states.
Throws:
ModbusException - if an I/O error, a slave exception or a transaction error occurs.

readInputRegisters

public InputRegister[] readInputRegisters(int ref,
                                          int count)
                                   throws ModbusException
Reads a given number of input registers from the slave.

Note that the number of input registers returned (i.e. array length) will be according to the number received in the slave response.

Parameters:
ref - the offset of the input register to start reading from.
count - the number of input registers to be read.
Returns:
a InputRegister[] with the received input registers.
Throws:
ModbusException - if an I/O error, a slave exception or a transaction error occurs.

readMultipleRegisters

public Register[] readMultipleRegisters(int ref,
                                        int count)
                                 throws ModbusException
Reads a given number of registers from the slave.

Note that the number of registers returned (i.e. array length) will be according to the number received in the slave response.

Parameters:
ref - the offset of the register to start reading from.
count - the number of registers to be read.
Returns:
a Register[] holding the received registers.
Throws:
ModbusException - if an I/O error, a slave exception or a transaction error occurs.

writeSingleRegister

public void writeSingleRegister(int ref,
                                Register register)
                         throws ModbusException
Writes a single register to the slave.

Parameters:
ref - the offset of the register to be written.
register - a Register holding the value of the register to be written.
Throws:
ModbusException - if an I/O error, a slave exception or a transaction error occurs.

writeMultipleRegisters

public void writeMultipleRegisters(int ref,
                                   Register[] registers)
                            throws ModbusException
Writes a number of registers to the slave.

Parameters:
ref - the offset of the register to start writing to.
registers - a Register[] holding the values of the registers to be written.
Throws:
ModbusException - if an I/O error, a slave exception or a transaction error occurs.

jamod at SF

Copyright © 2002-2004 jamod development team.