public static bool IsParamAvailable(this Int16 cameraHandle, UInt32 paramId) { IntPtr unmngIsAvaiable = Marshal.AllocHGlobal(sizeof(UInt16)); Boolean retValue = false; if (Pvcam.pl_get_param(cameraHandle, paramId, (Int16)PvTypes.AttributeIDs.ATTR_AVAIL, unmngIsAvaiable)) { retValue = Convert.ToBoolean(Marshal.ReadInt16(unmngIsAvaiable)); } //free unmanaged memory Marshal.FreeHGlobal(unmngIsAvaiable); unmngIsAvaiable = IntPtr.Zero; return(retValue); }
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 UInt32 GetEstReadoutTime(this Int16 cameraHandle) { UInt32 time = 0; if (cameraHandle.IsParamAvailable(PvTypes.PARAM_READOUT_TIME)) { IntPtr unmgReadoutTime = Marshal.AllocHGlobal(sizeof(Int32)); if (Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_READOUT_TIME, (Int16)PvTypes.AttributeIDs.ATTR_CURRENT, unmgReadoutTime)) { time = (UInt32)Marshal.ReadInt32(unmgReadoutTime); } Marshal.FreeHGlobal(unmgReadoutTime); unmgReadoutTime = IntPtr.Zero; } return(time); }
public static bool ReadCoolingParameters(this Int16 cameraHandle, out Int16 min, out Int16 max, out Int16 setPoint) { min = 0; max = 0; setPoint = 0; //Get Temperature setpoint - range and current CCD temperature IntPtr unmgTempSetpoint = Marshal.AllocHGlobal(sizeof(Int16)); var result = Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_TEMP_SETPOINT, (Int16)PvTypes.AttributeIDs.ATTR_CURRENT, unmgTempSetpoint); setPoint = Marshal.ReadInt16(unmgTempSetpoint); Marshal.FreeHGlobal(unmgTempSetpoint); unmgTempSetpoint = IntPtr.Zero; IntPtr unmgTempSetpointMin = Marshal.AllocHGlobal(sizeof(Int16)); result &= Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_TEMP_SETPOINT, (Int16)PvTypes.AttributeIDs.ATTR_MIN, unmgTempSetpointMin); min = Marshal.ReadInt16(unmgTempSetpointMin); Marshal.FreeHGlobal(unmgTempSetpointMin); unmgTempSetpointMin = IntPtr.Zero; IntPtr unmgTempSetpointMax = Marshal.AllocHGlobal(sizeof(Int16)); result &= Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_TEMP_SETPOINT, (Int16)PvTypes.AttributeIDs.ATTR_MAX, unmgTempSetpointMax); max = Marshal.ReadInt16(unmgTempSetpointMax); Marshal.FreeHGlobal(unmgTempSetpointMax); unmgTempSetpointMax = IntPtr.Zero; return(result); }
public static bool ReadRegions(this Int16 cameraHandle, ICameraInfo cameraInfo) { int maxRoiCount = 1; //Set Max Roi count to 1, if multiroi is not available if (IsParamAvailable(cameraHandle, PvTypes.PARAM_ROI_COUNT)) { cameraInfo.CameraParas.MultiRoiAvailable = true; // read Max ROI available IntPtr unmgRoiCount = Marshal.AllocHGlobal(sizeof(UInt16)); if (Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_ROI_COUNT, (Int16)PvTypes.AttributeIDs.ATTR_MAX, unmgRoiCount)) { maxRoiCount = Marshal.ReadInt16(unmgRoiCount); } Marshal.FreeHGlobal(unmgRoiCount); unmgRoiCount = IntPtr.Zero; } else { cameraInfo.CameraParas.MultiRoiAvailable = false; } //define Region type array var regions = new PvTypes.RegionType[maxRoiCount]; //set current roi count to 1 and set default CCD region to full size regions[0].s1 = 0; regions[0].s2 = (UInt16)(cameraInfo.CameraParas.SizeX - 1); regions[0].p1 = 0; regions[0].p2 = (UInt16)(cameraInfo.CameraParas.SizeY - 1); regions[0].sbin = 1; regions[0].pbin = 1; cameraInfo.CameraSettings.Regions = regions; cameraInfo.CameraSettings.RegionRoiCount = 1; 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); }
public static void ReadCameraParametersToInfos(this Int16 cameraHandle, ICameraInfo cameraInfo) { //build speed tabls cameraHandle.BuildSpeedTable(cameraInfo); //get serial (X) and parallel (Y) size of the CCD IntPtr unmngCcdSize = Marshal.AllocHGlobal(sizeof(Int16)); Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_PAR_SIZE, (Int16)PvTypes.AttributeIDs.ATTR_CURRENT, unmngCcdSize); cameraInfo.CameraParas.SizeX = Marshal.ReadInt16(unmngCcdSize); Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_SER_SIZE, (Int16)PvTypes.AttributeIDs.ATTR_CURRENT, unmngCcdSize); cameraInfo.CameraParas.SizeY = Marshal.ReadInt16(unmngCcdSize); Marshal.FreeHGlobal(unmngCcdSize); unmngCcdSize = IntPtr.Zero; //read the camera chip name, currently used for main identification of the camera model IntPtr unmngChipName = Marshal.AllocHGlobal(PvTypes.CCD_NAME_LEN); Pvcam.pl_get_param(cameraHandle, PvTypes.PARAM_CHIP_NAME, (Int16)PvTypes.AttributeIDs.ATTR_CURRENT, unmngChipName); cameraInfo.CameraParas.ChipName = new StringBuilder(Marshal.PtrToStringAnsi(unmngChipName, PvTypes.CCD_NAME_LEN)); Marshal.FreeHGlobal(unmngChipName); unmngChipName = IntPtr.Zero; //temperature always available if (ReadCoolingParameters(cameraHandle, out var min, out var max, out var setPoint)) { cameraInfo.CameraParas.TemperatureMin = min; cameraInfo.CameraParas.TemperatureMax = max; cameraInfo.CameraSettings.Temperature = setPoint; } //regions, will always get at leat one ROI, must after sizex and sizey gettings ReadRegions(cameraHandle, cameraInfo); //set optional params, may not supported by camera GetCameraParas(cameraHandle, cameraInfo); //exposeTime cameraInfo.CameraSettings.ExposureTime = new CameraPrimitiveParameter("Explore Time", (int)10); //default ////Read Trigger input Modes available on the camera if (ReadEnumeration(cameraHandle, out var list, PvTypes.PARAM_EXPOSURE_MODE)) { cameraInfo.CameraParas.TriggerModes = list; cameraInfo.CameraSettings.TriggerMode = list[0].Value; } //Check if Expose Out Parameter is available on the camera cameraInfo.CameraParas.IsExposeOutModeSupported = IsParamAvailable(cameraHandle, PvTypes.PARAM_EXPOSE_OUT_MODE); if (cameraInfo.CameraParas.IsExposeOutModeSupported) { if (ReadEnumeration(cameraHandle, out var exposeOutList, PvTypes.PARAM_EXPOSE_OUT_MODE)) { cameraInfo.CameraParas.ExposeOutModes = exposeOutList; cameraInfo.CameraSettings.ExposeOutMode = exposeOutList[0].Value; } } }