The QModbusDevice class is the base class for Modbus classes, QModbusServer and QModbusClient . 更多...
| 頭: | #include <QModbusDevice> |
| qmake: | QT += serialbus |
| Since: | Qt 5.8 |
| 繼承: | QObject |
| 繼承者: | QModbusClient and QModbusServer |
| enum | ConnectionParameter { SerialPortNameParameter, SerialParityParameter, SerialBaudRateParameter, SerialDataBitsParameter, ..., UserParameter } |
| enum | Error { NoError, ReadError, WriteError, ConnectionError, ..., UnknownError } |
| enum | State { UnconnectedState, ConnectingState, ConnectedState, ClosingState } |
| QModbusDevice (QObject * parent = nullptr) | |
| virtual | ~QModbusDevice () |
| bool | connectDevice () |
| QVariant | connectionParameter (int parameter ) const |
| void | disconnectDevice () |
| QModbusDevice::Error | error () const |
| QString | errorString () const |
| void | setConnectionParameter (int parameter , const QVariant & value ) |
| QModbusDevice::State | state () const |
| void | errorOccurred (QModbusDevice::Error error ) |
| void | stateChanged (QModbusDevice::State state ) |
| const QMetaObject | staticMetaObject |
| virtual void | close () = 0 |
| virtual bool | open () = 0 |
| void | setError (const QString & errorText , QModbusDevice::Error error ) |
| void | setState (QModbusDevice::State newState ) |
The QModbusDevice class is the base class for Modbus classes, QModbusServer and QModbusClient .
This enum describes the possible values that can be set for a Modbus device connection.
The general purpose value (and the associated types) are:
| 常量 | 值 | 描述 |
|---|---|---|
QModbusDevice::SerialPortNameParameter
|
0
|
This parameter holds the serial port used for device communication, e.g. COM1.
QString
|
QModbusDevice::SerialParityParameter
|
1
|
此參數保持奇偶校驗模式。
QSerialPort::Parity
|
QModbusDevice::SerialBaudRateParameter
|
2
|
This parameter holds the data baud rate for the communication.
QSerialPort::BaudRate
|
QModbusDevice::SerialDataBitsParameter
|
3
|
此參數保持幀中的數據位。
QSerialPort::DataBits
|
QModbusDevice::SerialStopBitsParameter
|
4
|
This parameter holds the number of stop bits in a frame.
QSerialPort::StopBits
|
QModbusDevice::NetworkPortParameter
|
5
|
此參數保持網絡端口。
int
|
QModbusDevice::NetworkAddressParameter
|
6
|
This parameter holds the host address for network communication.
QString
|
用戶選項:
| 常量 | 值 | 描述 |
|---|---|---|
QModbusDevice::UserParameter
|
0x100
|
The first parameter that can be used for user-specific purposes.
QVariant
|
此枚舉描述所有可能的錯誤條件。
| 常量 | 值 | 描述 |
|---|---|---|
QModbusDevice::NoError
|
0
|
沒有齣現錯誤。 |
QModbusDevice::ReadError
|
1
|
在讀取操作期間齣現錯誤。 |
QModbusDevice::WriteError
|
2
|
在寫入操作期間齣現錯誤。 |
QModbusDevice::ConnectionError
|
3
|
An error occurred when attempting to open the backend. |
QModbusDevice::ConfigurationError
|
4
|
An error occurred when attempting to set a configuration parameter. |
QModbusDevice::TimeoutError
|
5
|
A timeout occurred during I/O. An I/O operation did not finish within a given time frame. |
QModbusDevice::ProtocolError
|
6
|
齣現 Modbus 特定協議錯誤。 |
QModbusDevice::ReplyAbortedError
|
7
|
The reply was aborted due to a disconnection of the device. |
QModbusDevice::UnknownError
|
8
|
齣現未知錯誤。 |
此枚舉描述所有可能的設備狀態。
| 常量 | 值 | 描述 |
|---|---|---|
QModbusDevice::UnconnectedState
|
0
|
設備已斷開連接。 |
QModbusDevice::ConnectingState
|
1
|
設備正在連接。 |
QModbusDevice::ConnectedState
|
2
|
設備已連接到 Modbus 網絡。 |
QModbusDevice::ClosingState
|
3
|
設備正在關閉。 |
構造 Modbus 設備采用指定 parent .
[虛擬]
QModbusDevice::
~QModbusDevice
()
銷毀 QModbusDevice 實例
[pure virtual protected]
void
QModbusDevice::
close
()
This function is responsible for closing the Modbus connection. The implementation must ensure that the instance's state () 被設為 QModbusDevice::UnconnectedState .
另請參閱 disconnectDevice ().
把設備連接到 Modbus 網絡。返迴
true
若成功初啓連接進程;否則
false
。最終連接成功,確認要求
state
() 改變成
QModbusDevice::ConnectedState
.
此函數調用 open () 作為其實現的一部分。
另請參閱 open ().
返迴的值關聯給定連接 parameter 。返迴值可以為空。
默認情況下
QModbusDevice
is initialized with some common values. The serial port settings are even parity, a baud rate of 19200 bits per second, eight data bits and one stop bit. The network settings for the host address is set to local host and port to 502.
注意: 要成功連接串行, SerialPortNameParameter 需要被設為有效通信端口。有效串口的有關信息可以獲得從 QSerialPortInfo .
注意: 若設備已連接,在重新連接設備後考慮設置。
另請參閱 setConnectionParameter () 和 ConnectionParameter .
斷開設備連接。
此函數調用 close () 作為其實現的一部分。
返迴設備的錯誤狀態。
另請參閱 setError () 和 QModbusDevice::Error .
[signal]
void
QModbusDevice::
errorOccurred
(
QModbusDevice::Error
error
)
This signal is emitted when an error of the type, error ,齣現。
返迴用於設備錯誤的描述性錯誤文本。
另請參閱 QModbusDevice::Error .
[pure virtual protected]
bool
QModbusDevice::
open
()
此函數被調用通過
connectDevice
(). Subclasses must provide an implementation that returns
true
on successful Modbus connection or connection initiation; otherwise returns
false
.
實現必須確保實例的 state () 被設為 QModbusDevice::ConnectingState or QModbusDevice::ConnectedState upon success; otherwise QModbusDevice::UnconnectedState 。通常, QModbusDevice::ConnectingState is used when the connection process reports back asynchronously and QModbusDevice::ConnectedState in case of synchronous connect behavior.
另請參閱 connectDevice ().
設置值為 parameter to value 。若 parameter already exists, the previous value is overwritten. A active or running connection is not affected by such parameter changes.
另請參閱 ConnectionParameter and connectionParameter ().
[protected]
void
QModbusDevice::
setError
(const
QString
&
errorText
,
QModbusDevice::Error
error
)
Sets the error state of the device. ModBus device implementations must use this function in case of an error to set the error type and a descriptive errorText .
另請參閱 error () 和 QModbusDevice::Error .
[protected]
void
QModbusDevice::
setState
(
QModbusDevice::State
newState
)
把設備的狀態設為 newState . Modbus device implementations must use this function to update the device state.
另請參閱 state ().
返迴設備的當前狀態。
另請參閱 setState () 和 stateChanged ().
[signal]
void
QModbusDevice::
stateChanged
(
QModbusDevice::State
state
)
This signal is emitted every time the state of the device changes. The new state is represented by state .