CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    37

    Access native camera driver (sensoray)

    I have done some PInvoke of native dlls but this one is beyond my capability.

    The client of this driver (sx11.dll) has to declare a variable 'buffer' of type
    Code:
    typedef struct {                        //image buffer structure;
        HBUF hbuf;                          //handle to buffer;
        DWORD dwFrames;                     //number of frames in buffer;
        FRAME frame[SYS_FRAMES];            //array of FRAME structures;
    } BUFFER;
    Then a function has to be called which initializes this variable and allocates the 'frame'
    array. This type is
    Code:
    typedef struct {                        //frame structure;
        LPBITMAPINFO lpbmi;                 //pointer to BITMAPINFO structure;
        void *lpvbits;			//pointer to image data;
    } FRAME;
    The native image acquisition function has to be called with the argument buffer.hbuf,
    and it writes the image data into buffer.frame. My questions are:

    1. How to translate the last BUFFER field 'FRAME frame[SYS_FRAMES]' into C#?
    2. Call the acquisition function in a 'fixed' environment? How exactly?
    3. How to copy lets say 'buffer.frame[1].lpvbits to a C# array byte[]?

    Any suggestion is welcome.

  2. #2
    Join Date
    Jan 2012
    Posts
    1

    Re: Access native camera driver (sensoray)

    I have above problem, Is there any solution?

  3. #3
    Join Date
    Dec 2007
    Location
    Brazil
    Posts
    37

    Re: Access native camera driver (sensoray)

    Quote Originally Posted by pajand View Post
    I have above problem, Is there any solution?
    The interface I came up with follows. I don't remember my reasoning because I never worked again on that. I hope it helps.

    Code:
    // type aliases for sx11.dll
    using ECODE	= System.UInt32;
    using DWORD	= System.UInt32;
    
      [StructLayout (LayoutKind.Sequential)]
      struct PCI
      { public System.UInt32	board;
        [MarshalAs (UnmanagedType.ByValArray, SizeConst=SYS_GRABBERS)]
        public System.UInt32[]	PCIslot;
      }
    
      [StructLayout (LayoutKind.Sequential)]
      struct MODE_ADVANCED
      { public DWORD interlace;	//interlacing flag;
        public DWORD xTotal;        //total hor pixels;
        public DWORD xActive;       //active hor pixels;
        public DWORD xDelay;        //hor delay;
        public float yFactor;       //vert scaling factor;
        public DWORD yActive;       //active vert pixels (lines);
        public DWORD yDelay;        //vert delay, lines;
        public DWORD FORMAT;        //input video format;
        public DWORD BRIGHT;        //brightness;
        public DWORD CONTRAST;      //contrast;
        public DWORD SAT_U;         //chroma (U) gain;
        public DWORD SAT_V;         //chroma (V) gain;
        public DWORD HUE;           //hue;
        public DWORD LNOTCH;        //luma notch filter control;
        public DWORD LDEC;          //luma decimation control;
        public DWORD DEC_RAT;       //temporal decimation control;
        public DWORD PEAK;          //luma LPF peaking control (Bt848A/849A);
        public DWORD CAGC;          //chroma ADC control;
        public DWORD CKILL;         //low color removal control;
        public DWORD HFILT;         //luma low pass filter mode;
        public DWORD RANGE;         //luma output range;
        public DWORD CORE;          //luma coring control;
        public DWORD YCOMB;         //luma comb enable;
        public DWORD CCOMB;         //chroma comb enable;
        public DWORD ADELAY;        //AGC gate delay for back-porch sampling;
        public DWORD BDELAY;        //burst gate delay for sub-carrier sampling;
        public DWORD SLEEP;         //ADCs' sleep mode;
        public DWORD CRUSH;         //adaptive AGC;
        public DWORD VFILT;         //vertical scaling filter control;
        public DWORD COLOR_BARS;    //color bars test enable;
        public DWORD GAMMA;         //gamma correction removal;
        public DWORD PKTP;          //FIFO trigger point;
        public DWORD bimodal;       //bimodal buffer flag;
        public DWORD colorkey;      //color key for DirectDraw overlay;
        public DWORD buffertype;    //type of buffer: memory, external, or video;
        public DWORD gpintmode;	//GP interrupt mode;
        public DWORD reserved1;     //reserved;
        public DWORD reserved2;     //reserved;
        public DWORD reserved3;     //reserved;
        public DWORD reserved4;     //reserved;
      }
    
      [StructLayout (LayoutKind.Sequential)]
      struct MODE
      { public DWORD scale;                        //image scale;
        public DWORD color;                        //output color encoding;
        public DWORD store;                        //store as DIB or flat;
        public DWORD input;                        //input channel;
        public MODE_ADVANCED advanced;
      }
    
      [StructLayout (LayoutKind.Sequential)]
      struct FRAME
      { public IntPtr		lpbmi;
        public byte[]		lpvbits;
      }
    
      [StructLayout (LayoutKind.Sequential)]
      struct BUFFER
      { public IntPtr 		hbuf;
        public System.UInt32	dwFrames;
        [MarshalAs (UnmanagedType.ByValArray, SizeConst=SYS_FRAMES)]
        public FRAME[]		frame;
      }
    
    
      [DllImport("sx11.dll")] static extern
      ECODE X11_InitSystem (out PCI pci);
    
      [DllImport("sx11.dll")] static extern
      void X11_CloseSystem();
    
      [DllImport("sx11.dll")] static extern
      ECODE X11_GetHFG (out IntPtr fgHandle, System.UInt32 slot);
    
      [DllImport("sx11.dll")] static extern
      ECODE X11_AllocBuffer (ref MODE mode, ref BUFFER buffer, DWORD dwParameter);
    
      [DllImport("sx11.dll")] static extern
      ECODE X11_FreeBuffer (ref BUFFER buffer);
    
      [DllImport("sx11.dll")] static extern
      ECODE X11_SetMode (IntPtr fgHandle, ref MODE mode);
    
      [DllImport("sx11.dll")] static extern
      ECODE X11_GetImageSize (ref MODE mode, ref DWORD pxsize, ref DWORD pysize);
    
      [DllImport("sx11.dll")] static extern
      ECODE X11_Acquire (IntPtr fgHandle, IntPtr hbuf, float timeout,
    	out DWORD status);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured