FOCUS Software Engineering has a new name: proconX - Professional Fieldbus Connections   

MbusAsciiMasterProtocol Class Reference
[Serial Protocols]

Inheritance diagram for MbusAsciiMasterProtocol:

Inheritance graph
Collaboration diagram for MbusAsciiMasterProtocol:

Collaboration graph
List of all members.

Detailed Description

Modbus® ASCII Master Protocol.

This class realizes the Modbus ASCII master protocol. It provides functions to open and to close serial port as well as data and control functions which can be used at any time after a serial port has been opened. The data and control functions are organized in three different conformance classes. This implementation implements all functions of conformance class 0 and class 1. In addition some frequently used functions of conformance class 2 are also implemented. This rich function set enables a user to solve nearly every Modbus data transfer problem. For a more detailed description of the data and control functions see section Data and Control Functions for all Protocols.

All functions have been implemented thread-safe. It is also possible to instantiate multiple instances for establishing multiple connections on different serial ports.

Version:
1.1
See also:
mbusmaster


Specialised Serial Port Management Functions

synchronized void openProtocol (String portName, int baudRate, int dataBits, int stopBits, int parity) throws IOException, PortInUseException, UnsupportedCommOperationException
 Opens a Modbus ASCII serial port with specific port parameters.


Serial Port Management Functions

synchronized void openProtocol (String portName, int baudRate) throws Exception, PortInUseException, UnsupportedCommOperationException
 Opens a Modbus serial port with default port parameters.

synchronized void closeProtocol () throws IOException
 Closes the serial port and releases any system resources associated with the port.

boolean isOpen ()
 Returns whether the port is open or not.


Class 0 Modbus Functions

synchronized void writeMultipleRegisters (int slaveAddr, int startRef, short[] regArr) throws IOException, BusProtocolException
 Modbus function 16 (10 hex), Preset Multiple Registers/Write Multiple Registers.

synchronized void writeMultipleRegisters (int slaveAddr, int startRef, int[] int32Arr) throws IOException, BusProtocolException
 Modbus function 16 (10 hex) for 32-bit int data types, Preset Multiple Registers/Write Multiple Registers with int data.

synchronized void writeMultipleRegisters (int slaveAddr, int startRef, float[] float32Arr) throws IOException, BusProtocolException
 Modbus function 16 (10 hex) for 32-bit float data types, Preset Multiple Registers/Write Multiple Registers with float data.

synchronized void readMultipleRegisters (int slaveAddr, int startRef, short[] regArr) throws IOException, BusProtocolException
 Modbus function 3 (03 hex), Read Holding Registers/Read Multiple Registers.

synchronized void readMultipleRegisters (int slaveAddr, int startRef, int[] int32Arr) throws IOException, BusProtocolException
 Modbus function 3 (03 hex) for 32-bit int data types, Read Holding Registers/Read Multiple Registers as int data.

synchronized void readMultipleRegisters (int slaveAddr, int startRef, float[] float32Arr) throws IOException, BusProtocolException
 Modbus function 3 (03 hex) for 32-bit float data types, Read Holding Registers/Read Multiple Registers as float data.


Class 1 Modbus Functions

synchronized void readCoils (int slaveAddr, int startRef, boolean[] bitArr) throws IOException, BusProtocolException
 Modbus function 1 (01 hex), Read Coil Status/Read Coils.

synchronized void readInputDiscretes (int slaveAddr, int startRef, boolean[] bitArr) throws IOException, BusProtocolException
 Modbus function 2 (02 hex), Read Inputs Status/Read Input Discretes.

synchronized void readInputRegisters (int slaveAddr, int startRef, short[] regArr) throws IOException, BusProtocolException
 Modbus function 4 (04 hex), Read Input Registers.

synchronized void readInputRegisters (int slaveAddr, int startRef, int[] int32Arr) throws IOException, BusProtocolException
 Modbus function 4 (04 hex) for 32-bit int data types, Read Input Registers as int data.

synchronized void readInputRegisters (int slaveAddr, int startRef, float[] float32Arr) throws IOException, BusProtocolException
 Modbus function 4 (04 hex) for 32-bit float data types, Read Input Registers as float data.

synchronized void writeCoil (int slaveAddr, int bitAddr, boolean bitVal) throws IOException, BusProtocolException
 Modbus function 5 (05 hex), Force Single Coil/Write Coil.

synchronized void writeSingleRegister (int slaveAddr, int regAddr, short regVal) throws IOException, BusProtocolException
 Modbus function 6 (06 hex), Preset Single Register/Write Single Register.

synchronized byte readExceptionStatus (int slaveAddr) throws IOException, BusProtocolException
 Modbus function 7 (07 hex), Read Exception Status.


Class 2 Modbus Functions

synchronized void forceMultipleCoils (int slaveAddr, int startRef, boolean[] bitArr) throws IOException, BusProtocolException
 Modbus function 15 (0F hex), Force Multiple Coils.

synchronized void maskWriteRegister (int slaveAddr, int regAddr, short andMask, short orMask) throws IOException, BusProtocolException
 Modbus function 22 (16 hex), Mask Write Register.

synchronized void readWriteRegisters (int slaveAddr, int readRef, short[] readArr, int writeRef, short[] writeArr) throws IOException, BusProtocolException
 Modbus function 23 (17 hex), Read/Write Registers.


