コード例 #1
0
        public static string GetFullAttributeName(ImaqdxSessionHandle session, string partialName)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(partialName != null, "The partialName parameter cannot be null.");

            IntPtr stringPtr = IntPtr.Zero;

            try
            {
                int status = NiImaqdxDll.IMAQdxGetFullyQualifiedAttributeName(session, partialName, ref stringPtr);
                if (status == -1074360305)
                {
                    // This error is returned when the attribute is not supported by the camera
                    // In this case we do not want to return an exception
                    // Return an empty string to indicate the the attribute was not found
                    return(string.Empty);
                }

                ExceptionBuilder.CheckErrorAndThrow(status);
                return(Marshal.PtrToStringAnsi(stringPtr));
            }
            finally
            {
                if (stringPtr != IntPtr.Zero)
                {
                    int status = NiImaqdxDll.IMAQdxDispose(stringPtr);
                    ExceptionBuilder.CheckErrorAndThrow(status);
                }
            }
        }
コード例 #2
0
        public static void Reset(string cameraName)
        {
            Debug.Assert(cameraName != null, "The cameraName parameter cannot be null.");

            int status = NiImaqdxDll.IMAQdxResetCamera(cameraName, Convert.ToUInt32(false));

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #3
0
        public static void DiscoverEthernetCameras(IPAddress address, int timeout)
        {
            Debug.Assert(address != null, "The address parameter cannot be null.");

            int status = NiImaqdxDll.IMAQdxDiscoverEthernetCameras(address.ToString(), timeout);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #4
0
        public static void WriteRegister(ImaqdxSessionHandle session, ulong offset, uint value)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");

            int status = NiImaqdxDll.IMAQdxWriteRegister(session, (uint)offset, value);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #5
0
        public static void ReadAttributesFromCameraFile(ImaqdxSessionHandle session)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");

            int status = NiImaqdxDll.IMAQdxReadAttributes(session, null);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #6
0
        public static void Close(ImaqdxSessionHandle session)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");

            int status = NiImaqdxDll.IMAQdxCloseCamera(session);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #7
0
        protected override bool ReleaseHandle()
        {
            HandleRef handleRef = new HandleRef(this, handle);
            int       status    = NiImaqdxDll.IMAQdxCloseCamera(handleRef);

            handle = IntPtr.Zero;

            return((status < 0) ? false : true);
        }
コード例 #8
0
        public static void Snap(ImaqdxSessionHandle session, VisionImage image)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(image != null, "The image parameter cannot be null.");

            int status = NiImaqdxDll.IMAQdxSnap(session, image._image);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #9
0
        public static void WriteAttributesToFile(ImaqdxSessionHandle session, string fullPath)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(fullPath != null, "The fullPath parameter cannot be null.");

            int status = NiImaqdxDll.IMAQdxWriteAttributes(session, fullPath);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #10
0
        public static void SetAttribute(ImaqdxSessionHandle session, string name, string value)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(name != null, "The name parameter cannot be null.");

            int status = NiImaqdxDll.IMAQdxSetAttribute(session, name, ImaqdxAttributeType.String, value);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #11
0
        public static void WriteMemory(ImaqdxSessionHandle session, ulong offset, byte[] values)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(values != null, "The values parameter cannot be null.");

            int status = NiImaqdxDll.IMAQdxWriteMemory(session, (uint)offset, values, (uint)values.Length);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #12
0
        public static void InstallImageAcquiredEventHandler(ImaqdxSessionHandle session, ImaqdxFrameDoneEventHandler callback)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(callback != null, "The callback parameter cannot be null.");

            int status = NiImaqdxDll.IMAQdxRegisterFrameDoneEvent(session, DefaultBufferInterval, callback, IntPtr.Zero);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #13
0
        public static void InstallPnpEventHandler(ImaqdxSessionHandle session, ImaqdxPnpEvent pnpEvent, ImaqdxPnpEventHandler callback)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(callback != null, "The callback parameter cannot be null.");

            int status = NiImaqdxDll.IMAQdxRegisterPnpEvent(session, pnpEvent, callback, IntPtr.Zero);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #14
0
        public static ImaqdxSessionHandle Open(string cameraName, ImaqdxCameraControlMode mode)
        {
            Debug.Assert(cameraName != null, "The cameraName parameter cannot be null.");

            ImaqdxSessionHandle session;
            int status = NiImaqdxDll.IMAQdxOpenCamera(cameraName, mode, out session);

            ExceptionBuilder.CheckErrorAndThrow(status);
            return(session);
        }
コード例 #15
0
        public static void ConfigureAcquisition(ImaqdxSessionHandle session, ImaqdxAcquisitionType acquisitionType, int bufferCount)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(bufferCount > 0, "The bufferCount parameter must be greater than zero.");

            bool isContinuous = (acquisitionType == ImaqdxAcquisitionType.Continuous);
            int  status       = NiImaqdxDll.IMAQdxConfigureAcquisition(session, Convert.ToUInt32(isContinuous), (uint)bufferCount);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #16
0
        public static void ResetEthernetCameraAddress(string name, IPAddress address, IPAddress subnet, IPAddress gateway, int timeout)
        {
            Debug.Assert(name != null, "The name parameter cannot be null.");
            Debug.Assert(address != null, "The address parameter cannot be null.");
            Debug.Assert(subnet != null, "The subnet parameter cannot be null.");
            Debug.Assert(gateway != null, "The gateway parameter cannot be null.");

            int status = NiImaqdxDll.IMAQdxResetEthernetCameraAddress(name, address.ToString(), subnet.ToString(), gateway.ToString(), timeout);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }
コード例 #17
0
        public static ImaqdxAttributeVisibility GetAttributeVisibility(ImaqdxSessionHandle session, string name)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(name != null, "The name parameter cannot be null.");

            ImaqdxAttributeVisibility visibility;
            int status = NiImaqdxDll.IMAQdxGetAttributeVisibility(session, name, out visibility);

            ExceptionBuilder.CheckErrorAndThrow(status);
            return(visibility);
        }
コード例 #18
0
        public static bool GetIsAttributeWritable(ImaqdxSessionHandle session, string name)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(name != null, "The name parameter cannot be null.");

            uint writable;
            int  status = NiImaqdxDll.IMAQdxIsAttributeWritable(session, name, out writable);

            ExceptionBuilder.CheckErrorAndThrow(status);
            return(Convert.ToBoolean(writable));
        }
