Пример #1
0
        /// <summary>
        /// Sets a filter to be applied to upcoming messages at the session level.
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="messageDelegate"></param>
        public void SetFilter(HCondition filter, Action <HMessage> messageDelegate)
        {
            HMessage cmdMessage = BuildCommand("session", "hSetFilter", filter, null, null);

            this.filter = filter;
            cmdMessage.SetTimeout(options.GetMsgTimeout());
            Send(cmdMessage, messageDelegate);
        }
Пример #2
0
        /// <summary>
        /// since v0.5
        /// The client MUST be connected to access to this service.
        /// Allow a hubapp client to create a hMessage with a hCommand payload.
        /// </summary>
        /// <param name="actor"></param>
        /// <param name="cmd"></param>
        /// <param name="params"></param>
        /// <param name="filter"></param>
        /// <param name="mOptions"></param>
        /// <returns></returns>
        public HMessage BuildCommand(string actor, string cmd, JToken @params, HCondition filter, HMessageOptions mOptions)
        {
            if (actor == null || actor.Length <= 0)
            {
                throw new MissingAttrException("actor");
            }
            if (cmd == null || cmd.Length <= 0)
            {
                throw new MissingAttrException("cmd");
            }

            HCommand hcommand = new HCommand(cmd, @params, filter);

            HMessage hmessage = BuildMessage(actor, "hCommand", hcommand, mOptions);

            return(hmessage);
        }
Пример #3
0
        private void setFilterBt_Click(object sender, RoutedEventArgs e)
        {
            HCondition    filter     = new HCondition();
            HArrayOfValue valueArray = new HArrayOfValue();

            valueArray.SetName("publisher");
            JArray ja = new JArray();

            ja.Add("urn:localhost:u1");
            ja.Add("urn:localhost:u2");
            valueArray.SetValues(ja);
            filter.SetInValue(valueArray);

            Debug.WriteLine("\n-- set filer --");
            Debug.WriteLine(filter);
            Debug.WriteLine("---------------\n");

            //Remove the filter.
            //HCondition filter = new HCondition(JObject.Parse("{}"));
            client.SetFilter(filter, callback);
        }
Пример #4
0
        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);
                }
            }
        }