OmronPID
Loading...
Searching...
No Matches
Data Structures | Public Types | Signals | Public Member Functions | Properties
Communication Class Reference

The Communication class provides an interface for communicating with he E5CC temperature controller via Modbus protocol. More...

#include <communication.h>

Inheritance diagram for Communication:

Data Structures

class  E5CC_Address
 The E5CC_Address nested class defines an enum class Type for ModBus addresses used for communication with the E5CC temperature controller. More...
 

Public Types

enum  timing {
  modbus = 300 , getTempTimer = 500 , clockUpdate = 50 , timeUp = 1000 * 60 * 10 ,
  timeOut = 700
}
 The timing enumeration defines various timing intervals in milliseconds. More...
 

Signals

void TemperatureUpdated (double temperature)
 This signal is emitted when the temperature value is updated.
 
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.
 
void MVupperUpdated (double MVupper)
 This signal is emitted when the output upper value is updated.
 
void MVlowerUpdated (double MVlower)
 This signal is emitted when the output lower value is updated.
 
void PID_PUpdated (double PID_P)
 Emitted when the proportional (P) gain value of the PID controller is updated.
 
void PID_IUpdated (double PID_I)
 Emitted when the integral (I) gain value of the PID controller is updated.
 
void PID_DUpdated (double PID_D)
 Emitted when the derivative (D) gain value of the PID controller is updated.
 
void ATSendFinish (int atFlag)
 Emitted when an AT command is sent to the Omron device and the send is finished.
 
void SVSendFinish (double SV)
 Emitted when a set value (SV) command is sent to the Omron device and the send is finished.
 
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 statusUpdate ()
 Emitted when the status of the controller is updated.
 
void deviceConnect ()
 Emitted when a connection to the Omron device is established.
 
void failedConnect ()
 Emitted when a connection to the Omron device fails.
 
void OmronIDChanged ()
 Emitted when the Omron device ID is changed.
 
void serialPortRemove (QString str)
 Emitted when a serial port is removed from the system.
 
void intervalUpdateChanged (int interval)
 Emitted when the interval for updating values is changed.
 
void intervalConectionCheckChanged (int interval)
 Emitted when the interval for checking the connection is changed.
 

Public Member Functions

 Communication (QMainWindow *parent, QStatusBar *statusBar)
 Constructor for Communication class.
 
 ~Communication ()
 Destructs a Communication object.
 
void request (QModbusPdu::FunctionCode code, QByteArray cmd)
 Sends a Modbus request to the Omron device.
 
QString formatHex (int value, int digit)
 Formats an integer value to a hexadecimal string with the specified number of digits.
 
QString formatE5CCAddress (E5CC_Address::Type address, int width=4)
 Formats an E5CC register address as a hexadecimal string with the specified width.
 
void askTemperature ()
 Sends a request to get the temperature from the E5CC temperature controller.
 
void askMV ()
 Sends a request to get the output power from the E5CC temperature controller.
 
void askSV ()
 Sends a request to get the set value from the E5CC temperature controller.
 
void askMVupper ()
 Sends a request to get the output upper limit from the E5CC temperature controller.
 
void askMVlower ()
 Sends a request to get the output lower limit from the E5CC temperature controller.
 
void askPID (QString PID)
 Sends a request to get the specified PID parameter from the E5CC temperature controller.
 
void executeConnection ()
 Executes the connection to the ModBus device.
 
void executeRun ()
 Executes the Run command on the ModBus device.
 
void executeStop ()
 Executes the Stop command on the ModBus device.
 
void executeSendRequestSV (double SV)
 Sends a request to set the set value (SV) of the E5CC temperature controller.
 
void executeSendRequestAT (int atFlag)
 Sends a request to set the AT flag of the E5CC temperature controller.
 
void changeMVlowerValue (double MVlower)
 Changes the value of the output lower limit of the E5CC temperature controller.
 
void changeMVupperValue (double MVupper)
 Changes the value of the output upper limit of the E5CC temperature controller.
 
void changeSVValue (double SV)
 Changes the set value (SV) of the E5CC temperature controller. This function calculates the integer value to be sent to the temperature controller based on the given set value in degrees Celsius and the temperature decimal factor of the temperature controller. It then creates a Modbus command with the calculated value and sends it to the controller to change the SV.
 
void read (QModbusDataUnit::RegisterType type, quint16 adress, int size)
 Sends a Modbus request with the specified function code and command data.
 
void setSerialPortName (QString portName)
 Sets the name of the serial port to use for Modbus communication.
 
bool isTimerUpdateRunning () const
 Checks if the update timer is currently running.
 
void setTemperature (double temperature)
 Sets the current temperature.
 
void setSV (double SV)
 Sets the set value for temperature.
 
