示例#1
0
        private static CameraProperty ReadFloatProperty(PYLON_DEVICE_HANDLE deviceHandle, string symbol)
        {
            CameraProperty p = new CameraProperty();

            p.Identifier = symbol;

            NODEMAP_HANDLE nodeMapHandle = Pylon.DeviceGetNodeMap(deviceHandle);
            NODE_HANDLE    nodeHandle    = GenApi.NodeMapGetNode(nodeMapHandle, symbol);

            if (!nodeHandle.IsValid)
            {
                return(p);
            }

            EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle);

            if (accessMode == EGenApiAccessMode._UndefinedAccesMode || accessMode == EGenApiAccessMode.NA ||
                accessMode == EGenApiAccessMode.NI || accessMode == EGenApiAccessMode.WO)
            {
                return(p);
            }

            p.Supported = true;
            p.ReadOnly  = accessMode != EGenApiAccessMode.RW;

            EGenApiNodeType type = GenApi.NodeGetType(nodeHandle);

            if (type != EGenApiNodeType.FloatNode)
            {
                return(p);
            }

            p.Type = CameraPropertyType.Float;

            double min = GenApi.FloatGetMin(nodeHandle);
            double max = GenApi.FloatGetMax(nodeHandle);
            EGenApiRepresentation repr = GenApi.FloatGetRepresentation(nodeHandle);
            double currentValue        = GenApi.FloatGetValue(nodeHandle);

            // We don't support a dedicated control for "pure numbers" just use the regular slider.
            if (repr == EGenApiRepresentation.PureNumber)
            {
                repr = EGenApiRepresentation.Linear;
            }

            // Fix values that should be log.
            double range = Math.Log(max - min, 10);

            if (range > 4 && repr == EGenApiRepresentation.Linear)
            {
                repr = EGenApiRepresentation.Logarithmic;
            }

            p.Minimum        = min.ToString(CultureInfo.InvariantCulture);
            p.Maximum        = max.ToString(CultureInfo.InvariantCulture);
            p.Representation = ConvertRepresentation(repr);
            p.CurrentValue   = currentValue.ToString(CultureInfo.InvariantCulture);

            return(p);
        }