Ejemplo n.º 1
0
        private static CameraProperty ReadIntegerProperty(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)
            {
                log.WarnFormat("Could not read Basler property {0}: node handle is not valid. (The property is not supported).", symbol);
                return(p);
            }

            EGenApiAccessMode accessMode = GenApi.NodeGetAccessMode(nodeHandle);

            if (accessMode == EGenApiAccessMode._UndefinedAccesMode || accessMode == EGenApiAccessMode.NA ||
                accessMode == EGenApiAccessMode.NI || accessMode == EGenApiAccessMode.WO)
            {
                log.WarnFormat("Could not read Basler property {0}: Access mode not supported. (The property is not readable).", symbol);
                return(p);
            }

            EGenApiNodeType type = GenApi.NodeGetType(nodeHandle);

            if (type != EGenApiNodeType.IntegerNode)
            {
                log.WarnFormat("Could not read Basler property {0}: the node is of the wrong type. Expected: Integer. Received:{1}", symbol, type.ToString());
                return(p);
            }

            p.Supported = true;
            p.Type      = CameraPropertyType.Integer;
            p.ReadOnly  = accessMode != EGenApiAccessMode.RW;

            long min  = GenApi.IntegerGetMin(nodeHandle);
            long max  = GenApi.IntegerGetMax(nodeHandle);
            long step = GenApi.IntegerGetInc(nodeHandle);
            EGenApiRepresentation repr = GenApi.IntegerGetRepresentation(nodeHandle);

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

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

            long currentValue = GenApi.IntegerGetValue(nodeHandle);

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

            return(p);
        }
Ejemplo n.º 2
0
        private static CameraProperty ReadIntegerProperty(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.IntegerNode)
            {
                return(p);
            }

            p.Type = CameraPropertyType.Integer;

            long min  = GenApi.IntegerGetMin(nodeHandle);
            long max  = GenApi.IntegerGetMax(nodeHandle);
            long step = GenApi.IntegerGetInc(nodeHandle);
            EGenApiRepresentation repr = GenApi.IntegerGetRepresentation(nodeHandle);

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

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

            long currentValue = GenApi.IntegerGetValue(nodeHandle);

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

            return(p);
        }