Thanks to help from Wofram this code works.
Needs["NETLink`"];
InstallNET[];
LoadNETAssembly["C:\\XIMEA\\API\\x64"];
LoadNETType["xiApi.NET.xiCam"];
LoadNETType["System.Runtime.InteropServices.GCHandle"];
LoadNETType["System.Runtime.InteropServices.GCHandleType"];
XIMeaCameraOpen[] :=
Module[{cam},
myCam = NETNew["xiApi.NET.xiCam"];
myCam@OpenDevice[0];
]
XIMeaCameraSetup[] :=
Module[
{exposure = 100(* Set device exposure in micro seconds *),
gain = 1 (* gain in decibels *),
tempImage,
bytesPerPixel
},
myCam@SetParam["exposure", exposure];
myCam@SetParam["gain", gain];
(* Set image output format to RGB 32 bit - 3 / RGB24 - 2 / Mono8 -
0 / Mono16 - 1 / RAW8 - 5 / RAW16 - 6 *)
myCam@SetParam["imgdataformat", 3]; (* RGB32 *)
(*
BUFF_POLICY class
Buffer policy settings (can be safe,data will be copied to user/
app buffer or unsafe,
user will get internally allocated buffer without data copy).
(1) BUFF_POLICYUNSAFE:User gets pointer to internally allocated \
circle buffer and data may be overwritten by device.
(0) BUFF_POLICY.SAFE:
Data from device will be copied to user allocated buffer or xiApi \
allocated memory.
*)
myCam@SetParam["buffer_policy", 0]; (* BUFF_POLICYSAFE *)
(*myCam@SetParam["auto_wb", 1]; Automatic white balance *)
myCam@SetParam["wb_kr", 1];
myCam@SetParam["wb_kg", 1];
myCam@SetParam["wb_kb", 1];
If[ValueQ@buffer ,
(* true this has been run before do nothing*) ,
(* Start acquisition to find bytes per pixel*)
myCam@StartAcquisition[];
myCam@GetImage[tempImage, 1000];
bytesPerPixel = tempImage@Format@BitsPerPixel/8;
(* Stop acquisition *)
myCam@StopAcquisition[];
myCam@GetParam["height", imageHeight];
myCam@GetParam["width", imageWidth];
(* Create location to receive image data *)
buffer =
NETNew["System.Byte[]", imageHeight imageWidth bytesPerPixel]
];
myCam@SetParam["buffer_policy", 1]; (* BUFF_POLICYUNSAFE *)
(* Set to tirgered operation *)
(*
Triger Selector
0, Invalid, Selects a trigger starting the capture of one frame
1, Selects a trigger controlling the duration of one frame
2, Selects a trigger starting the capture of the bursts of frames \
in an acquisition
3, Selects a trigger controlling the duration of the capture of \
the bursts of frames in an acquisition
4, Invalid,
Selects a trigger which when first trigger starts exposure and \
consequent pulses are gating exposure(active HI)
5, Invalid,
Selects a trigger controlling the start of the exposure of one Frame
6, Invalid,
Selects a trigger controlling the multi slope phase in one Frame \
(phase0\[Rule]phase1) or (phase1\[Rule]phase2)
7, Invalid, Selects a trigger starting acquisition of first frame.
*)
myCam@SetParam["gpi_selector", 1];
myCam@SetParam["gpi_mode", 1] ; (* GPI_TRIGGER, Off = 0, On =1 *)
(*
Trigger Source
0, Camera works in free run mode
1, External trigger (rising edge)
2, External trigger (falling edge)
3, Software(manual) trigger
4, Specifies that the trigger is considered valid as long as the \
level of the source signal is high
5, Specifies that the trigger is considered valid as long as the \
level of the source signal is low.
*)
myCam@SetParam["trigger_source", 1];
];
currentImageXIMea[camera_, timeouts_] :=
Module[
{
rawImage
},
camera@GetImageByteArray[buffer, timeouts];
rawImage = buffer // NETObjectToExpression;
Image[
ArrayReshape[rawImage, {imageHeight, imageWidth, 4}][[All,
All, {3, 2, 1}]],
"Byte"]
];
XIMeaCameraOpen[];
XIMeaCameraSetup[];
myCam@StartAcquisition[];
currentImageXIMea[myCam, 10000]
myCam@StopAcquisition[];