public class ASCIIModbus extends Object implements Hardware
Built atop the CCS Serial 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 by encodeFrame(). 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.
| Constructor and Description |
|---|
ASCIIModbus(org.lsst.ccs.drivers.serial.SerialPort port,
java.time.Duration timeout,
boolean debug)
Saves a reference to the open serial port used for the device and saves the given
parameters.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
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 |
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 ASCIIModbus(org.lsst.ccs.drivers.serial.SerialPort port,
java.time.Duration timeout,
boolean debug)
port - The open SerialPort.timeout - How long to wait for a response to a command.debug - Only if true, all frames sent and received will be printed on stdout.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 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.Copyright © 2016 LSST. All rights reserved.