using Microsoft.VisualBasic.ApplicationServices; using LB_VisionProcesses; using Newtonsoft.Json.Linq; using OpenCvSharp; using MVAPI; using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing.Imaging; using System.Dynamic; using System.Linq; using System.Net.NetworkInformation; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using LB_VisionProcesses.Cameras; namespace LB_VisionProcesses.Cameras.MicroCameras { public class MicroCamera : BaseCamera { #region variable IntPtr m_hCam = IntPtr.Zero;// 设备对象 | device object private int camIndex = -1; IntPtr m_hImage = IntPtr.Zero; MVAPI.MV_PixelFormatEnums m_PixelFormat; int m_nWidth; int m_nHeight; UInt32 m_nCapture; UInt32 m_nCapCntBase; UInt16 m_nLastID; UInt32 m_nReceive; MVAPI.MV_SNAPPROC StreamCBDelegate = null; public delegate int InvokeDraw(); InvokeDraw invokeDraw = null; IAsyncResult ia = null; #endregion public MicroCamera() : base() { Brand = CameraBrand.MicroCamera; //MVGigE.MVInitLib(); } public override bool AutoBalanceWhite() { try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVSetBalanceWhiteAuto(m_hCam, BalanceWhiteAutoEnums.BalanceWhiteAuto_Once); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) { Debug.WriteLine($"【{DateTime.Now:HH:mm:ss.fff}】MVSetBalanceWhiteAuto failed! ErrorCode[{res}]"); return false; } return true; } catch { return false; } } public override bool CloseDevice() { try { if (IntPtr.Zero == m_hCam) return true; // 保存相机属性配置文件 // Save configuration of the device SaveUserConfiguration(); StreamCBDelegate -= new MVAPI.MV_SNAPPROC(StreamCB); StopGrabbing(); MVGigE.MVCloseCam(m_hCam); MVAPI.MVImage.MVImageRelease(m_hImage); m_hCam = IntPtr.Zero; return true; } catch { return false; } } private bool SaveUserConfiguration() { try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; // 设置UserSet1配置为下次相机启动时使用的默认配置 res = MVGigE.MVSetDefaultUserSet(m_hCam, UserSetSelectorEnums.UserSetSelector_UserSet1); res = MVGigE.MVSaveUserSet(m_hCam, UserSetSelectorEnums.UserSetSelector_UserSet1); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSaveUserSet failed! ErrorCode[{res}]"); return true; } catch { return false; } } private bool LoadUserConfiguration() { try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVLoadUserSet(m_hCam, UserSetSelectorEnums.UserSetSelector_UserSet1); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVLoadUserSet failed! ErrorCode[{res}]"); // 设置UserSet1配置为下次相机启动时使用的默认配置 res = MVGigE.MVSetDefaultUserSet(m_hCam, UserSetSelectorEnums.UserSetSelector_UserSet1); return true; } catch { return false; } } public override bool GetExpouseTime(out double value) { value = 0; try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVGetExposureTime(m_hCam, out double pExposuretime); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVGetExposureTime failed! ErrorCode[{res}]"); value = Convert.ToDouble(pExposuretime); return true; } catch { return false; } } public override bool GetGain(out double value) { value = 0; try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVGetGain(m_hCam, out double pGain); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVGetGain failed! ErrorCode[{res}]"); value = Convert.ToDouble(pGain); return true; } catch { return false; } } public override bool GetLineStatus(IOLines line, out LineStatus lineStatus) { lineStatus = LineStatus.Low; try { if (IntPtr.Zero == m_hCam) return false; return true; } catch { return false; } } public override List GetListEnum() { List snList = new List(); try { bool isfirst = true; MVGigE.MVUpdateCameraList(); if (MVGigE.MVGetNumOfCameras(out int nCameraCount) == MVAPI.MVSTATUS_CODES.MVST_SUCCESS) { for (int i = 0; i < nCameraCount; i++) { MVAPI.MVCamInfo info; MVGigE.MVGetCameraInfo((byte)i, out info); IntPtr hCam; string str = "否"; if (MVGigE.MVOpenCamByIndex((byte)i, out hCam) == MVAPI.MVSTATUS_CODES.MVST_SUCCESS) { str = "是"; MVGigE.MVCloseCam(hCam); if (isfirst == true) { isfirst = false; } } ListViewItem lvi = new ListViewItem(); lvi.Tag = i; lvi.Text = str; lvi.SubItems.Add(info.mModelName); lvi.SubItems.Add(info.mSerialNumber); snList.Add($"{info.mSerialNumber}-{info.mUserDefinedName}"); } } else Debug.WriteLine("无法刷新列表"); } catch { } return snList; } public override bool GetTriggerDelay(out double delay) { delay = 0; try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVGetTriggerDelay(m_hCam, out uint time); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVGetTriggerDelay failed! ErrorCode[{res}]"); delay = Convert.ToDouble(time); return true; } catch { return false; } } public override bool GetTriggerFliter(out double flitertime) { flitertime = 0; try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVGetTimerDuration(m_hCam, out uint Duration); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVGetTimerDuration failed! ErrorCode[{res}]"); flitertime = Convert.ToDouble(Duration); return true; } catch { return false; } } public override bool GetTriggerMode(out TriggerMode mode, out TriggerSource source) { mode = TriggerMode.Off; source = TriggerSource.Software; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; try { if (IntPtr.Zero == m_hCam) return false; res = MVGigE.MVGetTriggerMode(m_hCam, out MVAPI.TriggerModeEnums pMode); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) { Debug.WriteLine($"MVGetTriggerMode failed! ErrorCode[{res}]"); return false; } switch (pMode) { case MVAPI.TriggerModeEnums.TriggerMode_Off: mode = TriggerMode.Off; break; case MVAPI.TriggerModeEnums.TriggerMode_On: mode = TriggerMode.On; break; } res = MVGigE.MVGetTriggerSource(m_hCam, out MVAPI.TriggerSourceEnums pSource); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) { Debug.WriteLine($"MVGetTriggerSource failed! ErrorCode[{res}]"); return false; } switch (pSource) { case MVAPI.TriggerSourceEnums.TriggerSource_Software: source = TriggerSource.Software; break; case MVAPI.TriggerSourceEnums.TriggerSource_Line1: source = TriggerSource.Line1; break; } return true; } catch { return false; } } public override bool GetTriggerPolarity(out TriggerPolarity polarity) { polarity = TriggerPolarity.RisingEdge; try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVGetTriggerActivation(m_hCam, out TriggerActivationEnums pAct); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVGetTriggerActivation failed! ErrorCode[{res}]"); switch (pAct) { case TriggerActivationEnums.TriggerActivation_RisingEdge: polarity = TriggerPolarity.RisingEdge; break; case TriggerActivationEnums.TriggerActivation_FallingEdge: polarity = TriggerPolarity.FallingEdge; break; } return true; } catch { return false; } } public override bool InitDevice(string CamSN, object handle) { try { bool isFind = false; bool isfirst = true; MVGigE.MVUpdateCameraList(); if (MVGigE.MVGetNumOfCameras(out int nCameraCount) == MVAPI.MVSTATUS_CODES.MVST_SUCCESS) { for (int i = 0; i < nCameraCount; i++) { MVAPI.MVCamInfo info; MVGigE.MVGetCameraInfo((byte)i, out info); string str = "否"; if (MVGigE.MVOpenCamByIndex((byte)i, out IntPtr hCam) == MVAPI.MVSTATUS_CODES.MVST_SUCCESS) { str = "是"; MVGigE.MVCloseCam(hCam); if (isfirst == true) { isfirst = false; } } ListViewItem lvi = new ListViewItem(); lvi.Tag = i; lvi.Text = str; lvi.SubItems.Add(info.mModelName); lvi.SubItems.Add(info.mSerialNumber); if (CamSN == $"{info.mSerialNumber}-{info.mUserDefinedName}") { SN = CamSN; camIndex = i; } } } if (camIndex != -1) { // 创建设备句柄 // Create Device Handle // open device MVAPI.MVSTATUS_CODES res = MVGigE.MVOpenCamByIndex((byte)camIndex, out m_hCam); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) { MessageBox.Show($"MVOpenCamByIndex failed! ErrorCode[{res}]", "异常"); return false; } int w, h; res = MVGigE.MVGetWidth(m_hCam, out w); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVGetWidth failed! ErrorCode[{res}]"); res = MVGigE.MVGetHeight(m_hCam, out h); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVGetHeight failed! ErrorCode[{res}]"); res = MVGigE.MVGetPixelFormat(m_hCam, out m_PixelFormat); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVGetPixelFormat failed! ErrorCode[{res}]"); if (res == MVSTATUS_CODES.MVST_SUCCESS) { m_nWidth = w; m_nHeight = h; if (m_PixelFormat == MVAPI.MV_PixelFormatEnums.PixelFormat_Mono8) m_hImage = MVAPI.MVImage.MVImageCreate(m_nWidth, m_nHeight, 8); else m_hImage = MVAPI.MVImage.MVImageCreate(m_nWidth, m_nHeight, 24); } // 设置为Off会一直触发回调 SetTriggerMode(TriggerMode.On, TriggerSource.Software); //LoadUserConfiguration(); StreamCBDelegate += new MVAPI.MV_SNAPPROC(StreamCB); // 开始拉流 // Start grabbing if (!StartGrabbing()) { Debug.WriteLine("开始采集失败"); return false; } return true; } else { MessageBox.Show("相机未找到,请检查连接或SN是否正确!", "异常"); return false; } } catch { return false; } } private ColorPalette m_MonoColorPalette = null; public Bitmap ImageData2Bitmap(IntPtr hImage) { try { Bitmap bitmap = null; IntPtr ptrSrc = MVAPI.MVImage.MVImageGetBits(hImage); int nWidth = MVAPI.MVImage.MVImageGetWidth(hImage); int nHeight = MVAPI.MVImage.MVImageGetHeight(hImage); int bpp = MVImage.MVImageGetBPP(hImage); if (bpp == 8) { bitmap = new Bitmap(nWidth, nHeight, nWidth, System.Drawing.Imaging.PixelFormat.Format8bppIndexed, ptrSrc); if (m_MonoColorPalette == null) { Bitmap monoBitmap = new Bitmap(1, 1, PixelFormat.Format8bppIndexed); m_MonoColorPalette = monoBitmap.Palette; for (int i = 0; i < 256; i++) m_MonoColorPalette.Entries[i] = Color.FromArgb(i, i, i); } bitmap.Palette = m_MonoColorPalette; } else { bitmap = new Bitmap(nWidth, nHeight, 3 * nWidth, System.Drawing.Imaging.PixelFormat.Format24bppRgb, ptrSrc); } return bitmap; } catch { return null; } } // 数据帧回调函数 private int StreamCB(ref MVAPI.IMAGE_INFO pInfo, IntPtr UserVal) { //[FieldOffset(0)] //public UInt64 nTimeStamp; ///< 时间戳,采集到图像的时刻,精度为0.01us ; //[FieldOffset(8)] //public ushort nBlockId; ///< 帧号,从开始采集开始计数 //[FieldOffset(28)] //public byte nMissingPackets;///< 传输过程中丢掉的包数量 Debug.WriteLine($"StreamCB callback success!" + $"[时间戳:{pInfo.nTimeStamp}][帧号:{pInfo.nBlockId}][丢包数:{pInfo.nMissingPackets}]"); UInt16 id = pInfo.nBlockId; if (id < m_nLastID) { if ((id < 100) && (m_nLastID > 60000)) { m_nCapCntBase += 65535; } } m_nLastID = id; m_nCapture = m_nCapCntBase + id; m_nReceive++; MVGigE.MVInfo2Image(m_hCam, ref pInfo, m_hImage); try { if (this.ImageGrabbed != null) this.ImageGrabbed(this, new CameraEventArgs(SN, ImageData2Bitmap(m_hImage))); CallBackImg = ImageData2Bitmap(m_hImage); try { if (GetTriggerMode(out TriggerMode mode, out TriggerSource source)) { if (mode == TriggerMode.On && source != TriggerSource.Software) TriggerRunMessageReceived?.Invoke(SN, source.ToString()); // 触发运行事件 } } catch { } } catch { return -1; } return 0; } public override bool SetExpouseTime(double value) { try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVGetExposureTimeRange(m_hCam, out double minExp, out double maxExp); if (value >= minExp && value <= maxExp && res == MVAPI.MVSTATUS_CODES.MVST_SUCCESS) res = MVGigE.MVSetExposureTime(m_hCam, value); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSetExposureTime failed! ErrorCode[{res}]"); return true; } catch { return false; } } public override bool SetGain(double gain) { try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVGetGainRange(m_hCam, out double minGaim, out double maxGain); if (gain >= minGaim && gain <= maxGain && res == MVAPI.MVSTATUS_CODES.MVST_SUCCESS) res = MVGigE.MVSetGain(m_hCam, gain); else Debug.WriteLine($"Gain value out of range! Min: {minGaim}, Max: {maxGain}"); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSetGain failed! ErrorCode[{res}]"); return true; } catch { return false; } } public override bool SetLineMode(IOLines line, LineMode mode) { try { if (IntPtr.Zero == m_hCam) return false; return true; } catch { return false; } } public override bool SetLineStatus(IOLines line, LineStatus linestatus) { try { if (IntPtr.Zero == m_hCam) return false; return true; } catch { return false; } } public override bool SetTriggerDelay(double delay) { try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVSetTriggerDelay(m_hCam, Convert.ToUInt16(delay)); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSetTriggerDelay failed! ErrorCode[{res}]"); return true; } catch { return false; } } public override bool SetTriggerFliter(double flitertime) { try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVSetTimerDuration(m_hCam, Convert.ToUInt16(flitertime)); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSetTimerDuration failed! ErrorCode[{res}]"); return true; } catch { return false; } } public override bool SetTriggerMode(TriggerMode mode, TriggerSource source = TriggerSource.None) { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; // 设置触发模式 // Set trigger mode to On res = MVGigE.MVSetTriggerMode(m_hCam, mode == TriggerMode.On ? MVAPI.TriggerModeEnums.TriggerMode_On : MVAPI.TriggerModeEnums.TriggerMode_Off); if (mode != TriggerMode.On) { double fps = 0; double fpsMin = 0; int t = 0; MVGigE.MVGetFrameRateRange(m_hCam, out fpsMin, out fps); t = (int)(1500 / fps); Thread.Sleep(t); } if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSetTriggerMode failed! ErrorCode[{res}]"); res = MVGigE.MVSetTriggerSource(m_hCam, source == TriggerSource.Software ? MVAPI.TriggerSourceEnums.TriggerSource_Software : MVAPI.TriggerSourceEnums.TriggerSource_Line1); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSetTriggerSource failed! ErrorCode[{res}]"); if (source != TriggerSource.Software) { res = MVGigE.MVSetStrobeSource(m_hCam, MVAPI.LineSourceEnums.LineSource_ExposureActive); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSetStrobeSource failed! ErrorCode[{res}]"); MVGigE.MVSetStrobeInvert(m_hCam, true); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSetStrobeInvert failed! ErrorCode[{res}]"); } return true; } public override bool SetTriggerPolarity(TriggerPolarity polarity) { try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVSetTriggerActivation(m_hCam, TriggerActivationEnums.TriggerActivation_FallingEdge); switch (polarity) { case TriggerPolarity.RisingEdge: res = MVGigE.MVSetTriggerActivation(m_hCam, TriggerActivationEnums.TriggerActivation_RisingEdge); break; case TriggerPolarity.FallingEdge: res = MVGigE.MVSetTriggerActivation(m_hCam, TriggerActivationEnums.TriggerActivation_FallingEdge); break; default: res = MVSTATUS_CODES.MVST_ERROR; break; } if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVSetTriggerActivation failed! ErrorCode[{res}]"); return true; } catch { return false; } } public override bool SoftTrigger() { try { if (IntPtr.Zero == m_hCam) return false; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVTriggerSoftware(m_hCam); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVTriggerSoftware failed! ErrorCode[{res}]"); //else // Debug.WriteLine("MVTriggerSoftware success!"); //StreamCBDelegate -= new MVAPI.MV_SNAPPROC(StreamCB); //res = MVGigE.MVSingleGrab(m_hCam, m_hImage, 1000); //Bitmap bitmap = ImageData2Bitmap(m_hImage); //if (bitmap == null) // Debug.WriteLine("ImageData2Bitmap failed!"); //CallBackImg = bitmap.Clone() as Bitmap; //if (this.ImageGrabbed != null) // this.ImageGrabbed(this, new CameraEventArgs(SN, CallBackImg)); //StreamCBDelegate += new MVAPI.MV_SNAPPROC(StreamCB); return true; } catch { return false; } } public override bool StartGrabbing() { try { if (IntPtr.Zero == m_hCam) { Debug.WriteLine($"m_hCam is NULL!"); return false; } CallBackImg = null; MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVStartGrab(m_hCam, StreamCBDelegate, IntPtr.Zero); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVStartGrab failed! ErrorCode[{res}]"); isGrabbing = true; return true; } catch { return false; } } public override bool StopGrabbing() { try { if (IntPtr.Zero == m_hCam) return true; // 停止拉流 // Stop grabbing MVAPI.MVSTATUS_CODES res = MVSTATUS_CODES.MVST_SUCCESS; res = MVGigE.MVStopGrab(m_hCam); if (res != MVAPI.MVSTATUS_CODES.MVST_SUCCESS) Debug.WriteLine($"MVStopGrab failed! ErrorCode[{res}]"); isGrabbing = false; CallBackImg = null; return true; } catch { return false; } } public override bool GetImage(out Bitmap bitmap, int outtime = 3000) { bitmap = null; try { // 设置超时时间 DateTime lastTime = DateTime.Now.AddMilliseconds(outtime); // 判断是否超时 while (lastTime > DateTime.Now)// 设置超时时间为 3 秒 { try { if (CallBackImg != null) { // 保存旧 Bitmap 并释放 bitmap = CallBackImg.Clone() as Bitmap; // 创建副本 // 释放旧资源 CallBackImg.Dispose(); CallBackImg = null; return true; } } catch { } Thread.Sleep(10); } return false; } catch { return bitmap == null ? false : true; } } public override bool GetImageWithSoftTrigger(out Bitmap bitmap, int outtime = 3000) { if (!isGrabbing) { StartGrabbing(); } GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); if (triggerMode != TriggerMode.On && triggerSource != TriggerSource.Software) { SetTriggerMode(TriggerMode.On, TriggerSource.Software); } bitmap = null; CallBackImg = null; if (!SoftTrigger()) { return false; } // 开始时间 DateTime startTime = DateTime.Now; // 当前时间 // 判断是否超时 while (DateTime.Now < startTime.AddMilliseconds(outtime))// 设置超时时间为 3 秒 { GetImage(out bitmap, 50); if (bitmap != null) { break; } Thread.Sleep(10); } if (triggerMode != TriggerMode.On) { SetTriggerMode(TriggerMode.On, triggerSource); } return (bitmap != null); } public override void SetCamConfig(CameraConfig config) { if (Enum.TryParse(config.Params.Inputs["触发模式"].ToString(), out TriggerMode TriggerMode) && Enum.TryParse(config.Params.Inputs["触发方式"].ToString(), out TriggerSource TriggerSource) && Enum.TryParse(config.Params.Inputs["触发极性"].ToString(), out TriggerPolarity TriggerPolarity) ) { SetTriggerMode(TriggerMode, TriggerSource); SetTriggerPolarity(TriggerPolarity); //SetTriggerFliter(Convert.ToDouble(config.Params.Inputs["触发消抖"].ToString())); //SetTriggerDelay(Convert.ToDouble(config.Params.Inputs["触发延时"].ToString())); SetExpouseTime(Convert.ToDouble(config.Params.Inputs["曝光时间"].ToString())); SetGain(Convert.ToDouble(config.Params.Inputs["增益"].ToString())); } } public override void GetCamConfig(out CameraConfig config) { GetTriggerMode(out TriggerMode triggerMode, out TriggerSource triggerSource); GetTriggerPolarity(out TriggerPolarity triggerPolarity); //GetTriggerFliter(out double triggerfilter); //GetTriggerDelay(out double triggerdelay); GetExpouseTime(out double expouseTime); GetGain(out double gain); config = new CameraConfig(null); config.Params.Inputs.Add("触发模式", triggerMode); config.Params.Inputs.Add("触发方式", triggerSource); config.Params.Inputs.Add("触发极性", triggerPolarity); //config.Params.Inputs.Add("触发消抖", triggerfilter); //config.Params.Inputs.Add("触发延时", triggerdelay); config.Params.Inputs.Add("曝光时间", expouseTime); config.Params.Inputs.Add("增益", gain); } public override bool StartWith_SoftTriggerModel() { SetTriggerMode(TriggerMode.Off, TriggerSource.Software); return StartGrabbing(); } public override bool StartWith_HardTriggerModel(TriggerSource hardtriggeritem = TriggerSource.Line0) { if (hardtriggeritem == TriggerSource.Software) hardtriggeritem = TriggerSource.Line0; SetTriggerMode(TriggerMode.On, hardtriggeritem); return StartGrabbing(); } public override bool StartContinuousGrab() { throw new NotImplementedException(); } } }