public static bool ReadEnumeration(this Int16 cameraHandle, out List <CameraAttributeEnumeratePairValue> nvpList, UInt32 paramId) { nvpList = new List <CameraAttributeEnumeratePairValue>(); IntPtr unmngIsAvaiable = Marshal.AllocHGlobal(sizeof(UInt16)); bool result = Pvcam.pl_get_param(cameraHandle, paramId, (Int16)PvTypes.AttributeIDs.ATTR_AVAIL, unmngIsAvaiable) && Marshal.ReadInt16(unmngIsAvaiable) == 1; Marshal.FreeHGlobal(unmngIsAvaiable); unmngIsAvaiable = IntPtr.Zero; if (!result) { return(false); } IntPtr unmngCount = Marshal.AllocHGlobal(sizeof(UInt32)); result = Pvcam.pl_get_param(cameraHandle, paramId, (Int16)PvTypes.AttributeIDs.ATTR_COUNT, unmngCount); var count = result? Convert.ToUInt32(Marshal.ReadInt32(unmngCount)):0; Marshal.FreeHGlobal(unmngCount); unmngCount = IntPtr.Zero; if (!result) { return(false); } StringBuilder paramName = new StringBuilder(); //Now get the value and name associated for (UInt32 i = 0; i < count; i++) { if (!Pvcam.pl_enum_str_length(cameraHandle, paramId, i, out UInt32 strLength)) { return(false); } if (!Pvcam.pl_get_enum_param(cameraHandle, paramId, i, out Int32 paramValue, paramName, strLength)) { return(false); } nvpList.Add(new CameraAttributeEnumeratePairValue(paramValue, paramName.ToString())); } return(true); }
public static bool BuildSpeedTable(this Int16 cameraHandle, ICameraInfo cameraInfo) { StringBuilder desc = new StringBuilder(100); IntPtr unmngRdPortCount = Marshal.AllocHGlobal(sizeof(UInt32)); IntPtr unmngRdPortSet = Marshal.AllocHGlobal(sizeof(UInt32)); IntPtr unmngSpdTabIndexCount = Marshal.AllocHGlobal(sizeof(UInt32)); IntPtr unmngBitDepth = Marshal.AllocHGlobal(sizeof(Int16)); IntPtr unmngGainCount = Marshal.AllocHGlobal(sizeof(Int32)); IntPtr unmngSpdTabIdx = Marshal.AllocHGlobal(sizeof(Int16)); IntPtr unmngPixTime = Marshal.AllocHGlobal(sizeof(UInt16)); IntPtr unmngGainMax = Marshal.AllocHGlobal(sizeof(UInt16)); var speedTable = new SpeedTable(); speedTable.ReadoutOptions.Clear(); //read number of available ports Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_READOUT_PORT, (Int16)PvTypes.AttributeIDs.ATTR_COUNT, unmngRdPortCount); speedTable.ReadoutPorts = Convert.ToUInt32(Marshal.ReadInt32(unmngRdPortCount)); Marshal.FreeHGlobal(unmngRdPortCount); unmngRdPortCount = IntPtr.Zero; //set each port and find number of readout speeds on that port for (Int16 i = 0; i < speedTable.ReadoutPorts; i++) { Marshal.WriteInt32(unmngRdPortSet, i); //set readout port Pvcam.pl_set_param(cameraHandle, PvTypes.PARAM_READOUT_PORT, unmngRdPortSet); //get port description //NOTE: for Interline and sCMOS cameras this often returns "Mutliplication gain" even though the port does //not have any multiplication gain capability Pvcam.pl_get_enum_param(cameraHandle, PvTypes.PARAM_READOUT_PORT, (UInt32)i, out _, desc, 100); //get number of readout speeds on each readout port Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_SPDTAB_INDEX, (Int16)PvTypes.AttributeIDs.ATTR_COUNT, unmngSpdTabIndexCount); speedTable.ReadoutSpeeds = Convert.ToUInt32(Marshal.ReadInt32(unmngSpdTabIndexCount)); //for all readout speeds for (Int16 j = 0; j < speedTable.ReadoutSpeeds; j++) { Marshal.WriteInt16(unmngSpdTabIdx, j); Pvcam.pl_set_param(cameraHandle, PvTypes.PARAM_SPDTAB_INDEX, unmngSpdTabIdx); //Get Number of gains available on this speed, note that use ATTR_MAX to find max gains available as ATTR_COUNT //has issues in certain version of PVCAM Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_GAIN_INDEX, (Int16)PvTypes.AttributeIDs.ATTR_COUNT, unmngGainMax); var gainMax = (UInt16)Marshal.ReadInt16(unmngGainMax); //get bit depth of the speed Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_BIT_DEPTH, (Int16)PvTypes.AttributeIDs.ATTR_CURRENT, unmngBitDepth); Int16 bidDepth = Marshal.ReadInt16(unmngBitDepth); //get readout frequency (pixel time) of the speed Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_PIX_TIME, (Int16)PvTypes.AttributeIDs.ATTR_CURRENT, unmngPixTime); double pixTime = Convert.ToDouble(Marshal.ReadInt16(unmngPixTime)); //add new readout option to our list of options speedTable.ReadoutOptions.Add(new ReadoutOption(i, j, bidDepth, gainMax, $"{1000/pixTime}MZ ")); } } cameraInfo.CameraParas.SpeedTable = speedTable; cameraInfo.CameraSettings.ReadOutOptions = new CameraOptionParameter ("ReadOutSpeed", speedTable.ReadoutOptions.Select(x => x.ToString()).ToList(), 1); Marshal.FreeHGlobal(unmngRdPortSet); unmngRdPortSet = IntPtr.Zero; Marshal.FreeHGlobal(unmngSpdTabIndexCount); unmngSpdTabIndexCount = IntPtr.Zero; Marshal.FreeHGlobal(unmngBitDepth); unmngBitDepth = IntPtr.Zero; Marshal.FreeHGlobal(unmngGainCount); unmngGainCount = IntPtr.Zero; Marshal.FreeHGlobal(unmngSpdTabIdx); unmngSpdTabIdx = IntPtr.Zero; Marshal.FreeHGlobal(unmngPixTime); unmngPixTime = IntPtr.Zero; return(true); }