コード例 #19
0
        public static Imaqdx.ImaqdxCameraInformation[] GetCameraInformation(bool connectedOnly)
        {
            uint count;
            int  status = NiImaqdxDll.IMAQdxEnumerateCameras(null, out count, Convert.ToUInt32(connectedOnly));

            ExceptionBuilder.CheckErrorAndThrow(status);
            Internal.ImaqdxCameraInformation[] cameraInfoArray = new Internal.ImaqdxCameraInformation[count];
            status = NiImaqdxDll.IMAQdxEnumerateCameras(cameraInfoArray, out count, Convert.ToUInt32(connectedOnly));
            ExceptionBuilder.CheckErrorAndThrow(status);

            return(ImaqdxCameraInformation.CreateCameraInformationArray(cameraInfoArray));
        }
コード例 #20
0
        public static void GetAttribute(ImaqdxSessionHandle session, string name, out string value)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(name != null, "The name parameter cannot be null.");

            object objectValue;
            int    status = NiImaqdxDll.IMAQdxGetAttributeCW(session, name, ImaqdxAttributeType.String, out objectValue);

            ExceptionBuilder.CheckErrorAndThrow(status);
            value = (objectValue == null ? string.Empty : (string)objectValue);
        }
コード例 #21
0
        public static byte[] ReadMemory(ImaqdxSessionHandle session, ulong offset, int count)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(count > 0, "The count parameter must be greater than zero.");

            byte[] values = new byte[count];
            int    status = NiImaqdxDll.IMAQdxReadMemory(session, (uint)offset, values, (uint)count);

            ExceptionBuilder.CheckErrorAndThrow(status);
            return(values);
        }
コード例 #22
0
        public static void GetAttribute(ImaqdxSessionHandle session, string name, out ImaqdxEnumAttributeItem value)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(name != null, "The name parameter cannot be null.");

            ImaqdxEnumItem enumItemValue;
            int            status = NiImaqdxDll.IMAQdxGetAttribute(session, name, ImaqdxAttributeType.Enum, out enumItemValue);

            ExceptionBuilder.CheckErrorAndThrow(status);
            value = new ImaqdxEnumAttributeItem(enumItemValue);
        }
