OmronPID
Loading...
Searching...
No Matches
communication.h
1
8#ifndef COMMUNICATION_H
9#define COMMUNICATION_H
10
11#include <QtSerialBus/QModbusRtuSerialMaster>
12#include <QSerialPort>
13#include <QStatusBar>
14#include <QModbusTcpClient>
15#include <QMutex>
16#include "mainwindow.h"
17
18
19class Communication : public QObject{
20 Q_OBJECT
21 Q_PROPERTY(double Temperature READ getTemperature WRITE setTemperature NOTIFY TemperatureUpdated)
22 Q_PROPERTY(double SV READ getSV WRITE setSV NOTIFY SVUpdated)
23 Q_PROPERTY(double MV READ getMV WRITE setMV NOTIFY MVUpdated)
24 Q_PROPERTY(double MVupper READ getMVupper WRITE setMVupper NOTIFY MVupperUpdated)
25 Q_PROPERTY(double MVlower READ getMVlower WRITE setMVlower NOTIFY MVlowerUpdated)
26 Q_PROPERTY(int OmronID READ getOmronID WRITE setOmronID NOTIFY OmronIDChanged)
27 Q_PROPERTY(int intervalUpdate READ getIntervalUpdate WRITE setIntervalUpdate NOTIFY intervalUpdateChanged)
28 Q_PROPERTY(int intervalConectionCheck READ getIntervalConectionCheck WRITE setIntervalConectionCheck NOTIFY intervalConectionCheckChanged)
29public:
35 Communication(QMainWindow *parent, QStatusBar *statusBar);
36
41
47 public:
52 enum class Type {
53 PV = 0x0000,
54 MV = 0x0008,
55 SV = 0x0106,
56 MVupper = 0x0A0A,
57 MVlower = 0x0A0C,
58 PID_P = 0x0A00,
59 PID_I = 0x0A02,
60 PID_D = 0x0A04
61 };
62 };
63
72 void request(QModbusPdu::FunctionCode code, QByteArray cmd);
73
84 QString formatHex(int value, int digit);
85
96 QString formatE5CCAddress(E5CC_Address::Type address, int width = 4);
97
101 void askTemperature();
102
106 void askMV();
107
111 void askSV();
112
116 void askMVupper();
117
121 void askMVlower();
122
127 void askPID(QString PID);
128
132 void executeConnection(){Connection();}
133
137 void executeRun(){Run();}
138
142 void executeStop(){Stop();}
143
148 void executeSendRequestSV(double SV){sendRequestSV(SV);}
149
154 void executeSendRequestAT(int atFlag){sendRequestAT(atFlag);}
155
160 void changeMVlowerValue(double MVlower);
161
166 void changeMVupperValue(double MVupper);
167
176 void changeSVValue(double SV);
177
190 void read(QModbusDataUnit::RegisterType type, quint16 adress, int size);
191
196 void setSerialPortName(QString portName);
197
202 bool isTimerUpdateRunning() const;
203
208 void setTemperature(double temperature);
209
214 void setSV(double SV);
215
220 void setMV(double MV);
221
226 void setMVupper(double MVupper);
227
232 void setMVlower(double MVlower);
238 void setOmronID(int omronID);
239
244 void setIntervalUpdate(int interval);
245
250 void setIntervalConectionCheck(int interval);
251
256 QModbusRtuSerialMaster* getOmron() const;
257
262 QList<QSerialPortInfo> getSerialPortDevices() const;
263
268 QString getPortName() const;
269
274 double getTemperature() const;
275
280 double getMV() const;
281
286 double getSV() const;
287
292 double getMVupper() const;
293
298 double getMVlower() const;
299
304 double getPID_P() const;
305
310 double getPID_I() const;
311
316 double getPID_D() const;
317
322 int getOmronID() const;
323
328 int getIntervalUpdate() const;
329
334 int getIntervalConectionCheck() const;
335
336 QTimer* getTimerUpdate() const;
337
342 enum timing {
343 modbus = 300,
346 timeUp = 1000 * 60 * 10,
347 timeOut = 700
348 };
349
350signals:
355 void TemperatureUpdated(double temperature);
356
361 void MVUpdated(double MV);
362
367 void SVUpdated(double SV);
368
373 void MVupperUpdated(double MVupper);
374
379 void MVlowerUpdated(double MVlower);
380
385 void PID_PUpdated(double PID_P);
386
391 void PID_IUpdated(double PID_I);
392
397 void PID_DUpdated(double PID_D);
398
403 void ATSendFinish(int atFlag);
404
409 void SVSendFinish(double SV);
410
415
421 void logMsg(QString string, bool newline = true);
422
427
432
437
442
447 void serialPortRemove(QString str);
448
453 void intervalUpdateChanged(int interval);
454
460
461private:
462 QMainWindow* mainwindow_{nullptr};
463 QStatusBar* statusBar_{nullptr};
464 QModbusRtuSerialMaster* omron_{nullptr};
465 QList<QSerialPortInfo> infos_;
466 QModbusTcpClient* modbusDevice_{nullptr};
467 QModbusReply* modbusReply_{nullptr};
468 QTimer* timerUpdate_{nullptr};
469 QTimer* connectTimer_{nullptr};
470 QMutex mutex_;
471 QString portName_;
472 QSerialPort* serialPort_{nullptr};
473 int respondType_{};
474 int omronID_{};
475 int intervalUpdate_{3000};
476 int intervalConectionCheck_{10000};
477 bool modbusReady_{false};
478 bool isSerialPortRemoved_{false};
479 double temperature_{};
480 double SV_{};
481 double MV_{};
482 double MVupper_{};
483 double MVlower_{};
484 double tempDecimal_{0.1};
485 double pid_P_{};
486 double pid_I_{};
487 double pid_D_{};
497 void Connection();
498
502 void Run();
503 void Stop();
504 void sendRequestSV(double SV);
511 void sendRequestAT(int afFlag);
512
513private slots:
518 void waitForMsec(int msec);
519
529 void readReady();
530
534 void askStatus();
535
539 void checkConnection();
540};
541#endif // COMMUNICATION_H
542
543
The E5CC_Address nested class defines an enum class Type for ModBus addresses used for communication ...
Definition: communication.h:46
Type
The Type enum class defines the ModBus addresses for communication with the E5CC temperature controll...
Definition: communication.h:52
The Communication class provides an interface for communicating with he E5CC temperature controller v...
Definition: communication.h:19
void executeSendRequestSV(double SV)
Sends a request to set the set value (SV) of the E5CC temperature controller.
Definition: communication.h:148
double getMV() const
Gets the set value.
Definition: communication.cpp:377
void SVSendFinish(double SV)
Emitted when a set value (SV) command is sent to the Omron device and the send is finished.
QList< QSerialPortInfo > getSerialPortDevices() const
Returns a list of QSerialPortInfo objects containing information about available serial port devices.
Definition: communication.cpp:374
void read(QModbusDataUnit::RegisterType type, quint16 adress, int size)
Sends a Modbus request with the specified function code and command data.
Definition: communication.cpp:67
void TemperatureUpdated(double temperature)
This signal is emitted when the temperature value is updated.
double getPID_D() const
Returns the Difference value of the PID control for the temperature controller.
Definition: communication.cpp:383
void intervalUpdateChanged(int interval)
Emitted when the interval for updating values is changed.
void setIntervalConectionCheck(int interval)
Sets the interval in milliseconds for checking the Modbus connection status.
Definition: communication.cpp:369
void setTemperature(double temperature)
Sets the current temperature.
Definition: communication.cpp:362
void askPID(QString PID)
Sends a request to get the specified PID parameter from the E5CC temperature controller.
Definition: communication.cpp:269
void askMVlower()
Sends a request to get the output lower limit from the E5CC temperature controller.
Definition: communication.cpp:252
double getSV() const
Gets the current output power value.
Definition: communication.cpp:378
void setIntervalUpdate(int interval)
Sets the interval in milliseconds for updating the temperature and output power values.
Definition: communication.cpp:368
void PID_DUpdated(double PID_D)
Emitted when the derivative (D) gain value of the PID controller is updated.
void OmronIDChanged()
Emitted when the Omron device ID is changed.
void ATSendFinish(int atFlag)
Emitted when an AT command is sent to the Omron device and the send is finished.
void setMV(double MV)
Sets the current output power.
Definition: communication.cpp:364
void changeMVlowerValue(double MVlower)
Changes the value of the output lower limit of the E5CC temperature controller.
Definition: communication.cpp:309
QModbusRtuSerialMaster * getOmron() const
Returns a pointer to the QModbusRtuSerialMaster object used for communication with the Omron PLC.
Definition: communication.cpp:373
double getPID_I() const
Returns the Integration value of the PID control for the temperature controller.
Definition: communication.cpp:382
QString formatHex(int value, int digit)
Formats an integer value to a hexadecimal string with the specified number of digits.
Definition: communication.cpp:149
void deviceConnect()
Emitted when a connection to the Omron device is established.
double getTemperature() const
Gets the current temperature value.
Definition: communication.cpp:376
void MVlowerUpdated(double MVlower)
This signal is emitted when the output lower value is updated.
void connectTimeout()
Emitted when a connection attempt to the Omron device times out.
void logMsg(QString string, bool newline=true)
Emitted when a log message is generated.
void executeStop()
Executes the Stop command on the ModBus device.
Definition: communication.h:142
void request(QModbusPdu::FunctionCode code, QByteArray cmd)
Sends a Modbus request to the Omron device.
Definition: communication.cpp:38
void setSerialPortName(QString portName)
Sets the name of the serial port to use for Modbus communication.
Definition: communication.cpp:361
QString formatE5CCAddress(E5CC_Address::Type address, int width=4)
Formats an E5CC register address as a hexadecimal string with the specified width.
Definition: communication.cpp:157
void setOmronID(int omronID)
Sets the Omron ID for Modbus communication.
Definition: communication.cpp:367
void executeSendRequestAT(int atFlag)
Sends a request to set the AT flag of the E5CC temperature controller.
Definition: communication.h:154
~Communication()
Destructs a Communication object.
Definition: communication.cpp:25
void askMVupper()
Sends a request to get the output upper limit from the E5CC temperature controller.
Definition: communication.cpp:246
void askMV()
Sends a request to get the output power from the E5CC temperature controller.
Definition: communication.cpp:240
void PID_PUpdated(double PID_P)
Emitted when the proportional (P) gain value of the PID controller is updated.
double getMVlower() const
Gets the output lower value.
Definition: communication.cpp:380
void MVUpdated(double MV)
This signal is emitted when the output power value is updated.
void SVUpdated(double SV)
This signal is emitted when the set value is updated.
double getMVupper() const
Gets the output upper value.
Definition: communication.cpp:379
int getIntervalConectionCheck() const
Returns the interval time in seconds at which the connection to the Omron temperature controller is c...
Definition: communication.cpp:386
void statusUpdate()
Emitted when the status of the controller is updated.
void failedConnect()
Emitted when a connection to the Omron device fails.
bool isTimerUpdateRunning() const
Checks if the update timer is currently running.
Definition: communication.cpp:358
void askSV()
Sends a request to get the set value from the E5CC temperature controller.
Definition: communication.cpp:234
int getIntervalUpdate() const
Returns the interval time in seconds at which the temperature and control data are updated.
Definition: communication.cpp:385
double getPID_P() const
Returns the Proportional value of the PID control for the temperature controller.
Definition: communication.cpp:381
timing
The timing enumeration defines various timing intervals in milliseconds.
Definition: communication.h:342
@ timeUp
Definition: communication.h:346
@ timeOut
Definition: communication.h:347
@ clockUpdate
Definition: communication.h:345
@ getTempTimer
Definition: communication.h:344
@ modbus
Definition: communication.h:343
void PID_IUpdated(double PID_I)
Emitted when the integral (I) gain value of the PID controller is updated.
void executeConnection()
Executes the connection to the ModBus device.
Definition: communication.h:132
void serialPortRemove(QString str)
Emitted when a serial port is removed from the system.
void setMVupper(double MVupper)
Sets the upper limit for the output power.
Definition: communication.cpp:365
void MVupperUpdated(double MVupper)
This signal is emitted when the output upper value is updated.
void askTemperature()
Sends a request to get the temperature from the E5CC temperature controller.
Definition: communication.cpp:228
void setMVlower(double MVlower)
Sets the lower limit for the output power.
Definition: communication.cpp:366
QString getPortName() const
Returns the name of the currently set serial port.
Definition: communication.cpp:375
void executeRun()
Executes the Run command on the ModBus device.
Definition: communication.h:137
void changeMVupperValue(double MVupper)
Changes the value of the output upper limit of the E5CC temperature controller.
Definition: communication.cpp:320
void setSV(double SV)
Sets the set value for temperature.
Definition: communication.cpp:363
void intervalConectionCheckChanged(int interval)
Emitted when the interval for checking the connection is changed.
void changeSVValue(double SV)
Changes the set value (SV) of the E5CC temperature controller. This function calculates the integer v...
Definition: communication.cpp:331
int getOmronID() const
Returns the ID of the Omron temperature controller connected to the system.
Definition: communication.cpp:384
This file contains the declaration of the MainWindow class and its associated methods.