Attribute VB_Name = "modPlot" Option Explicit 'Public Type COORD 'The co-ordinates in Long ' x As Long ' y As Long 'End Type '----- Plot Data ----- 'Public PlotCursor As COORD Public OldPlotCursor As COORD Public YPlotBuffer(8192) As Long 'holds y position data for cursor updates Public YPlotMAX As Long Public XPlotMAX As Long Private Const ALTERNATE = 1 ' ALTERNATE and WINDING are Private Const WINDING = 2 ' constants for FillMode. Private Declare Function CreatePolygonRgn Lib "gdi32" (lpPoint As Any, ByVal nCount As Long, ByVal nPolyFillMode As Long) As Long Private Declare Function FillRgn Lib "gdi32" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long '----- Save Plot ----- Public isDataAcq As Boolean Public isSavingPlot As Boolean Public SaveBuffer(8192) As Long ' spectrum data Public SaveChannels As Integer ' number of acquired channels Public SaveStatus As DPP_STATUS Public strSaveSettings As String Public AcqStartTime As String Public Function DrawFilledPolygon(Pic As PictureBox, ByRef Pnt() As COORD, _ Optional ByVal NumPoints As Double = 4) As Boolean Dim PolyPoint As Integer Dim hBrush As Long Dim hRgn As Long 'Defining color filling Variables On Error GoTo DrawFilledPolygonErr If Val(NumPoints) < 3 Then DrawFilledPolygon = False Exit Function 'Exiting none valid Sidecount End If Dim Vtx() As COORD 'Defining new verticies in Pixel Mode ReDim Vtx(1 To NumPoints) For PolyPoint = 1 To NumPoints Vtx(PolyPoint).X = (Pnt(PolyPoint).X / Screen.TwipsPerPixelX) Vtx(PolyPoint).Y = (Pnt(PolyPoint).Y / Screen.TwipsPerPixelY) Next PolyPoint hBrush = CreateSolidBrush(Pic.FillColor) hRgn = CreatePolygonRgn(Vtx(1), NumPoints, ALTERNATE) 'Getting the polygon region from the Vertices If hRgn Then FillRgn Pic.hdc, hRgn, hBrush 'Filling the determined area DeleteObject hRgn DeleteObject hBrush DrawFilledPolygon = True Exit Function DrawFilledPolygonErr: MsgBox "DrawFilledPolygon: Unexpected error occured." & vbCrLf & "Err." & Err.Number & " : " & Err.Description, vbCritical, "Error" DrawFilledPolygon = False End Function '------------------------------------------------------------------------- Public Sub CopyBufferLong(ByRef Source() As Long, ByRef Destination() As Long, Size As Integer) Dim i As Long For i = 0 To Size Destination(i) = Source(i) Next End Sub Public Sub SetAcqStartTime() AcqStartTime = Format(Now, "MM/DD/YYYY HH:NN:SS") End Sub Public Function StripNulls(OriginalStr As String) As String ' This removes the extra Nulls so String comparisons will work If (InStr(OriginalStr, Chr(0)) > 0) Then OriginalStr = Left(OriginalStr, InStr(OriginalStr, Chr(0)) - 1) End If StripNulls = OriginalStr End Function 'Gets the data from the DPP and stores it in file Public Function SaveMCADataPlot(CmnDlgFIO As CommonDialog) As String Dim strFileName As String SaveMCADataPlot = "No data saved." If (objDppApi = 0) Then Exit Function 'only run if api is already running If (dlgSave(CmnDlgFIO, dlgMCA_Filter)) Then strFileName = CmnDlgFIO.filename SaveMCADataPlot = SaveMCADataPlotToPath(strFileName) End If End Function 'Gets the data from the DPP and stores it in file Public Function SaveMCADataPlotToPath(strFileName As String) As String Dim adc As Integer Dim DataBuffer(8192) As Long Dim NumChan As Integer Dim StatusLst As DPP_STATUS Dim strSettings As String Dim CfgSet As DPP_CONFIG_SETTINGS Dim fileHnd As Integer Dim idxChan As Integer SaveMCADataPlotToPath = "No data saved." If (objDppApi = 0) Then Exit Function 'only run if api is already running While (isDataAcq) 'wait until current data acquisition is done DoEvents Wend 'stop the acquisition timer here to prevent the data from being accessed while in use isSavingPlot = True 'lock the plot data, don't update until local copy is done 'Copy Data NumChan = SaveChannels CopyBufferLong SaveBuffer, DataBuffer, NumChan 'Copy Status StatusLst = SaveStatus strSettings = strSaveSettings isSavingPlot = False 'Copy Configuration 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 - "; AcqStartTime 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 SaveMCADataPlotToPath = "Acqusition data saved." End Function '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