CANpie FD
CAN programming interface environment - Version 3.08
Signals | Public Member Functions
QCanSocket Class Reference

Detailed Description

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()).

+ Inheritance diagram for QCanSocket:

Signals

void connected (void)
 
void disconnected (void)
 
void error (QAbstractSocket::SocketError teSockErrorV)
 
void readyRead (void)
 

Public Member Functions

 QCanSocket (QObject *pclParentV=Q_NULLPTR)
 
bool connectNetwork (const CAN_Channel_e &teChannelR)
 
void disconnectNetwork (void)
 
QAbstractSocket::SocketError error () const
 
QString errorString () const
 
int32_t framesAvailable (void) const
 
bool isConnected (void) const
 
bool read (QCanFrame &clFrameR)
 
void setHostAddress (const QHostAddress clHostAddressV, const uint16_t uwPortV=QCAN_WEB_SOCKET_DEFAULT_PORT)
 
CAN_State_e state (void) const
 
QUuid uuid (void) const
 
QString uuidString (void) const
 
bool write (const QCanFrame &clFrameR)
 

Constructor & Destructor Documentation

◆ QCanSocket()

QCanSocket::QCanSocket ( QObject *  pclParentV = Q_NULLPTR)
Parameters
[in]pclParentVPointer to QObject parent class

Create a new CAN socket which is in unconnected state.

Member Function Documentation

◆ connected

void QCanSocket::connected ( void  )
signal

This signal is emitted after connectNetwork() has been called and a connection has been successfully established.

◆ connectNetwork()

bool QCanSocket::connectNetwork ( const CAN_Channel_e teChannelR)
Parameters
[in]teChannelRCAN 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  )
See also
connectNetwork()

Disconnect the CAN socket from a CAN network (class QCanNetwork). The signal disconnected() is used on disconnection from the CAN network.

◆ error() [1/2]

QAbstractSocket::SocketError QCanSocket::error ( ) const
Returns
SocketError value

Returns the type of error that last occurred.

◆ error [2/2]

void QCanSocket::error ( QAbstractSocket::SocketError  teSockErrorV)
signal
Parameters
[in]teSockErrorVType 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()

int32_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]clFrameRReference 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()

void QCanSocket::setHostAddress ( const QHostAddress  clHostAddressV,
const uint16_t  uwPortV = QCAN_WEB_SOCKET_DEFAULT_PORT 
)
Parameters
[in]clHostAddressVHost address
[in]uwPortVPort 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()

CAN_State_e QCanSocket::state ( void  ) const
inline
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]clFrameRReference 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.