private bool CreateObjects() { // Create acquisition object if (m_Acquisition != null) { if (m_Acquisition.Create() == false) { DestroyObjects(); return(false); } } // Create buffer object if (m_Buffers != null) { if (m_Buffers.Create() == false) { DestroyObjects(); return(false); } m_Buffers.Clear(); } // Create Xfer object if (m_Xfer != null) { if (m_Xfer.Create() == false) { DestroyObjects(); return(false); } } return(true); }
/// <summary> /// 创建 相关的采集、传输、缓存对象 /// </summary> /// <returns></returns> private bool SeparaInterface_CreateObjects() { // Create acquisition object if (m_Acquisition != null && !m_Acquisition.Initialized) { if (m_Acquisition.Create() == false) { SeparaInterface_DestroyObjects(); return(false); } } // Create buffer object if (m_Buffers != null && !m_Buffers.Initialized) { if (m_Buffers.Create() == false) { SeparaInterface_DestroyObjects(); return(false); } m_Buffers.Clear(); } // Create Xfer object if (m_Xfer != null && !m_Xfer.Initialized) { if (m_Xfer.Create() == false) { SeparaInterface_DestroyObjects(); return(false); } } return(true); }
public bool CAM_connect() { try { //server名称 int ServerCount = SapManager.GetServerCount(); int ServerIndex = ServerCount - 1; string ServerName = SapManager.GetServerName(ServerIndex); //设备Index int CameraCount = SapManager.GetResourceCount(ServerName, SapManager.ResourceType.AcqDevice); int ResourceIndex = CameraCount - 1; //if (CameraCount == 0) MessageBox.Show("没有相机。"); loc = new SapLocation(ServerName, ResourceIndex); //配置文件 string ConfigFileName; string ConfigPath = Environment.GetEnvironmentVariable("SAPERADIR") + "\\camFiles\\User\\"; string[] ccffiles = Directory.GetFiles(ConfigPath, "*.ccf"); int configFileCount = ccffiles.Length; ConfigFileName = ccffiles[0]; //创建对象 if (SapManager.GetResourceCount(ServerName, SapManager.ResourceType.AcqDevice) > 0) { AcqDevice = new SapAcqDevice(loc, ConfigFileName); Buffers = new SapBuffer(1, AcqDevice, SapBuffer.MemoryType.ScatterGather); Xfer = new SapAcqDeviceToBuf(AcqDevice, Buffers); if (!AcqDevice.Create()) { return(false); } } if (!Buffers.Create()) { return(false); } if (!Xfer.Create()) { return(false); } ////ManagedBusManager busMgr = new ManagedBusManager(); ////uint numCameras = busMgr.GetNumOfCameras(); ////ManagedPGRGuid guid = busMgr.GetCameraFromIndex(0); ////m_camera = new ManagedCamera(); ////m_camera.Connect(guid); //m_camera.IsConnected() //CameraInfo camInfo = m_camera.GetCameraInfo(); } catch (FC2Exception ex)//要修改 { MessageBox.Show("相机连接失败。"); MessageBox.Show("Failed to load form successfully: " + ex.Message); return(false); } return(true); }
public void InitDevice(MyAcquisitionParams acqParams = null) { _acqParams = acqParams; if (acqParams == null) { string[] args = new string[0]; if (!ExampleUtils.GetOptions(args, acqParams)) { Console.WriteLine("\nPress any key to terminate\n"); Console.ReadKey(true); return; } } _loc = new SapLocation(acqParams.ServerName, acqParams.ResourceIndex); if (SapManager.GetResourceCount(acqParams.ServerName, SapManager.ResourceType.AcqDevice) > 0) { _acqDevice = new SapAcqDevice(_loc, acqParams.ConfigFileName); _buffers = new SapBufferWithTrash(2, _acqDevice, SapBuffer.MemoryType.ScatterGather); _transfer = new SapAcqDeviceToBuf(_acqDevice, _buffers); // Create acquisition object if (!_acqDevice.Create()) { Console.WriteLine("Error during SapAcqDevice creation!\n"); DestroysObjects(null, _acqDevice, _buffers, _transfer, _view); return; } } _transfer.Pairs[0].EventType = SapXferPair.XferEventType.EndOfFrame; _transfer.XferNotify += new SapXferNotifyHandler(xfer_XferNotify); _transfer.XferNotifyContext = _buffers; // Create buffer object if (!_buffers.Create()) { Console.WriteLine("Error during SapBuffer creation!\n"); DestroysObjects(null, _acqDevice, _buffers, _transfer, _view); return; } // Create buffer object if (!_transfer.Create()) { Console.WriteLine("Error during SapTransfer creation!\n"); DestroysObjects(null, _acqDevice, _buffers, _transfer, _view); return; } _transfer.Grab(); }
public override bool?EvtResist( ) { if (GrabDoneFunc == null) { return(null); } Xfer.XferNotify += new SapXferNotifyHandler(GrabDoneFunc); Xfer.XferNotifyContext = View; Buffers.Create(); Xfer.Create(); return(true); }
/// <summary> /// 注册回调 /// </summary> /// <returns></returns> private bool CreateObjects() { // Create acquisition object if (m_AcqDevice != null && !m_AcqDevice.Initialized) { if (m_AcqDevice.Create() == false) { DestroyObjects(); return(false); } } // Create buffer object if (m_Buffers != null && !m_Buffers.Initialized) { if (m_Buffers.Create() == false) { DestroyObjects(); return(false); } m_Buffers.Clear(); } // Create view object if (m_View != null && !m_View.Initialized) { if (m_View.Create() == false) { DestroyObjects(); return(false); } } if (m_Xfer != null && m_Xfer.Pairs[0] != null) { m_Xfer.Pairs[0].Cycle = SapXferPair.CycleMode.NextWithTrash; if (m_Xfer.Pairs[0].Cycle != SapXferPair.CycleMode.NextWithTrash) { DestroyObjects(); return(false); } } // Create Xfer object if (m_Xfer != null && !m_Xfer.Initialized) { if (m_Xfer.Create() == false) { DestroyObjects(); return(false); } } return(true); }
private void btnTest_Click(object sender, EventArgs e) { //************整个的处理******************// string picpath = "E:\\pic\\7.jpg"; SapBuffer picbuffer = null; picbuffer = new SapBuffer(picpath, SapBuffer.MemoryType.Default); picbuffer.Create(); picbuffer.Load(picpath, -1); IntPtr BufAddress; picbuffer.GetAddress(out BufAddress); mChipDetection.ProcessImage(BufAddress, (uint)picbuffer.Width, (uint)picbuffer.Height); lblwordx.Text = mChipDetection.realworldx.ToString(); lblwordy.Text = mChipDetection.realworldy.ToString(); }
private bool CreateObjects() { // Create acquisition object if (m_Acquisition != null && !m_Acquisition.Initialized) { if (m_Acquisition.Create() == false) { DestroyObjects(); return(false); } } // Create buffer object if (m_Buffers != null && !m_Buffers.Initialized) { if (m_Buffers.Create() == false) { DestroyObjects(); return(false); } m_Buffers.Clear(); } // Create view object if (m_View != null && !m_View.Initialized) { if (m_View.Create() == false) { DestroyObjects(); return(false); } } // Create Xfer object if (m_Xfer != null && !m_Xfer.Initialized) { if (m_Xfer.Create() == false) { DestroyObjects(); return(false); } } return(true); }
// // Step 2: Snap a bright image to calculate the gain coefficients // private void button_Acq_Bright_Click(object sender, EventArgs e) { int nbImagesUsed = m_pFlatField.CorrectionType == SapFlatField.ScanCorrectionType.Field ? int.Parse(textBox_Frame_Avg.Text) : 1; // Set maximum deviation from average pixel value for bright image m_pFlatField.DeviationMaxWhite = int.Parse(textBox_Max_Dev.Text); // Set number of lines to average and vertical offset m_pFlatField.NumLinesAverage = int.Parse(textBox_Line_Avg.Text); m_pFlatField.VerticalOffset = int.Parse(textBox_Vert_Offset.Text); // Set wether to declare pixels with clipped coefficient as defective m_pFlatField.ClippedGainOffsetDefects = ClippedCoefsDefects_checkbox.Checked; if (m_pXfer != null && m_pXfer.Initialized) { m_pLocalBuffer = new SapBuffer(nbImagesUsed, m_pBuffer, SapBuffer.MemoryType.Default); m_pLocalBuffer.Create(); // Acquire an image if (!Snap()) { LogMessage(LogTypes.Error, "Unable to acquire an image"); if (m_pLocalBuffer != null) { m_pLocalBuffer.Destroy(); m_pLocalBuffer.Dispose(); m_pLocalBuffer = null; } return; } } else { // Load an image m_pLocalBuffer = new SapBuffer(1, m_pBuffer, SapBuffer.MemoryType.Default); m_pLocalBuffer.Create(); LoadSaveDlg dlg = new LoadSaveDlg(null, true, false); if (dlg.ShowDialog() != DialogResult.OK) { if (m_pLocalBuffer != null) { m_pLocalBuffer.Destroy(); m_pLocalBuffer.Dispose(); m_pLocalBuffer = null; } return; } String path = dlg.PathName; // Create a temporary buffer in order to know the selected file's native format and pixel depth SapBuffer loadBuffer = new SapBuffer(path, SapBuffer.MemoryType.Default); loadBuffer.Create(); if (loadBuffer.Format != m_pBuffer.Format || loadBuffer.PixelDepth != m_pBuffer.PixelDepth) { LogMessage(LogTypes.Warning, "Image file has a different format than expected. Pixel values may get shifted."); } if (loadBuffer.Width != m_pBuffer.Width || loadBuffer.Height != m_pBuffer.Height) { LogMessage(LogTypes.Error, "Image file selected doesn't have same dimensions as buffer."); if (m_pLocalBuffer != null) { m_pLocalBuffer.Destroy(); m_pLocalBuffer.Dispose(); m_pLocalBuffer = null; } return; } loadBuffer.Load(path, 1); m_pLocalBuffer.Copy(loadBuffer); String str; str = String.Format("Loaded bright image: '{0}'", path); LogMessage(LogTypes.Info, str); } BrightImage(); }
public void CreatEndSqObject(SapBuffer buf, SapTransfer xfer, SapView view) { buf.Create(); xfer.Create(); //view.Create(); }