A QCanSocket is used for connection to an existing QCanNetwork. Connection can be made eiter via LocalSockets or WebSockets. The number of either socket type that can be connected to a QCanNetwork is limited by the symbols QCAN_LOCAL_SOCKET_MAX and QCAN_WEB_SOCKET_MAX during compile time.
Upon creation, the socket is in an unconnected state. The current socket state can be evaluated with isConnected() and error(). Each CAN socket has an unique identifier for socket management (uuidString()).
#include <qcan_socket.hpp>
Inherits QObject.
◆ QCanSocket()
| QCanSocket::QCanSocket |
( |
QObject * | pclParentV = nullptr | ) |
|
- Parameters
-
| [in] | pclParentV | Pointer to QObject parent class |
Create a new CAN socket which is in unconnected state.
◆ connected
| void QCanSocket::connected |
( |
void | | ) |
|
|
signal |
This signal is emitted after connectNetwork() has been called and a connection has been successfully established.
◆ connectNetwork()
- Parameters
-
| [in] | teChannelR | CAN channel |
- Returns
true if connection is possible
- See also
- disconnectNetwork()
Connect the CAN socket to a CAN network (class QCanNetwork). The signal connected() is used on connection to the CAN network. On failure, the reason can be evaluated by the error() signal. A socket can connect only once to a single CAN network. If the socket is already connected, the method returns false.
The connection is made to QHostAddress::LocalHost, using the port QCAN_WEB_SOCKET_DEFAULT_PORT. The host address can be changed with setHostAddress().
◆ disconnected
| void QCanSocket::disconnected |
( |
void | | ) |
|
|
signal |
This signal is emitted when the socket has been disconnected.
◆ disconnectNetwork()
| void QCanSocket::disconnectNetwork |
( |
void | | ) |
|
◆ error()
| QAbstractSocket::SocketError QCanSocket::error |
( |
| ) |
const |
- Returns
- SocketError value
Returns the type of error that last occurred.
◆ errorOccurred
| void QCanSocket::errorOccurred |
( |
QAbstractSocket::SocketError | teSockErrorV | ) |
|
|
signal |
- Parameters
-
| [in] | teSockErrorV | Type of error |
This signal is emitted after an error occurred. The teSockErrorV parameter describes the type of error that occurred.
◆ errorString()
| QString QCanSocket::errorString |
( |
| ) |
const |
- Returns
- Error string
Returns a description of error that last occurred.
◆ framesAvailable()
| uint32_t QCanSocket::framesAvailable |
( |
void | | ) |
const |
- Returns
- Number of CAN frames available
- See also
- read()
Returns the number of CAN frames available on the socket.
◆ isConnected()
| bool QCanSocket::isConnected |
( |
void | | ) |
const |
|
inline |
- Returns
true if socket is connected
The function returns the connection state of the socket: true if connected to a CAN network, false if not connected.
◆ read()
| bool QCanSocket::read |
( |
QCanFrame & | clFrameR | ) |
|
- Parameters
-
| [out] | clFrameR | Reference to CAN frame |
- Returns
true if CAN frame was read
- See also
- write()
The function reads a CAN frame from the socket and places the result in clFrameDataR. If no CAN frame is available, the function returns false.
◆ readyRead
| void QCanSocket::readyRead |
( |
void | | ) |
|
|
signal |
This signal is emitted when CAN frames are available for reading from the socket.
◆ setHostAddress()
- Parameters
-
| [in] | clHostAddressV | Host address |
| [in] | uwPortV | Port number of server |
- See also
- connectNetwork()
Set the host address of the CAN server. The host address can only be modified in unconnected state.
◆ state()
- Returns
- CAN error state
Get the actual CAN error state, which is defined by the QCan::CAN_State_e enumeration.
◆ uuid()
| QUuid QCanSocket::uuid |
( |
void | | ) |
const |
|
inline |
- Returns
- UUID
Get the Universal unique identifier of the CAN socket.
◆ uuidString()
| QString QCanSocket::uuidString |
( |
void | | ) |
const |
|
inline |
- Returns
- UUID string
Get the Universal unique identifier of the CAN socket.
◆ write()
| bool QCanSocket::write |
( |
const QCanFrame & | clFrameR | ) |
|
- Parameters
-
| [in] | clFrameR | Reference to CAN frame |
- Returns
true if CAN frame was written
- See also
- read()
The function writes the CAN frame clFrameR to the CAN socket. If writing fails, the function returns false.