Attribute VB_Name = "modSaveMcaSpectrum" Option Explicit Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) 'USEAGE: 'Save 10 Second Data Spectrum 'Private Sub cmdSavePlot_Click() ' cmdSavePlot.Enabled = False ' cmdSavePlot.Caption = "Please wait 10 seconds..." ' SaveData App.Path & "\" & Format(Now, "YYYYMMDD_HHNNSS") & ".mca" ' cmdSavePlot.Caption = "Save 10 Second Data Spectrum" ' cmdSavePlot.Enabled = True 'End Sub Public Sub SaveData(strFileName As String) Dim fileHnd As Integer Dim idxChan As Integer Dim adc As Integer Dim numdev As Integer ' number of usb devices Dim objDppApi As Long ' pointer to dpp api Dim szStatus As String * 2000 ' status text Dim DataBuffer(8192) As Long ' spectrum data Dim NumChan As Integer ' number of acquired channels Dim SelDevNum As Integer Dim StatusLst As DPP_STATUS Dim CfgSet As DPP_CONFIG_SETTINGS Dim strSettings As String * 3000 Dim StartTime As Date Dim LoopCount As Integer objDppApi = OpenDppApi() ' create/open DPPAPI SelDevNum = 1 'defalut device is 1 numdev = OpenUSBDeviceEx(objDppApi, SelDevNum) ' open USB communications If (numdev > 0) Then GetStatusString objDppApi, 1, szStatus, 2000 ' get device status, dp5 sets api fpga clock mode GetConfigFromDpp objDppApi ' configure api from hardware PauseDppData objDppApi, 1 ClearDppData objDppApi, 1 GetTempConfigSettings objDppApi, CfgSet, 1 'Copy Configuration settings If (CfgSet.PresetTime <> 100) Then CfgSet.PresetTime = 100 'set preset to 10 seconds SetTempConfigSettings objDppApi, CfgSet, 1 'Save Configuration settings SendConfigToDpp objDppApi End If PauseDppData objDppApi, 0 'start the acquisition StartTime = Now LoopCount = 0 Do LoopCount = LoopCount + 1 DoEvents Sleep 1000 GetStatusStruct objDppApi, 1, StatusLst 'get the current status Loop Until ((LoopCount = 12) Or (Not StatusLst.StatMcaEnabled)) NumChan = GetDppData(objDppApi, VarPtr(DataBuffer(0))) ' acquire data 'create a snapshot of the current configuration and status for file save CreateMCAFileDPPSettings objDppApi, strSettings, 3000 'display string for <> section' If (InStr(strSettings, Chr(0)) > 0) Then 'strip the trailing nulls strSettings = Left(strSettings, InStr(strSettings, Chr(0)) - 1) End If GetTempConfigSettings objDppApi, CfgSet, 1 'Copy Configuration settings Select Case NumChan Case 16384 adc = 6 Case 8192 adc = 5 Case 4096 adc = 4 Case 2048 adc = 3 Case 1024 adc = 2 Case 512 adc = 1 Case 256 adc = 0 End Select fileHnd = FreeFile Open strFileName For Output As #fileHnd Print #fileHnd, "<>" Print #fileHnd, "TAG - DPPAPI" Print #fileHnd, "DESCRIPTION - "; strFileName Print #fileHnd, "GAIN - "; adc Print #fileHnd, "THRESHOLD - 0" Print #fileHnd, "LIVE_MODE - 0" Print #fileHnd, "PRESET_TIME - "; Trim(Format(CfgSet.PresetTime / 10, "0.0")) Print #fileHnd, "LIVE_TIME - "; CalcLiveTime(StatusLst.FastCount, StatusLst.SlowCount, StatusLst.AccumulationTime) Print #fileHnd, "REAL_TIME - "; StatusLst.AccumulationTime Print #fileHnd, "START_TIME - "; Format(StartTime, "MM/DD/YYYY HH:NN:SS") Print #fileHnd, "SERIAL_NUMBER - "; StatusLst.SerialNumber Print #fileHnd, "<>" For idxChan = 0 To (NumChan - 1) Print #fileHnd, DataBuffer(idxChan) Next idxChan Print #fileHnd, "<>" Print #fileHnd, strSettings Close #fileHnd End If CloseUSBDevice (objDppApi) ' close usb CloseDppApi (objDppApi) ' close DPPAPI End Sub 'Calculate percentage live/dead time based on fast/slow counts Public Function CalcLiveTime(FastCounts As Double, SlowCounts As Double, RealTime As Double) As String Dim CorrectedFastCounts As Double Dim dblPercentDeadTime As Double Dim SysDeadTime As Double Dim dblLiveTime As Double CalcLiveTime = " " SysDeadTime = (400# * (10 ^ -9)) If (SlowCounts > FastCounts) Then CalcLiveTime = " " Else If ((1# - (FastCounts * SysDeadTime)) > 0#) Then CorrectedFastCounts = FastCounts / (1# - (FastCounts * SysDeadTime)) If (CorrectedFastCounts > 0#) Then dblPercentDeadTime = (1# - (SlowCounts / CorrectedFastCounts)) dblLiveTime = (1# - dblPercentDeadTime) * RealTime CalcLiveTime = Format(dblLiveTime, "0.00") Else CalcLiveTime = " " End If Else CalcLiveTime = " " End If End If End Function