V20260112-2.3.7
在更多关键的地方添加了错误捕获。 CsvWriter修改为DataRecorder。 打包图片不再开启新线程处理。 部分错误修复。
This commit is contained in:
@@ -166,8 +166,8 @@ void __stdcall ReconnectDevice(unsigned int nMsgType, void* pUser){
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << QString::fromStdString(Username) << " reconnect failed, waiting 1 seconds before retry...";
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
qDebug() << QString::fromStdString(Username) << " reconnect failed, waiting 500 ms before retry...";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
|
||||
// 如果runFlag为false,线程退出
|
||||
@@ -332,11 +332,11 @@ bool Hd_CameraModule_HIK_General::writeData(std::vector<cv::Mat>& mat, QByteArra
|
||||
data = lastError.toUtf8();
|
||||
return true;
|
||||
}
|
||||
if (data == "clearCache") {
|
||||
QMutexLocker locker(n_mutex);
|
||||
queuepic.clear();
|
||||
return true;
|
||||
}
|
||||
//if (data == "clearCache") {
|
||||
// QMutexLocker locker(n_mutex);
|
||||
// queuepic.clear();
|
||||
// return true;
|
||||
//}
|
||||
if (data.contains("exposure")){
|
||||
auto commandList = data.split('_');
|
||||
QMutexLocker locker(n_mutex);
|
||||
|
||||
@@ -136,23 +136,23 @@ void SetGain(float GainValue)
|
||||
}
|
||||
|
||||
//断线重连
|
||||
void __stdcall ReconnectDevice(unsigned int nMsgType, void* pUser){
|
||||
void __stdcall ReconnectDevice(unsigned int nMsgType, void* pUser) {
|
||||
|
||||
qDebug() << "[Error] " << " MV camera disconnects!";
|
||||
|
||||
if (nMsgType == MV_EXCEPTION_DEV_DISCONNECT && cameraStatus.load() == CONNECTED){
|
||||
|
||||
|
||||
if (nMsgType == MV_EXCEPTION_DEV_DISCONNECT && cameraStatus.load() == CONNECTED) {
|
||||
|
||||
// 防止重复启动重连线程
|
||||
bool expected = false;
|
||||
if (!reconnecting.compare_exchange_strong(expected, true)) {
|
||||
qDebug() << "[Warning] Reconnect already in progress, skipping duplicate request";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
cameraStatus.store(RECONNECTING);
|
||||
// 启动后台线程负责重连,避免在回调线程中长时间阻塞
|
||||
std::thread([]() {
|
||||
qDebug() << QString::fromStdString(Username) << " start reconnect thread";
|
||||
qDebug() << QString::fromStdString(Username) << " start reconnect thread";
|
||||
|
||||
// 确保设备资源关闭
|
||||
CloseDevice();
|
||||
@@ -162,21 +162,21 @@ void __stdcall ReconnectDevice(unsigned int nMsgType, void* pUser){
|
||||
qDebug() << QString::fromStdString(Username) << " reconnect attempt:" << times++;
|
||||
if (connectDevice())
|
||||
{
|
||||
qWarning() << QString::fromStdString(Username) << " reconnect success!";
|
||||
qWarning() << QString::fromStdString(Username) << " reconnect success!";
|
||||
cameraStatus.store(CONNECTED);
|
||||
reconnecting.store(false);
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << QString::fromStdString(Username) << " reconnect failed, waiting 1 seconds before retry...";
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
||||
qDebug() << QString::fromStdString(Username) << " reconnect failed, waiting 500 ms before retry...";
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||
}
|
||||
|
||||
|
||||
// 如果runFlag为false,线程退出
|
||||
qDebug() << "[Info] reconnect thread stopped (runFlag=false)";
|
||||
cameraStatus.store(DISCONNECTED);
|
||||
reconnecting.store(false);
|
||||
}).detach();
|
||||
}).detach();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ bool Hd_CameraModule_HIK_General::readData(std::vector<cv::Mat>& mat, QByteArray
|
||||
QMutexLocker locker(n_mutex);
|
||||
cv::Mat img = queuepic.dequeue();
|
||||
mat.push_back(img);
|
||||
|
||||
queuepic.clear();
|
||||
qDebug() << "[INFO] " << __FUNCTION__ << " line:" << __LINE__ << " checkImg readData--CameraName:" << QString::fromStdString(Username) << "--imgIndex : " << imgIndex;
|
||||
return true;
|
||||
}
|
||||
@@ -340,11 +340,11 @@ bool Hd_CameraModule_HIK_General::writeData(std::vector<cv::Mat>& mat, QByteArra
|
||||
data = lastError.toUtf8();
|
||||
return true;
|
||||
}
|
||||
if (data == "clearCache") {
|
||||
/* if (data == "clearCache") {
|
||||
QMutexLocker locker(n_mutex);
|
||||
queuepic.clear();
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
if (data.contains("exposure")) {
|
||||
auto commandList = data.split('_');
|
||||
QMutexLocker locker(n_mutex);
|
||||
|
||||
@@ -77,7 +77,7 @@ bool Hd_VirtualCamera::run()//�����
|
||||
}
|
||||
else {
|
||||
vector<cv::Mat> mats;
|
||||
mats.push_back(cv::Mat(2096,3200,CV_8UC3,cv::Scalar(0,255,0)));
|
||||
mats.push_back(cv::Mat(2096,4800,CV_8UC3,cv::Scalar(0,0,0)));
|
||||
queuePic.enqueue(mats);
|
||||
}
|
||||
n_mutex->unlock();
|
||||
|
||||
Reference in New Issue
Block a user