|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.eurotech.framework.protocol.modbus.ModbusProtocolDevice com.eurotech.framework.protocol.modbus.Modbus
public class Modbus
The Modbus protocol implements a subset of the Modbus standard command set. It also provides for the extension of some data typing to allow register pairings to hold 32 bit data (see the configureDataMap for more detail).
The protocol only supports RTU mode operation.
ProtocolDevice
Field Summary | |
---|---|
static String |
PROTOCOL_CONNECTION_TYPE_ETHER_TCP
|
static String |
PROTOCOL_CONNECTION_TYPE_SERIAL
|
Constructor Summary | |
---|---|
Modbus()
creates the default data map |
Method Summary | |
---|---|
void |
configureConnection(org.osgi.service.io.ConnectionFactory connFactory,
Properties connectionConfig)
two connection types are available, PROTOCOL_CONNECTION_TYPE_SERIAL and PROTOCOL_CONNECTION_TYPE_ETHER_TCP. |
void |
configureDataMap(Properties dataConfig)
use of this method is optional, Modbus initializes with a default DataMap. |
void |
configureProtocol(Properties protocolConfig)
modbus protocol configuration. |
void |
connect()
attempt to connect to the field device using the provided configuration. |
void |
disconnect()
attempt to disconnect from the field device. |
int |
getConnectStatus()
for expedience, can test the status of the connection prior to attempting a command. |
String |
getDataType(int dataAddress)
get the primitive data type for the selected address. |
int |
getEndOfRange(int dataAddress)
gets the last address in a contiguous block of the same type data. |
NmeaPosition |
getNmeaPosition()
|
org.osgi.util.position.Position |
getPosition()
|
String |
getProtocolName()
get the name "modbus" for this protocol |
int |
getStartOfRange(int dataAddress)
gets the first address in a contiguous block of the same type data. |
String |
getUnitAddress()
Modbus unit addresses must always be in the range of 1-255 |
boolean |
isAddressMapped(int dataAddress)
validate that the protocol has a mapping for the desired address. |
boolean[] |
readBooleans(int dataAddress,
int count)
read 1 or more boolean points from the attached field device. |
float[] |
readFloats(int dataAddress,
int count)
read 1 or more float points from the attached field device. |
int[] |
readInts(int dataAddress,
int count)
read 1 or more int points from the attached field device. |
short[] |
readShorts(int dataAddress,
int count)
read 1 or more short points from the attached field device. |
long[] |
readUnsignedInts(int dataAddress,
int count)
read 1 or more unsigned int points from the attached field device. |
int[] |
readUnsignedShorts(int dataAddress,
int count)
read 1 or more unsigned short points from the attached field device. |
String |
toString()
get the unit name registered for this instance |
void |
writeBooleans(int dataAddress,
boolean[] data)
write 1 or more boolean values to the attached field device. |
void |
writeFloats(int dataAddress,
float[] data)
write 1 or more float values to the attached field device. |
void |
writeInts(int dataAddress,
int[] data)
write 1 or more int values to the attached field device. |
void |
writeShorts(int dataAddress,
short[] data)
write 1 or more short values to the attached field device. |
void |
writeUnsignedInts(int dataAddress,
long[] data)
write 1 or more unsigned int values to the attached field device. |
void |
writeUnsignedShorts(int dataAddress,
int[] data)
write 1 or more unsigned short values to the attached field device. |
Methods inherited from class com.eurotech.framework.protocol.modbus.ModbusProtocolDevice |
---|
readBytes, readChars, readDoubles, readLongs, readObject, writeBytes, writeChars, writeDoubles, writeLongs, writeObject |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String PROTOCOL_CONNECTION_TYPE_SERIAL
public static final String PROTOCOL_CONNECTION_TYPE_ETHER_TCP
Constructor Detail |
---|
public Modbus()
Method Detail |
---|
public void configureProtocol(Properties protocolConfig) throws ModbusProtocolException
Key | Description |
---|---|
unitName | Name to be returned by toString |
unitAddress | Modbus address of the unit (1-255) |
txMode | Must be set to "RTU", "ASCII" not supported |
respTimeout | maximum time, in milliseconds, to wait for a response to a command |
configureProtocol
in class ModbusProtocolDevice
protocolConfig
- key/value pairing directly from configuration file or may be
generated.
ModbusProtocolException
public void configureConnection(org.osgi.service.io.ConnectionFactory connFactory, Properties connectionConfig) throws ModbusProtocolException
CommConnection
package for more
detail.
Key | Description |
---|---|
connectionType | "SERIAL" (from PROTOCOL_CONNECTION_TYPE_SERIAL). This parameter
indicates the connection type for the configuration. See
CommConnection for more details on serial
port configuration.
|
port | the actual device port, such as "/dev/ttyUSB0" in linux |
baudRate | baud rate to be configured for the port |
stopBits | number of stop bits to be configured for the port |
parity | parity mode to be configured for the port |
bitsPerWord | only RTU mode supported, bitsPerWord must be 8 |
Key | Description |
---|---|
connectionType | "ETHERTCP" (from PROTOCOL_CONNECTION_TYPE_ETHER_TCP). This parameter indicates the connection type for the configurator. |
ipAddress | the 4 octet IP address of the field device (xxx.xxx.xxx.xxx) |
port | port on the field device to connect to |
configureConnection
in class ModbusProtocolDevice
connectionConfig
- key/value pairing directly from configuration file or may be
generated.
ModbusProtocolException
public void configureDataMap(Properties dataConfig) throws ModbusProtocolException
New data maps do not cause the removal of existing data maps, but may displace them or even split them into two separate maps.
See modbusFieldDeviceDataMap
for more detail.
Key | Description |
---|---|
startAddressn | starting address of field as seen by client |
countn | number of readable points in this field |
dataOrdern | data order in data stream |
dataFormationn | Modbus data streams may contain 1 bit, 16 bit or 32 bit data |
modbusDataOffsetn | offset of associated data in the field device |
modbusReadCommandn | the Modbus command used to read the data helps to identify the specific Modbus data |
Key | Description |
---|---|
startAddress0 | 1 |
count0 | 9999 |
dataOrder0 | MODBUS_BOOLEAN_ORDER |
dataFormation0 | BOOLEAN |
modbusDataOffset0 | 0 |
modbusReadCommand0 | READ_COIL_STATUS |
startAddress1 | 10001 |
count1 | 9999 |
dataOrder1 | MODBUS_BOOLEAN_ORDER |
dataFormation1 | BOOLEAN |
modbusDataOffset1 | 0 |
modbusReadCommand1 | READ_INPUT_STATUS |
startAddress2 | 30001 |
count2 | 9999 |
dataOrder2 | MODBUS_WORD_ORDER_BIG_ENDIAN |
dataFormation2 | SINGLE16 |
modbusDataOffset2 | 0 |
modbusReadCommand2 | READ_INPUT_REGS |
startAddress3 | 40001 |
count3 | 65535 |
dataOrder3 | MODBUS_WORD_ORDER_BIG_ENDIAN |
dataFormation3 | SINGLE16 |
modbusDataOffset3 | 0 |
modbusReadCommand3 | READ_HOLDING_REGS |
configureDataMap
in class ModbusProtocolDevice
dataConfig
- key/value pairing directly from configuration file or may be
generated.
ModbusProtocolException
public String toString()
toString
in class ModbusProtocolDevice
Object.toString()
public String getProtocolName()
getProtocolName
in class ModbusProtocolDevice
public String getUnitAddress()
getUnitAddress
in class ModbusProtocolDevice
public void connect() throws ModbusProtocolException
ModbusProtocolDevice
Refer to getConnectStatus
to determine if the
connection is completed.
All protocols must implement this method.
connect
in class ModbusProtocolDevice
ModbusProtocolException
public void disconnect()
ModbusProtocolDevice
All protocols must implement this method.
disconnect
in class ModbusProtocolDevice
ModbusProtocolDevice.getConnectStatus()
public int getConnectStatus()
ModbusProtocolDevice
All protocols must implement this method.
getConnectStatus
in class ModbusProtocolDevice
EsfConnectionStatus
.public String getDataType(int dataAddress) throws ModbusProtocolException
ModbusProtocolDevice
All protocols must implement this method.
getDataType
in class ModbusProtocolDevice
dataAddress
- address of the data point for which the data type is being
requested
PrototocolPrimitiveDataTypes
ModbusProtocolException
public int getEndOfRange(int dataAddress) throws ModbusProtocolException
ModbusProtocolDevice
All protocols must implement this method.
getEndOfRange
in class ModbusProtocolDevice
dataAddress
- may be the first or last address or anywhere n between for the
range determined.
ModbusProtocolException
public int getStartOfRange(int dataAddress) throws ModbusProtocolException
ModbusProtocolDevice
All protocols must implement this method.
getStartOfRange
in class ModbusProtocolDevice
dataAddress
- may be the first or last address or anywhere in between for
the range determined.
ModbusProtocolException
public boolean isAddressMapped(int dataAddress)
ModbusProtocolDevice
All protocols must implement this method.
isAddressMapped
in class ModbusProtocolDevice
dataAddress
- this is the local address, not the field address
public boolean[] readBooleans(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
readBooleans
in class ModbusProtocolDevice
dataAddress
- first point to readcount
- count of points to read
ModbusProtocolException
public float[] readFloats(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
readFloats
in class ModbusProtocolDevice
dataAddress
- first point to readcount
- count of points to read
ModbusProtocolException
public long[] readUnsignedInts(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
readUnsignedInts
in class ModbusProtocolDevice
dataAddress
- first point to readcount
- count of points to read
ModbusProtocolException
public int[] readInts(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
readInts
in class ModbusProtocolDevice
dataAddress
- first point to readcount
- count of points to read
ModbusProtocolException
public int[] readUnsignedShorts(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
readUnsignedShorts
in class ModbusProtocolDevice
dataAddress
- first point to readcount
- count of points to read
ModbusProtocolException
public short[] readShorts(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
readShorts
in class ModbusProtocolDevice
dataAddress
- first point to readcount
- count of points to read
ModbusProtocolException
public void writeBooleans(int dataAddress, boolean[] data) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
writeBooleans
in class ModbusProtocolDevice
dataAddress
- first address to write todata
- array of 1 or more booleans to write. The data will be written
to consecutive addresses starting with dataAddress.
ModbusProtocolException
public void writeFloats(int dataAddress, float[] data) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
writeFloats
in class ModbusProtocolDevice
dataAddress
- first address to write todata
- array of 1 or more floats to write. The data will be written
to consecutive addresses starting with dataAddress.
ModbusProtocolException
public void writeUnsignedInts(int dataAddress, long[] data) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
writeUnsignedInts
in class ModbusProtocolDevice
dataAddress
- first address to write todata
- array of 1 or more longs to write. The data will be written to
consecutive addresses starting with dataAddress.
ModbusProtocolException
public void writeInts(int dataAddress, int[] data) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
writeInts
in class ModbusProtocolDevice
dataAddress
- first address to write todata
- array of 1 or more ints to write. The data will be written to
consecutive addresses starting with dataAddress.
ModbusProtocolException
public void writeUnsignedShorts(int dataAddress, int[] data) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
writeUnsignedShorts
in class ModbusProtocolDevice
dataAddress
- first address to write todata
- array of 1 or more ints to write. The data will be written to
consecutive addresses starting with dataAddress.
ModbusProtocolException
public void writeShorts(int dataAddress, short[] data) throws ModbusProtocolException
ModbusProtocolDevice
Protocols are not required to implement this method.
writeShorts
in class ModbusProtocolDevice
dataAddress
- first address to write todata
- array of 1 or more shorts to write. The data will be written
to consecutive addresses starting with dataAddress.
ModbusProtocolException
public org.osgi.util.position.Position getPosition()
getPosition
in class ModbusProtocolDevice
public NmeaPosition getNmeaPosition()
getNmeaPosition
in class ModbusProtocolDevice
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |