org.lsst.ccs.drivers.wattsup
Class WattsUp

java.lang.Object
  extended by org.lsst.ccs.drivers.wattsup.WattsUp
All Implemented Interfaces:
gnu.io.SerialPortEventListener, java.util.EventListener

public class WattsUp
extends java.lang.Object
implements gnu.io.SerialPortEventListener

Controls a WattsUp? meter

Author:
Owen Saxton

Nested Class Summary
static interface WattsUp.DataListener
          Defines a data listener
 
Field Summary
static int FLD_AMPS
          Data field - amps
static int FLD_AMPS_MAX
          Data field - maximum amps during interval
static int FLD_AMPS_MIN
          Data field - minimum amps during interval
static int FLD_COST
          Data field - cost over collection period
static int FLD_COST_MONTH
          Data field - cost per month
static int FLD_DUTY_CYCLE
          Data field - duty cycle (fraction of time over power threshold)
static int FLD_FREQUENCY
          Data field - line frequency
static int FLD_POWER_CYCLE
          Data field - power cycle (number of times power was cycled)
static int FLD_POWER_FACTOR
          Data field - power factor (watts / volt-amps)
static int FLD_VOLT_AMPS
          Data field - volt-amps (product of volts and amps)
static int FLD_VOLTS
          Data field - volts
static int FLD_VOLTS_MAX
          Data field - maximum volts during interval
static int FLD_VOLTS_MIN
          Data field - minimum volts during interval
static int FLD_WATT_HOURS
          Data field - watt-hours over collection period
static int FLD_WATTS
          Data field - watts
static int FLD_WATTS_MAX
          Data field - maximum watts during interval
static int FLD_WATTS_MIN
          Data field - minimum watts during interval
static int FLD_WH_MONTH
          Data field - watt-hours per month
static int LOG_STA_EXTERNAL
          Logging status - external
static int LOG_STA_INTERNAL
          Logging status - active internal
static int LOG_STA_SUSPENDED
          Logging status - suspended (memory full)
static int MEM_OPT_CONDENSE
          Memory-full option - condense (sparsify) the data
static int MEM_OPT_OVERWRITE
          Memory-full option - overwrite oldest data
static int MEM_OPT_SUSPEND
          Memory-full option - suspend logging
static int N_CAL_FIELDS
          Number of calibration fields
static int N_FIELDS
          Number of data fields
static int N_VER_FIELDS
          Number of version fields
static int VER_FLD_CHECKSUM
          Version field - checksum
static int VER_FLD_FWMAJOR
          Version field - major firmware version
static int VER_FLD_FWMINOR
          Version field - minor firmware version
static int VER_FLD_FWTSTAMP
          Version field - firmware time stamp (YYYYMMDDHHMM)
static int VER_FLD_HW_MINOR
          Version field - minor hardware version
static int VER_FLD_HWMAJOR
          Version field - major hardware version
static int VER_FLD_MEMORY
          Version field - memory size
static int VER_FLD_MODEL
          Version field - model
 
Constructor Summary
WattsUp()
          Constructor
 
Method Summary
 void addDataListener(WattsUp.DataListener listener)
          Adds a data listener
 void close()
          Closes the connection to the meter
 int[] getCalibrationData()
          Gets the calibration data
 int getFullOption()
          Gets the memory-full handling option
 java.lang.String[] getHeaderRecord()
          Gets the header record
 int getLoggedData()
          Gets all the logged data
 int getLoggedFields()
          Gets the bit mask of fields being logged
 int getLoggingInterval()
          Gets the logging interval
 int getLoggingState()
          Gets the logging state
 int getRecordLimit()
          Gets the record count limit
 boolean getUserEuro()
          Gets the user-set euro flag
 float getUserRate()
          Gets the user-set electricity rate
 int getUserThreshold()
          Gets the user-set duty cycle threshold
 java.lang.String[] getVersionData()
          Gets the version information
 void open()
          Opens a connection to the meter
 void open(java.lang.String portName)
          Opens a connection to the meter
 void removeDataListener()
          Removes a data listener
 void resetMemory()
          Resets (clears) data memory
 void restart()
          Restarts the meter
 void serialEvent(gnu.io.SerialPortEvent event)
          Receives serial port events
 void setExternalLogging(int interval)
          Sets external logging
 void setFullOption(int option)
          Sets the memory-full handling option
 int setInternalLogging(int interval)
          Sets internal logging
 int setLoggedFields(int mask)
          Sets the fields to be logged
 void setLoggingInterval(int interval)
          Sets the logging interval
 void setUserParameters(float rate, int threshold, boolean euro)
          Sets the user parameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLD_WATTS

public static final int FLD_WATTS
Data field - watts

See Also:
Constant Field Values

FLD_VOLTS

public static final int FLD_VOLTS
Data field - volts

See Also:
Constant Field Values

FLD_AMPS

public static final int FLD_AMPS
Data field - amps

See Also:
Constant Field Values

FLD_WATT_HOURS

public static final int FLD_WATT_HOURS
Data field - watt-hours over collection period

See Also:
Constant Field Values

FLD_COST

public static final int FLD_COST
Data field - cost over collection period

See Also:
Constant Field Values

FLD_WH_MONTH

public static final int FLD_WH_MONTH
Data field - watt-hours per month

See Also:
Constant Field Values

FLD_COST_MONTH

public static final int FLD_COST_MONTH
Data field - cost per month

See Also:
Constant Field Values

FLD_WATTS_MAX

public static final int FLD_WATTS_MAX
Data field - maximum watts during interval

See Also:
Constant Field Values

FLD_VOLTS_MAX

public static final int FLD_VOLTS_MAX
Data field - maximum volts during interval

See Also:
Constant Field Values

FLD_AMPS_MAX

public static final int FLD_AMPS_MAX
Data field - maximum amps during interval

See Also:
Constant Field Values

FLD_WATTS_MIN

public static final int FLD_WATTS_MIN
Data field - minimum watts during interval

See Also:
Constant Field Values

FLD_VOLTS_MIN

public static final int FLD_VOLTS_MIN
Data field - minimum volts during interval

See Also:
Constant Field Values

FLD_AMPS_MIN

public static final int FLD_AMPS_MIN
Data field - minimum amps during interval

See Also:
Constant Field Values

FLD_POWER_FACTOR

public static final int FLD_POWER_FACTOR
Data field - power factor (watts / volt-amps)

See Also:
Constant Field Values

FLD_DUTY_CYCLE

public static final int FLD_DUTY_CYCLE
Data field - duty cycle (fraction of time over power threshold)

See Also:
Constant Field Values

FLD_POWER_CYCLE

public static final int FLD_POWER_CYCLE
Data field - power cycle (number of times power was cycled)

See Also:
Constant Field Values

FLD_FREQUENCY

public static final int FLD_FREQUENCY
Data field - line frequency

See Also:
Constant Field Values

FLD_VOLT_AMPS

public static final int FLD_VOLT_AMPS
Data field - volt-amps (product of volts and amps)

See Also:
Constant Field Values

N_FIELDS

public static final int N_FIELDS
Number of data fields

See Also:
Constant Field Values

N_CAL_FIELDS

public static final int N_CAL_FIELDS
Number of calibration fields

See Also:
Constant Field Values

MEM_OPT_SUSPEND

public static final int MEM_OPT_SUSPEND
Memory-full option - suspend logging

See Also:
Constant Field Values

MEM_OPT_OVERWRITE

public static final int MEM_OPT_OVERWRITE
Memory-full option - overwrite oldest data

See Also:
Constant Field Values

MEM_OPT_CONDENSE

public static final int MEM_OPT_CONDENSE
Memory-full option - condense (sparsify) the data

See Also:
Constant Field Values

LOG_STA_SUSPENDED

public static final int LOG_STA_SUSPENDED
Logging status - suspended (memory full)

See Also:
Constant Field Values

LOG_STA_INTERNAL

public static final int LOG_STA_INTERNAL
Logging status - active internal

See Also:
Constant Field Values

LOG_STA_EXTERNAL

public static final int LOG_STA_EXTERNAL
Logging status - external

See Also:
Constant Field Values

VER_FLD_MODEL

public static final int VER_FLD_MODEL
Version field - model

See Also:
Constant Field Values

VER_FLD_MEMORY

public static final int VER_FLD_MEMORY
Version field - memory size

See Also:
Constant Field Values

VER_FLD_HWMAJOR

public static final int VER_FLD_HWMAJOR
Version field - major hardware version

See Also:
Constant Field Values

VER_FLD_HW_MINOR

public static final int VER_FLD_HW_MINOR
Version field - minor hardware version

See Also:
Constant Field Values

VER_FLD_FWMAJOR

public static final int VER_FLD_FWMAJOR
Version field - major firmware version

See Also:
Constant Field Values

VER_FLD_FWMINOR

public static final int VER_FLD_FWMINOR
Version field - minor firmware version

See Also:
Constant Field Values

VER_FLD_FWTSTAMP

public static final int VER_FLD_FWTSTAMP
Version field - firmware time stamp (YYYYMMDDHHMM)

See Also:
Constant Field Values

VER_FLD_CHECKSUM

public static final int VER_FLD_CHECKSUM
Version field - checksum

See Also:
Constant Field Values

N_VER_FIELDS

public static final int N_VER_FIELDS
Number of version fields

See Also:
Constant Field Values
Constructor Detail

WattsUp

public WattsUp()
Constructor

Method Detail

open

public void open()
Opens a connection to the meter

Connects to the meter using the default serial port (/dev/ttyUSB0)

Throws:
WattsUpException

open

public void open(java.lang.String portName)
Opens a connection to the meter

Parameters:
portName - The name of the serial port to use.
Throws:
WattsUpException

close

public void close()
Closes the connection to the meter

Throws:
WattsUpException

addDataListener

public void addDataListener(WattsUp.DataListener listener)
Adds a data listener

Parameters:
listener - The data listener object, containing the process method.

removeDataListener

public void removeDataListener()
Removes a data listener


getLoggedFields

public int getLoggedFields()
Gets the bit mask of fields being logged

Returns:
A bit mask where each set bit represents a field being logged.
Throws:
WattsUpException

setLoggedFields

public int setLoggedFields(int mask)
Sets the fields to be logged

Parameters:
mask - A bit mask where each set bit represents a field to be logged.
Returns:
The number of data records that can be logged internally.
Throws:
WattsUpException

getCalibrationData

public int[] getCalibrationData()
Gets the calibration data

Returns:
A 48-element integer array containing the calibration data.
Throws:
WattsUpException

getHeaderRecord

public java.lang.String[] getHeaderRecord()
Gets the header record

Returns:
An 18-element string array containing short names for the defined fields.
Throws:
WattsUpException

getLoggedData

public int getLoggedData()
Gets all the logged data

All the logged data currently stored in the meter is read out and passed to the data listener's process method, one record at a time. This may take many seconds, depending on the amount of logged data.

Returns:
The current logging interval (seconds).
Throws:
WattsUpException

setInternalLogging

public int setInternalLogging(int interval)
Sets internal logging

Data logging is set to be internal, where each logged data record is stored in the meter's internal memory, for subsequent retrieval via getLoggedData.

Parameters:
interval - The logging interval to set. This is ignored if the memory-full option is set to 2 (sparsify).
Returns:
The actual current logging interval.
Throws:
WattsUpException

setExternalLogging

public void setExternalLogging(int interval)
Sets external logging

Data logging is set to be external, where a data record is sent to the serial port at the end of each logging interval and then passed to the process method of the data listener object.

Parameters:
interval - The logging interval to set.
Throws:
WattsUpException

getRecordLimit

public int getRecordLimit()
Gets the record count limit

Returns:
The maximum number of data records than can be stored internally.
Throws:
WattsUpException

getFullOption

public int getFullOption()
Gets the memory-full handling option

Returns:
The memory-full handling option, encoded as follows: 0 = pause; 1 = wrap; 2 = sparsify.
Throws:
WattsUpException

setFullOption

public void setFullOption(int option)
Sets the memory-full handling option

Parameters:
option - The memory-full option to set, encoded as follows: 0 = pause; 1 = wrap; 2 = sparsify by deleting every other record and doubling the logging interval.
Throws:
WattsUpException

resetMemory

public void resetMemory()
Resets (clears) data memory

Throws:
WattsUpException

getLoggingInterval

public int getLoggingInterval()
Gets the logging interval

Returns:
The current logging interval in effect.
Throws:
WattsUpException

getLoggingState

public int getLoggingState()
Gets the logging state

Returns:
The current logging state, encoded as follows: 0 = paused internal; 1 = active internal; 2 = external.
Throws:
WattsUpException

setLoggingInterval

public void setLoggingInterval(int interval)
Sets the logging interval

Parameters:
interval - The logging interval to set. This is ignored for internal logging with the memory-full option set to 2 (sparsify).
Throws:
WattsUpException

getUserRate

public float getUserRate()
Gets the user-set electricity rate

Returns:
The user-set electricity rate in currency units (dollars or euros) per KWH.
Throws:
WattsUpException

getUserThreshold

public int getUserThreshold()
Gets the user-set duty cycle threshold

Returns:
The user-set power threshold (watts) used for calculating the duty cycle.
Throws:
WattsUpException

getUserEuro

public boolean getUserEuro()
Gets the user-set euro flag

Returns:
The user-set euro flag, true if the currency is euros and false if dollars.
Throws:
WattsUpException

setUserParameters

public void setUserParameters(float rate,
                              int threshold,
                              boolean euro)
Sets the user parameters

Parameters:
rate - The electricity rate in currency units (dollars or euros) per KWH.
threshold - The power threshold (watts) used for calculating the duty cycle.
euro - The euro flag, true if the currency is euros and false if dollars. This is used to display the correct currency symbol on the meter.
Throws:
WattsUpException

getVersionData

public java.lang.String[] getVersionData()
Gets the version information

Returns:
An 8-element string array containing version information.
Throws:
WattsUpException

restart

public void restart()
Restarts the meter

This has the same effect as power cycling the meter.

Throws:
WattsUpException

serialEvent

public void serialEvent(gnu.io.SerialPortEvent event)
Receives serial port events

This is an event listener method to receive notifications of changes in the serial port. It reacts only to DATA_AVAILABLE events and wakes the reading thread whenever one occurs.

Specified by:
serialEvent in interface gnu.io.SerialPortEventListener


Copyright © 2012 LSST. All Rights Reserved.