void setMV (double MV)
 Sets the current output power.
 
void setMVupper (double MVupper)
 Sets the upper limit for the output power.
 
void setMVlower (double MVlower)
 Sets the lower limit for the output power.
 
void setOmronID (int omronID)
 Sets the Omron ID for Modbus communication.
 
void setIntervalUpdate (int interval)
 Sets the interval in milliseconds for updating the temperature and output power values.
 
void setIntervalConectionCheck (int interval)
 Sets the interval in milliseconds for checking the Modbus connection status.
 
QModbusRtuSerialMaster * getOmron () const
 Returns a pointer to the QModbusRtuSerialMaster object used for communication with the Omron PLC.
 
QList< QSerialPortInfo > getSerialPortDevices () const
 Returns a list of QSerialPortInfo objects containing information about available serial port devices.
 
QString getPortName () const
 Returns the name of the currently set serial port.
 
double getTemperature () const
 Gets the current temperature value.
 
double getMV () const
 Gets the set value.
 
double getSV () const
 Gets the current output power value.
 
double getMVupper () const
 Gets the output upper value.
 
double getMVlower () const
 Gets the output lower value.
 
double getPID_P () const
 Returns the Proportional value of the PID control for the temperature controller.
 
double getPID_I () const
 Returns the Integration value of the PID control for the temperature controller.
 
double getPID_D () const
 Returns the Difference value of the PID control for the temperature controller.
 
int getOmronID () const
 Returns the ID of the Omron temperature controller connected to the system.
 
int getIntervalUpdate () const
 Returns the interval time in seconds at which the temperature and control data are updated.
 
int getIntervalConectionCheck () const
 Returns the interval time in seconds at which the connection to the Omron temperature controller is checked.
 
QTimer * getTimerUpdate () const
 

Properties

double Temperature
 
double SV
 
double MV
 
double MVupper
 
double MVlower
 
int OmronID
 
int intervalUpdate
 
int intervalConectionCheck
 

Detailed Description

The Communication class provides an interface for communicating with he E5CC temperature controller via Modbus protocol.

Member Enumeration Documentation

◆ timing

The timing enumeration defines various timing intervals in milliseconds.

Enumerator
modbus 

The time in milliseconds between Modbus communication

getTempTimer 

The time in milliseconds between requests for temperature

clockUpdate 

The time in milliseconds between clock updates

timeUp 

The maximum time in milliseconds before resetting the clock

timeOut 

The time in milliseconds before a Modbus communication times out

Constructor & Destructor Documentation

◆ Communication()

Communication::Communication ( QMainWindow *  parent,
QStatusBar *  statusBar 
)

Constructor for Communication class.

Parameters
parentThe parent window that the Communication object belongs to.
statusBarThe status bar of the parent window.

Member Function Documentation

◆ askPID()

void Communication::askPID ( QString  PID)

Sends a request to get the specified PID parameter from the E5CC temperature controller.

Asks for the PID value specified by the parameter.

Parameters
ThePID term to read. If it is not "P", "I", or "D", all three PID terms are read.

If the input parameter is "P", it reads the value of the PID P term, emits the PID_PUpdated signal and stores the result in the variable pid_P_. If the input parameter is "I", it reads the value of the PID I term, emits the PID_IUpdated signal and stores the result in the variable pid_I_. If the input parameter is "D", it reads the value of the PID D term, emits the PID_DUpdated signal and stores the result in the variable pid_D_. If the input parameter is not "P", "I", or "D", it reads the values of all three PID terms, emits all three corresponding signals and stores the results in the corresponding variables pid_P_, pid_I_, and pid_D_.

◆ ATSendFinish

void Communication::ATSendFinish ( int  atFlag)
signal

Emitted when an AT command is sent to the Omron device and the send is finished.

Parameters
atFlagThe flag indicating which AT command was sent.

◆ changeMVlowerValue()

void Communication::changeMVlowerValue ( double  MVlower)

Changes the value of the output lower limit of the E5CC temperature controller.

Parameters
MVlowerThe new value of the output lower limit.

◆ changeMVupperValue()

void Communication::changeMVupperValue ( double  MVupper)

Changes the value of the output upper limit of the E5CC temperature controller.

Parameters
MVupperThe new value of the output upper limit.

◆ changeSVValue()

void Communication::changeSVValue ( double  SV)

Changes the set value (SV) of the E5CC temperature controller. This function calculates the integer value to be sent to the temperature controller based on the given set value in degrees Celsius and the temperature decimal factor of the temperature controller. It then creates a Modbus command with the calculated value and sends it to the controller to change the SV.

Parameters
SVThe set value to be set in degrees Celsius.

◆ executeSendRequestAT()

void Communication::executeSendRequestAT ( int  atFlag)
inline

Sends a request to set the AT flag of the E5CC temperature controller.

Parameters
atFlagThe value of the AT flag to set.

◆ executeSendRequestSV()

void Communication::executeSendRequestSV ( double  SV)
inline

Sends a request to set the set value (SV) of the E5CC temperature controller.

Parameters
SVThe value to set as the set value (SV).

◆ formatE5CCAddress()

QString Communication::formatE5CCAddress ( E5CC_Address::Type  address,
int  width = 4 
)

Formats an E5CC register address as a hexadecimal string with the specified width.

This function takes an E5CC register address as an enumeration type and formats it as a hexadecimal string with the specified width. If the resulting string is shorter than the specified width, leading zeroes are added to the beginning of the string.

Parameters
addressThe E5CC register address to format.
widthThe width of the resulting hexadecimal string.
Returns
QString A QString object containing the formatted hexadecimal string.

◆ formatHex()

QString Communication::formatHex ( int  value,
int  digit 
)

Formats an integer value to a hexadecimal string with the specified number of digits.

This function takes an integer value and formats it as a hexadecimal string with the specified number of digits. If the resulting string is shorter than the specified width, leading zeroes are added to the beginning of the string.

Parameters
valueThe integer value to format.
digitThe number of digits for the resulting hexadecimal string.
Returns
QString A QString object containing the formatted hexadecimal string.

◆ getIntervalConectionCheck()

int Communication::getIntervalConectionCheck ( ) const

Returns the interval time in seconds at which the connection to the Omron temperature controller is checked.

Returns
The interval time in seconds at which the connection to the Omron temperature controller is checked.

◆ getIntervalUpdate()

int Communication::getIntervalUpdate ( ) const

Returns the interval time in seconds at which the temperature and control data are updated.

Returns
The interval time in seconds at which the temperature and control data are updated.

◆ getMV()

double Communication::getMV ( ) const

Gets the set value.

Returns
The set value

◆ getMVlower()

double Communication::getMVlower ( ) const

Gets the output lower value.

Returns
The output lower value

◆ getMVupper()

double Communication::getMVupper ( ) const

Gets the output upper value.

Returns
The output upper value

◆ getOmron()

QModbusRtuSerialMaster * Communication::getOmron ( ) const

Returns a pointer to the QModbusRtuSerialMaster object used for communication with the Omron PLC.

Returns
A pointer to the QModbusRtuSerialMaster object

◆ getOmronID()

int Communication::getOmronID ( ) const

Returns the ID of the Omron temperature controller connected to the system.

Returns
The ID of the Omron temperature controller connected to the system.

◆ getPID_D()

double Communication::getPID_D ( ) const

Returns the Difference value of the PID control for the temperature controller.

Returns
The Difference value of the PID control.

◆ getPID_I()

double Communication::getPID_I ( ) const

Returns the Integration value of the PID control for the temperature controller.

Returns
The Integration value of the PID control.

◆ getPID_P()

double Communication::getPID_P ( ) const

Returns the Proportional value of the PID control for the temperature controller.

Returns
The Proportional value of the PID control.

◆ getPortName()

QString Communication::getPortName ( ) const

Returns the name of the currently set serial port.

Returns
The name of the currently set serial port

◆ getSerialPortDevices()

QList< QSerialPortInfo > Communication::getSerialPortDevices ( ) const

Returns a list of QSerialPortInfo objects containing information about available serial port devices.

Returns
A list of QSerialPortInfo objects

◆ getSV()

double Communication::getSV ( ) const

Gets the current output power value.

Returns
The current output power value

◆ getTemperature()

double Communication::getTemperature ( ) const

Gets the current temperature value.

Returns
The current temperature value

◆ intervalConectionCheckChanged

void Communication::intervalConectionCheckChanged ( int  interval)
signal

Emitted when the interval for checking the connection is changed.

Parameters
intervalThe new interval in milliseconds.

◆ intervalUpdateChanged

void Communication::intervalUpdateChanged ( int  interval)
signal

Emitted when the interval for updating values is changed.

Parameters
intervalThe new interval in milliseconds.

◆ isTimerUpdateRunning()

bool Communication::isTimerUpdateRunning ( ) const

Checks if the update timer is currently running.

Returns
true if the update timer is running, false otherwise.

◆ logMsg

void Communication::logMsg ( QString  string,
bool  newline = true 
)
signal

Emitted when a log message is generated.

Parameters
stringThe log message.
newlineTrue if a new line should be added to the log message, false otherwise.

◆ MVlowerUpdated

void Communication::MVlowerUpdated ( double  MVlower)
signal

This signal is emitted when the output lower value is updated.

Parameters
MVlowerThe new output lower value.

◆ MVUpdated

void Communication::MVUpdated ( double  MV)
signal

This signal is emitted when the output power value is updated.

Parameters
MVThe new output power value.

◆ MVupperUpdated

void Communication::MVupperUpdated ( double  MVupper)
signal

This signal is emitted when the output upper value is updated.

Parameters
MVupperThe new output upper value.

◆ PID_DUpdated

void Communication::PID_DUpdated ( double  PID_D)
signal

Emitted when the derivative (D) gain value of the PID controller is updated.

Parameters
PID_DThe updated PID D value.

◆ PID_IUpdated

void Communication::PID_IUpdated ( double  PID_I)
signal

Emitted when the integral (I) gain value of the PID controller is updated.

Parameters
PID_IThe updated PID I value.

◆ PID_PUpdated

void Communication::PID_PUpdated ( double  PID_P)
signal

Emitted when the proportional (P) gain value of the PID controller is updated.

Parameters
PID_PThe updated PID P value.

◆ read()

void Communication::read ( QModbusDataUnit::RegisterType  type,
quint16  adress,
int  size 
)

Sends a Modbus request with the specified function code and command data.

Parameters
codeThe Modbus function code.
cmdThe command data to be sent. This method sends a Modbus request with the specified function code and command data to the Omron device. The status bar message is cleared and the modbusReady_ flag is set to false before the request is sent. If the request is successful, the reply is checked for errors. If there is a protocol error, the error message and exception code are displayed in the status bar. If there is another type of error, the error message and error code are displayed. Once the reply has been handled, the modbusReady_ flag is set to true and the reply is deleted. If the request fails, an error message is displayed in the status bar.

◆ request()

void Communication::request ( QModbusPdu::FunctionCode  code,
QByteArray  cmd 
)

Sends a Modbus request to the Omron device.

Parameters
codeThe function code to be sent.
cmdThe command to be sent. This function sends a Modbus request to the Omron device. It first clears the status bar, sets the modbusReady_ flag to false, and creates a QModbusPdu object with the provided function code and data. It then creates a QModbusRequest object with the QModbusPdu, and sends it to the Omron device using the sendRawRequest() function. If successful, it connects a lambda function to the finished() signal of the QModbusReply object returned by the sendRawRequest() function. This lambda function checks for any errors in the reply and displays the appropriate message on the status bar. If the request was a broadcast, the reply is deleted immediately. Finally, the modbusReady_ flag is set to true.
Note
This function assumes that the Omron device has already been connected to and configured through the QModbusTcpClient object omron_.

◆ serialPortRemove

void Communication::serialPortRemove ( QString  str)
signal

Emitted when a serial port is removed from the system.

Parameters
strThe name of the removed serial port.

◆ setIntervalConectionCheck()

void Communication::setIntervalConectionCheck ( int  interval)

Sets the interval in milliseconds for checking the Modbus connection status.

Parameters
intervalThe interval in milliseconds to set

◆ setIntervalUpdate()

void Communication::setIntervalUpdate ( int  interval)

Sets the interval in milliseconds for updating the temperature and output power values.

Parameters
intervalThe interval in milliseconds to set

◆ setMV()

void Communication::setMV ( double  MV)

Sets the current output power.

Parameters
MVThe current output power to set

◆ setMVlower()

void Communication::setMVlower ( double  MVlower)

Sets the lower limit for the output power.

Parameters
MVlowerThe lower limit for the output power to set

◆ setMVupper()

void Communication::setMVupper ( double  MVupper)

Sets the upper limit for the output power.

Parameters
MVupperThe upper limit for the output power to set

◆ setOmronID()

void Communication::setOmronID ( int  omronID)

Sets the Omron ID for Modbus communication.

Parameters
omronIDThe Omron ID to set

◆ setSerialPortName()

void Communication::setSerialPortName ( QString  portName)

Sets the name of the serial port to use for Modbus communication.

Parameters
portNameThe name of the serial port to use

◆ setSV()

void Communication::setSV ( double  SV)

Sets the set value for temperature.

Parameters
SVThe set value to set

◆ setTemperature()

void Communication::setTemperature ( double  temperature)

Sets the current temperature.

Parameters
temperatureThe current temperature to set

◆ SVSendFinish

void Communication::SVSendFinish ( double  SV)
signal

Emitted when a set value (SV) command is sent to the Omron device and the send is finished.

Parameters
SVThe updated SV value.

◆ SVUpdated

void Communication::SVUpdated ( double  SV)
signal

This signal is emitted when the set value is updated.

Parameters
SVThe new set value.

◆ TemperatureUpdated

void Communication::TemperatureUpdated ( double  temperature)
signal

This signal is emitted when the temperature value is updated.

Parameters
temperatureThe new temperature value.

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