目前已经可以正常保存数据到XML文件

main
seiyu 1 year ago
parent d5303e4de1
commit 5aa4f78df5

@ -19,11 +19,6 @@ void CaptureThread::fpsTimeout(void)
m_cntLastGrabbedImages = m_cntGrabbedImages;
QString data = QString("%1").arg(delta);
emit updateStatistics(data.left(4), Local_Num);
#ifdef __ExportData
_XMLExportDataInfo exportXMLDataInfo;
exportXMLDataInfo.AcquisitionSpeed = data.left(4).toStdString();
export_XMLData_Info_queue->put(exportXMLDataInfo);
#endif
}
CaptureThread::~CaptureThread()
@ -120,11 +115,6 @@ void CaptureThread::process( void )
{
QString data = QString::fromStdString(statistics.framesPerSecond.readS());
emit updateStatistics(data.left(4),Local_Num);
#ifdef __ExportData
_XMLExportDataInfo exportXMLDataInfo;
exportXMLDataInfo.AcquisitionSpeed = data.left(3).toStdString();
export_XMLData_Info_queue->put(exportXMLDataInfo);
#endif
}
}
else

@ -165,11 +165,6 @@ void CaptureThreadBasler::fpsTimeout()
m_cntLastGrabbedImages = m_cntGrabbedImages;
QString data = QString("%1").arg(delta);
emit updateStatistics(data.left(4), Local_Num);
#ifdef __ExportData
_XMLExportDataInfo exportXMLDataInfo;
exportXMLDataInfo.AcquisitionSpeed = data.left(3).toStdString();
export_XMLData_Info_queue->put(exportXMLDataInfo);
#endif
}
void CaptureThreadBasler::ioTimeout()

@ -204,11 +204,6 @@ void CaptureThreadHIK::fpsTimeout(void)
m_cntLastGrabbedImages = m_cntGrabbedImages;
QString data = QString("%1").arg(delta);
emit updateStatistics(data.left(4), Local_Num);
#ifdef __ExportData
_XMLExportDataInfo exportXMLDataInfo;
exportXMLDataInfo.AcquisitionSpeed = data.left(3).toStdString();
export_XMLData_Info_queue->put(exportXMLDataInfo);
#endif
}
//-----------------------------------------------------------------------------

