Browse Source

Add Get Status

AddStatus
nasi 3 years ago
parent
commit
11ab0aaca0
  1. 2
      Servo/include/ModbusWrapper.h
  2. 18
      Servo/include/ServoController.h
  3. 8
      Servo/src/ModbusWrapper.cpp
  4. 14
      Servo/src/ServoController.cpp
  5. 13
      Test/MainWindow.cpp
  6. 34
      Test/MainWindow.ui

2
Servo/include/ModbusWrapper.h

@ -21,7 +21,7 @@ public:
~ModbusWrapper();
void connectToDevice(ModbusConfig modbusConfig);
void init();
void close();
QBitArray getCoil(int startAddress, quint16 readSize);
QBitArray getInputCoil(int startAddress, quint16 readSize);
QVector<quint16> getHoldingRegister(int startAddress, quint16 readSize);

18
Servo/include/ServoController.h

@ -11,14 +11,14 @@ private:
const int SRV_START_ANGLE_INT_PART_REG = 2000;
const int SRV_STOP_ANGLE_INT_PART_REG = 2001;
const int SRV_AZIMUTH_SPEED_REG = 2002;
const int SRV_APPLY_SETTING_REG = 2004;
const int SRV_START_STOP_REG = 2005;
const int SRV_ZERO_OFFSET_ANGLE = 2007;
const int SRV_START_ANGLE_FRAC_PART_REG = 2010;
const int SRV_STOP_ANGLE_FRAC_PART_REG = 2011;
const int SRV_CALIBRATE_REG = 2013;
const int SRV_ENABLE_DRIVE_REG = 2017;
const int SRV_AZIMUTH_REG = 2030;
const int SRV_APPLY_SETTING_REG = 2003; //2004;
const int SRV_START_STOP_REG = 2004; //2005;
const int SRV_ZERO_OFFSET_ANGLE = 2005; //2007;
const int SRV_START_ANGLE_FRAC_PART_REG = 2006; //2010;
const int SRV_STOP_ANGLE_FRAC_PART_REG = 2007; //2011;
const int SRV_CALIBRATE_REG = 2008; //2013;
const int SRV_ENABLE_DRIVE_REG = 2009; //2017;
const int SRV_AZIMUTH_REG = 2010; //2030;
const double SRV_ANGLE_FACTOR = 100.0;
const double SRV_SPEED_FACTOR = 1000.0;
@ -48,6 +48,8 @@ public:
double getAngleOffset();
void setAngleOffset(double offset);
double getAzimuth();
bool getStatus();
};
#endif //SERVOCONTROLLER_H

8
Servo/src/ModbusWrapper.cpp

@ -83,6 +83,14 @@ void ModbusWrapper::init()
}
}
/*************************************************************************************************/
void ModbusWrapper::close()
{
_modbusMaster.close();
_workerThread.quit();
_workerThread.wait();
}
/*************************************************************************************************/
QBitArray ModbusWrapper::getCoil(int startAddress, quint16 readSize)
{

14
Servo/src/ServoController.cpp

@ -73,6 +73,7 @@ void ServoController::changeMode(double startAngle, double stopAngle, double spe
/*************************************************************************************************/
void ServoController::init(QString serialPort)
{
_modbusWrapper.close();
_modbusWrapper.init();
_modbusWrapper.connectToDevice(initiateConfig(serialPort));
}
@ -155,3 +156,16 @@ double ServoController::getAzimuth()
return (azimuthVector[0] / SRV_ANGLE_FACTOR);
}
/*************************************************************************************************/
bool ServoController::getStatus()
{
try {
getSpeed();
return true;
} catch (ServoException ex) {
_modbusWrapper.close();
return false;
}
}

13
Test/MainWindow.cpp

@ -212,15 +212,18 @@ void MainWindow::on_init_clicked()
void MainWindow::handleGetRequestFromServo()
{
try {
ui->showSpeed->setText(QString::number(_servoControler.getSpeed()));
ui->showStartAngle->setText(QString::number(_servoControler.getStartAngle()));
ui->showStopAngle->setText(QString::number(_servoControler.getStopAngle()));
ui->showAngleOffset->setText(QString::number(_servoControler.getAngleOffset()));
ui->showAzimuth->setText(QString::number(_servoControler.getAzimuth()));
// ui->showSpeed->setText(QString::number(_servoControler.getSpeed()));
//ui->showStartAngle->setText(QString::number(_servoControler.getStartAngle()));
//ui->showStopAngle->setText(QString::number(_servoControler.getStopAngle()));
//ui->showAngleOffset->setText(QString::number(_servoControler.getAngleOffset()));
//ui->showAzimuth->setText(QString::number(_servoControler.getAzimuth()));
ui->connectionState->setText(QVariant(_servoControler.getStatus()).toString());
}
catch(ServoException exp)
{
timer->stop();
ui->showServoError->setText(exp.getMessage());
}
}

34
Test/MainWindow.ui

@ -621,6 +621,40 @@ background-color: rgb(186, 178, 158);</string>
</rect>
</property>
</widget>
<widget class="QLabel" name="label_18">
<property name="geometry">
<rect>
<x>180</x>
<y>0</y>
<width>181</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Connection State to Client:</string>
</property>
</widget>
<widget class="QLabel" name="connectionState">
<property name="geometry">
<rect>
<x>370</x>
<y>0</y>
<width>121</width>
<height>20</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgb(52, 101, 164);
color: rgb(238, 238, 236);
</string>
</property>
<property name="text">
<string/>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_12">
<property name="geometry">

Loading…
Cancel
Save