Exemplo n.º 1
0
 public static void throwOperator(int err, string logicalName)
 {
     if (HalconAPI.IsFailure(err))
     {
         throw new HOperatorException(err, HalconAPI.GetErrorMessage(err) + " in operator " + logicalName);
     }
 }
Exemplo n.º 2
0
        public static int LoadD(IntPtr proc, int parIndex, int err, out double doubleValue)
        {
            if (HalconAPI.IsFailure(err))
            {
                doubleValue = -1.0;
                return(err);
            }
            IntPtr tuple = IntPtr.Zero;

            HalconAPI.GetOutputTuple(proc, parIndex, out tuple);
            err = HalconAPI.HCkSingle(tuple, HTupleType.DOUBLE);
            if (err == 2)
            {
                return(HalconAPI.GetD(tuple, 0, out doubleValue));
            }
            err = HalconAPI.HCkSingle(tuple, HTupleType.INTEGER);
            if (err != 2)
            {
                doubleValue = -1.0;
                return(err);
            }
            int intValue = -1;

            err         = HalconAPI.GetI(tuple, 0, out intValue);
            doubleValue = (double)intValue;
            return(err);
        }
Exemplo n.º 3
0
 private static void HCkH(int err)
 {
     if (HalconAPI.IsFailure(err))
     {
         throw new HOperatorException(err);
     }
 }
Exemplo n.º 4
0
        internal static HSerializedItem Deserialize(Stream stream)
        {
            BinaryReader binaryReader = new BinaryReader(stream);

            byte[] header = binaryReader.ReadBytes(16);
            ulong  size;

            if (header.Length < 16 || HalconAPI.IsFailure(HalconAPI.GetSerializedSize(header, out size)))
            {
                throw new HalconException("Input stream is no serialized HALCON object");
            }
            if (size > 2415918079UL)
            {
                throw new HalconException("Input stream too large");
            }
            byte[] numArray = binaryReader.ReadBytes((int)size);
            if (numArray.Length < (int)size || HalconAPI.IsFailure(HalconAPI.GetSerializedSize(header, out size)))
            {
                throw new HalconException("Unexpected end of serialization data");
            }
            byte[] data = new byte[(int)size + 16];
            header.CopyTo((Array)data, 0);
            numArray.CopyTo((Array)data, 16);
            return(new HSerializedItem(data));
        }
Exemplo n.º 5
0
 internal static void HCkP(IntPtr proc, int err)
 {
     if (!HalconAPI.IsFailure(err))
     {
         return;
     }
     HalconAPI.PostCall(proc, err);
 }
Exemplo n.º 6
0
 internal static void throwOperator(int err, int procIndex)
 {
     if (HalconAPI.IsFailure(err))
     {
         string logicalName = HalconAPI.GetLogicalName(procIndex);
         throw new HOperatorException(err, HalconAPI.GetErrorMessage(err) + " in operator " + logicalName);
     }
 }
Exemplo n.º 7
0
        internal static int CreateInputTuple(IntPtr proc, int parIndex, int length, out IntPtr tuple)
        {
            int inputTuple = HalconAPI.GetInputTuple(proc, parIndex, out tuple);

            if (!HalconAPI.IsFailure(inputTuple))
            {
                return(HalconAPI.CreateElements(tuple, length));
            }
            return(inputTuple);
        }
Exemplo n.º 8
0
        public static int Load(IntPtr tuple, out HTupleMixed data)
        {
            int err = 2;
            int length;

            HalconAPI.GetTupleLength(tuple, out length);
            object[] o = new object[length];
            for (int index = 0; index < length; ++index)
            {
                if (!HalconAPI.IsFailure(err))
                {
                    HTupleType type;
                    HalconAPI.GetElementType(tuple, index, out type);
                    switch (type)
                    {
                    case HTupleType.INTEGER:
                        if (HalconAPI.isPlatform64)
                        {
                            long longValue;
                            err      = HalconAPI.GetL(tuple, index, out longValue);
                            o[index] = (object)longValue;
                            continue;
                        }
                        int intValue;
                        err      = HalconAPI.GetI(tuple, index, out intValue);
                        o[index] = (object)intValue;
                        continue;

                    case HTupleType.DOUBLE:
                        double doubleValue;
                        err      = HalconAPI.GetD(tuple, index, out doubleValue);
                        o[index] = (object)doubleValue;
                        continue;

                    case HTupleType.STRING:
                        string stringValue;
                        err      = HalconAPI.GetS(tuple, index, out stringValue);
                        o[index] = (object)stringValue;
                        continue;

                    default:
                        continue;
                    }
                }
            }
            data = new HTupleMixed(o, false);
            return(err);
        }
