Attribute VB_Name = "modDppApi" Option Explicit 'Amptek DppApi v1.0.2.6 04/29/2009 Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Public Type COORD 'The co-ordinates in Long X As Long Y As Long End Type '----- Plot Data ----- Public PlotCursor As COORD Public HasPlotCursorSupport As Boolean 'Amptek DPP Device Types ''''Public Const DPPDP4 = &H0 ''''Public Const DPPPX4 = &H1 Public Const DPPNONE = &H0 Public Const DPPDP4 = &H1 Public Const DPPPX4 = &H2 Public Const DPPDP4EMUL = &H3 Public Const DPPDP5 = &H4 Public Const BootOptSetBootFlags = &H92 'Set DP5 boot options* Public Const BootOptSetPC5HV = &H93 'Set PC5 HV Public Const BootOptPC5TECTemp = &H94 'Set PC5 TEC temperature Public Const BootOptDP5InputOffset = &H95 'Set DP5 input offset Public Const BootOptSetDP5uCtrADC = &H96 'Set DP5 microcontroller ADC/Temperature calibration (RESERVED) Public Const BootOptSetDP5SpectrumOffset = &H97 'Set DP5 spectrum offset 'indicates type and version of device currently connected to Public DppDevice As Integer Public DppFirmwareRev As Double Public DppFPGARev As Double Public Dpp80MHzMode As Integer Public DppSerialNumber As Long 'Gain Range Constants Public Const DP4MINGAIN = 6# ' dp4 5x-150x (5.7143-142.8572 required for continuous range) Public Const DP4MAXGAIN = 142# Public Const PX4MINGAIN = 4# ' px4 3x-687.25x (3.0975x-703.5375x based on calculated values) Public Const PX4MAXGAIN = 700# 'Fine Gain UpDown Control Ranges Public Const FineGainMin = 6144 ' default fine gain settings Public Const FineGainMax = 10240 'Coarse Gain UpDown Control Ranges Public Const CoarseGainMin = 0 ' lowest coarse gain setting is always 0 Public Const DP4CoarseGainMax = 3 ' dp4 gain control settings 0-3 Public Const PX4CoarseGainMax = 27 ' px4 gain control settings 0-27 Public Const DP5CoarseGainMax = 15 ' DP5 gain control settings 0-15 Public CfgEditUpdatesDone As Boolean Public XLCfgUpdatesDone As Boolean '' -------------------------------------------------------------------------------------- '' DppConfigSettingsType '' -------------------------------------------------------------------------------------- Public Type DPP_CONFIG_SETTINGS ' MCA Properties AcqMode As Byte ' acquisition mode 0=MCA,1=MCS MCSTimebase As Byte ' MCS timebase value (0-15) see CAcqMode MCAChannels As Byte ' number of channels 0=256,1=512,2=1024,3=2048,4=4096,5=8192 BufferSelect As Byte ' Holds Buffer Sel A&B,Buffer Sel Hardware,see DPPBufferSelect TTLGate As Byte ' gate input settings, determines events included/excluded from spectrum, see DPPGate SlowThreshold As Byte ' Slow ch threshold, Events w/amp lower not added to spectrum PresetTime As Long ' var holds preset time, used in usb PresetCount As Long ' preset count in selected channels, ch are set in SCA8 SCA(0 To 7) As Long ' SCA values, LL, UL, and Enable are stored together ' Shaping Properties TimeToPeak As Byte ' TimeToPeak register setting Decimation As Byte ' decimation setting for pulse shaping FlatTop As Byte ' flatop register setting PUREnable As Byte ' pile-up rejection enabled FastThreshold As Byte ' Fast Ch Threshold, events w/fch amp below this are rejected RTDSlow As Byte ' Risetime Discrimination slow threshold RTDOn As Byte ' Turns RTD on, and sets the amplitude and timing thresholds RTDFast As Byte ' RTD Time Threshold,Events w/HWHM wider than this are rejected BLR As Byte ' Baseline Restoration, see udBLR.Value notes for values BaselineOn As Byte ' use autobaseline during detector reset ' Gain PZ Properties CoarseGain As Byte ' stores current coarse gain value FineGain As Long ' stores current fine gain value PoleZero As Long ' pole zero adjust value InputOffset As Long ' input offset InputPolarity As Byte ' use InvertEnable during detector reset DetReset As Byte ' detector reset lockout period ' Power Properties TEC As Long ' TEC temperature setting (displayed in Kelvin) HVEnabled As Byte ' high voltage setting enable HV As Long ' high voltage setting value PreampPower As Byte ' preamp power select value (5v or 8.5v) ' Misc Properties AnalogOut As Byte ' dac enabled and DAC output type,(stobed peak,shaped pulse,dec inp,fast ch) OutputOffset As Byte ' Output DAC offset, -64…+63,(signed)(D7-D1) (-500mV to +492mV) AuxOut As Byte ' Aux output type AudibleCounter As Byte ' audio volume setting End Type '' -------------------------------------------------------------------------------------- '' DppStatusType (DPP_STATUS) DPP Status Storage Type '' -------------------------------------------------------------------------------------- Public Type DPP_STATUS ' Identification FPGA As Double ' FPGA Firmware As Double ' firmware revision SerialNumber As Double ' unit serial number StatDevInd As Byte ' device indicator from status block (0=dp4,1=px4) ' Configuration BootStatus As Byte ' boot status byte (PwrBtnConfig,SwConfigRcvd,McaEnabled) PwrBtnConfig As Byte ' dpp has loaded config from power button SwConfigRcvd As Byte ' software has sent valid config to unit since startup ' Tuning SetFastThreshDone As Byte ' DPP tune fast thresh has successfully done SetSlowThreshDone As Byte ' DPP tune slow thresh has successfully done SetInputOffsetDone As Byte ' DPP tune input offset has successfully done ' Monitors BoardTemp As Double ' board temperature monitor value HVMonitor As Double ' high voltage monitor value TECMonitor As Double ' TEC temperature monitor value (displayed in Kelvin) ' Acquisition Parameters FastCount As Double ' fast channel count SlowCount As Double ' slow channel count AccumulationTime As Double ' real time duration of present data acquisition interval ' Acquisition Mode StatMcaEnabled As Byte ' mca enabled status, high during acq, preset time resets flag MCSDone As Byte ' MCS done flag 1=finished, 0=not finished PresetCountExpired As Byte ' indicates presets counts have been reached End Type '' -------------------------------------------------------------------------------------- '' DppBootOptions (DPP_BOOT_OPTIONS) DPP Boot Options Status Storage Type '' -------------------------------------------------------------------------------------- Public Type DPP_BOOT_OPTIONS BootFlags As Integer 'Boot flags HVDACSet As Integer 'HV DAC setting (not used in PX4 mode) TECDACSet As Integer 'TEC DAC setting (not used in PX4 mode) InputOffsetTuning As Integer 'Input offset DAC setting (not used in PX4 mode) uCTempCal As Integer 'uC temp cal (Reserved, do not change) SpectrumOffset As Integer 'Spectrum offset End Type 'these flags are used to track changes made to settings in the configuration dialog Public Enum DppConfigDataChanged cfgNone 'MCA cfgAcqMode cfgMCSTimebase cfgMCAChannels cfgBufferSelect cfgGate cfgPresetTime cfgSlowThreshold cfgPresetCount cfgSCA 'Shaping 'cfgShaping cfgTimeToPeak cfgFlatTop cfgPUREnable cfgFastThreshold cfgRTD cfgBLR cfgBaselineOn 'Gain PZ cfgCoarseGain cfgFineGain cfgPoleZero cfgInputOffset cfgInputPolarity cfgDetReset 'Power cfgTEC cfgHV cfgPreampPower 'Misc cfgDAC cfgOffset cfgAuxOut cfgAudibleCounter cfgModified cfgAll End Enum 'pointer to the DPP API Public objDppApi As Long Public Declare Sub InitCommonControls Lib "comctl32.dll" () 'forces load of common controls '=== Create/Destroy Dpp Api ====================================================== Public Declare Function OpenDppApi Lib "DppApi.dll" () As Long Public Declare Sub CloseDppApi Lib "DppApi.dll" (ByVal objptr As Long) '================================================================================= '=== USB Messaging Functions ===================================================== Public Declare Function OpenUSBDevice Lib "DppApi.dll" (ByVal objptr As Long) As Integer Public Declare Function OpenUSBDeviceEx Lib "DppApi.dll" (ByVal objptr As Long, ByVal Device As Long) As Integer Public Declare Sub CloseUSBDevice Lib "DppApi.dll" (ByVal objptr As Long) Public Declare Function MonitorUSBDppDevices Lib "DppApi.dll" (ByVal objptr As Long) As Integer Public Declare Function GetUSBDppDeviceInfo Lib "DppApi.dll" (ByVal objptr As Long, ByVal Device As Long, ByRef lSerialNumber As Long) As Integer '================================================================================= '=== DPP Configuration =========================================================== Public Declare Sub GetConfigFromDpp Lib "DppApi.dll" (ByVal objptr As Long) Public Declare Sub SendConfigToDpp Lib "DppApi.dll" (ByVal objptr As Long) Public Declare Sub GetConfigFromFile Lib "DppApi.dll" (ByVal objptr As Long, ByVal pszFilename As String, ByVal cSize As Long, ByVal DppDeviceType As Byte) Public Declare Sub SaveConfigToFile Lib "DppApi.dll" (ByVal objptr As Long, ByVal pszFilename As String, ByVal cSize As Long) Public Declare Sub GetConfigString Lib "DppApi.dll" (ByVal objptr As Long, ByVal pszConfig As String, ByVal cSize As Long) Public Declare Sub GetConfigFromBuffer Lib "DppApi.dll" (ByVal objptr As Long, ByVal ConfigBuffer As Long, ByVal DppDeviceType As Byte) Public Declare Sub SendConfigToBuffer Lib "DppApi.dll" (ByVal objptr As Long, ByVal ConfigBuffer As Long, ByRef Preset As Long) '================================================================================= '=== DPP Status ================================================================== Public Declare Sub GetStatusString Lib "DppApi.dll" (ByVal objptr As Long, ByVal isBufferA As Integer, ByVal pszStatus As String, ByVal DisplaySize As Long) Public Declare Sub GetStatusBuffer Lib "DppApi.dll" (ByVal objptr As Long, ByVal isBufferA As Integer, ByVal Status As Long) Public Declare Sub ProcessStatusBuffer Lib "DppApi.dll" (ByVal objptr As Long, ByVal Status As Long) Public Declare Sub DisplayStatusBuffer Lib "DppApi.dll" (ByVal objptr As Long, ByVal Status As Long, ByVal pszStatus As String, ByVal DisplaySize As Long) Public Declare Sub CreateMCAFileDPPSettings Lib "DppApi.dll" (ByVal objptr As Long, ByVal pszSettings As String, ByVal cSize As Long) Public Declare Sub GetStatusStruct Lib "DppApi.dll" (ByVal objptr As Long, ByVal isBufferA As Integer, ByRef StatusStruct As DPP_STATUS) Public Declare Sub GetBootOptionsStruct Lib "DppApi.dll" (ByVal objptr As Long, ByVal isBufferA As Integer, ByRef BootOptionsStruct As DPP_BOOT_OPTIONS) Public Declare Sub GetStatusStringFromBuffer Lib "DppApi.dll" (ByVal objptr As Long, ByVal isBufferA As Integer, ByVal pszStatus As String, ByVal cSize As Long, ByVal Status As Long) Public Declare Sub GetStatusStructFromBuffer Lib "DppApi.dll" (ByVal objptr As Long, ByVal isBufferA As Integer, ByRef StatusStruct As DPP_STATUS, ByVal Status As Long) '================================================================================= '=== DPP Data Acquisition ======================================================== Public Declare Function GetDppData Lib "DppApi.dll" (ByVal objptr As Long, ByVal DataBuffer As Long) As Integer Public Declare Sub ClearDppData Lib "DppApi.dll" (ByVal objptr As Long, ByVal isBufferA As Integer) Public Declare Sub PauseDppData Lib "DppApi.dll" (ByVal objptr As Long, ByVal boolPauseData As Integer) Public Declare Function ProcessDppData Lib "DppApi.dll" (ByVal objptr As Long, ByVal DataBuffer As Long, ByVal RawData As Long, ByVal ByteCount As Long) As Integer '================================================================================= '=== Configuration Settings ====================================================== Public Declare Sub GetCoarseGainSpinFromText Lib "DppApi.dll" (ByVal objptr As Long, ByRef Spin As Byte, ByVal pszCoarseGain As String) Public Declare Sub GetCoarseGainTextFromSpin Lib "DppApi.dll" (ByVal objptr As Long, ByVal Spin As Byte, ByVal pszCoarseGain As String, ByVal TextSize As Long) Public Declare Sub GetTempConfigSettings Lib "DppApi.dll" (ByVal objptr As Long, ByRef CfgSet As DPP_CONFIG_SETTINGS, ByVal CurrentUpdate As Integer) Public Declare Sub SetTempConfigSettings Lib "DppApi.dll" (ByVal objptr As Long, ByRef CfgSet As DPP_CONFIG_SETTINGS, ByVal CurrentUpdate As Integer) Public Declare Sub GetTempConfigString Lib "DppApi.dll" (ByVal objptr As Long, ByVal pszConfig As String, ByVal cSize As Long) Public Declare Sub GetOutputOffsetTextFromSpin Lib "DppApi.dll" (ByVal objptr As Long, ByVal Spin As Byte, ByVal pszOffset As String, ByVal TextSize As Long) Public Declare Sub GetOutputOffsetSpinFromText Lib "DppApi.dll" (ByVal objptr As Long, ByRef Spin As Byte, ByVal pszOffset As String) Public Declare Sub GetPresetTimeStringFromVal Lib "DppApi.dll" (ByVal objptr As Long, ByVal lPresetTime As Long, ByVal pszPresetTime As String, ByVal cSize As Long) Public Declare Sub GetPresetTimeValFromString Lib "DppApi.dll" (ByVal objptr As Long, ByRef lPresetTime As Long, ByVal pszPresetTime As String) Public Declare Sub GetSlowThreshStringsFromSpin Lib "DppApi.dll" (ByVal objptr As Long, ByVal Spin As Byte, ByVal pszPercent As String, ByVal cSizePer As Long, ByVal pszChannels As String, ByVal cSizeChan As Long) Public Declare Sub GetSlowThreshSpinFromPercent Lib "DppApi.dll" (ByVal objptr As Long, ByVal dblPercent As Double, ByRef Spin As Byte) Public Declare Sub GetSlowThreshSpinFromChannel Lib "DppApi.dll" (ByVal objptr As Long, ByVal dblChannel As Double, ByRef Spin As Byte) Public Declare Sub GetTimeToPeakDecimationFromSpin Lib "DppApi.dll" (ByVal objptr As Long, ByRef TimeToPeak As Byte, ByRef Decimation As Byte, ByVal Spin As Byte) Public Declare Sub GetTimeToPeakSpinFromValues Lib "DppApi.dll" (ByVal objptr As Long, ByVal TimeToPeak As Byte, ByVal Decimation As Byte, ByRef Spin As Byte) '================================================================================= '=== PX4 Text Message ====================================================== Public Declare Sub SetPX4Text Lib "DppApi.dll" (ByVal objptr As Long, ByVal pszPX4Test As String) Public Declare Sub GetPX4Text Lib "DppApi.dll" (ByVal objptr As Long, ByVal pszPX4Test As String, ByVal TextSize As Long) '================================================================================= '=== DP5 Text Message ====================================================== Public Declare Sub SetDP5Text Lib "DppApi.dll" (ByVal objptr As Long, ByVal pszDP5Test As String) Public Declare Sub GetDP5Text Lib "DppApi.dll" (ByVal objptr As Long, ByVal pszDP5Test As String, ByVal TextSize As Long) '================================================================================= '=== DP4/PX4 Tune Functions =============================================== Public Declare Sub TuneFastThreshold Lib "DppApi.dll" (ByVal objptr As Long) Public Declare Sub TuneInputOffsetInit Lib "DppApi.dll" (ByVal objptr As Long) Public Declare Sub TuneInputOffset Lib "DppApi.dll" (ByVal objptr As Long) '================================================================================= '=== PX4 Test Functions =================================================== Public Declare Sub SendDiodeCalVal Lib "DppApi.dll" (ByVal objptr As Long, ByVal DCalVal As Integer) Public Declare Sub GetDiodeCalVal Lib "DppApi.dll" (ByVal objptr As Long, ByRef DblCalVal As Double) '================================================================================= '=== DPP/DP5 Functions ==================================================== Public Declare Sub SendDppVendorRequest Lib "DppApi.dll" (ByVal objptr As Long, ByVal Request As Integer, ByVal value As Integer) 'Run GetStatusStruct or GetStatusString before running Get80MHzMode Public Declare Function Get80MHzMode Lib "DppApi.dll" (ByVal objptr As Long) As Long Public Declare Sub SetFPGAClockDefault Lib "DppApi.dll" (ByVal objptr As Long, ByVal b80MHzMode As Integer, ByVal DppDeviceType As Byte) '================================================================================= Public DPPAPIBUSY As Boolean Public Sub SetAPIBusyFlag(isBusy As Boolean) DPPAPIBUSY = isBusy If (DPPAPIBUSY) Then Sleep (1000) 'give chance for requesta to finish End Sub Public Function DPPTypeFromStatus(ByRef StatusStruct As DPP_STATUS) As Integer Dim indDPP5 As Long 'DPP5 20071023 If (StatusStruct.SerialNumber < 1) Then Exit Function indDPP5 = Abs(StatusStruct.Firmware >= 5#) 'DPP5 20071023 indicates DPP5 type device DPPTypeFromStatus = ((indDPP5 * 2) + (StatusStruct.StatDevInd * 1)) + 1 End Function Public Function DPPTypeString(DPPDeviceVal As Integer) As String Select Case (DPPDeviceVal) Case DPPDP4 DPPTypeString = "DP4" Case DPPPX4 DPPTypeString = "PX4" Case DPPDP4EMUL DPPTypeString = "DP4 EMUL" Case DPPDP5 DPPTypeString = "DP5" Case Else DPPTypeString = "DPP" 'default End Select End Function Public Function GetDPPTypeFromString(strDPPDeviceIn As String) As Integer Dim strDPPDevice As String strDPPDevice = UCase(strDPPDeviceIn) Select Case (strDPPDevice) Case "DP4" GetDPPTypeFromString = DPPDP4 Case "GAMMARAD" GetDPPTypeFromString = DPPDP4 Case "PX4" GetDPPTypeFromString = DPPPX4 Case "DP4 EMUL" GetDPPTypeFromString = DPPDP4EMUL Case "DP4EMUL" GetDPPTypeFromString = DPPDP4 Case "DP5" GetDPPTypeFromString = DPPDP5 Case "PX4 EMUL" GetDPPTypeFromString = DPPDP5 Case "PX4EMUL" GetDPPTypeFromString = DPPDP5 Case "DPP" GetDPPTypeFromString = DPPPX4 Case "X-123" GetDPPTypeFromString = DPPDP4 Case "X123" GetDPPTypeFromString = DPPDP4 Case "X-123 SDD" GetDPPTypeFromString = DPPDP5 Case "X123 SDD" GetDPPTypeFromString = DPPDP5 Case "X-123SDD" GetDPPTypeFromString = DPPDP5 Case "X123SDD" GetDPPTypeFromString = DPPDP5 Case Else GetDPPTypeFromString = DPPNONE End Select End Function