Option Strict Off Option Explicit On Imports VB = Microsoft.VisualBasic Friend Module modSpectrumFile '========================================================= Public Function ShowStatusValueStrings(ByVal m_DP5_Status As modDP5_Protocol.Stat) As String ShowStatusValueStrings = "" Dim strConfig As String = "" Dim strTemp As String = "" Dim strIntPart As String = "" Dim strFracPart As String = "" strConfig = "Device Type: " & m_DP5_Status.strDeviceID & vbNewLine strTemp = "Serial Number: " & (m_DP5_Status.SerialNumber).ToString() & vbNewLine 'SerialNumber strConfig = strConfig & strTemp strTemp = "Firmware: " + VersionToStr(m_DP5_Status.Firmware) & vbNewLine strConfig = strConfig & strTemp strTemp = "FPGA: " + VersionToStr(m_DP5_Status.FPGA) & vbNewLine strConfig = strConfig & strTemp strTemp = "Fast Count: " & (CDbl(m_DP5_Status.FastCount)).ToString() & vbNewLine 'FastCount strConfig = strConfig & strTemp strTemp = "Slow Count: " & (CDbl(m_DP5_Status.SlowCount)).ToString() & vbNewLine 'FastCount strConfig = strConfig & strTemp strTemp = "Accumulation Time: " & (m_DP5_Status.AccumulationTime).ToString() '& vbNewLine 'AccumulationTime strConfig = strConfig & strTemp ShowStatusValueStrings = strConfig End Function 'Public Function AppendCmdDesc(ByVal cstrCmd As String, ByVal cstrCfgData As String) As String ' AppendCmdDesc = "" ' Dim iStart As Short, iEnd As Short, iCmd As Integer ' Dim cstrNew As String = "" ' Dim cstrDesc As String = "" ' AppendCmdDesc = cstrCfgData ' cstrNew = "" ' If (Len(cstrCfgData) < 7) Then Exit Function ' no data ' If (Len(cstrCmd) <> 4) Then Exit Function ' bad command ' iCmd = InStr(1, cstrCfgData, cstrCmd + "=", CompareMethod.Text) ' If (iCmd = 0) Then Exit Function ' cmd not found ' cstrDesc = GetCmdDesc(cstrCmd) ' If (Len(cstrDesc) = 0) Then Exit Function ' cmd desc not found ' iStart = InStr(iCmd, cstrCfgData, "=", CompareMethod.Text) ' If (iStart <> (iCmd + 4)) Then Exit Function ' data start not found ' iEnd = InStr(iStart + 1, cstrCfgData, ";", CompareMethod.Text) ' If (iEnd > (iStart + 11)) Then Exit Function ' data end not found ' cstrNew = VB.Left(cstrCfgData, iEnd) + " " + cstrDesc + Mid(cstrCfgData, iEnd + 1) ' AppendCmdDesc = cstrNew 'End Function Public Function isLineTerminated(ByVal strLine As String, Optional ByVal strTerm As String = vbNewLine) As Boolean If (VB.Right(strLine, VB.Len(strTerm)) = strTerm) Then isLineTerminated = True Else isLineTerminated = False End If End Function Public Function RemoveLineTerminator(ByVal strLine As String, Optional ByVal strTerm As String = vbNewLine) As String If (VB.Right(strLine, VB.Len(strTerm)) = strTerm) Then RemoveLineTerminator = VB.Left(strLine, (VB.Len(strLine) - VB.Len(strTerm))) Else RemoveLineTerminator = strLine End If End Function Public Sub SaveSpectrum(ByVal strFilename As String, ByVal SPECTRUM As Spec, ByVal strCfg As String, ByVal STATUS As Stat, ByRef strTag As String, ByVal strDescription As String, ByVal dateStart As Date) Dim idxData As Integer Dim iFile As Short Dim strDate As String = "" Dim strStatus As String = "" Dim strCfgMCA As String = "" iFile = FreeFile() FileOpen(iFile, strFilename, OpenMode.Output) If (Len(strTag) = 0) Then strTag = "live_data" PrintLine(iFile, "<>") PrintLine(iFile, "TAG - " & strTag) PrintLine(iFile, "DESCRIPTION - " & strDescription) PrintLine(iFile, "") PrintLine(iFile, "") PrintLine(iFile, "") Select Case SPECTRUM.Channels Case 256 PrintLine(iFile, "GAIN - 0") Case 512 PrintLine(iFile, "GAIN - 1") Case 1024 PrintLine(iFile, "GAIN - 2") Case 2048 PrintLine(iFile, "GAIN - 3") Case 4096 PrintLine(iFile, "GAIN - 4") Case 8192 PrintLine(iFile, "GAIN - 5") Case Else PrintLine(iFile, "GAIN - 2") End Select 'Print #iFile, "THRESHOLD - 0" PrintLine(iFile, "LIVE_MODE - 0") PrintLine(iFile, "PRESET_TIME - 0") PrintLine(iFile, "LIVE_TIME - 0") PrintLine(iFile, "REAL_TIME -" & Str(STATUS.AccumulationTime)) 'Print #iFile, "START_TIME - "; Date & " " & Time 'MM/DD/YYYY HH:MM:SS strDate = (dateStart).ToString("MM/DD/YYYY HH:MM:SS") PrintLine(iFile, "START_TIME - " & Today & " " & TimeOfDay) 'MM/DD/YYYY HH:MM:SS PrintLine(iFile, "SERIAL_NUMBER -" & Str(STATUS.SerialNumber)) PrintLine(iFile, "<>") For idxData = 0 To SPECTRUM.Channels - 1 PrintLine(iFile, Str(SPECTRUM.DATA(idxData))) Next idxData PrintLine(iFile, "<>") strCfgMCA = strCfg If (isLineTerminated(strCfgMCA)) Then strCfgMCA = RemoveLineTerminator(strCfgMCA) End If PrintLine(iFile, "<>") PrintLine(iFile, strCfgMCA) PrintLine(iFile, "<>") PrintLine(iFile, "<>") strStatus = ShowStatusValueStrings(STATUS) If (strStatus = "") Then PrintLine(iFile, "Device Type: DP5") PrintLine(iFile, "Serial Number: 0") Else PrintLine(iFile, strStatus) End If PrintLine(iFile, "<>") FileClose(iFile) End Sub Public Sub LogEvent(ByVal strEvent As String, Optional ByVal bOverWrite As Boolean = False) Dim FileNumber As Short Dim strMsg As String = "" strMsg = Now & "," & strEvent FileNumber = FreeFile() If (bOverWrite) Then FileOpen(FileNumber, "EventLog.txt", OpenMode.Output) Else FileOpen(FileNumber, "EventLog.txt", OpenMode.Append) End If PrintLine(FileNumber, strMsg) FileClose(FileNumber) End Sub End Module