|
|
@ -273,6 +273,7 @@ Cigarette::Cigarette(QWidget* parent)
|
|
|
|
g_modbus_conf.debug = 0;
|
|
|
|
g_modbus_conf.debug = 0;
|
|
|
|
g_modbus_conf.reset = 0;
|
|
|
|
g_modbus_conf.reset = 0;
|
|
|
|
g_modbus_conf.alarm = 0;
|
|
|
|
g_modbus_conf.alarm = 0;
|
|
|
|
|
|
|
|
g_modbus_conf.heart = 0;
|
|
|
|
read_modbus_config(g_modbus_conf); //初始化modbus地址
|
|
|
|
read_modbus_config(g_modbus_conf); //初始化modbus地址
|
|
|
|
|
|
|
|
|
|
|
|
//保存图片线程
|
|
|
|
//保存图片线程
|
|
|
@ -483,6 +484,11 @@ Cigarette::Cigarette(QWidget* parent)
|
|
|
|
//报警标签双击消警
|
|
|
|
//报警标签双击消警
|
|
|
|
connect(ui.label_alarm, SIGNAL(QlabelDoubleClick()), this, SLOT(OnCancelAlarm()));//
|
|
|
|
connect(ui.label_alarm, SIGNAL(QlabelDoubleClick()), this, SLOT(OnCancelAlarm()));//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//心跳检测
|
|
|
|
|
|
|
|
heartbeat_pTimer = new QTimer(this);
|
|
|
|
|
|
|
|
connect(heartbeat_pTimer, SIGNAL(timeout()), this, SLOT(heartbeat()));
|
|
|
|
|
|
|
|
heartbeat_pTimer->start(5000);
|
|
|
|
|
|
|
|
|
|
|
|
//无参对有参需要利用信号转发器QSignalMapper(this)
|
|
|
|
//无参对有参需要利用信号转发器QSignalMapper(this)
|
|
|
|
//信号转发器
|
|
|
|
//信号转发器
|
|
|
|
image_lable_DBsignalMapper0 = new QSignalMapper(this);
|
|
|
|
image_lable_DBsignalMapper0 = new QSignalMapper(this);
|
|
|
@ -1585,6 +1591,12 @@ void Cigarette::admin_timeout()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//心跳检测
|
|
|
|
|
|
|
|
void Cigarette::heartbeat()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int ret = m_PLCDevice->write_bit_2_plc(g_modbus_conf.heart, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Cigarette::handleTimeout()//获取时间,读取PLC产量、剔除数;检测相机状态;读取PLC报警信息
|
|
|
|
void Cigarette::handleTimeout()//获取时间,读取PLC产量、剔除数;检测相机状态;读取PLC报警信息
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QDateTime ts_start = QDateTime::currentDateTime();
|
|
|
|
QDateTime ts_start = QDateTime::currentDateTime();
|
|
|
@ -2699,6 +2711,10 @@ bool Cigarette::read_modbus_config(ModbusConf& conf)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
conf.alarm = atoi(line.substr(pos + 1).c_str());
|
|
|
|
conf.alarm = atoi(line.substr(pos + 1).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (tmp_key == "HEART")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
conf.heart = atoi(line.substr(pos + 1).c_str());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cfg_file.close();
|
|
|
|
cfg_file.close();
|
|
|
@ -3703,39 +3719,70 @@ void Cigarette::record_output_statistic(qint64 quantity, int Kick[NumberOfSuppor
|
|
|
|
QString file_name, file_path;
|
|
|
|
QString file_name, file_path;
|
|
|
|
for (int i = 0; i < NumberOfSupportedCameras; i++)
|
|
|
|
for (int i = 0; i < NumberOfSupportedCameras; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (SingleCamInfo[i].IsOpen && quantity > 0) {
|
|
|
|
if (SingleCamInfo[i].IsOpen) //&& quantity > 0
|
|
|
|
|
|
|
|
{
|
|
|
|
std::fstream cfg_file;
|
|
|
|
std::fstream cfg_file;
|
|
|
|
file_name = QString(STATISTIC_FILE).arg(i);
|
|
|
|
file_name = QString(STATISTIC_FILE).arg(i);
|
|
|
|
file_path = g_conf_path.config_path + "/" + file_name;
|
|
|
|
file_path = g_conf_path.config_path + "/" + file_name;
|
|
|
|
|
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
char buf[256];
|
|
|
|
memset(buf, 0, 256);
|
|
|
|
QDateTime date = QDateTime::currentDateTime();
|
|
|
|
sprintf(buf, "%s", file_path.toLocal8Bit().constData());
|
|
|
|
string nowtime = date.toString("yyyy-MM-dd_HH:mm:ss").toStdString().c_str();
|
|
|
|
|
|
|
|
double ng_rate;
|
|
|
|
cfg_file.open(buf, std::ios::app);
|
|
|
|
if (ng[i] > 0)
|
|
|
|
if (cfg_file.good())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ng_rate = double(ng[i]) / production_number[i];
|
|
|
|
if (last_shift == 2 || last_shift == 256) {
|
|
|
|
}
|
|
|
|
memset(buf, 0, 256);
|
|
|
|
else
|
|
|
|
sprintf(buf, "\n\n**************************************************************************************\n");
|
|
|
|
{
|
|
|
|
cfg_file.write(buf, strlen(buf));
|
|
|
|
ng_rate = 0;
|
|
|
|
//QDate date = QDate::currentDate();
|
|
|
|
}
|
|
|
|
QDateTime date = QDateTime::currentDateTime();
|
|
|
|
if (quantity > 0)
|
|
|
|
memset(buf, 0, 256);
|
|
|
|
{
|
|
|
|
sprintf(buf, "%s:\n", date.toString("yyyy-MM-dd_HH-mm-ss").toStdString().c_str());
|
|
|
|
|
|
|
|
cfg_file.write(buf, strlen(buf));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(buf, 0, 256);
|
|
|
|
|
|
|
|
double ng_rate;
|
|
|
|
|
|
|
|
if (ng[i] > 0)
|
|
|
|
|
|
|
|
ng_rate = double(ng[i]) / production_number[i];
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
ng_rate = 0;
|
|
|
|
|
|
|
|
sprintf(buf, "%c 总产量:%010I64d 剔除率:%02.5f%% 合格率:%02.5f%% NG率:%02.5f%%\n", (shift == 0) ? 'A' : ((shift == 1) ? 'B' : 'C'), quantity, ((double)Kick[i] / quantity) * 100, (1.0 - ng_rate) * 100, ng_rate * 100);
|
|
|
|
sprintf(buf, "%c 总产量:%010I64d 剔除率:%02.5f%% 合格率:%02.5f%% NG率:%02.5f%%\n", (shift == 0) ? 'A' : ((shift == 1) ? 'B' : 'C'), quantity, ((double)Kick[i] / quantity) * 100, (1.0 - ng_rate) * 100, ng_rate * 100);
|
|
|
|
cfg_file.write(buf, strlen(buf));
|
|
|
|
|
|
|
|
memset(buf, 0, 256);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cfg_file.close();
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
sprintf(buf, "%c 总产量:%010I64d 剔除率:%02.5f%% 合格率:%02.5f%% NG率:%02.5f%%\n", (shift == 0) ? 'A' : ((shift == 1) ? 'B' : 'C'), quantity, 0.00, 0.00, 0.00);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::ifstream file(file_path.toStdString());
|
|
|
|
|
|
|
|
std::ifstream file_(file_path.toStdString());
|
|
|
|
|
|
|
|
std::vector<std::string> lines; //用于存储文件的所有行
|
|
|
|
|
|
|
|
if (file_.good())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
file_.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::ofstream outFile(file_path.toStdString());
|
|
|
|
|
|
|
|
std::string fristNews = "**************************************************************************************\n" + nowtime + "\n" + buf;
|
|
|
|
|
|
|
|
outFile << fristNews << endl;
|
|
|
|
|
|
|
|
outFile.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (file.is_open())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
std::string line;
|
|
|
|
|
|
|
|
while (std::getline(file, line))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lines.push_back(line);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
// 在第一行添加数据
|
|
|
|
|
|
|
|
std::string newData = "**************************************************************************************\n"+nowtime +"\n" + buf;
|
|
|
|
|
|
|
|
if (!lines.empty())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
lines.insert(lines.begin(), newData); // 在vector的开始位置插入新数据
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 将修改后的数据写回文件
|
|
|
|
|
|
|
|
std::ofstream outFile(file_path.toStdString());
|
|
|
|
|
|
|
|
if (outFile.is_open())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
for (const auto& l : lines)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
outFile << l << std::endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
outFile.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
last_shift = shift;
|
|
|
|
last_shift = shift;
|
|
|
|