private List <string> getAvilableInterface() { List <string> avilabeInterface = new List <string>(); string halconroot = Environment.GetEnvironmentVariable("HALCONROOT"); string halconarch = Environment.GetEnvironmentVariable("HALCONARCH"); string a = halconroot + "/bin/" + halconarch; var acquisitionInterface = Directory.EnumerateFiles(a, "hacq*.dll"); foreach (var item in acquisitionInterface) { string interfacename = Regex.Match(item, "hAcq(.+)(?:\\.dll)").Groups[1].Value; HTuple device; try { HInfo.InfoFramegrabber(interfacename, "info_boards", out device); if (device.Length > 0) { avilabeInterface.Add(interfacename); } } catch (Exception ex) { } } return(avilabeInterface); }
/** * Display all the available devices of an acquisition interface. * * @param AcqInterface Acquisition interface. * @return List of the detected devices. */ static HTuple showAvailableDevices(HTuple AcqInterface) { HTuple devices; Console.WriteLine(System.Environment.NewLine + "Detect and show all available devices..." + System.Environment.NewLine); HInfo.InfoFramegrabber(AcqInterface.S.ToString(), "device", out devices); if (devices.Length > 0) { Console.WriteLine("Available devices:"); } else { Console.WriteLine("Found no devices."); return(devices); } for (int i = 0; i < devices.Length; i++) { Console.WriteLine((i + 1) + ")" + devices.TupleSelect(i).S.ToString()); } return(devices); }
/** * Display all available interfaces that have at least one device available. * * @return List of the detected interfaces. */ static HTuple showAvailableInterfaces() { HTuple deviceInfo, deviceValue, interfacesAll, temp; HTuple interfaces = new HTuple(); Console.WriteLine(System.Environment.NewLine + "Detect and show all available interfaces..." + System.Environment.NewLine); interfacesAll = HInfo.GetParamInfo("info_framegrabber", "Name", "values"); if (interfacesAll.Length > 0) { Console.WriteLine("Available interfaces:"); } else { Console.WriteLine("Found no interfaces."); return(interfaces); } ErrorModes errorMode = GetErrorMode(); // Disable error dialog boxes on interface detection. SetErrorMode(ErrorModes.SEM_FAILCRITICALERRORS | ErrorModes.SEM_NOGPFAULTERRORBOX | ErrorModes.SEM_NOOPENFILEERRORBOX); for (int i = 0; i < interfacesAll.Length; i++) { try { temp = interfacesAll.TupleSelect(i); deviceInfo = HInfo.InfoFramegrabber(temp.S.ToString(), "device", out deviceValue); } catch (HalconException) { // Interface not available. continue; } if (deviceValue.Length > 0) { interfaces.Append(interfacesAll.TupleSelect(i)); Console.WriteLine(interfaces.Length + ")" + interfacesAll.TupleSelect(i).S.ToString()); } } // Restore previous error mode. SetErrorMode(errorMode); return(interfaces); }
private List <string> getAvailableInterfaces() { DictDevicesAvailable.Clear(); //------------------------------------------------------------ // Khai báo thư mục mặc định của Halcon //------------------------------------------------------------ List <string> availableInterfaces = new List <string>(); string halconRoot = Environment.GetEnvironmentVariable("HALCONROOT"); string halconArch = Environment.GetEnvironmentVariable("HALCONARCH"); string a = halconRoot + "/bin/" + halconArch; //------------------------------------------------------------ // Lấy tất cả Interface của Halcon //------------------------------------------------------------ var acquisitionInterfaces = Directory.EnumerateFiles(a, "hacq*.dll"); //------------------------------------------------------------ // Với mỗi Interface, tìm tất cả Device không phải dạng XL //------------------------------------------------------------ foreach (string item in acquisitionInterfaces) { // Extract the interface name with an regular expression string interfaceName = Regex.Match(item, "hAcq(.+)(?:\\.dll)").Groups[1].Value; if (!interfaceName.EndsWith("xl")) { try { // Querry available devices HTuple devices; HInfo.InfoFramegrabber(interfaceName, "info_boards", out devices); // In case that devices were found add it to the available interfaces if (devices.Length > 0) { availableInterfaces.Add(interfaceName); DictDevicesAvailable.Add(interfaceName, devices.SArr.ToList()); } } catch (Exception ex) { } } } return(availableInterfaces); }
private void cbxInterface_SelectedIndexChanged(object sender, EventArgs e) { cbxCamera.Items.Clear(); string interfacename = cbxInterface.SelectedItem.ToString(); HTuple device; HInfo.InfoFramegrabber(interfacename, "device", out device); for (int i = 0; i < device.Length; i++) { cbxCamera.Items.Add(device[i].S); } if (cbxCamera.Items.Count == 0) { cbxCamera.Items.Add(Application.StartupPath + "/images/barcode/code128"); } else { cbxCamera.SelectedIndex = device.Length - 1; } }
// lay ve Interface theo list private List <string> getAvailableInterfaces() { // Detect the HALCON binary folder List <string> availableInterfaces = new List <string>(); string halconRoot = Environment.GetEnvironmentVariable("HALCONROOT"); string halconArch = Environment.GetEnvironmentVariable("HALCONARCH"); string a = halconRoot + "/bin/" + halconArch; // Querry all available interfaces var acquisitionInterfaces = Directory.EnumerateFiles(a, "hacq*.dll"); // For each Interface (check for non XL version) we test with InfoFramegrabber if devices are connected foreach (string item in acquisitionInterfaces) { // Extract the interface name with an regular expression string interfaceName = Regex.Match(item, "hAcq(.+)(?:\\.dll)").Groups[1].Value; // only check non XL interfaces if (!interfaceName.EndsWith("xl")) { try { // Querry available devices HTuple devices; HInfo.InfoFramegrabber(interfaceName, "info_boards", out devices); // In case that devices were found add it to the available interfaces if (devices.Length > 0) { availableInterfaces.Add(interfaceName); } } catch (Exception ex) { } } } return(availableInterfaces); }
static void Main(string[] args) { HTuple interfaces; HTuple devices; HTuple callbackTypes; HTuple openDefaults; long callbackIndex; long interfaceIndex; long deviceIndex; HFramegrabber acq = null; Payload userContext = default(Payload); bool bWaitUserInteraction = true; try { gAcqCondition = new HCondition("", ""); gAcqMutex = new HMutex("", ""); // Get available interfaces. interfaces = showAvailableInterfaces(); if (interfaces.Length < 1) { exitProgram(ref acq, null, bWaitUserInteraction); } Console.Write(System.Environment.NewLine + "Enter the number of the interface you want to use: "); interfaceIndex = readUserSelection(interfaces.Length); // Show selected interface and revision. HTuple revision; HInfo.InfoFramegrabber( interfaces.TupleSelect(interfaceIndex - 1).S.ToString(), "revision", out revision); Console.WriteLine( System.Environment.NewLine + "Interface selected: " + interfaces.TupleSelect(interfaceIndex - 1).S.ToString() + " (Rev. " + revision.S.ToString() + ")"); // Get available devices for the selected interface. devices = showAvailableDevices(interfaces.TupleSelect(interfaceIndex - 1)); if (devices.Length < 1) { exitProgram(ref acq, null, bWaitUserInteraction); } Console.Write(System.Environment.NewLine + "Enter the number of the device you want to connect to: "); deviceIndex = readUserSelection(devices.Length); // Get open_framegrabber default values and open the selected device. Console.WriteLine( System.Environment.NewLine + "Open the specified device by calling open_framegrabber()..."); HInfo.InfoFramegrabber( interfaces.TupleSelect(interfaceIndex - 1).S.ToString(), "defaults", out openDefaults); int vRes = 0, hRes = 0, iWidth = 0, iHeight = 0, sRow = 0, sColumn = 0; try { hRes = Convert.ToInt32(openDefaults.TupleSelect(0).L); vRes = Convert.ToInt32(openDefaults.TupleSelect(1).L); iWidth = Convert.ToInt32(openDefaults.TupleSelect(2).L); iHeight = Convert.ToInt32(openDefaults.TupleSelect(3).L); sRow = Convert.ToInt32(openDefaults.TupleSelect(4).L); sColumn = Convert.ToInt32(openDefaults.TupleSelect(5).L); } catch (Exception) { // Failed to convert one of the parameters. Console.WriteLine("Failed to convert long to int"); exitProgram(ref acq, null, bWaitUserInteraction); } acq = new HFramegrabber( interfaces.TupleSelect(interfaceIndex - 1).S.ToString(), hRes, vRes, iWidth, iHeight, sRow, sColumn, openDefaults.TupleSelect(6).S.ToString(), openDefaults.TupleSelect(7), openDefaults.TupleSelect(8), openDefaults.TupleSelect(9), openDefaults.TupleSelect(10).S.ToString(), cCameraType, devices.TupleSelect(deviceIndex - 1), openDefaults.TupleSelect(13), openDefaults.TupleSelect(14)); // If the interface supports it, enable a helper that activates GenICam // events during SetFramegrabberCallback. try { acq.SetFramegrabberParam("event_notification_helper", "enable"); } catch (Exception) {} // Show the available callback types and register a specific one. callbackTypes = showAvailableCallbackTypes(ref acq); if (callbackTypes.Length < 1) { exitProgram(ref acq, null, bWaitUserInteraction); } Console.Write(System.Environment.NewLine + "Enter the number of the " + "callback type you like to register: "); callbackIndex = readUserSelection(callbackTypes.Length); // Use the userContext to pass your own class or structure with the // information that you need on the other side of the callback. // Since we are using Thread.Start(obj) save the variables we need // in userContext, before passing it to the Thread. // Note that if you want to do changes to 'acq' on different threads // the you should sincronize all thread an use a single // 'acq' reference. Additionally, if you change any of the // internal values of 'userContext' will not be reflected // on the other side. userContext = new Payload(acq, callbackTypes.TupleSelect(callbackIndex - 1)); // Start worker thread to manage the incoming callbacks. With the // provided userContext. gThreadRunning = false; gThreadHandle = new Thread(new ParameterizedThreadStart(workerThread)); gThreadHandle.Start(userContext); gAcqMutex.LockMutex(); // Register the callback after we start the thread. This is to avoid // cases where the events start comming immediately. If you don't do // it this way you might lose some events. if (!registerCallbackType(ref acq, userContext.eventType, userContext)) { gAcqMutex.UnlockMutex(); exitProgram(ref acq, userContext.eventType.S.ToString(), bWaitUserInteraction); } // Please place your code here, to force the execution of a specific // callback type. Console.WriteLine( System.Environment.NewLine + "If the registered event is signaled, the previously registered" + System.Environment.NewLine + "user-specific callback function will be executed." + System.Environment.NewLine); // e.g. 'ExposureEnd' Console.WriteLine( "Start grabbing an image." + System.Environment.NewLine + "If e.g. an exposure_end was registered, the image grabbing will " + System.Environment.NewLine + "force the execution of the user-specific callback function." + System.Environment.NewLine); Console.WriteLine("This example is going to process " + cMaxGrabImages + " incoming callbacks"); try { acq.GrabImageStart(-1); } catch (HalconException exc) { Console.WriteLine(exc.GetErrorMessage()); } gAcqMutex.UnlockMutex(); // Wait for user interaction to kill the program. waitUserInteraction(); bWaitUserInteraction = false; exitProgram(ref acq, userContext.eventType.S.ToString(), bWaitUserInteraction); } catch (HOperatorException exc) { Console.WriteLine(exc.GetErrorMessage()); if (exc.GetExtendedErrorCode() != 0 || exc.GetExtendedErrorMessage().Length > 0) { Console.WriteLine("Extended error code: " + exc.GetExtendedErrorCode()); Console.WriteLine("Extended error message: " + exc.GetExtendedErrorMessage()); } if (userContext.eventType == null || userContext.eventType.Length == 0) { exitProgram(ref acq, null, bWaitUserInteraction); } else { exitProgram(ref acq, userContext.eventType.S.ToString(), bWaitUserInteraction); } } }