| | |
| | | // 采集回调 |
| | | private AcquisitionCallbackZA _acquisitionCallback; |
| | | private AcquisitionCompletedCallback _acquisitionCompletedCallback; |
| | | |
| | | private bool _isConnected = false; |
| | | |
| | | public bool _isConnected = false; |
| | | private int _frameCount = 0; // 采集帧计数 |
| | | |
| | | // 图像缓冲 |
| | |
| | | { |
| | | byte[] moduleTypeBytes = new byte[64]; |
| | | byte[] serialNumberBytes = new byte[64]; |
| | | |
| | | |
| | | if (PHM6000Profiler.GetCameraInformation(tempHandle, i, moduleTypeBytes, serialNumberBytes) == 0) |
| | | { |
| | | string currentSn = Encoding.UTF8.GetString(serialNumberBytes).TrimEnd('\0'); |
| | | |
| | | |
| | | // 匹配SN或IP |
| | | if (currentSn == sn || sn.Contains(currentSn)) |
| | | { |
| | |
| | | if (System.Net.IPAddress.TryParse(sn, out _)) |
| | | { |
| | | targetIp = sn; |
| | | targetPort = 5577; |
| | | targetPort = 5577; |
| | | } |
| | | else |
| | | { |
| | |
| | | |
| | | var addr = Encoding.ASCII.GetBytes(targetIp); |
| | | int result = PHM6000Profiler.ConnectToCamera(_cameraHandle, addr, targetPort); |
| | | |
| | | |
| | | if (result == 0) |
| | | { |
| | | _isConnected = true; |
| | |
| | | AsyncLogHelper.Error($"LBCamera[{SN}]: ConnectToCamera failed, result={result}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | catch (Exception ex) |
| | | { |
| | | AsyncLogHelper.Error($"LBCamera: InitDevice异常 - {ex.Message}"); |
| | | if (tempHandle != IntPtr.Zero) PHM6000Profiler.DestroyCameraEntry(tempHandle); |
| | | } |
| | |
| | | if (PHM6000Profiler.GetCameraInformation(tempHandle, i, moduleTypeBytes, serialNumberBytes) == 0) |
| | | { |
| | | string sn = Encoding.UTF8.GetString(serialNumberBytes).TrimEnd('\0'); |
| | | if (!string.IsNullOrEmpty(sn)) |
| | | if (!string.IsNullOrEmpty(sn) && sn.Contains("L")) |
| | | { |
| | | cameraList.Add(sn); |
| | | } |
| | |
| | | public bool StartSingleGrab() |
| | | { |
| | | if (!_isConnected) return false; |
| | | |
| | | |
| | | _isContinuous = false; |
| | | InitBuffer(); |
| | | AsyncLogHelper.Info($"LBCamera[{SN}]: 开始单次采集"); |
| | |
| | | _isContinuous = false; |
| | | if (!_isConnected) return true; |
| | | PHM6000Profiler.StopAcquisition(_cameraHandle); |
| | | |
| | | |
| | | // 停止时如果有未显示的缓存数据,将其显示出来(支持显示不完整的帧) |
| | | lock (_bufferLock) |
| | | { |
| | |
| | | _currentLineCount = 0; |
| | | } |
| | | } |
| | | |
| | | |
| | | isGrabbing = false; |
| | | return true; |
| | | } |
| | |
| | | public override void SetCamConfig(CameraConfig config) { } |
| | | public override void GetCamConfig(out CameraConfig config) { config = new CameraConfig(null); } |
| | | public override bool GetImage(out Bitmap bitmap, int outtime = 3000) { bitmap = null; return false; } |
| | | public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000) |
| | | public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000) |
| | | { |
| | | // 简单实现:软触发等待 |
| | | bitmap = null; |
| | | if(!_isConnected) return false; |
| | | if (!_isConnected) return false; |
| | | |
| | | // 计算理论最小耗时 (仅当使用固定频率触发时) |
| | | int minTime = 0; |
| | |
| | | actualTimeout = minTime + 3000; // 预留3秒余量 |
| | | AsyncLogHelper.Warn($"LBCamera: Provided timeout {outtime}ms is too short for {minTime}ms scan. Extended to {actualTimeout}ms."); |
| | | } |
| | | |
| | | |
| | | using (AutoResetEvent waitHandle = new AutoResetEvent(false)) |
| | | { |
| | | Bitmap res = null; |
| | | EventHandler<CameraEventArgs> handler = (s, e) => { |
| | | if(e.Bitmap != null) { |
| | | res = e.Bitmap.Clone() as Bitmap; |
| | | waitHandle.Set(); |
| | | EventHandler<CameraEventArgs> handler = (s, e) => |
| | | { |
| | | if (e.Bitmap != null) |
| | | { |
| | | res = e.Bitmap.Clone() as Bitmap; |
| | | waitHandle.Set(); |
| | | } |
| | | }; |
| | | ImageGrabbed += handler; |
| | | |
| | | |
| | | if (StartSingleGrab()) |
| | | { |
| | | if (!waitHandle.WaitOne(actualTimeout)) |
| | |
| | | } |
| | | |
| | | ImageGrabbed -= handler; |
| | | |
| | | |
| | | // 确保停止采集 |
| | | StopGrabbing(); |
| | | |
| | | |
| | | bitmap = res; |
| | | return bitmap != null; |
| | | } |
| | |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region Callbacks |
| | |
| | | // 提取灰度(Intensity/Alpha)数据填充到 _rawPixelBuffer |
| | | // LBPointZA结构: float(4) + res(3) + alpha(1). Alpha在偏移7 |
| | | int bufferOffset = _currentLineCount * _currentBitmapWidth; |
| | | |
| | | |
| | | for (int i = 0; i < points; i++) |
| | | { |
| | | if (bufferOffset + i < _rawPixelBuffer.Length) |
| | |
| | | if (_currentLineCount >= _currentBitmapHeight) |
| | | { |
| | | CreateAndFireBitmap(); |
| | | |
| | | |
| | | // 重置,准备下一帧 (如果是连续采集) |
| | | _currentLineCount = 0; |
| | | // _rawPixelBuffer 可以复用,不需要置空 |
| | |
| | | { |
| | | // 如果在连续模式下收到结束信号,尝试自动重启采集 |
| | | AsyncLogHelper.Info($"LBCamera[{SN}]: Continuous mode frame ended, restarting..."); |
| | | Task.Run(() => |
| | | Task.Run(() => |
| | | { |
| | | if (_isContinuous && _isConnected) |
| | | { |
| | |
| | | int intValue = 0; |
| | | double doubleValue = 0; |
| | | int enumValue = 0; |
| | | |
| | | |
| | | if (PHM6000Profiler.GetProfilerParameter(_cameraHandle, (int)nameId, ref intValue, ref doubleValue, ref enumValue) == 0) |
| | | { |
| | | if (p.PropertyType == typeof(int)) |