public class ASCIIModbus extends Object implements Hardware
Built atop the CCS ASCII device driver.
The internal form of a Modbus command or response used by this class is an array of int where each int contains a byte value 0-255. The last byte is reserved for the Linear Redundancy Check to be calculated prior to encoding as a frame. Big-endian byte order is used for multi-byte quantities such as register addresses. The non-LRC bytes for a register reading command are:
The register writing command format is similar except that the number of registers to read is replaced by the value to write to the register. Note that all Modbus registers are 16 bits wide.
The internal form of a normal response to a read-registers command echos the slave number and function code of the command, then follows with:
The normal response to a write-register command is to echo the command without change.
An exception (abnormal) response looks like this:
The transmitted (framed) representation of the internal binary command or response conforms to the older 7-bit ASCII variant of the Modbus protocol. The frame starts with a colon, is followed by two hex characters for each data byte and ends with CRLF. "Data byte" includes the LRC byte which is calculated before framing and set as the last data byte. The LRC is simply the lowest-order eight bits of the twos-complement of the sum of the non-LRC data bytes (before framing).
The Lighthouse counter implements just two classes of Modbus registers: holding (16-bit read/write) and input (16-bit read-only). The register addresses used in commands are not those that appear in the documentation. There, input register addresses start at 30001 and holding register addresses start at 40001. Each command deals with only a single class of register and so the address in the command is the documented address minus the starting address of the class.
This software treats all Modbus registers as 16-bit unsigned values. In order to use streams and avoid problems with sign extension, ints are used for eight-bit and 16-bit quantities while longs are used for 32-bit quantities. A register value is represented as first the high-order byte, then the low. A 32-bit unsigned int is represented using a pair of consecutive registers with the high 16 bits in the lower-addressed register. An IEEE single-precision floating-point value also uses two consecutive registers but in this case the high portion containing the exponent is in the second register. A string is represented as a series of eight-bit bytes occupying a series of consecutive registers, read from lowest to highest address. The first character in each register is in the high-order byte. The number of registers depends on the maximum length of the string. Strings shorter than the maximum are padded on the right with NULs, but no NUL appears for a string that uses all the bytes in the assigned registers.
| Modifier and Type | Field and Description |
|---|---|
static int |
ALARM_FLAGS_OFFSET
The offset from
RECORD_ADDRESS of the first input register containing
channel alarm flags. |
static int |
ANALOG_CHANNEL_OFFSET
The offset from
RECORD_ADDRESS of the first input register with
analog channel data. |
static int |
DEVICE_STATUS_OFFSET
offset from
RECORD_ADDRESS of the device-status-high register. |
static int |
LOCATION_NUMBER_OFFSET
The offset from
RECORD_ADDRESS of the location-number-high register. |
static int |
PARTICLE_CHANNEL_OFFSET
The offset from
RECORD_ADDRESS of the first input register with
particle channel data. |
static int |
RECORD_ADDRESS
The address (less 3001) of the first input register in the record header.
|
static int |
RECORD_HEADER_SIZE
The number of registers in the record header.
|
static int |
SAMPLE_TIME_OFFSET
The offset from
RECORD_ADDRESS of the sample-time-high register. |
static int |
TIMESTAMP_OFFSET
The offset from
RECORD_ADDRESS of the timestamp-high register. |
| Constructor and Description |
|---|
ASCIIModbus(Transport transport,
java.time.Duration timeout,
boolean debug)
Saves a reference to the transport used for the device and saves the given
parameters.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
alarmIsEnabled(DataChannel chan)
Gets the alarm enable status for a particle channel.
|
boolean |
channelIsEnabled(DataChannel chan)
Checks whether the given data channel is enabled.
|
void |
close()
Closes the underlying connection to the device.
|
long |
getAlarmThreshold(DataChannel chan)
Gets the current alarm threshold for a particle channel.
|
long |
getClock()
Gets the device's time-of-day clock.
|
String |
getDeviceLocationName()
Gets the label for the current location set for the device.
|
ChannelType |
readChannelType(DataChannel chan)
Reads the data type registers for a data channel of the current record.
|
ChannelUnits |
readChannelUnits(DataChannel chan)
Reads the units registers for a data channel of the current record.
|
double |
readChannelValue(DataChannel chan)
Reads the value registers for a data channel of the current record.
|
Set<DeviceFlag> |
readDeviceFlags()
Reads the device status register.
|
int |
readDeviceMapVersion()
Reads the Modbus map version register.
|
String |
readDeviceModel()
Reads the model designation registers.
|
String |
readLocationString(int location)
Reads the location string corresponding to a location number.
|
DataRecord |
readRecord()
Reads the current data record from the device faster than one could by combining
the other methods exported by this interface.
|
int |
readRecordCount()
Reads the record count register.
|
java.time.Duration |
readRecordDuration()
Reads the record sample time register.
|
Set<RecordFlag> |
readRecordFlags()
Reads the device status registers of the current record.
|
String |
readRecordLocation()
Reads the registers for location number and location name.
|
java.time.Instant |
readRecordStartTime()
Reads the record timestamp register.
|
void |
setAlarmEnable(DataChannel chan,
boolean on)
Enables or disables the alarm for a particle channel.
|
void |
setAlarmThreshold(DataChannel chan,
long threshold)
Sets the particle count alarm threshold for a particle channel but doesn't
change the alarm enable status.
|
void |
setClock(long epochSecond)
Sets the device's time-of-day clock.
|
void |
setDeviceLocationIndex(int index)
Sets the current-location register for the device.
|
void |
writeDeviceCommand(DeviceCommand cmd)
Writes to the device command register.
|
void |
writeRecordIndex(int index)
Writes to the record index register, making the data registers show the contents
of a particular record in its memory.
|
public static final int RECORD_ADDRESS
public static final int TIMESTAMP_OFFSET
RECORD_ADDRESS of the timestamp-high register.public static final int SAMPLE_TIME_OFFSET
RECORD_ADDRESS of the sample-time-high register.public static final int LOCATION_NUMBER_OFFSET
RECORD_ADDRESS of the location-number-high register.public static final int DEVICE_STATUS_OFFSET
RECORD_ADDRESS of the device-status-high register.public static final int PARTICLE_CHANNEL_OFFSET
RECORD_ADDRESS of the first input register with
particle channel data.public static final int ANALOG_CHANNEL_OFFSET
RECORD_ADDRESS of the first input register with
analog channel data.public static final int ALARM_FLAGS_OFFSET
RECORD_ADDRESS of the first input register containing
channel alarm flags.public static final int RECORD_HEADER_SIZE
public ASCIIModbus(Transport transport, java.time.Duration timeout, boolean debug)
transport - The open transport link.timeout - How long to wait for a response to a command.debug - Only if true, all frames sent and received will be logged with
<package logger>.debug().public void close()
throws org.lsst.ccs.drivers.commons.DriverException
public String readDeviceModel() throws org.lsst.ccs.drivers.commons.DriverException
readDeviceModel in interface Hardwareorg.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public int readDeviceMapVersion()
throws org.lsst.ccs.drivers.commons.DriverException
readDeviceMapVersion in interface Hardwareorg.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public Set<DeviceFlag> readDeviceFlags() throws org.lsst.ccs.drivers.commons.DriverException
readDeviceFlags in interface Hardwareorg.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public void writeDeviceCommand(DeviceCommand cmd) throws org.lsst.ccs.drivers.commons.DriverException
writeDeviceCommand in interface Hardwarecmd - A valid device command.org.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public int readRecordCount()
throws org.lsst.ccs.drivers.commons.DriverException
readRecordCount in interface Hardwareorg.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public void writeRecordIndex(int index)
throws org.lsst.ccs.drivers.commons.DriverException
writeRecordIndex in interface Hardwareindex - The zero-based record index. 0 .. N - 1, or -1 for the latest record.org.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public java.time.Instant readRecordStartTime()
throws org.lsst.ccs.drivers.commons.DriverException
readRecordStartTime in interface Hardwareorg.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public java.time.Duration readRecordDuration()
throws org.lsst.ccs.drivers.commons.DriverException
readRecordDuration in interface Hardwareorg.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public String readRecordLocation() throws org.lsst.ccs.drivers.commons.DriverException
readRecordLocation in interface Hardwareorg.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public String readLocationString(int location) throws org.lsst.ccs.drivers.commons.DriverException
location - The location number, >= 1.org.lsst.ccs.drivers.commons.DriverException - for I/O errors.public Set<RecordFlag> readRecordFlags() throws org.lsst.ccs.drivers.commons.DriverException
readRecordFlags in interface HardwareRecordFlag.flagsFromMask(int).org.lsst.ccs.drivers.commons.DriverException - if communication problems arise.public ChannelType readChannelType(DataChannel chan) throws org.lsst.ccs.drivers.commons.DriverException
readChannelType in interface Hardwarechan - The channel.org.lsst.ccs.drivers.commons.DriverException - if communication problems arise or
if the channel type label read from the device isn't what's specified by chan.public ChannelUnits readChannelUnits(DataChannel chan) throws org.lsst.ccs.drivers.commons.DriverException
readChannelUnits in interface Hardwarechan - The channel.org.lsst.ccs.drivers.commons.DriverException - if communication problems arise or
if the units label read from the device isn't what's specified by chan.public double readChannelValue(DataChannel chan) throws org.lsst.ccs.drivers.commons.DriverException
readChannelValue in interface Hardwarechan - The channel.org.lsst.ccs.drivers.commons.DriverException - if communication problems arise or
if the channel isn't enabled on the device.public boolean channelIsEnabled(DataChannel chan) throws org.lsst.ccs.drivers.commons.DriverException
channelIsEnabled in interface Hardwarechan - The channel to check.org.lsst.ccs.drivers.commons.DriverException - upon I/O error.public DataRecord readRecord() throws org.lsst.ccs.drivers.commons.DriverException
readRecord in interface Hardwareorg.lsst.ccs.drivers.commons.DriverException - for I/O errors.public void setAlarmThreshold(DataChannel chan, long threshold) throws org.lsst.ccs.drivers.commons.DriverException
setAlarmThreshold in interface Hardwarechan - The channel to be affected.threshold - The limiting particle count.org.lsst.ccs.drivers.commons.DriverException - for I/O errors.public long getAlarmThreshold(DataChannel chan) throws org.lsst.ccs.drivers.commons.DriverException
getAlarmThreshold in interface Hardwarechan - The channel to query.org.lsst.ccs.drivers.commons.DriverException - for I/O errors.public void setAlarmEnable(DataChannel chan, boolean on) throws org.lsst.ccs.drivers.commons.DriverException
setAlarmEnable in interface Hardwarechan - The channel to affect.on - true to enable alarms, false to disable.org.lsst.ccs.drivers.commons.DriverException - for I/O errors.public boolean alarmIsEnabled(DataChannel chan) throws org.lsst.ccs.drivers.commons.DriverException
alarmIsEnabled in interface Hardwarechan - The channel to query.org.lsst.ccs.drivers.commons.DriverException - for I/O errors.public void setClock(long epochSecond)
throws org.lsst.ccs.drivers.commons.DriverException
public long getClock()
throws org.lsst.ccs.drivers.commons.DriverException
public void setDeviceLocationIndex(int index)
throws org.lsst.ccs.drivers.commons.DriverException
setDeviceLocationIndex in interface Hardwareindex - The index (lowest = 1).org.lsst.ccs.drivers.commons.DriverException - for I/O errors.public String getDeviceLocationName() throws org.lsst.ccs.drivers.commons.DriverException
getDeviceLocationName in interface Hardwareorg.lsst.ccs.drivers.commons.DriverException - for I/O errors.Copyright © 2016 LSST. All rights reserved.