org.lsst.ccs.drivers.modbus
Class Modbus

java.lang.Object
  extended by org.lsst.ccs.drivers.modbus.Modbus

public class Modbus
extends Object

Handles Modbus RTU messages on a serial line

Author:
Owen Saxton

Constructor Summary
Modbus()
           
 
Method Summary
 void close()
          Closes the connection to the Modbus
 org.lsst.ccs.drivers.ftdi.Ftdi getFtdi()
          Gets the associated Ftdi object
 void open(int index, String serial)
          Opens a connection to the Modbus
 void open(String node, int index, String serial)
          Opens a connection to the Modbus
 byte[] readCoils(short dAddr, short cNmbr, short count)
          Reads a set of coils
 byte[] readDiscretes(short dAddr, short iNmbr, short count)
          Reads a set of discrete inputs
 short[] readInputs(short dAddr, short rNmbr, short count)
          Reads a set of input registers
 short[] readRegisters(short dAddr, short rNmbr, short count)
          Reads a set of holding registers
 byte[] send(short addr, byte[] cmnd, int timeout)
          Sends a command to a device on the Modbus and returns its response
 void writeCoil(short dAddr, short cNmbr, boolean value)
          Writes a coil
 void writeCoils(short dAddr, short cNmbr, short count, byte[] value)
          Writes a set of coils
 void writeRegister(short dAddr, short rNmbr, short value)
          Writes a holding register
 void writeRegisters(short dAddr, short rNmbr, short[] value)
          Writes a set of holding registers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Modbus

public Modbus()
Method Detail

open

public void open(int index,
                 String serial)
          throws ModbusException
Opens a connection to the Modbus

Parameters:
index - The zero-based index of the Modbus adapter within the list of FTDI devices selected by the serial argument
serial - A string which, if non-null and non-empty, restricts the list of available devices to those with a serial number containing this string
Throws:
ModbusException

open

public void open(String node,
                 int index,
                 String serial)
          throws ModbusException
Opens a connection to the Modbus

Parameters:
node - The name of the node from which the Modbus is being served, or null for the local node
index - The zero-based index of the Modbus adapter within the list of FTDI devices selected by the serial argument
serial - A string which, if non-null and non-empty, restricts the list of available devices to those with a serial number containing this string
Throws:
ModbusException

close

public void close()
           throws ModbusException
Closes the connection to the Modbus

Throws:
ModbusException

getFtdi

public org.lsst.ccs.drivers.ftdi.Ftdi getFtdi()
Gets the associated Ftdi object


readCoils

public byte[] readCoils(short dAddr,
                        short cNmbr,
                        short count)
                 throws ModbusException
Reads a set of coils

Parameters:
dAddr - The Modbus address of the device
cNmbr - The number (starting at 1) of the first coil to read
count - The number of coils to read
Returns:
The array of read coil values, one per bit
Throws:
ModbusException

readDiscretes

public byte[] readDiscretes(short dAddr,
                            short iNmbr,
                            short count)
                     throws ModbusException
Reads a set of discrete inputs

Parameters:
dAddr - The Modbus address of the device
iNmbr - The number (starting at 1) of the first input to read
count - The number of inputs to read
Returns:
The array of read discrete values, one per bit
Throws:
ModbusException

readRegisters

public short[] readRegisters(short dAddr,
                             short rNmbr,
                             short count)
                      throws ModbusException
Reads a set of holding registers

Parameters:
dAddr - The Modbus address of the device
rNmbr - The number (starting at 1) of the first register to read
count - The number of registers to read
Returns:
The array of read register values
Throws:
ModbusException

readInputs

public short[] readInputs(short dAddr,
                          short rNmbr,
                          short count)
                   throws ModbusException
Reads a set of input registers

Parameters:
dAddr - The Modbus address of the device
rNmbr - The number (starting at 1) of the first register to read
count - The number of registers to read
Returns:
The array of read register values
Throws:
ModbusException

writeRegister

public void writeRegister(short dAddr,
                          short rNmbr,
                          short value)
                   throws ModbusException
Writes a holding register

Parameters:
dAddr - The Modbus address of the device
rNmbr - The number (starting at 1) of the register to write
value - The (16-bit) value to write
Throws:
ModbusException

writeCoil

public void writeCoil(short dAddr,
                      short cNmbr,
                      boolean value)
               throws ModbusException
Writes a coil

Parameters:
dAddr - The Modbus address of the device
cNmbr - The number (starting at 1) of the coil to write
value - The value (false = off, true = on) to write
Throws:
ModbusException

writeRegisters

public void writeRegisters(short dAddr,
                           short rNmbr,
                           short[] value)
                    throws ModbusException
Writes a set of holding registers

Parameters:
dAddr - The Modbus address of the device
rNmbr - The number (starting at 1) of the first register to write
value - The array of register values to write
Throws:
ModbusException

writeCoils

public void writeCoils(short dAddr,
                       short cNmbr,
                       short count,
                       byte[] value)
                throws ModbusException
Writes a set of coils

Parameters:
dAddr - The Modbus address of the device
cNmbr - The number (starting at 1) of the first coil to write
count - The number of coil values to write
value - The array of coil values to write
Throws:
ModbusException

send

public byte[] send(short addr,
                   byte[] cmnd,
                   int timeout)
            throws ModbusException
Sends a command to a device on the Modbus and returns its response

Parameters:
addr - The destination Modbus address
cmnd - The command byte array to send.
timeout - The timeout period (ms)
Returns:
The response byte array
Throws:
ModbusException


Copyright © 2013 LSST. All Rights Reserved.