@ -81,6 +81,7 @@ int quantity_stop_count; //
int g_seconds;
int CurOpLabel;
bool onrestart = false;
bool flag = false;
VOID BeforeWork(int shoot[])
{
@ -256,6 +257,7 @@ Cigarette::Cigarette(QWidget *parent)
#ifdef __ExportData
exportDataThread.init();
exportDataThread.start_work();
connect(this, &Cigarette::sendMsgToExportData, &exportDataThread, &ExportDataThread::EDrecMsgFromCigarette);
#endif
m_PLCDevice = new PLCDevice;
@ -1244,6 +1246,7 @@ void Cigarette::OnNotifyHub(int Num, int Cnt,cv::Mat m)
void Cigarette::OnDisplayTimeCostHub(int Num, int ms)
{
label_timecost_mat[Num]->setText(QString::number(ms) + "ms");
exportData[Num].detectTime = QString::number(ms) + "ms";
}
void Cigarette::OnDisplayCheckNumberHub(int Num, long no)
@ -1262,6 +1265,10 @@ void Cigarette::OnDisplayCheckNumberHub(int Num, long no)
void Cigarette::OnDisplayJdNoHub(int Num, QString jd_no)
{
label_jd_no_mat[Num]->setText(jd_no);
#ifdef __ExportData
exportData[Num].cameraId = Num;
exportData[Num].jdNum = jd_no;
#endif
}
void Cigarette::OnOKHub(int Num)
@ -1278,7 +1285,7 @@ void Cigarette::OnOKHub(int Num)
label_reslut_mat[Num]->setText("OK");
label_reslut_mat[Num]->setStyleSheet(tr("background-color: rgb(0, 255, 0);"));
exportData[Num].okNum = ok[Num];
}
void Cigarette::OnNGHub(int Num)
@ -1294,10 +1301,11 @@ void Cigarette::OnNGHub(int Num)
lcdNumber_ng_mat[Num]->display(ng[Num]);
label_reslut_mat[Num]->setText("NG");
label_reslut_mat[Num]->setStyleSheet(tr("background-color: rgb(255, 0, 0);"));
exportData[Num].ngNum = ng[Num];
}
void Cigarette::updateStatisticsHub(const QString& statisticalData, int Num)
{
void Cigarette::updateStatisticsHub(const QString& statisticalData, int Num) {
label_cap_speed_mat[Num]->setText(statisticalData + QStringLiteral("个/秒"));
_UDPSendInfo UDPSendInfo;
UDPSendInfo.FrameID = speed_frame;
@ -1306,6 +1314,7 @@ void Cigarette::updateStatisticsHub(const QString& statisticalData, int Num)
#ifdef __UDPSend
UDP_Info_queue->put(UDPSendInfo);
#endif
exportData[Num].acquisitionTime = statisticalData + QStringLiteral("个/秒");
}
//不剔除模式
@ -1479,13 +1488,16 @@ void Cigarette::handleTimeout()
int ret = m_PLCDevice->read_short_from_plc(g_modbus_conf.kick[i], 2, dest16);
if (ret == 2) {
Kick[i] = dest16[0] + (dest16[1] << 16);
lcdNumber_kick_mat[i]->display(Kick[i]);
lcdNumber_kick_mat[i]->display(dest16[0] + (dest16[1] << 16));
#ifdef __UDPSend
_UDPSendInfo UDPSendInfo;
UDPSendInfo.FrameID = kick_frame;
UDPSendInfo.index = 0;
UDPSendInfo.index = i;
UDPSendInfo.Kick[UDPSendInfo.index] = dest16[0] + (dest16[1] << 16);
UDP_Info_queue->put(UDPSendInfo);
#endif
#ifdef __ExportData
exportData[i].kick = dest16[0] + (dest16[1] << 16);
#endif
}
}
@ -1860,10 +1872,9 @@ void Cigarette::on_toolButton_alarm_released()
}
void Cigarette::on_pushButton_clear_released()//换班
{
#ifdef __ExportData
_XMLExportDataInfo exportXMLDataInfo;
#endif
emit sengMsgToClog("Change shift.");
emit sendMsgToExportData();
if (!g_admin_mode)
{
if (!g_op_mode)
@ -1889,10 +1900,6 @@ void Cigarette::on_pushButton_clear_released()//
{
production_number[i]=0;
lcdNumber_total_mat[i]->display(production_number[i]);
#ifdef __ExportData
exportXMLDataInfo.okNum[i] = ok[i];
exportXMLDataInfo.ngNum[i] = ng[i];
#endif
ok[i] = 0;
lcdNumber_ok_mat[i]->display(ok[i]);
ng[i] = 0;
@ -1943,29 +1950,44 @@ void Cigarette::on_pushButton_clear_released()//
{
int cur_quantity = dest16[0] + (dest16[1] << 16);
ui.lcdNumber_total_no_last->display(cur_quantity);
exportXMLDataInfo.TotalCheckNum = cur_quantity;
#ifdef __ExportData
exportData->totalCheckNum = cur_quantity;
#endif
#ifdef __UDPSend
sThread.sendData("totallast_" + QString::number(cur_quantity), g_sys_conf.FeedbackPort);
#endif
}
#ifdef __ExportData
// 读取剔除值
for (int i = 0; i < NumberOfSupportedCameras; i++) {
#if defined(NumberOfSupportedCameras) && (NumberOfSupportedCameras > i)
if (g_modbus_conf.kick[i] > 0) {
uint16_t dest16[2];
int ret = m_PLCDevice->read_short_from_plc(g_modbus_conf.kick[i], 2, dest16);
if (ret == 2) {
exportXMLDataInfo.kickNum[i] = dest16[0] + (dest16[1] << 16);
}
//发送换班消息给PLC
if (g_modbus_conf.shift > 0)
{
int ret = m_PLCDevice->write_bit_2_plc( g_modbus_conf.shift, 1);
if (g_modbus_conf.alarm >0)///给报警地址alarm对应的PLC地址清零
{
uint16_t dest16[2] = { 0,0 };
int ret = m_PLCDevice->write_short_2_plc(g_modbus_conf.alarm, 2, dest16);
}
}
#endif
}
}
g_op_time = OP_TIME;
#ifdef __ExportData
for (int i = 0; i < NumberOfSupportedCameras; i++) {
_XMLExportDataInfo exportXMLDataInfo;
exportXMLDataInfo.cameraTotal = NumberOfSupportedCameras;
exportXMLDataInfo.cameraId = exportData[i].cameraId;
exportXMLDataInfo.TotalCheckNum = exportData[i].totalCheckNum;
exportXMLDataInfo.shotCounts = g_sys_conf.shoot[i];
exportXMLDataInfo.DetectSpeed = exportData[i].detectTime;
exportXMLDataInfo.AcquisitionSpeed = exportData[i].acquisitionTime;
exportXMLDataInfo.jdNum = exportData[i].jdNum;
exportXMLDataInfo.okNum = exportData[i].okNum;
exportXMLDataInfo.ngNum = exportData[i].ngNum;
exportXMLDataInfo.kickNum= exportData[i].kick;
int flag = 0;
for (int i = 1; i < NumberOfSupportedCameras; i++) {
if (exportXMLDataInfo.kickNum[i] != exportXMLDataInfo.kickNum[0]) {
if (exportData[i].kick != exportData[0].kick) {
flag = 1;
break;
}
@ -1973,32 +1995,21 @@ void Cigarette::on_pushButton_clear_released()//
if (flag == 1) {
// Kick值不一致
for (int i = 0; i < NumberOfSupportedCameras; i++) {
exportXMLDataInfo.TotalKickNum += exportXMLDataInfo.kickNum[i];
exportXMLDataInfo.TotalKickNum += exportData[i].kick;
}
}
else
exportXMLDataInfo.TotalKickNum = exportXMLDataInfo.kickNum[0];
exportXMLDataInfo.KickRate = ((double)exportXMLDataInfo.TotalKickNum / (double)exportXMLDataInfo.TotalCheckNum) * 100;
exportXMLDataInfo.PassRate = (1.0 - exportXMLDataInfo.KickRate) * 100;
exportXMLDataInfo.TotalKickNum = exportData[0].kick;
if (exportXMLDataInfo.TotalKickNum == 0)
exportXMLDataInfo.KickRate = 0;
else
exportXMLDataInfo.KickRate = (double)exportXMLDataInfo.TotalKickNum / exportXMLDataInfo.TotalCheckNum;
exportXMLDataInfo.PassRate = 1.0 - exportXMLDataInfo.KickRate;
export_XMLData_Info_queue->put(exportXMLDataInfo);
#endif
}
//发送换班消息给PLC
if (g_modbus_conf.shift > 0)
{
int ret = m_PLCDevice->write_bit_2_plc( g_modbus_conf.shift, 1);
if (g_modbus_conf.alarm >0)///给报警地址alarm对应的PLC地址清零
{
uint16_t dest16[2] = { 0,0 };
int ret = m_PLCDevice->write_short_2_plc(g_modbus_conf.alarm, 2, dest16);
}
}
}
}
g_op_time = OP_TIME;
flag = false;
#endif
}
//读取系统管理员密码

@ -162,6 +162,19 @@ public:
WorkThread work_thread[NumberOfSupportedCameras];
DebugThread debug_thread[NumberOfSupportedCameras];
struct export_info {
int cameraId = -1;
int totalCheckNum = 0;
int totalKickNum = 0;
int kick = 0;
QString detectTime = "0";
QString acquisitionTime = "0";
QString jdNum = QString("0,0,0");
int okNum = 0;
int ngNum = 0;
};
export_info exportData[NumberOfSupportedCameras];
SaveThread saveThread;
void record_output_statistic(qint64 cur_quantity, int Kick[NumberOfSupportedCameras], int shift);
@ -196,6 +209,7 @@ public slots:
signals:
void sengMsgToClog(QString);
void sendMsgToExportData();
};
#endif // CIGARETTE_H

@ -12,6 +12,7 @@ Cigarette* cg;
//extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue;
extern ConfPath g_conf_path;
extern bool flag;
ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
{
@ -63,6 +64,7 @@ ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
void ExportDataThread::init()
{
b_quit = false;
flag = 0;
}
void ExportDataThread::start_work()
@ -192,14 +194,14 @@ int ExportDataThread::insertXMLNode(const char* xmlPath, _XMLExportDataInfo& dat
// 合格率
XMLElement* PassRate = pDocument[data.cameraId]->NewElement("PassRate");
std::string temp_str = std::to_string(data.PassRate);
std::string temp_str = std::to_string(data.PassRate * 100);
const char* temp_char = temp_str.c_str();
PassRate->InsertEndChild(pDocument[data.cameraId]->NewText(temp_char));
Total->InsertEndChild(PassRate);
// 剔除率
XMLElement* KickRate = pDocument[data.cameraId]->NewElement("KickRate");
temp_str = std::to_string(data.KickRate);
temp_str = std::to_string(data.KickRate * 100);
temp_char = temp_str.c_str();
KickRate->InsertEndChild(pDocument[data.cameraId]->NewText(temp_char));
Total->InsertEndChild(KickRate);
@ -215,35 +217,37 @@ int ExportDataThread::insertXMLNode(const char* xmlPath, _XMLExportDataInfo& dat
XMLElement* JudgeNum = pDocument[data.cameraId]->NewElement("JudgeNum");
// 各相机ok数量
XMLElement* okNum = pDocument[data.cameraId]->NewElement("OkNum");
okNum->InsertEndChild(pDocument[data.cameraId]->NewText(itoa(data.okNum[data.cameraId], s, 10)));
okNum->InsertEndChild(pDocument[data.cameraId]->NewText(itoa(data.okNum, s, 10)));
JudgeNum->InsertEndChild(okNum);
// 各相机ng数量
XMLElement* ngNum = pDocument[data.cameraId]->NewElement("NgNum");
ngNum->InsertEndChild(pDocument[data.cameraId]->NewText(itoa(data.ngNum[data.cameraId], s, 10)));
ngNum->InsertEndChild(pDocument[data.cameraId]->NewText(itoa(data.ngNum, s, 10)));
JudgeNum->InsertEndChild(ngNum);
// 各相机实际剔除数量(单通道剔除时为总剔除数量)
XMLElement* kickNum = pDocument[data.cameraId]->NewElement("KickNum");
kickNum->InsertEndChild(pDocument[data.cameraId]->NewText(itoa(data.kickNum[data.cameraId], s, 10)));
kickNum->InsertEndChild(pDocument[data.cameraId]->NewText(itoa(data.kickNum, s, 10)));
JudgeNum->InsertEndChild(kickNum);
// 各相机胶点识别个数
XMLElement* JdNum = pDocument[data.cameraId]->NewElement("JdNum");
JdNum->InsertEndChild(pDocument[data.cameraId]->NewText(itoa(data.shotCounts, s, 10)));
for (int j = 0; j < data.shotCounts; j++)
JdNum->InsertEndChild(pDocument[data.cameraId]->NewText(itoa(data.jdNum[j], s, 10)));
JdNum->InsertEndChild(pDocument[data.cameraId]->NewText(data.jdNum.toStdString().c_str()));
JudgeNum->InsertEndChild(JdNum);
XMLElement* shotCounts = pDocument[data.cameraId]->NewElement("ShotCounts");
shotCounts->InsertEndChild(pDocument[data.cameraId]->NewText(itoa(data.shotCounts, s, 10)));
JudgeNum->InsertEndChild(shotCounts);
CameraNode->InsertEndChild(JudgeNum);
// 各相机采集速度
XMLElement* speed = pDocument[data.cameraId]->NewElement("Speed");
XMLElement* AcquisitionSpeed = pDocument[data.cameraId]->NewElement("AcquisitionSpeed");
AcquisitionSpeed->InsertEndChild(pDocument[data.cameraId]->NewText(data.AcquisitionSpeed.c_str()));
AcquisitionSpeed->InsertEndChild(pDocument[data.cameraId]->NewText(data.AcquisitionSpeed.toStdString().c_str()));
speed->InsertEndChild(AcquisitionSpeed);
// 各相机检测速度
XMLElement* DetectSpeed = pDocument[data.cameraId]->NewElement("DetectSpeed");
DetectSpeed->InsertEndChild(pDocument[data.cameraId]->NewText(data.DetectSpeed.c_str()));
DetectSpeed->InsertEndChild(pDocument[data.cameraId]->NewText(data.DetectSpeed.toStdString().c_str()));
speed->InsertEndChild(DetectSpeed);
CameraNode->InsertEndChild(speed);
@ -259,7 +263,8 @@ void ExportDataThread::run()
//export_Data_Info_queue->take(element);
_XMLExportDataInfo element;
export_XMLData_Info_queue->take(element);
if (element.cameraId != -1) {
if (element.cameraId != -1 && flag == 1) {
char buf[256];
memset(buf, 0, 256);
QString xmlPath = QString(EXPORTDATA_FILE).arg(element.cameraId);
@ -275,13 +280,13 @@ void ExportDataThread::run()
/* 设置通讯协议 */
url.setScheme("ftp");
/* 设置用户名 */
url.setUserName("xxx");
url.setUserName("FTP2");
/* 设置密码 */
url.setPassword("xxxxxx");
url.setPassword("123");
/* 设置主机,也可以是域名 */
url.setHost("127.0.0.1");
url.setHost("192.168.1.170");
/* 设置端口号一般为21 */
url.setPort(21);
url.setPort(666);
/* 设置路径 */
url.setPath("/tmp/" + xmlPath);
@ -336,3 +341,7 @@ void ExportDataThread::check_save_dir(std::string dir_path)
vec_save_dirs.push_back(dir_path);
}
}
void ExportDataThread::EDrecMsgFromCigarette(){
flag = true;
}

@ -18,20 +18,20 @@ using namespace tinyxml2;
class _XMLExportDataInfo {
public:
// 总的统计数据
long long cameraTotal;
int TotalCheckNum; // 总检测数量
int TotalKickNum; // 总剔除数量
double PassRate; // 合格率
double KickRate; // 剔除率
// 各相机数据
long long cameraTotal;
int cameraId;
int shotCounts; // 拍摄张数
int okNum[NumberOfSupportedCameras]; // 各相机ok数量
int ngNum[NumberOfSupportedCameras]; // 各相机ng数量
int kickNum[NumberOfSupportedCameras]; // 各相机实际剔除数量(单通道剔除时为总剔除数量)
string AcquisitionSpeed; // 各相机采集速度
int jdNum[20]; // 各相机胶点识别个数
string DetectSpeed; // 各相机检测速度(识别时间)
int okNum; // 各相机ok数量
int ngNum; // 各相机ng数量
int kickNum; // 各相机实际剔除数量(单通道剔除时为总剔除数量)
QString AcquisitionSpeed; // 各相机采集速度
QString jdNum; // 各相机胶点识别个数
QString DetectSpeed; // 各相机检测速度(识别时间)
_XMLExportDataInfo() {
// 总的统计数据
@ -40,17 +40,14 @@ public:
PassRate = 0.0; // 合格率
KickRate = 0.0; // 剔除率
cameraId = -1;
shotCounts = 0;
jdNum = QString("0,0,0");
// 各相机数据
for (int i = 0; i < NumberOfSupportedCameras; i++) {
okNum[i] = 0;
ngNum[i] = 0;
kickNum[i] = 0; // 各相机实际剔除数量(单通道剔除时为总剔除数量)
}
AcquisitionSpeed = "0ms"; // 各相机采集速度
for (int i = 0; i < 20; i++) jdNum[i] = 0; // 各相机胶点识别个数
DetectSpeed = "0ms"; // 各相机检测速度
shotCounts = 0;
okNum = 0;
ngNum = 0;
kickNum = 0; // 各相机实际剔除数量(单通道剔除时为总剔除数量)
AcquisitionSpeed = "0"; // 各相机采集速度
DetectSpeed = "0"; // 各相机检测速度
}
};
@ -117,7 +114,7 @@ public:
void init();
void start_work();
void stop();
int insertXMLNode(const char* xmlPath, _ExportDataInfo& data);
//int insertXMLNode(const char* xmlPath, _ExportDataInfo& data);
int insertXMLNode(const char* xmlPath, _XMLExportDataInfo& data);
protected:
void run();
@ -126,4 +123,8 @@ public:
bool b_quit;
std::vector<std::string> vec_save_dirs;
tinyxml2::XMLDocument *pDocument[NumberOfSupportedCameras];
int flag;
public slots:
void EDrecMsgFromCigarette();
};

@ -20,7 +20,6 @@ extern SyncQueue<std::pair<std::string, cv::Mat> >* g_save_queue; //ͼƬ
extern SyncQueue<std::pair<int, cv::Mat> >* g_image_queue[NumberOfSupportedCameras]; //int±íʾһ¸öÄ¿±êÅÄÁ˼¸ÕÅ
extern SyncQueue<_UDPSendInfo>* UDP_Info_queue;
//extern SyncQueue<_ExportDataInfo>* export_Data_Info_queue;
extern SyncQueue<_XMLExportDataInfo>* export_XMLData_Info_queue;
extern PLCDevice* m_PLCDevice;
extern bool g_debug_mode;
@ -88,10 +87,6 @@ void WorkThread::run()
//_ExportDataInfo exportDataInfo;
//exportDataInfo.cameraId = local_camera_number;
_XMLExportDataInfo exportXMLDataInfo;
exportXMLDataInfo.cameraTotal = NumberOfSupportedCameras;
exportXMLDataInfo.cameraId = local_camera_number;
exportXMLDataInfo.shotCounts = unit_count;
if (!image.data)
{
@ -107,8 +102,7 @@ void WorkThread::run()
std::vector<cv::Mat> vec_in;
int w = image.cols;
int h = image.rows / unit_count;
for(int index=0;index<unit_count;index++)
{
for (int index = 0; index < unit_count; index++) {
cv::Rect temp_Rect(0, h * index, w, h);
cv::Mat temp_image = image(temp_Rect).clone();
if (isNeedRotate[local_camera_number]) {
@ -138,18 +132,15 @@ void WorkThread::run()
emit display_timecost(local_camera_number, time_process);
UDPSendInfo.timecost = QString::number(time_process);
//exportDataInfo.timeCost = QString::number(time_process).toStdString();
exportXMLDataInfo.DetectSpeed = QString::number(time_process).toStdString();
cv::Mat image1;
cv::Mat image2;
QString jd_no;
for(int index=0;index<unit_count;index++)
{
for (int index = 0; index < unit_count; index++) {
jd_no += QString::number(vec_results[index].size()) + ",";
//exportDataInfo.jd[index] = vec_results[index].size();
//exportDataInfo.isJdExist[index] = vec_results[index].size() > 0;
exportXMLDataInfo.jdNum[index] = vec_results[index].size();
}
jd_no.chop(1);
emit display_jd_no(local_camera_number, jd_no);
@ -289,10 +280,6 @@ void WorkThread::run()
}
#ifdef __UDPSend
UDP_Info_queue->put(UDPSendInfo);
#endif
#ifdef __ExportData
//export_Data_Info_queue->put(exportDataInfo);
export_XMLData_Info_queue->put(exportXMLDataInfo);
#endif
}
}

Loading…
Cancel
Save