Vendor Specific Modbus Function Codes

synchronized void readHistoryLog (int slaveAddr, int channelNo, int resolution, short readArr[]) throws IOException, BusProtocolException
 Vendor Specific Modbus function 100 (64 hex), Read History Log.


Protocol Configuration

synchronized void setTimeout (int timeOut)
 Configures time-out.

int getTimeout ()
 Returns the operation time-out value.

synchronized void setPollDelay (int pollDelay)
 Configures poll delay.

int getPollDelay ()
 Returns the poll delay time.

synchronized void setRetryCnt (int retryCnt)
 Configures the automatic retry setting.

int getRetryCnt ()
 Returns the automatic retry count.


Transmission Statistic Functions

synchronized long getTotalCounter ()
 Returns how often a transmit/receive cycle has been executed.

synchronized void resetTotalCounter ()
 Resets total transmit/receive cycle counter.

synchronized long getSuccessCounter ()
 Returns how often a transmit/receive cycle was successful.

synchronized void resetSuccessCounter ()
 Resets successful transmit/receive counter.


Slave Configuration

void configureStandard32BitMode ()
 Configures all slaves for Standard 32-bit Mode.

synchronized void configureStandard32BitMode (int slaveAddr)
 Configures a slave for Standard 32-bit Register Mode.

void configureSingleReg32BitMode ()
 Configures all slaves for Single Register 32-bit Mode.

synchronized void configureSingleReg32BitMode (int slaveAddr)
 Configures all slaves for Single Register 32-bit Mode.

void configureCountFromOne ()
 Configures the reference counting scheme to start with one for all slaves.

synchronized void configureCountFromOne (int slaveAddr)
 Configures a slave's reference counting scheme to start with one.

void configureCountFromZero ()
 Configures the reference counting scheme to start with zero for all slaves.

synchronized void configureCountFromZero (int slaveAddr)
 Configures a slave's reference counting scheme to start with zero.

void configureLittleEndianInts ()
 Disables word swapping for int data type functions for all slaves.

synchronized void configureLittleEndianInts (int slaveAddr)
 Disables word swapping for int data type functions on a per slave basis.

void configureBigEndianInts ()
 Configures int data type functions to do a word swap for all slaves.

synchronized void configureBigEndianInts (int slaveAddr)
 Enables int data type functions to do a word swap on a per slave basis.

void configureLittleEndianFloats ()
 Disables float data type functions to do a word swap for all slaves.

synchronized void configureLittleEndianFloats (int slaveAddr)
 Disables float data type functions to do a word swap on a per slave basis.

void configureSwappedFloats ()
 Configures float data type functions to do a word swap for all slaves.

synchronized void configureSwappedFloats (int slaveAddr)
 Enables float data type functions to do a word swap on a per slave basis.


Static Public Attributes

final int DATABITS_7 = SerialPort.DATABITS_7
 7 data bits

final int DATABITS_8 = SerialPort.DATABITS_8
 8 data bits

final int STOPBITS_1 = SerialPort.STOPBITS_1
 1 stop bit

final int STOPBITS_1_5 = SerialPort.STOPBITS_1_5
 1.5 stop bits

final int STOPBITS_2 = SerialPort.STOPBITS_2
 2 stop bits

final int PARITY_NONE = SerialPort.PARITY_NONE
 no parity

final int PARITY_ODD = SerialPort.PARITY_ODD
 odd parity

final int PARITY_EVEN = SerialPort.PARITY_EVEN
 even parity

final int PARITY_MARK = SerialPort.PARITY_MARK
 mark parity

final int PARITY_SPACE = SerialPort.PARITY_SPACE
 space parity


Member Function Documentation

synchronized void openProtocol String  portName,
int  baudRate,
int  dataBits,
int  stopBits,
int  parity
throws IOException, PortInUseException, UnsupportedCommOperationException
 

Opens a Modbus ASCII serial port with specific port parameters.

This function opens the serial port. After a port has been opened data and control functions can be used.

Note:
The default time-out for the data transfer is 1000 ms.

The default poll delay is 0 ms.

Automatic retries are switched off (retry count is 0).

Parameters:
portName Serial port identifier (e.g. "COM1", "/dev/ser1 or /dev/ttyS0")
baudRate The port baudRate in bps (typically 1200 - 19200)
dataBits DATABITS_7: 7 data bits, DATABITS_8: data bits
stopBits STOPBITS_1: 1 stop bit, STOPBITS_1_5: 1.5 stop bits, STOPBITS_2: 2 stop bits
parity PARITY_NONE: no parity, PARITY_ODD: odd parity, PARITY_EVEN: even parity, PARITY_MARK: mark parity, PARITY_SPACE: space parity
Exceptions:
IOException An I/O error occured
UnsupportedCommOperationException A communication parameter is not supported
PortInUseException Port is already used by somebody else
InvalidParameterException A parameter is invalid

Reimplemented from MbusSerialMasterProtocol.

   Back | Top of page Info | Support | Contact | About   
Information in this document is subject to change without notice. Copyright © 2000-2010 proconX Pty Ltd. All rights reserved.
All product and brand names mentioned on this page may be trademarks or registered trademarks of their respective owners.