org.openmuc.framework.dataaccess
public interface Channel
Channel
class is used to access a single data field of a communication device. A desired channel can
be obtained using the DataAccessService
. A channel instance can be used to
setLatestRecord
.Note that only the call of the read or write functions will actually result in a corresponding read or write request being sent to the communication device.
Modifier and Type | Method and Description |
---|---|
void |
addListener(RecordListener listener)
Adds a listener that is notified of new records received by sampling or listening.
|
java.lang.String |
getChannelAddress()
Returns the address of this channel.
|
ChannelState |
getChannelState()
Returns the current channel state.
|
java.lang.String |
getDescription()
Returns the description of this channel.
|
java.lang.String |
getDeviceAddress()
Returns the channel's device address.
|
java.lang.String |
getDeviceDescription()
Returns the description of the communication device that this channel belongs to.
|
java.lang.String |
getDeviceName()
Returns the name of the communication device that this channel belongs to.
|
DeviceState |
getDeviceState()
Returns the current state of the communication device that this channel belongs to.
|
java.lang.String |
getDriverName()
Returns the unique name of the communication driver that is used by this channel to read/write data.
|
java.lang.String |
getId()
Returns the ID of this channel.
|
java.lang.String |
getInterfaceAddress()
Returns the channel's interface address.
|
Record |
getLatestRecord()
Returns the latest record of this channel.
|
Record |
getLoggedRecord(long time)
Returns the logged data record whose timestamp equals the given
time . |
java.util.List<Record> |
getLoggedRecords(long startTime)
Returns a list of all logged data records with timestamps from
startTime up until now. |
java.util.List<Record> |
getLoggedRecords(long startTime,
long endTime)
Returns a list of all logged data records with timestamps from
startTime to endTime
inclusive. |
int |
getLoggingInterval()
Returns the channel's configured logging interval in milliseconds.
|
int |
getLoggingTimeOffset()
Returns the channel's configured logging time offset in milliseconds.
|
ReadRecordContainer |
getReadContainer()
Returns a
ReadRecordContainer that corresponds to this channel. |
int |
getSamplingInterval()
Returns the channel's configured sampling interval in milliseconds.
|
int |
getSamplingTimeOffset()
Returns the channel's configured sampling time offset in milliseconds.
|
double |
getScalingFactor()
Returns the scaling factor.
|
java.lang.String |
getUnit()
Returns the unit of this channel.
|
ValueType |
getValueType()
Returns the value type of this channel.
|
WriteValueContainer |
getWriteContainer()
Returns a
WriteValueContainer that corresponds to this channel. |
boolean |
isConnected()
Returns
true if a connection to the channel's communication device exist. |
Record |
read()
Actively reads a value from the channel's corresponding data field in the connected communication device.
|
void |
removeListener(RecordListener listener)
Removes a record listener.
|
void |
setLatestRecord(Record record)
Sets the latest record of this channel.
|
void |
write(java.util.List<Record> records)
Schedules a List<records> with future timestamps as write tasks
This function will schedule single write tasks to the provided timestamps. Once this function is called, previously scheduled write tasks will be erased. |
Flag |
write(Value value)
Writes the given value to the channel's corresponding data field in the connected communication device.
|
java.lang.String getId()
DataAccessService
.java.lang.String getChannelAddress()
java.lang.String getDescription()
java.lang.String getUnit()
ValueType getValueType()
Usually an application does not need to know the value type of the channel because it can use the value type of
its choice by using the corresponding function of Value
(e.g. Value.asDouble()
). Necessary
conversions will be done transparently.
If no value type was configured, the default ValueType.DOUBLE
is used.
double getScalingFactor()
The scaling factor is applied in the following cases:
setLatestRecord(Record)
are multiplied
with the scaling factor before they are stored in the latest record.write(Value)
) are divided by the scaling factor before they are handed to
the driver for transmission.int getSamplingInterval()
int getSamplingTimeOffset()
int getLoggingInterval()
int getLoggingTimeOffset()
java.lang.String getDriverName()
java.lang.String getInterfaceAddress()
null
if not configured.java.lang.String getDeviceAddress()
java.lang.String getDeviceName()
java.lang.String getDeviceDescription()
ChannelState getChannelState()
DeviceState getDeviceState()
void addListener(RecordListener listener)
listener
- the record listener that is notified of new records.void removeListener(RecordListener listener)
listener
- the listener shall be removed.boolean isConnected()
true
if a connection to the channel's communication device exist.true
if a connection to the channel's communication device exist.Record getLatestRecord()
setLatestRecord
.write
are also stored as the latest recordvoid setLatestRecord(Record record)
Note that the framework treats the passed record in exactly the same way as if it had been received from a driver. In particular that means:
getLatestRecord
.addListener
.
record
- the record to be set.Flag write(Value value)
Flag
will indicate this.value
- the value that is to be writtenFlag.VALID
) or not (any
other flag).void write(java.util.List<Record> records)
records
- each record contains the value that is to be written and the timestamp indicating when it should be
written. The flag of the record is ignored.WriteValueContainer getWriteContainer()
WriteValueContainer
that corresponds to this channel. This container can be passed to the
write function of DataAccessService
to write several values in one transaction.WriteValueContainer
that corresponds to this channel.Record read()
Flag.VALID
) or a an error (any other flag).ReadRecordContainer getReadContainer()
ReadRecordContainer
that corresponds to this channel. This container can be passed to the
read
function of DataAccessService
to read several values in one transaction.ReadRecordContainer
that corresponds to this channel.Record getLoggedRecord(long time) throws DataLoggerNotAvailableException, java.io.IOException
time
. Note that it is the data
logger's choice whether it stores values using the timestamp that the driver recorded when it received it or the
timestamp at which the value is to be logged. If the former is the case then this function is not useful because
it is impossible for an application to know the exact time at which a value was received. In this case use
getLoggedRecords
instead.time
- the time in milliseconds since midnight, January 1, 1970 UTC.timestamp
.
Returns null
if no record exists for this point in time.DataLoggerNotAvailableException
- if no data logger is installed and therefore no logged data can be accessed.java.io.IOException
- if any kind of error occurs accessing the logged data.java.util.List<Record> getLoggedRecords(long startTime) throws DataLoggerNotAvailableException, java.io.IOException
startTime
up until now.startTime
- the starting time in milliseconds since midnight, January 1, 1970 UTC. inclusivestartTime
up until now.DataLoggerNotAvailableException
- if no data logger is installed and therefore no logged data can be accessed.java.io.IOException
- if any kind of error occurs accessing the logged data.java.util.List<Record> getLoggedRecords(long startTime, long endTime) throws DataLoggerNotAvailableException, java.io.IOException
startTime
to endTime
inclusive.startTime
- the starting time in milliseconds since midnight, January 1, 1970 UTC. inclusiveendTime
- the ending time in milliseconds since midnight, January 1, 1970 UTC. inclusivestartTime
to endTime
inclusive.DataLoggerNotAvailableException
- if no data logger is installed and therefore no logged data can be accessed.java.io.IOException
- if any kind of error occurs accessing the logged data.