|
|
 |
|
|
 |
MbusAsciiSlaveProtocol Class Reference
[Serial Protocols]
Inheritance diagram for MbusAsciiSlaveProtocol:
Collaboration diagram for MbusAsciiSlaveProtocol:
List of all members.
Detailed Description
Modbus ASCII Slave Protocol class.
This class realises the Modbus ASCII slave protocol. It provides functions to start-up and to execute the server engine which includes opening and closing of the serial port. Upon receipt of a valid master query the server engine calls Data Provider methods to exchange data with the user application. For a more detailed description which Modbus data and control functions have been implemented in the server engine see section Server Functions common to all Protocol Flavours.
It is possible to instantiate multiple instances for establishing multiple connections on different serial ports (They should be executed in separate threads).
- Version:
- 1.0
- See also:
- Server Functions common to all Protocol Flavours, MbusSlaveServer
|
Serial Server Management Functions |
| virtual int | startupServer (const char *const portName, long baudRate, int dataBits, int stopBits, int parity) |
| | Puts the Modbus server into operation.
|
| int | startupServer (const char *const portName, long baudRate) |
| | Puts the Modbus RTU server into operation and opens the associated serial port with default port parameters.
|
| virtual int | startupServer (int slaveAddr, const char *const portName, long baudRate, int dataBits, int stopBits, int parity) |
| | Puts the Modbus server into operation using a single slave address and data table.
|
| int | startupServer (int slaveAddr, const char *const portName, long baudRate) |
| | Puts the Modbus RTU server into operation and opens the associated serial port with default port parameters.
|
| void | shutdownServer () |
| | Shuts down the Modbus server.
|
| int | isStarted () |
| | Returns if server has been started up.
|
| virtual int | enableRs485Mode (int rtsDelay) |
| | Enables RS485 mode.
|
Server Management Functions |
| int | addDataTable (int slaveAddr, MbusDataTableInterface *dataTablePtr) |
| | Associates a protocol object with a Data Provider and a slave address.
|
Protocol Configuration |
| long | setTimeout (long timeOut) |
| | Configures master transmit time-out supervision.
|
| long | getTimeout () |
| | Returns the master time-out supervision value.
|
Transmission Statistic Functions |
| unsigned long | getTotalCounter () |
| | Returns how often a message transfer has been executed.
|
|
void | resetTotalCounter () |
| | Resets total message transfer counter.
|
| unsigned long | getSuccessCounter () |
| | Returns how often a message transfer was successful.
|
|
void | resetSuccessCounter () |
| | Resets successful message transfer counter.
|
Utility Functions |
| static char * | getPackageVersion () |
| | Returns the package version number.
|
Public Types |
| enum | { SER_DATABITS_7 = SerialPort::SER_DATABITS_7,
SER_DATABITS_8 = SerialPort::SER_DATABITS_8
} |
| enum | { SER_STOPBITS_1 = SerialPort::SER_STOPBITS_1,
SER_STOPBITS_2 = SerialPort::SER_STOPBITS_2
} |
| enum | { SER_PARITY_NONE = SerialPort::SER_PARITY_NONE,
SER_PARITY_EVEN = SerialPort::SER_PARITY_EVEN,
SER_PARITY_ODD = SerialPort::SER_PARITY_ODD
} |
Public Member Functions |
| | MbusAsciiSlaveProtocol () |
| | Constructs a MbusAsciiSlaveProtocol object.
|
| | MbusAsciiSlaveProtocol (MbusDataTableInterface *dataTablePtr) |
| | Constructs a MbusAsciiSlaveProtocol object and associates it with a Data Provider.
|
| int | serverLoop () |
| | Modbus ASCII slave server loop.
|
Protected Types |
| enum | { SER_RS232,
SER_RS485
} |
Member Enumeration Documentation
anonymous enum [inherited] |
|
|
|
- Enumeration values:
-
| SER_DATABITS_7 |
7 data bits |
| SER_DATABITS_8 |
8 data bits |
|
anonymous enum [inherited] |
|
|
|
- Enumeration values:
-
| SER_STOPBITS_1 |
1 stop bit |
| SER_STOPBITS_2 |
2 stop bits |
|
anonymous enum [inherited] |
|
|
|
- Enumeration values:
-
| SER_PARITY_NONE |
No parity. |
| SER_PARITY_EVEN |
Even parity. |
| SER_PARITY_ODD |
Odd parity. |
|
anonymous enum [protected, inherited] |
|
|
|
- Enumeration values:
-
| SER_RS232 |
RS232 mode w/o RTS/CTS handshake. |
| SER_RS485 |
RS485 mode: RTS enables/disables transmitter. |
|
Constructor & Destructor Documentation
|
|
Constructs a MbusAsciiSlaveProtocol object.
The association with a Data Provider is done after construction using the addDataTable method.
- Parameters:
-
| dataTablePtr | Modbus data table pointer. Must point to a Data Provider object derived from the MbusDataTableInterface class. The Data Provider is the interface between your application data and the Modbus network. |
|
|
|
Constructs a MbusAsciiSlaveProtocol object and associates it with a Data Provider.
Function is kept for compatibility with previous API versions, do not use for new implementations.
- Parameters:
-
| dataTablePtr | Modbus data table pointer. Must point to a Data Provider object derived from the MbusDataTableInterface class. The Data Provider is the interface between your application data and the Modbus network. |
- Deprecated:
- This function is deprecated. The preferred way of assigning a dataTable is using the default constructor and configuring data table and slave address using addDataTable method.
|
Member Function Documentation
| int serverLoop |
( |
|
) |
[virtual] |
|
|
|
Modbus ASCII slave server loop.
This server loop must be called continuously. It must not be blocked. The server has to be started before calling the serverLoop() method.
- Returns:
- FTALK_SUCCESS on success or error code. See Protocol Errors and Exceptions for a list of error codes.
Implements MbusSlaveServer. |
| int startupServer |
( |
const char *const |
portName, |
|
|
long |
baudRate, |
|
|
int |
dataBits, |
|
|
int |
stopBits, |
|
|
int |
parity |
|
) |
[virtual, inherited] |
|
|
|
Puts the Modbus server into operation.
This function opens the serial port. After the port has been opened queries from a Modbus master will be processed.
- Parameters:
-
| portName | Serial port identifier (e.g. "COM1", "/dev/ser1 or /dev/ttyS0") |
| baudRate | The port baudRate in bps (typically 1200 - 9600). |
| dataBits | Must be SER_DATABITS_8 for RTU |
| stopBits | SER_STOPBITS_1: 1 stop bit, SER_STOPBITS_2: 2 stop bits |
| parity | SER_PARITY_NONE: no parity, SER_PARITY_ODD: odd parity, SER_PARITY_EVEN: even parity |
- Returns:
- FTALK_SUCCESS on success or error code. See Protocol Errors and Exceptions for a list of error codes.
Reimplemented in MbusRtuSlaveProtocol. |
| int startupServer |
( |
const char *const |
portName, |
|
|
long |
baudRate |
|
) |
[inherited] |
|
|
|
Puts the Modbus RTU server into operation and opens the associated serial port with default port parameters.
This function opens the serial port with 8 databits, 1 stopbit and no parity and initialises the server engine.
- Parameters:
-
| portName | Serial port identifier (e.g. "COM1", "/dev/ser1" or "/dev/ttyS0") |
| baudRate | The port baudRate in bps (typically 1200 - 9600). |
- Returns:
- FTALK_SUCCESS on success or error code. See Protocol Errors and Exceptions for a list of error codes.
|
| int startupServer |
( |
int |
slaveAddr, |
|
|
const char *const |
portName, |
|
|
long |
baudRate, |
|
|
int |
dataBits, |
|
|
int |
stopBits, |
|
|
int |
parity |
|
) |
[virtual, inherited] |
|
|
|
Puts the Modbus server into operation using a single slave address and data table.
This function opens the serial port. After the port has been opened queries from a Modbus master will be processed.
Function is kept for compatibility with previous API versions, do not use for new implementations.
- Parameters:
-
| slaveAddr | Modbus slave address for server to listen on (1-255) |
| portName | Serial port identifier (e.g. "COM1", "/dev/ser1 or /dev/ttyS0") |
| baudRate | The port baudRate in bps (typically 1200 - 9600). |
| dataBits | Must be SER_DATABITS_8 for RTU |
| stopBits | SER_STOPBITS_1: 1 stop bit, SER_STOPBITS_2: 2 stop bits |
| parity | SER_PARITY_NONE: no parity, SER_PARITY_ODD: odd parity, SER_PARITY_EVEN: even parity |
- Returns:
- FTALK_SUCCESS on success or error code. See Protocol Errors and Exceptions for a list of error codes.
- Deprecated:
- This function is deprecated. The preferred way of assigning a slave address is using the default constructor and configuring data table and slave address using addDataTable method.
Reimplemented in MbusRtuSlaveProtocol. |
| int startupServer |
( |
int |
slaveAddr, |
|
|
const char *const |
portName, |
|
|
long |
baudRate |
|
) |
[inherited] |
|
|
|
Puts the Modbus RTU server into operation and opens the associated serial port with default port parameters.
This function opens the serial port with 8 databits, 1 stopbit and no parity and initialises the server engine.
Function is kept for compatibility with previous API versions, do not use for new implementations.
- Parameters:
-
| slaveAddr | Modbus slave address for server to listen on (1-255) |
| portName | Serial port identifier (e.g. "COM1", "/dev/ser1" or "/dev/ttyS0") |
| baudRate | The port baudRate in bps (typically 1200 - 9600). |
- Returns:
- FTALK_SUCCESS on success or error code. See Protocol Errors and Exceptions for a list of error codes.
- Deprecated:
- This function is deprecated. The preferred way of assigning a slave address is using the default constructor and configuring data table and slave address using addDataTable method.
|
| void shutdownServer |
( |
|
) |
[virtual, inherited] |
|
|
|
Shuts down the Modbus server.
This function also closes the serial port.
Reimplemented from MbusSlaveServer. |
| int isStarted |
( |
|
) |
[virtual, inherited] |
|
|
|
Returns if server has been started up.
- Return values:
-
| true | = started |
| false | = shutdown |
Implements MbusSlaveServer. |
| int enableRs485Mode |
( |
int |
rtsDelay |
) |
[virtual, 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. |
- Return values:
-
| FTALK_SUCCESS | Success |
| FTALK_ILLEGAL_ARGUMENT_ERROR | Argument out of range |
| FTALK_ILLEGAL_STATE_ERROR | Protocol is already open |
|
|
 |
|