FOCUS Software Engineering is now part of proconX   

TMbusRtuMasterProtocol Class Reference
[Serial Protocols]

Inheritance diagram for TMbusRtuMasterProtocol:

Inheritance graph
Collaboration diagram for TMbusRtuMasterProtocol:

Collaboration graph
List of all members.

Detailed Description

Modbus RTU Master Protocol class.

This class realizes the Modbus RTU 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 the protocol has been opened. The data and control functions are organized different conformance classes. For a more detailed description of the data and control functions see section Data and Control Functions for all Protocol Flavours.

It is possible to instantiate multiple instances of this class for establishing multiple connections on different serial ports (They should be executed in separate threads).

Version:
1.1
See also:
mbusmaster

TMbusSerialMasterProtocol, TMbusMasterFunctions


Serial Port Management Functions

 openProtocol ()
 Opens a serial Modbus protocol and the associated serial port with the port parameters configured via properties.

 enableRs485Mode (integer rtsDelay)
 Enables RS485 mode.

string portName
longint baudRate
integer dataBits
integer stopBits
integer parity

Class 0 Modbus Functions

 writeMultipleRegisters (integer slaveAddr, integer startRef, word &*regArr)
 Modbus function 16 (10 hex), Preset Multiple Registers/Write Multiple Registers.

 writeMultipleLongInts (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 16 (10 hex) for 32-bit long int data types, Preset Multiple Registers/Write Multiple Registers with long int data.

 writeMultipleMod10000 (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 16 (10 hex) for 32-bit modulo-10000 long int data types, Preset Multiple Registers/Write Multiple Registers with modulo-10000 long int data.

 writeMultipleFloats (integer slaveAddr, integer startRef, single &*float32Arr)
 Modbus function 16 (10 hex) for 32-bit float data types, Preset Multiple Registers/Write Multiple Registers with float data.

 readMultipleRegisters (integer slaveAddr, integer startRef, word &*regArr)
 Modbus function 3 (03 hex), Read Holding Registers/Read Multiple Registers.

 readMultipleLongInts (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 3 (03 hex) for 32-bit long int data types, Read Holding Registers/Read Multiple Registers as long int data.

 readMultipleMod10000 (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 3 (03 hex) for 32-bit modulo-10000 long int data types, Read Holding Registers/Read Multiple Registers as modulo-10000 long int data.

 readMultipleFloats (integer slaveAddr, integer startRef, single &*float32Arr)
 Modbus function 3 (03 hex) for 32-bit float data types, Read Holding Registers/Read Multiple Registers as float data.


Class 1 Modbus Procedures

 readCoils (integer slaveAddr, integer startRef, boolean &*bitArr)
 Modbus function 1 (01 hex), Read Coil Status/Read Coils.

 readInputDiscretes (integer slaveAddr, integer startRef, boolean &*bitArr)
 Modbus function 2 (02 hex), Read Inputs Status/Read Input Discretes.

 readInputRegisters (integer slaveAddr, integer startRef, word &*regArr)
 Modbus function 4 (04 hex), Read Input Registers.

 readInputLongInts (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 4 (04 hex) for 32-bit long int data types, Read Input Registers as long int data.

 readInputMod10000 (integer slaveAddr, integer startRef, integer &*int32Arr)
 Modbus function 4 (04 hex) for 32-bit modulo-10000 long int data types, Read Input Registers as modulo-10000 long int data.

 readInputFloats (integer slaveAddr, integer startRef, single &*float32Arr)
 Modbus function 4 (04 hex) for 32-bit float data types, Read Input Registers as float data.

 writeCoil (integer slaveAddr, integer bitAddr, boolean bitVal)
 Modbus function 5 (05 hex), Force Single Coil/Write Coil.

 writeSingleRegister (integer slaveAddr, integer regAddr, word regVal)
 Modbus function 6 (06 hex), Preset Single Register/Write Single Register.

 readExceptionStatus (integer slaveAddr, byte &statusByte)
 Modbus function 7 (07 hex), Read Exception Status.


Class 2 Modbus Procedures

 forceMultipleCoils (integer slaveAddr, integer startRef, boolean &*bitArr)
 Modbus function 15 (0F hex), Force Multiple Coils.

 maskWriteRegister (integer slaveAddr, integer regAddr, word andMask, word orMask)
 Modbus function 22 (16 hex), Mask Write Register.

 readWriteRegisters (integer slaveAddr, integer readRef, word &*readArr, integer writeRef, word &*writeArr)
 Modbus function 23 (17 hex), Read/Write Registers.


Protocol Configuration

 setTimeout (const integer timeOut)
 Configures time-out.

integer getTimeout ()
 Returns the time-out value.

 setPollDelay (const integer pollDelay)
 Configures poll delay.

integer getPollDelay ()
 Returns the poll delay time.

 setRetryCnt (const integer retryCnt)
 Configures the automatic retry setting.

integer getRetryCnt ()
 Returns the automatic retry count.

integer timeout
integer pollDelay
integer retryCnt
boolean bigEndianInts
boolean swappedFloats

Transmission Statistic Functions

cardinal getTotalCounter ()
 Returns how often a message transfer has been executed.

 resetTotalCounter ()
 Resets total message transfer counter.

cardinal getSuccessCounter ()
 Returns how often a message transfer was successful.

 resetSuccessCounter ()
 Resets successful message transfer counter.


Word Order Configuration

 configureBigEndianInts ()
 Configures int data type functions to do a word swap.

 configureSwappedFloats ()
 Configures float data type functions to do a word swap.

 configureLittleEndianInts ()
 Configures int data type functions not to do a word swap.

 configureIeeeFloats ()
 Configures float data type functions not to do a word swap.


Public Member Functions

 TMbusRtuMasterProtocol (TComponent aOwner)
 Constructs a TMbusRtuMasterProtocol object and initialises its data.

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

 closeProtocol ()
 Closes an open protocol including any associated communication resources (COM ports or sockets).

string getPackageVersion ()
 Returns the package version number.


Constructor & Destructor Documentation

TMbusRtuMasterProtocol TComponent  aOwner  ) 
 

Constructs a TMbusRtuMasterProtocol object and initialises its data.

Exceptions:
EOutOfResources Creation of class failed


Member Function Documentation

openProtocol  )  [inherited]
 

Opens a serial Modbus protocol and the associated serial port with the port parameters configured via properties.

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

Exceptions:
EInOutError An I/O error occurred
EOpenErr The serial port does not exist
EPortAlreadyOpen Port is already used by somedbody else
EPortNoAccess No permission to access serial
EIllegalArgumentError A parameter is invalid

enableRs485Mode integer  rtsDelay  )  [inherited]
 

Enables RS485 mode.

In RS485 mode the RTS signal can be used to enable and disable the transmitter of a RS232/RS485 converter. The RTS signal is asserted before sending data. It is cleared after the transmit buffer has been emptied and in addition the specified delay time has elapsed. The delay time is necessary because even the transmit buffer is already empty, the UART's FIFO will still contain unsent characters.

Warning:
The use of RTS controlled RS232/RS485 converters should be avoided if possible. It is difficult to determine the exact time when to switch off the transmitter with non real-time operating systems like Windows and Linux. If it is switched off to early characters might still sit in the FIFO or the transmit register of the UART and these characters will be lost. Hence the slave will not recognize the message. On the other hand if it is switched off too late then the slave's message is corrupted and the master will not recognize the message.
Remarks:
The delay value is indicative only and not guaranteed to be maintained. How precise it is followed depends on the operating system used, it's scheduling priority and it's system timer resolution.
Note:
A protocol must be closed in order to configure it.
Parameters:
rtsDelay Delay time in ms (Range: 0 - 100000) which applies after the transmit buffer is empty. 0 disables this mode.
Exceptions:
EIllegalStateError Protocol is already open
EIllegalArgumentError A parameter is out of range

boolean isOpen  )  [inherited]
 

Returns whether the protocol is open or not.

Return values:
true = open
false = closed


Member Data Documentation

string portName [inherited]
 

"COM1" or "/dev/ttyS0")

Note:
A protocol must be closed in order to configure it.
See also:
fPortName For reading

fPortName For writing

longint baudRate [inherited]
 

Note:
A protocol must be closed in order to configure it.
See also:
fBaudRate For reading

fBaudRate For writing

integer dataBits [inherited]
 

SER_DATABITS_7: 7 data bits (ASCII protocol only), SER_DATABITS_8: data bits

Note:
A protocol must be closed in order to configure it.
See also:
fDataBits For reading

fDataBits For writing

integer stopBits [inherited]
 

SER_STOPBITS_1: 1 stop bit, SER_STOPBITS_2: 2 stop bits

Note:
A protocol must be closed in order to configure it.
See also:
fStopBits For reading

fStopBits For writing

integer parity [inherited]
 

SER_PARITY_NONE: no parity, SER_PARITY_ODD: odd parity, SER_PARITY_EVEN: even parity

Note:
A protocol must be closed in order to configure it.
See also:
fParity For reading

fParity For writing

   Back | Top of page Info | Support | Contact | About   
Information in this document is subject to change without notice. Copyright © 2000-2013 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.