Exemplo n.º 9
0
        internal static IntPtr CopyObject(IntPtr key)
        {
            IntPtr proc = HalconAPI.PreCall(583);

            HalconAPI.HCkP(proc, HalconAPI.SetInputObject(proc, 1, key));
            HalconAPI.StoreI(proc, 0, 1);
            HalconAPI.StoreI(proc, 1, -1);
            int num = HalconAPI.CallProcedure(proc);

            if (!HalconAPI.IsFailure(num))
            {
                num = HalconAPI.GetOutputObject(proc, 1, out key);
            }
            HalconAPI.PostCall(proc, num);
            return(key);
        }
Exemplo n.º 10
0
        public static int Load(IntPtr tuple, out HTupleString data)
        {
            int err = 2;
            int length;

            HalconAPI.GetTupleLength(tuple, out length);
            string[] s = new string[length];
            for (int index = 0; index < length; ++index)
            {
                if (!HalconAPI.IsFailure(err))
                {
                    err = HalconAPI.GetS(tuple, index, out s[index]);
                }
            }
            data = new HTupleString(s, false);
            return(err);
        }
Exemplo n.º 11
0
        public static int LoadIP(IntPtr proc, int parIndex, int err, out IntPtr intPtrValue)
        {
            if (HalconAPI.IsFailure(err))
            {
                intPtrValue = IntPtr.Zero;
                return(err);
            }
            IntPtr tuple;

            HalconAPI.GetOutputTuple(proc, parIndex, out tuple);
            err = HalconAPI.HCkSingle(tuple, HTupleType.INTEGER);
            if (err == 2)
            {
                return(HalconAPI.GetIP(tuple, 0, out intPtrValue));
            }
            intPtrValue = IntPtr.Zero;
            return(err);
        }
Exemplo n.º 12
0
        public static int LoadS(IntPtr proc, int parIndex, int err, out string stringValue)
        {
            if (HalconAPI.IsFailure(err))
            {
                stringValue = "";
                return(err);
            }
            IntPtr tuple = IntPtr.Zero;

            HalconAPI.GetOutputTuple(proc, parIndex, out tuple);
            err = HalconAPI.HCkSingle(tuple, HTupleType.STRING);
            if (err == 2)
            {
                return(HalconAPI.GetS(tuple, 0, out stringValue));
            }
            stringValue = "";
            return(err);
        }
Exemplo n.º 13
0
 internal int Load(IntPtr proc, int parIndex, int err)
 {
     if (this.key != HObjectBase.UNDEF)
     {
         throw new HalconException("Undisposed object instance when loading output parameter");
     }
     if (HalconAPI.IsFailure(err))
     {
         return(err);
     }
     err = HalconAPI.GetOutputObject(proc, parIndex, out this.key);
     if (this.suppressedFinalization)
     {
         this.suppressedFinalization = false;
         GC.ReRegisterForFinalize((object)this);
     }
     return(err);
 }
Exemplo n.º 14
0
 internal int Load(IntPtr proc, int parIndex, int err)
 {
     if (this.handle != HTool.UNDEF)
     {
         throw new HalconException("Undisposed tool instance when loading output parameter");
     }
     if (HalconAPI.IsFailure(err))
     {
         return(err);
     }
     err           = HalconAPI.LoadIP(proc, parIndex, err, out this.handle);
     this.attached = true;
     if (this.suppressedFinalization)
     {
         this.suppressedFinalization = false;
         GC.ReRegisterForFinalize((object)this);
     }
     return(err);
 }
Exemplo n.º 15
0
        internal static string GetObjClass(IntPtr key)
        {
            HTuple tuple = (HTuple)"object";
            IntPtr proc  = HalconAPI.PreCall(594);

            HalconAPI.HCkP(proc, HalconAPI.SetInputObject(proc, 1, key));
            HalconAPI.InitOCT(proc, 0);
            int num = HalconAPI.CallProcedure(proc);

            if (!HalconAPI.IsFailure(num))
            {
                num = HTuple.LoadNew(proc, 0, num, out tuple);
            }
            HalconAPI.PostCall(proc, num);
            if (tuple.Length <= 0)
            {
                return("any");
            }
            return(tuple.S);
        }