Fotobot
Get data from your photovoltaic plant
Public Slots | Public Member Functions | Private Slots | Private Member Functions | Private Attributes | List of all members
MODBUSTCP Class Reference

Communicates with invertors using serial port. More...

#include <modbustcp.h>

Inheritance diagram for MODBUSTCP:
INVERTOR

Public Slots

void open ()
 Opens serial port. More...
 
- Public Slots inherited from INVERTOR
void quit ()
 Quits the running thread. More...
 

Public Member Functions

 MODBUSTCP ()
 Constructor. The very basic initializations. More...
 
- Public Member Functions inherited from INVERTOR
INVERTOR_status status ()
 Returns current status of the line.
 
virtual void setLine (const DBT_LINES &)
 Sets the parameters for the line. More...
 
virtual void setInvertors (const QList< DBT_INVERTORS > &)
 Sets the list of invertors connected to the line. More...
 
void start (Priority priority=InheritPriority)
 Starts the thread. More...
 

Private Slots

void slotInit ()
 Function called within running thread to initialize all needed child objects. More...
 
void slotQuit ()
 
void loop ()
 Loops the invertors's list. More...
 

Private Member Functions

void readInvertor ()
 
void readInvertorInfo (const DBT_INVERTORS &invertor)
 
QByteArray readModbus (const DBT_INVERTORS &invertor, quint16 regaddress, quint16 regcnt, quint16 expectedLength)
 
void incrementFrameId ()
 
float float32 (const QByteArray &data, int offset) const
 
qint16 integer16 (const QByteArray &data, int offset) const
 
qint32 integer32 (const QByteArray &data, int offset) const
 
QString stateToString (int)
 
QString exceptionCodeToString (int)
 

Private Attributes

QTimer * m_timer
 
quint16 m_frameid
 
int m_current_invertor_index
 Current index in INVERTOR::m_invertors list.
 
int m_number_of_ok
 
int m_number_of_err
 

Additional Inherited Members

- Signals inherited from INVERTOR
void data (DBT_DATA)
 Signal to send retrieved data to other objects. More...
 
void loopFinished (int number_of_ok, int number_of_err)
 Signal is sent when reading cycle was finished and all invertors were read. More...
 
- Static Public Member Functions inherited from INVERTOR
static INVERTORcreate (DBT_LINES::Type)
 Factory makes instances depending on type.
 
- Protected Slots inherited from INVERTOR
virtual void slotInit ()=0
 Initializes ancestors. More...
 
virtual void slotQuit ()=0
 Quits ancestors. More...
 
- Protected Member Functions inherited from INVERTOR
void setStatus (int address, int retries, const QString &command, const QString &status)
 Set status of line.
 
- Protected Attributes inherited from INVERTOR
DBT_LINES m_line
 Stores information about line.
 
QList< DBT_INVERTORSm_invertors
 Stores information about all invertors connected to the line.
 

Detailed Description

Communicates with invertors using serial port.

The class opens one serial port. If you have more ports, you have to have more instances of the MODBUSTCP class;

Definition at line 26 of file modbustcp.h.

Constructor & Destructor Documentation

MODBUSTCP::MODBUSTCP ( )

Constructor. The very basic initializations.

Only basic initializations can be made here. All needed objects must be created in slotInit() function. Constructor runs in different thread than the rest of the class!

Definition at line 35 of file modbustcp.cpp.

35  : INVERTOR() {
36  // qDebug() << "MODBUSTCP::MODBUSTCP()";
37  m_frameid = 0;
38  m_number_of_err=0;
39  m_number_of_ok=0;
41 }
Virtual class for invertor communication.
Definition: invertor.h:28
int m_current_invertor_index
Current index in INVERTOR::m_invertors list.
Definition: modbustcp.h:58

Member Function Documentation

void MODBUSTCP::loop ( )
privateslot

Loops the invertors's list.

Slot is called from timer's signal. Loops throw the invertors's list and call readInvertor() function for every invertor in the list, one invertor per call.

Current invertor index in m_invertors list is stored in m_current_invertor_index member variable.

At the end starts timer again so the event loop calls this function again when the inverval passes.

Definition at line 96 of file modbustcp.cpp.

96  {
97  if (m_invertors.size() <= 0) return;
98 
99  readInvertor();
100 
102  if (m_invertors.size() <= m_current_invertor_index) {
103  int secs = 3;
105  setStatus(
107  0,
108  QString(),
109  tr("Sleeping %1 secs to begin new reading cycle").arg(secs)
110  );
111  m_timer->setInterval(secs*1000); // wait a few seconds after whole cycle
112  emit loopFinished(m_number_of_ok, m_number_of_err);
113  m_number_of_err=0;
114  m_number_of_ok=0;
115  } else {
116  setStatus(
118  0,
119  QString(),
120  tr("Going to read next invertor")
121  );
122  m_timer->setInterval(10);
123  }
124 
125  m_timer->start();
126 }
QList< DBT_INVERTORS > m_invertors
Stores information about all invertors connected to the line.
Definition: invertor.h:127
void loopFinished(int number_of_ok, int number_of_err)
Signal is sent when reading cycle was finished and all invertors were read.
int m_current_invertor_index
Current index in INVERTOR::m_invertors list.
Definition: modbustcp.h:58
void setStatus(int address, int retries, const QString &command, const QString &status)
Set status of line.
Definition: invertor.cpp:54
void MODBUSTCP::open ( )
slot

Opens serial port.

Opens serial port and set all communication parameters. Starts timer for main loop when successfull.

Sends the data signal with error message set when an error occured.

Definition at line 79 of file modbustcp.cpp.

79  {
80 
81 }
void MODBUSTCP::slotInit ( )
privateslot

Function called within running thread to initialize all needed child objects.

This is the first function called when the object is created and new thread event loop is started. All needed objects must be created in this function.

Definition at line 51 of file modbustcp.cpp.

51  {
52  qDebug() << "MODBUSTCP::slotInit()" << this;
53  m_timer = new QTimer(this);
54  m_timer->setInterval(10);
55  m_timer->setSingleShot(true);
56  connect(m_timer, SIGNAL(timeout()),
57  this, SLOT(loop()));
58  m_timer->start();
59 
60  try {
61  SOCKETLIST->addLine(m_line.line, m_line.hostname, m_line.portnumber);
62  SOCKETLIST->open(m_line.line);
63  } catch (QString e) {};
64 }
DBT_LINES m_line
Stores information about line.
Definition: invertor.h:122
void loop()
Loops the invertors's list.
Definition: modbustcp.cpp:96

The documentation for this class was generated from the following files: