| | |
| | | |
| | | // 创建句柄 |
| | | int nRet = _camera.eidCreateDevice_Net(sn, EidCamera.EidDeviceDataType.eidDeviceDataTypeSN); |
| | | if (nRet != EidCamera.eidErrorOK) return false; |
| | | if (nRet != EidCamera.eidErrorOK) |
| | | { |
| | | _camera = null; |
| | |
| | | |
| | | public override bool Close() |
| | | { |
| | | if (!IsConnected) return true; |
| | | |
| | | try |
| | | { |
| | | if (IsConnected) |
| | | { |
| | | StopGrabbing(); |
| | | _camera.eidCloseDevice_Net(); |
| | | _camera.eidReleaseHandle_Net(); |
| | | _camera?.eidCloseDevice_Net(); |
| | | } |
| | | // 无论是否连接,都尝试释放句柄 |
| | |
| | | _camera = null; |
| | | |
| | | this.IsConnected = false; |
| | | this.SN = string.Empty; |
| | | this.IsGrabbing = false; |
| | | return true; |
| | | } |
| | |
| | | { |
| | | try |
| | | { |
| | | List<string> barcodes = new List<string>(); |
| | | List<BarcodeInfo> barcodeInfos = new List<BarcodeInfo>(); |
| | | // 解析条码 |
| | | for (int i = 0; i < frameInfo.codeNum; i++) |
| | |
| | | string data = Marshal.PtrToStringAnsi(codeInfo.data); |
| | | if (!string.IsNullOrEmpty(data)) |
| | | { |
| | | barcodes.Add(data); |
| | | BarcodeInfo info = new BarcodeInfo |
| | | { |
| | | Text = data, |
| | |
| | | } |
| | | } |
| | | |
| | | // 转换图像 (如果需要) |
| | | // 转换图像 |
| | | Bitmap bitmap = null; |
| | | if (frameInfo.imageDataLen > 0 && frameInfo.imageData != IntPtr.Zero) |
| | | { |
| | | // 这里简化处理,如果是Jpeg则直接从内存加载,如果是Raw则需转换 |
| | | // 实际项目中可根据 frameInfo.format 进行处理 |
| | | if (frameInfo.isJpeg) |
| | | { |
| | | byte[] managedArray = new byte[frameInfo.imageDataLen]; |
| | |
| | | } |
| | | |
| | | // 触发事件 |
| | | OnBarcodeRead(new BarcodeEventArgs(this.SN, barcodes, bitmap)); |
| | | OnBarcodeRead(new BarcodeEventArgs(this.SN, barcodeInfos, bitmap)); |
| | | } |
| | | catch (Exception ex) |