コード例 #23
0
        public static uint Grab(ImaqdxSessionHandle session, VisionImage image, bool waitForNextBuffer)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(image != null, "The image parameter cannot be null.");

            uint actualBufferNumber;
            int  status = NiImaqdxDll.IMAQdxGrab(session, image._image, Convert.ToUInt32(waitForNextBuffer), out actualBufferNumber);

            ExceptionBuilder.CheckErrorAndThrow(status);
            return(actualBufferNumber);
        }
コード例 #24
0
        public static void GetAttribute(ImaqdxSessionHandle session, string name, out bool value)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(name != null, "The name parameter cannot be null.");

            byte byteValue;
            int  status = NiImaqdxDll.IMAQdxGetAttribute(session, name, ImaqdxAttributeType.Boolean, out byteValue);

            ExceptionBuilder.CheckErrorAndThrow(status);
            value = Convert.ToBoolean(byteValue);
        }
コード例 #25
0
        private static void CreateImageDataArray(ImaqdxSessionHandle session, ref byte[] data)
        {
            uint bufferSize;
            int  status = NiImaqdxDll.IMAQdxGetRawBufferSize(session, out bufferSize);

            ExceptionBuilder.CheckErrorAndThrow(status);

            if (data == null || data.Length != bufferSize)
            {
                data = new byte[bufferSize];
            }
        }
コード例 #26
0
        public static uint GetImage(ImaqdxSessionHandle session, ImaqdxBufferNumberMode bufferNumberMode, VisionImage image)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(image != null, "The image parameter cannot be null.");

            uint actualBufferNumber;
            int  status = NiImaqdxDll.IMAQdxGetImage(session, image._image, bufferNumberMode, (uint)0, out actualBufferNumber);

            ExceptionBuilder.CheckErrorAndThrow(status);
            return(actualBufferNumber);
        }
コード例 #27
0
        public static string GetAttributeUnits(ImaqdxSessionHandle session, string name)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(name != null, "The name parameter cannot be null.");

            string units;
            int    status = NiImaqdxDll.IMAQdxGetAttributeUnitsCW(session, name, out units);

            ExceptionBuilder.CheckErrorAndThrow(status);
            return(units == null ? string.Empty : units);
        }
コード例 #28
0
        public static uint GetImageData(ImaqdxSessionHandle session, ImaqdxBufferNumberMode bufferNumberMode, ref byte[] data)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");

            CreateImageDataArray(session, ref data);

            uint actualBufferNumber;
            int  status = NiImaqdxDll.IMAQdxGetImageData(session, data, (uint)data.Length, bufferNumberMode, (uint)0, out actualBufferNumber);

            ExceptionBuilder.CheckErrorAndThrow(status);
            return(actualBufferNumber);
        }
コード例 #29
0
        public static ImaqdxAttributeInformation[] EnumeratePrivateAttributes(ImaqdxSessionHandle session)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");

            uint count;
            int  status = NiImaqdxDll.IMAQdxEnumerateAttributes2(session, null, out count, "", PrivateVisibility);

            ExceptionBuilder.CheckErrorAndThrow(status);
            ImaqdxAttributeInformation[] attributeInfoArray = new ImaqdxAttributeInformation[count];
            status = NiImaqdxDll.IMAQdxEnumerateAttributes2(session, attributeInfoArray, out count, "", PrivateVisibility);
            ExceptionBuilder.CheckErrorAndThrow(status);
            return(attributeInfoArray);
        }
コード例 #30
0
        public static void Sequence(ImaqdxSessionHandle session, VisionImage[] images)
        {
            Debug.Assert(session != null, "The session parameter cannot be null.");
            Debug.Assert(!session.IsInvalid, "The session parameter must be a valid handle.");
            Debug.Assert(images != null, "The images parameter cannot be null.");

            IntPtr[] imagePtrs = new IntPtr[images.Length];
            for (int i = 0; i < images.Length; i++)
            {
                imagePtrs[i] = images[i]._image;
            }
            int status = NiImaqdxDll.IMAQdxSequence(session, imagePtrs, (uint)imagePtrs.Length);

            ExceptionBuilder.CheckErrorAndThrow(status);
        }