V20251127-2.2.7

修复CLS切图函数。
同步最新的相机模块。
This commit is contained in:
2025-11-27 00:36:14 +08:00
parent eeffb1dcd6
commit b17e09fe2d
9 changed files with 162 additions and 807 deletions
@@ -15,7 +15,9 @@ enum triggerModeEnum {
HARDWARE,
EMPTY
};
statusEnum cameraStatus = DISCONNECTED;
std::atomic<statusEnum> cameraStatus(DISCONNECTED);
std::atomic<bool> reconnecting(false);
std::mutex handleMutex;
triggerModeEnum triggerMode = HARDWARE;
int getImageTimeOut = 3000;
bool runFlag = true;
@@ -90,8 +92,9 @@ bool connectDevice()
if (handle != NULL)
{
MV_CC_StopGrabbing(handle);
MV_CC_CloseDevice(handle);
MV_CC_DestroyHandle(handle);
handle = NULL;
//MV_CC_CloseDevice(handle);
//MV_CC_DestroyHandle(handle);
}
//打开相机
@@ -113,6 +116,7 @@ bool connectDevice()
if (MV_OK != nRet)
return false;
MV_CC_StartGrabbing(handle);
cameraStatus.store(CONNECTED);
return true;
}
void SetExposureTime(float exposureValue)
@@ -133,27 +137,42 @@ void __stdcall ReconnectDevice(unsigned int nMsgType, void* pUser) {
qDebug() << "[Error] " << " MV camera disconnects!";
if (nMsgType == MV_EXCEPTION_DEV_DISCONNECT && cameraStatus == CONNECTED) {
if (nMsgType == MV_EXCEPTION_DEV_DISCONNECT && cameraStatus.load() == CONNECTED) {
cameraStatus = RECONNECTING;
// 防止重复启动重连线程
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() << "[Info] start reconnect thread";
qDebug() << QString::fromStdString(Username) << " start reconnect thread";
// 确保设备资源关闭
CloseDevice();
int times = 0;
while (runFlag)
{
qDebug() << "[Info] reconnect times:" << times++;
qDebug() << QString::fromStdString(Username) << " reconnect attempt:" << times++;
if (connectDevice())
{
qWarning() << "[Hd_CameraModule_HIK] reconnect success!";
cameraStatus = CONNECTED;
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));
}
// 如果runFlag为false,线程退出
qDebug() << "[Info] reconnect thread stopped (runFlag=false)";
cameraStatus.store(DISCONNECTED);
reconnecting.store(false);
}).detach();
}
}
@@ -249,6 +268,7 @@ void CloseDevice()
//MV_CC_CloseDevice(handle);
//MV_CC_DestroyHandle(handle);
}
handle = NULL;
//nRet = MV_CC_CloseDevice(handle);
//nRet = MV_CC_DestroyHandle(handle);
}