|
||||||||||
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
public class ModbusProtocolDevice
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 supports RTU and ASCII mode operation.
Field Summary | |
---|---|
static String |
PROTOCOL_CONNECTION_TYPE_ETHER_TCP
|
static String |
PROTOCOL_CONNECTION_TYPE_SERIAL
|
static String |
SERIAL_232
|
static String |
SERIAL_485
|
Fields inherited from interface com.eurotech.framework.protocol.modbus.ModbusProtocolDeviceService |
---|
SERVICE_NAME |
Constructor Summary | |
---|---|
ModbusProtocolDevice()
|
Method Summary | |
---|---|
protected void |
activate(org.osgi.service.component.ComponentContext componentContext)
|
void |
configureConnection(Properties connectionConfig)
two connection types are available, PROTOCOL_CONNECTION_TYPE_SERIAL (SERIAL MODE 232 or 485) and PROTOCOL_CONNECTION_TYPE_ETHER_TCP. |
void |
configureProtocol(Properties protocolConfig)
modbus protocol configuration. |
void |
connect()
attempt to connect to the field device using the provided configuration. |
protected void |
deactivate(org.osgi.service.component.ComponentContext componentContext)
|
void |
disconnect()
attempt to disconnect from the field device. |
ModbusCommEvent |
getCommEventCounter()
Modbus function 11 (0x0B) Get a status word and an event count from the device. Return values in a ModbusCommEvent. |
ModbusCommEvent |
getCommEventLog()
Modbus function 12 (0x0C) Get a status word, an event count, a message count and a list of event bytes from the device. Return values in a ModbusCommEvent. |
int |
getConnectStatus()
for expedience, can test the status of the connection prior to attempting a command. |
NmeaPosition |
getNmeaPosition()
Return NMEA Position of the device |
org.osgi.util.position.Position |
getPosition()
Return OSGI Position of the device |
String |
getProtocolName()
get the name "modbus" for this protocol |
String |
getUnitAddress()
Modbus unit addresses must always be in the range of 1-255 |
boolean[] |
readCoils(int dataAddress,
int count)
Modbus function 01 Read 1 to 2000 contiguous status of coils from the attached field device. |
boolean[] |
readDiscreteInputs(int dataAddress,
int count)
Modbus function 02 Read 1 to 2000 contiguous status of discrete inputs from the attached field device. |
boolean[] |
readExceptionStatus()
Modbus function 07 read the content of 8 Exception Status outputs in the field device. |
int[] |
readHoldingRegisters(int dataAddress,
int count)
Modbus function 03 Read contents of 1 to 125 contiguous block of holding registers from the attached field device. |
int[] |
readInputRegisters(int dataAddress,
int count)
Modbus function 04 Read contents of 1 to 125 contiguous block of input registers from the attached field device. |
void |
setConnectionFactory(org.osgi.service.io.ConnectionFactory connectionFactory)
|
void |
setUsbService(UsbService usbService)
|
String |
toString()
get the unit name registered for this instance |
void |
unsetConnectionFactory(org.osgi.service.io.ConnectionFactory connectionFactory)
|
void |
unsetUsbService(UsbService usbService)
|
void |
writeMultipleCoils(int dataAddress,
boolean[] data)
Modbus function 15 (0x0F) write multiple coils in a sequence of coils to either ON or OFF in the attached field device. |
void |
writeMultipleRegister(int dataAddress,
int[] data)
Modbus function 16 (0x10) write a block of contiguous registers (1 to 123) in the attached field device. |
void |
writeSingleCoil(int dataAddress,
boolean data)
Modbus function 05 write a single output to either ON or OFF in the attached field device. |
void |
writeSingleRegister(int dataAddress,
int data)
Modbus function 06 write a single holding register in the attached field device. |
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 SERIAL_232
public static final String SERIAL_485
public static final String PROTOCOL_CONNECTION_TYPE_ETHER_TCP
Constructor Detail |
---|
public ModbusProtocolDevice()
Method Detail |
---|
public void setConnectionFactory(org.osgi.service.io.ConnectionFactory connectionFactory)
public void unsetConnectionFactory(org.osgi.service.io.ConnectionFactory connectionFactory)
public void setUsbService(UsbService usbService)
public void unsetUsbService(UsbService usbService)
protected void activate(org.osgi.service.component.ComponentContext componentContext)
protected void deactivate(org.osgi.service.component.ComponentContext componentContext)
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" or "ASCII" |
respTimeout | maximum time, in milliseconds, to wait for a response to a command |
configureProtocol
in interface ModbusProtocolDeviceService
protocolConfig
- (key/value pairing directly from configuration file)ModbusProtocolException
public void configureConnection(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 |
serialMode | SERIAL_232 or SERIAL_485 |
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 interface ModbusProtocolDeviceService
connectionConfig
- (key/value pairing directly from configuration file)ModbusProtocolException
public String toString()
toString
in interface ModbusProtocolDeviceService
toString
in class Object
Object.toString()
public String getProtocolName()
getProtocolName
in interface ModbusProtocolDeviceService
public String getUnitAddress()
getUnitAddress
in interface ModbusProtocolDeviceService
public void connect() throws ModbusProtocolException
ModbusProtocolDeviceService
Refer to getConnectStatus
to determine if the
connection is completed.
All protocols must implement this method.
connect
in interface ModbusProtocolDeviceService
ModbusProtocolException
public void disconnect()
ModbusProtocolDeviceService
All protocols must implement this method.
disconnect
in interface ModbusProtocolDeviceService
ModbusProtocolDeviceService.getConnectStatus()
public int getConnectStatus()
ModbusProtocolDeviceService
All protocols must implement this method.
getConnectStatus
in interface ModbusProtocolDeviceService
EsfConnectionStatus
.public org.osgi.util.position.Position getPosition()
ModbusProtocolDeviceService
getPosition
in interface ModbusProtocolDeviceService
Position
public NmeaPosition getNmeaPosition()
ModbusProtocolDeviceService
getNmeaPosition
in interface ModbusProtocolDeviceService
NmeaPosition
public boolean[] readCoils(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDeviceService
readCoils
in interface ModbusProtocolDeviceService
dataAddress
- starting addresscount
- quantity of coils
ModbusProtocolException
public boolean[] readDiscreteInputs(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDeviceService
readDiscreteInputs
in interface ModbusProtocolDeviceService
dataAddress
- starting addresscount
- quantity of inputs
ModbusProtocolException
public void writeSingleCoil(int dataAddress, boolean data) throws ModbusProtocolException
ModbusProtocolDeviceService
writeSingleCoil
in interface ModbusProtocolDeviceService
dataAddress
- Output address.data
- Output value (boolean) to write.
ModbusProtocolException
public void writeMultipleCoils(int dataAddress, boolean[] data) throws ModbusProtocolException
ModbusProtocolDeviceService
writeMultipleCoils
in interface ModbusProtocolDeviceService
dataAddress
- Starting Output address.data
- Outputs value (array of boolean) to write.
ModbusProtocolException
public int[] readHoldingRegisters(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDeviceService
readHoldingRegisters
in interface ModbusProtocolDeviceService
dataAddress
- starting addresscount
- quantity of registers (maximum 0x7D)
ModbusProtocolException
public int[] readInputRegisters(int dataAddress, int count) throws ModbusProtocolException
ModbusProtocolDeviceService
readInputRegisters
in interface ModbusProtocolDeviceService
dataAddress
- starting addresscount
- quantity of registers (maximum 0x7D)
ModbusProtocolException
public void writeSingleRegister(int dataAddress, int data) throws ModbusProtocolException
ModbusProtocolDeviceService
writeSingleRegister
in interface ModbusProtocolDeviceService
dataAddress
- Output address.data
- Output value (2 bytes) to write.
ModbusProtocolException
public void writeMultipleRegister(int dataAddress, int[] data) throws ModbusProtocolException
ModbusProtocolDeviceService
writeMultipleRegister
in interface ModbusProtocolDeviceService
dataAddress
- Output address.data
- Registers value (array of int converted in 2 bytes values) to write.
ModbusProtocolException
public boolean[] readExceptionStatus() throws ModbusProtocolException
ModbusProtocolDeviceService
readExceptionStatus
in interface ModbusProtocolDeviceService
ModbusProtocolException
public ModbusCommEvent getCommEventCounter() throws ModbusProtocolException
ModbusProtocolDeviceService
getCommEventCounter
in interface ModbusProtocolDeviceService
ModbusProtocolException
public ModbusCommEvent getCommEventLog() throws ModbusProtocolException
ModbusProtocolDeviceService
getCommEventLog
in interface ModbusProtocolDeviceService
ModbusProtocolException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |