* @brief This function creates a new instance of Serial if it's not created yet, otherwise return the existing one. Simultaneously, it also describe how to delete instance properly. Parameter increment & limit are optional, if not given, it will use the default values. Only the first time this function is called, the parameters will be used.
* @brief This function creates a new instance of Serial if it's not created yet, otherwise return the existing one. Simultaneously, it also describe how to delete instance properly. Parameter increment, limit, and breakInterval are optional, if not given, it will use the default values. Only the first time this function is called, the parameters will be used.
* @param increment Size increment of the records circular-queue, default value store in const_num.
* @param limit Size limit of the records circular-queue, default value store in const num.
* @param breakInterval Set auto-break frame interval, unit in millisecond, 0 means disable auto-break.
* @brief This function clears all records in the circular-queue.
*/
voidSerial::recordsClear(){
head=0;
tail=0;
count=0;
}
/**
* @brief This function sets the auto-break frame interval. If the interval is 0, it will disable the auto-break frame. Otherwise, it will set the interval.
* @param interval Target auto-break frame interval, unit in millisecond.
* @brief This function opens a new serial port with given parameters. Parameters is restricted to the defined values in constants.h, any other values will return PORT_ERR_PARAM. This function doesn't allow connect below a connected situation, so it will return PORT_ERR_USING if the port is already opened. If the port is opened successfully, it will connect the errorOccurred and readyRead signals to handleError and handleRxData slots respectively.
* @param name Name of port to be connected.
...
...
@@ -373,6 +401,7 @@ Serial::PortResult Serial::openPort(const std::string& name, int baudRate, int d
* @brief This function handles the received data from the connection. It reads all data from the connection and push it to the records circular-queue. The data will be pushed as a record with current time and emit signal in recordsPush().
* @brief This function handles the received data from the connection. If auto-break frame is disabled or buffer data pass ASCII/RTU frame-structure check, it'll trigger push signal immediately. Otherwise, it will start the auto-break timer.
*/
voidSerial::handleRxData(){
QByteArraydata=connection.readAll();
recordsPush({
QDateTime::currentDateTime(),
false,data.length()==0||data[0]!=':',data
});
buffer.append(data);
//if auto-break is disabled, push data immediately
if(autoBreakInterval==0)receiveFrame();
else{
//Break frame according to frame-structure(ASCII/RTU)
* @brief This function actually trigger the circular-queue push signal, which means a frame is received and pushed to the circular-queue. It will also stop the auto-break timer if it's active and clean rx buffer simultaneously.