Option Strict Off Option Explicit On Imports VB = Microsoft.VisualBasic Imports System.Runtime.InteropServices Friend Class frmDP5 Inherits System.Windows.Forms.Form Private Declare Sub InitCommonControls Lib "comctl32.dll" () Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Integer Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer) Private Sub cmdArmTrigger_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdArmTrigger.Click SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_ARM_DIGITAL_OSCILLOSCOPE) End Sub Private Sub cmdClearData_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClearData.Click SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_CLEAR_SPECTRUM_STATUS) End Sub Private Sub cmdClearMiscData_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdClearMiscData.Click txtMiscData.Text = "" End Sub Private Sub cmdSendConfiguration_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSendConfiguration.Click Dim idxCfg As Short Dim varCfgHw As Object Dim varCommentsHw As Object = Nothing Dim strCfg As String = "" Dim strDisplay As String = "" Dim strCmd As String = "" Dim bStatusDone As Boolean 'reduce size of configuration if necessary Dim lCfgLen As Long 'ASCII Configuration Command String Length Dim bSplitCfg As Boolean 'Configuration split flag Dim idxSplitCfg As Long 'Configuration split position, only if necessary Dim strSplitCfg As String 'Configuration split string second buffer lCfgLen = 0 bSplitCfg = False idxSplitCfg = 0 strSplitCfg = "" strDisplay = "" On Error GoTo cmdSendConfigurationErr If (dlgOpen(OpenFile, dlgTXT_Filter)) Then strIniFilename = OpenFile.FileName varCfgHw = GetDP5ConfigSection(strIniFilename, IniSectionCfg, varCommentsHw) 'read ini config from file If (IsNothing(varCfgHw)) Then Exit Sub 'not initialized strCfg = TypeName(varCfgHw) 'test variant data type If (strCfg = "String(,)") Then 'have data strCfg = "" 'clear cfg storage Else Exit Sub 'no data End If For idxCfg = 0 To UBound(varCfgHw, 1) strCmd = varCfgHw(idxCfg, 0) & "=" & varCfgHw(idxCfg, 1) & ";" strCfg = strCfg & strCmd strDisplay = strDisplay & strCmd & vbNewLine Next s.HwCfgReady = False s.HwCfgExReady = False strCfg = RemoveCmdByDeviceType(strCfg, STATUS.PC5_PRESENT, STATUS.DEVICE_ID, STATUS.isDP5_RevDxGains, STATUS.DPP_ECO) 'Test configuration size lCfgLen = Len(strCfg) If (lCfgLen > 512) Then strCfg = ReplaceText(strCfg, "US;", ";") strCfg = ReplaceText(strCfg, "OFF;", "OF;") strCfg = ReplaceText(strCfg, "RISING;", "RI;") strCfg = ReplaceText(strCfg, "FALLING;", "FA;") lCfgLen = Len(strCfg) If (lCfgLen > 512) Then 'configuration is still too large, split cfg bSplitCfg = True idxSplitCfg = GetCmdChunk(strCfg) strSplitCfg = Mid(strCfg, idxSplitCfg + 1) strCfg = VB.Strings.Left(strCfg, idxSplitCfg) End If End If If (Len(strCfg) > 0) Then lblCfgLenValue.Text = CStr(Len(strCfg)) s.HwCfgDP5Out = strCfg s.HwCfgReady = True SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_CONFIG_PACKET_TO_HW) s.HwCfgReady = False End If If (bSplitCfg) Then bStatusDone = msDelay(200) 'give time for timer to finish lblCfgLenValue.Text = CStr(Len(strSplitCfg)) s.HwCfgDP5Out = strSplitCfg s.HwCfgReady = True SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_CONFIG_PACKET_TO_HW) s.HwCfgReady = False End If 'txtSendCfgToHwNoEdit.Text = strDisplay Else 'a file was not selected End If Exit Sub cmdSendConfigurationErr: End Sub Private Sub cmdReadMiscData_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdReadMiscData.Click SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_512_BYTE_MISC_DATA) End Sub Private Sub cmdShowConfiguration_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdShowConfiguration.Click If (s.isDppConnected) Then s.DisplayCfg = True SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_FULL_READ_CONFIG_PACKET) End If End Sub Private Sub cmdStartAcquisition_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdStartAcquisition.Click SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_ENABLE_MCA_MCS) Timer2.Enabled = True End Sub Private Sub cmdColor_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdColor.Click PlotColor = RgbToQbColor(PlotColor) End Sub Private Sub cmdDiagnostics_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdDiagnostics.Click SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_DIAGNOSTIC_DATA) End Sub Private Sub cmdSaveSpectrum_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSaveSpectrum.Click Dim curStart As Decimal 'start time from system time in milliseconds Dim TimeExpired As Boolean 'time expired flag Dim curElapsed As Decimal 'Elapsed time from start time in milliseconds Dim strCfg As String = "" Dim strStatus As String = "" strStatus = "" If (s.isDppConnected) Then s.HwCfgReady = False 'clear cfg ready flag s.HwCfgDP5 = "" 'clear config readback string s.cstrRawCfgIn = "" TimeExpired = False curStart = msTimeStart() s.SpectrumCfg = True SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_FULL_READ_CONFIG_PACKET) Do 'wait until s.HwCfgReady or timeout System.Windows.Forms.Application.DoEvents() curElapsed = msTimeDiff(curStart) TimeExpired = msTimeExpired(curStart, 1000) '1000 milliseconds max wait Loop Until (TimeExpired Or s.HwCfgReady) 'read cfg in s.HwCfgDP5 If ((Len(s.HwCfgDP5) > 0) And s.HwCfgReady) Then strCfg = s.HwCfgDP5 If (VB.Right(strCfg, 2) = vbNewLine) Then strCfg = VB.Left(strCfg, Len(strCfg) - 2) End If End If End If If (STATUS.SerialNumber > 0) Then strStatus = ShowStatusValueStrings(STATUS) If (VB.Right(strStatus, 2) = vbNewLine) Then strStatus = VB.Left(strStatus, Len(strStatus) - 2) End If End If SaveSpectrum(SPECTRUM, strStatus, strCfg, SaveFile, txtSpectrumTag.Text, txtSpectrumDescription.Text) End Sub Private Sub cmdSingleUpdate_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSingleUpdate.Click Timer2.Enabled = False cmdSingleUpdate.Enabled = False If (chkDeltaMode.CheckState = System.Windows.Forms.CheckState.Checked) Then SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_CLEAR_SPECTRUM_STATUS) Else SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_SPECTRUM_STATUS) End If cmdSingleUpdate.Enabled = True End Sub Public Sub cmdUSBDeviceTest() SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_NETFINDER_PACKET) End Sub Private Sub cmdSelectCommunications_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdSelectCommunications.Click Dim bStatusDone As Boolean Timer2.Enabled = False bStatusDone = msDelay(500) 'give time for timer to finish s.CurrentInterface = USB NetfinderUnit = 0 InitAllEntries(DppEntries) frmDP5_Connect.ShowDialog() If (s.isDppConnected) Then lblSelectCommunications.Text = "USB - " & "WinUSB" SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_STATUS) bStatusDone = msDelay(500) s.Dp5CmdList = New Collection MakeDp5CmdList((s.Dp5CmdList)) EnableDppCmdControls(True) 'MsgBox(WinUsbDeviceToString(DppWinUSB)) 'display DppWinUSB device information Else lblSelectCommunications.Text = "Select Communications" EnableDppCmdControls(False) End If End Sub Private Sub cmdStopAcquisition_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdStopAcquisition.Click SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_DISABLE_MCA_MCS) End Sub Private Sub cmdWriteMiscData_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdWriteMiscData.Click SendCommandData(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_WRITE_512_BYTE_MISC_DATA, (txtMiscData.Text)) End Sub Private Sub Form_Initialize_Renamed() On Error Resume Next LoadLibrary("shell32.dll") InitCommonControls() On Error GoTo 0 End Sub Private Sub frmDP5_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load LoadApplicationSettings(Me) InitAllEntries(NfPktEntries) CurrentUSBDevice = 1 NumUSBDevices = 0 s.CfgReadBack = False s.DisplayCfg = False s.SaveCfg = False s.SpectrumCfg = False s.Dp5CmdList = New Collection MakeDp5CmdList((s.Dp5CmdList)) s.HwCfgDP5 = "" EnableDppCmdControls(False) USBDeviceTest = False lblVersion.BorderStyle = System.Windows.Forms.FormBorderStyle.None Whitespace = Chr(0) & Chr(9) & Chr(10) & Chr(11) & Chr(12) & Chr(13) & Chr(32) s.CurrentInterface = USB PlotColor = &HFF USBDevicePathName = "" USBDeviceConnected = False USBDeviceNotificationHandle = 0 pnlStatus.Text = "DP5 test application ready..." lblVersion.Text = "DP5 SDK vbDP5 v" & VB.Right(Str(My.Application.Info.Version.Major), 1) & "." & VB.Right(Str(My.Application.Info.Version.Minor), 2) End Sub Private Sub frmDP5_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed SaveApplicationSettings(Me) CloseDeviceHandle(DppWinUSB) CloseProgram() End Sub Public Sub CloseProgram() Dim frm As System.Windows.Forms.Form For Each frm In My.Application.OpenForms frm.Close() Next frm End Sub Private Sub UpdateStatusDisplay(ByRef STATUS As Stat) Dim m As Single Dim H As Single Dim s As Single Dim strStatus As String = "" Dim strParam As String = "" Dim strValue As String = "" strParam = strParam & "Device Type: " & vbNewLine strValue = STATUS.strDeviceID strStatus = strStatus & strValue & vbNewLine strParam = strParam & "Serial Number: " & vbNewLine strValue = CStr(STATUS.SerialNumber) strStatus = strStatus & strValue & vbNewLine strParam = strParam & "Firmware: " & vbNewLine strValue = "v" & VB6.Format(Fix(STATUS.Firmware / 16), "0") & "." & VB6.Format(STATUS.Firmware And 15, "00") strStatus = strStatus & strValue & vbNewLine strParam = strParam & "FPGA: " & vbNewLine strValue = "v" & VB6.Format(Fix(STATUS.FPGA / 16), "0") & "." & VB6.Format(STATUS.FPGA And 15, "00") strStatus = strStatus & strValue & vbNewLine strParam = strParam & "Fast Count: " & vbNewLine strValue = VB6.Format(STATUS.FastCount, "#,###,###,##0") strStatus = strStatus & strValue & vbNewLine strParam = strParam & "SlowCount: " & vbNewLine strValue = VB6.Format(STATUS.SlowCount, "#,###,###,##0") strStatus = strStatus & strValue & vbNewLine strParam = strParam & "Accumulation Time: " & vbNewLine If STATUS.AccumulationTime < 1000 Then strValue = VB6.Format(STATUS.AccumulationTime, "##0.000s") Else H = Fix(STATUS.AccumulationTime / 3600) m = Fix((STATUS.AccumulationTime - (H * 3600)) / 60) s = STATUS.AccumulationTime - H * 3600 - m * 60 strValue = VB6.Format(H, "###0h ") & VB6.Format(m, "#0m ") & VB6.Format(s, "#0.0s") End If strStatus = strStatus & strValue & vbNewLine strParam = strParam & "PC5 Serial Number: " & vbNewLine If STATUS.PC5_PRESENT Then strValue = Str(STATUS.PC5_SerialNumber) Else strValue = "N/A" End If strStatus = strStatus & strValue & vbNewLine If (STATUS.DEVICE_ID <> modParsePacket.DP5_DPP_TYPES.dppDP5G) Then strParam = strParam & "Detector HV: " & vbNewLine strValue = VB6.Format(STATUS.HV, "###0V") ' round to nearest volt strStatus = strStatus & strValue & vbNewLine strParam = strParam & "Detector Temp: " & vbNewLine strValue = VB6.Format(STATUS.DET_TEMP, "##0°C") ' round to nearest degree strStatus = strStatus & strValue & vbNewLine End If strParam = strParam & "DP5 Temp: " & vbNewLine strValue = Str(STATUS.DP5_TEMP) & "°C" strStatus = strStatus & strValue & vbNewLine strParam = strParam & "G.P. Counter: " & vbNewLine strValue = Str(STATUS.GP_COUNTER) strStatus = strStatus & strValue & vbNewLine If (STATUS.DEVICE_ID = modParsePacket.DP5_DPP_TYPES.dppDP5) Then strParam = strParam & "PC5 Present: " & vbNewLine strValue = Str(STATUS.PC5_PRESENT) strStatus = strStatus & strValue & vbNewLine If STATUS.PC5_PRESENT Then strParam = strParam & "PC5 HV Polarity: " & vbNewLine If (STATUS.PC5_HV_POL) Then strValue = "Positive" Else strValue = "Negative" End If strStatus = strStatus & strValue & vbNewLine strParam = strParam & "PC5 Preamp: " & vbNewLine If (STATUS.PC5_8_5V) Then strValue = "+/-8.5V" Else strValue = "+/-5V" End If strStatus = strStatus & strValue & vbNewLine End If strParam = strParam & "DP5 Temp: " & vbNewLine strValue = Str(STATUS.DP5_TEMP) & "°C" strStatus = strStatus & strValue & vbNewLine ElseIf (STATUS.DEVICE_ID = modParsePacket.DP5_DPP_TYPES.dppDP5G) Then strParam = strParam & "PC5G Present: " & vbNewLine strValue = Str(STATUS.PC5_PRESENT) strStatus = strStatus & strValue & vbNewLine ElseIf (STATUS.DEVICE_ID = modParsePacket.DP5_DPP_TYPES.dppPX5) Then 'STATUS.DPP_options = 1 'STATUS.HPGe_HV_INH = True 'STATUS.HPGe_HV_INH_POL = True If STATUS.DPP_options > 0 Then '===============PX5 Options================== strParam = strParam & "PX5 Options: " & vbNewLine If (STATUS.DPP_options = 1) Then strValue = "HPGe HVPS" Else strValue = "Unknown" End If strStatus = strStatus & strValue & vbNewLine '===============HPGe HVPS HV Status================== strParam = strParam & "HPGe HV: " & vbNewLine If STATUS.HPGe_HV_INH Then strValue = "not inhibited" Else strValue = "inhibited" End If strStatus = strStatus & strValue & vbNewLine '===============HPGe HVPS Inhibit Status================== strParam = strParam & "INH Polarity: " & vbNewLine If STATUS.HPGe_HV_INH_POL Then strValue = "high" Else strValue = "low" End If strStatus = strStatus & strValue & vbNewLine Else strParam = strParam & "PX5 Options: " & vbNewLine strValue = "No Options Installed" strStatus = strStatus & strValue & vbNewLine End If End If lblStatusDisplay(0).Text = strParam lblStatusDisplay(1).Text = strStatus End Sub Private Sub picScope_DoubleClick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles picScope.DoubleClick If Not (picScope.Image Is Nothing) Then picScope.Image.Dispose() picScope.Image = Nothing End If End Sub Private Sub Timer2_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer2.Tick If (chkDeltaMode.CheckState = System.Windows.Forms.CheckState.Checked) Then SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_CLEAR_SPECTRUM_STATUS) Else SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_SPECTRUM_STATUS) End If End Sub Public Sub RemCallParsePacket(ByRef PacketIn() As Byte) DppState.ReqProcess = ParsePacket(PacketIn, PIN) ParsePacketEx(PIN, DppState) End Sub Private Sub ParsePacketEx(ByRef PIN As Packet_In, ByRef DppState As DppStateType) Select Case DppState.ReqProcess Case preqProcessStatus ProcessStatusEx(PIN, DppState) Case preqProcessSpectrum ProcessSpectrumEx(PIN, DppState) Case preqProcessScopeData ProcessScopeDataEx(PIN, DppState) Case preqProcessTextData ProcessTextDataEx(PIN, DppState) '==================================================================== ' Case preqProcessScopeDataOverFlow ' ProcessScopeDataEx PIN, DppState ' 'ProcessScopeDataOverFlowEx PIN, DppState ' Case preqProcessInetSettings ' ProcessInetSettingsEx PIN, DppState Case preqProcessDiagData ProcessDiagDataEx(PIN, DppState) ' Case preqProcessHwDesc ' ProcessHwDescEx PIN, DppState Case preqProcessCfgRead ProcessCfgReadEx(PIN, DppState) Case preqProcessNetFindRead ProcessNetFindReadEx(PIN, DppState) ' Case preqProcessSCAData ' ProcessSCADataEx PIN, DppState '==================================================================== Case preqProcessAck ProcessAck(PIN.PID2) Case preqProcessError DisplayError(PIN, DppState) Case Else 'do nothing End Select End Sub Private Sub ProcessNetFindReadEx(ByRef PIN As Packet_In, ByRef DppState As DppStateType) Dim Buffer(4095) As Byte '0-4095, 4096 bytes Dim strDisplay As String = "" Dim idxNfInfo As Short For idxNfInfo = 0 To (PIN.LEN_Renamed - 1) Buffer(idxNfInfo) = PIN.DATA(idxNfInfo) Next InitEntry(NfPktEntries(DppState.Interface_Renamed)) AddEntry(NfPktEntries(DppState.Interface_Renamed), Buffer, 0) If (USBDeviceTest) Then USBDeviceTest = False strDisplay = EntryToStrUSB(NfPktEntries(DppState.Interface_Renamed), "USB Device " & CurrentUSBDevice & " of " & NumUSBDevices) frmDP5_Connect.rtbStatus.Text = strDisplay isDppFound = True frmDP5_Connect.lblDppFound.Visible = True pnlStatus.Text = "USB NetFind Found" & vbCrLf End If End Sub Private Sub ProcessCfgReadEx(ByRef PIN As Packet_In, ByRef DppState As DppStateType) Dim cstrRawCfgIn As String Dim cstrCmdD As String Dim strCfg As String Dim cstrDisplayCfgOut As String Dim idxCfg As Integer Dim varCmd As Object Dim strHwCfgDP5 As String cstrRawCfgIn = "" strHwCfgDP5 = "" ' ============================= ' === Create Raw Configuration Buffer From Hardware === For idxCfg = 0 To PIN.LEN_Renamed - 1 cstrRawCfgIn = cstrRawCfgIn & Chr(PIN.DATA(idxCfg)) strHwCfgDP5 = strHwCfgDP5 & Chr(PIN.DATA(idxCfg)) If (PIN.DATA(idxCfg) = Asc(";")) Then cstrRawCfgIn = cstrRawCfgIn & vbNewLine End If Next lblCfgLenValue.Text = CStr(Len(strHwCfgDP5)) If (s.DisplayCfg) Then s.DisplayCfg = False strCfg = cstrRawCfgIn 'MsgBox(Len(strHwCfgDP5)) cstrDisplayCfgOut = cstrRawCfgIn For Each varCmd In s.Dp5CmdList cstrCmdD = CStr(varCmd) If (Len(cstrCmdD) > 0) Then 'cstrDisplayCfgOut = ReplaceCmdDesc(cstrCmdD, cstrDisplayCfgOut) cstrDisplayCfgOut = AppendCmdDesc(cstrCmdD, cstrDisplayCfgOut) End If Next varCmd frmDppConfigDisplay.m_strMessage = cstrDisplayCfgOut 'frmDppConfigDisplay.m_strDelimiter = ";" frmDppConfigDisplay.m_strDelimiter = vbNewLine frmDppConfigDisplay.m_strTitle = "DPP Configuration" frmDppConfigDisplay.ShowDialog() ElseIf (s.CfgReadBack) Then s.CfgReadBack = False s.HwCfgDP5 = strHwCfgDP5 s.cstrRawCfgIn = cstrRawCfgIn s.HwCfgReady = True ElseIf (s.SpectrumCfg) Then s.SpectrumCfg = False cstrDisplayCfgOut = cstrRawCfgIn For Each varCmd In s.Dp5CmdList cstrCmdD = CStr(varCmd) If (Len(cstrCmdD) > 0) Then cstrDisplayCfgOut = AppendCmdDesc(cstrCmdD, cstrDisplayCfgOut) End If Next varCmd s.HwCfgDP5 = cstrDisplayCfgOut s.cstrRawCfgIn = cstrRawCfgIn s.HwCfgReady = True End If s.DisplayCfg = False s.CfgReadBack = False s.SpectrumCfg = False End Sub Private Sub DisplayError(ByRef PIN As Packet_In, ByRef DppState As DppStateType) pnlStatus.Text = PID2_TextToString("Received packet", CByte(PIN.STATUS)) ' bad PID, assigned by ParsePacket If (PIN.STATUS = modDP5_Protocol.PID2_ACK_TYPE.PID2_ACK_PID_ERROR) Then pnlStatus.Text = "Received packet: PID1=0x" & FmtHex(PIN.PID1, 2) & ", PID2=0x" & FmtHex(PIN.PID2, 2) & ", LEN=" & Str(PIN.LEN_Renamed) & vbCrLf End If End Sub Private Sub ProcessAck(ByRef PID2 As Byte) pnlStatus.Text = PID2_TextToString("ACK", PID2) End Sub Private Sub ProcessStatusEx(ByRef PIN As Packet_In, ByRef DppState As DppStateType) Dim X As Short STATUS.Initialize() For X = 0 To 63 STATUS.RAW(X) = PIN.DATA(X) Next X Call Process_Status(STATUS) RequestScopeData(STATUS.SCOPE_DR) UpdateStatusDisplay(STATUS) pnlStatus.Text = "Status Received" & vbCrLf End Sub Private Function ShowStatusValueStrings(ByRef m_DP5_Status As Stat) As String Dim strConfig As String Dim strTemp As String strConfig = "Device Type: " & m_DP5_Status.strDeviceID & vbNewLine strTemp = "Serial Number: " & CStr(m_DP5_Status.SerialNumber) & vbNewLine 'SerialNumber strConfig = strConfig & strTemp strTemp = "Firmware: " & VersionToStr(m_DP5_Status.Firmware) & vbNewLine strConfig = strConfig & strTemp If (m_DP5_Status.Firmware > &H65) Then strTemp = "Build: " & VersionToStr(m_DP5_Status.Build) & vbNewLine strConfig = strConfig & strTemp End If strTemp = "FPGA: " & VersionToStr(m_DP5_Status.FPGA) & vbNewLine strConfig = strConfig & strTemp If (m_DP5_Status.DEVICE_ID <> DP5_DPP_TYPES.dppMCA8000D) Then strTemp = "Fast Count: " & CStr(CDbl(m_DP5_Status.FastCount)) & vbNewLine 'FastCount strConfig = strConfig & strTemp End If strTemp = "Slow Count: " & CStr(CDbl(m_DP5_Status.SlowCount)) & vbNewLine 'SlowCount strConfig = strConfig & strTemp strTemp = "GP Count: " & CStr(CDbl(m_DP5_Status.GP_COUNTER)) & vbNewLine 'GP Count strConfig = strConfig & strTemp If (m_DP5_Status.DEVICE_ID <> DP5_DPP_TYPES.dppMCA8000D) Then strTemp = "Accumulation Time: " & CStr(m_DP5_Status.AccumulationTime) & vbNewLine 'AccumulationTime strConfig = strConfig & strTemp End If strTemp = "Real Time: " & CStr(m_DP5_Status.RealTime) & vbNewLine 'RealTime strConfig = strConfig & strTemp If (m_DP5_Status.DEVICE_ID <> DP5_DPP_TYPES.dppMCA8000D) Then strTemp = "Live Time: " & CStr(m_DP5_Status.LiveTime) & vbNewLine 'LiveTime strConfig = strConfig & strTemp End If If ((m_DP5_Status.DEVICE_ID <> DP5_DPP_TYPES.dppDP5G) And (m_DP5_Status.DEVICE_ID <> DP5_DPP_TYPES.dppMCA8000D)) Then strTemp = "Detector Temp: " & CStr(CInt(m_DP5_Status.DET_TEMP)) & "K" & vbNewLine 'Detector Temp strConfig = strConfig & strTemp strTemp = "Detector HV: " & CStr(CInt(m_DP5_Status.HV)) & "V" & vbNewLine 'Detector HV strConfig = strConfig & strTemp strTemp = "Board Temp: " & CStr(CInt(m_DP5_Status.DP5_TEMP)) & "°C" & vbNewLine 'Board Temp strConfig = strConfig & strTemp ElseIf (m_DP5_Status.DEVICE_ID = DP5_DPP_TYPES.dppDP5G) Then ' GAMMARAD5 If (m_DP5_Status.DET_TEMP > 0) Then strTemp = "Detector Temp: " & CStr(CInt(m_DP5_Status.DET_TEMP)) & "K" & vbNewLine 'Detector Temp strConfig = strConfig & strTemp Else strConfig = strConfig & "" End If ' strTemp.Format("HV Set: %.0fV\r\n",m_DP5_Status.HV); strConfig = strConfig & strTemp ElseIf (m_DP5_Status.DEVICE_ID = DP5_DPP_TYPES.dppMCA8000D) Then ' Digital MCA strTemp = "Board Temp: " & CStr(CInt(m_DP5_Status.DP5_TEMP)) & "°C" & vbNewLine 'Board Temp strConfig = strConfig & strTemp End If If (m_DP5_Status.DEVICE_ID = DP5_DPP_TYPES.dppPX5) Then strTemp = PX5_OptionsString(m_DP5_Status) strConfig = strConfig & strTemp strTemp = "TEC V: " & VB6.Format(m_DP5_Status.TEC_Voltage, "0.000") & "V" & vbNewLine 'LiveTime strConfig = strConfig & strTemp End If ShowStatusValueStrings = strConfig End Function Private Function PX5_OptionsString(ByRef m_DP5_Status As Stat) As String Dim strOptions As String = "" Dim strValue As String = "" If (m_DP5_Status.DEVICE_ID = DP5_DPP_TYPES.dppPX5) Then 'm_DP5_Status.DPP_options = 1; 'm_DP5_Status.HPGe_HV_INH = true; 'm_DP5_Status.HPGe_HV_INH_POL = true; If (m_DP5_Status.DPP_options > 0) Then '===============PX5 Options================== strOptions = strOptions & "PX5 Options: " If ((m_DP5_Status.DPP_options And 1) = 1) Then strOptions = strOptions & "HPGe HVPS" & vbNewLine Else strOptions = strOptions & "Unknown" & vbNewLine End If '===============HPGe HVPS HV Status================== strOptions = strOptions & "HPGe HV: " If (m_DP5_Status.HPGe_HV_INH) Then strOptions = strOptions & "not inhibited" & vbNewLine Else strOptions = strOptions & "inhibited" & vbNewLine End If '===============HPGe HVPS Inhibit Status================== strOptions = strOptions & "INH Polarity: " If (m_DP5_Status.HPGe_HV_INH_POL) Then strOptions = strOptions & "high" & vbNewLine Else strOptions = strOptions & "low" & vbNewLine End If Else strOptions = strOptions & "PX5 Options: None" & vbNewLine 'strOptions += "No Options Installed" End If End If PX5_OptionsString = strOptions End Function Private Sub ProcessSpectrumEx(ByRef PIN As Packet_In, ByRef DppState As DppStateType) Dim X As Short SPECTRUM.Channels = 256 * (2 ^ (((PIN.PID2 - 1) And 14) \ 2)) ReDim SPECTRUM.DATA(SPECTRUM.Channels) For X = 0 To SPECTRUM.Channels - 1 SPECTRUM.DATA(X) = CInt(PIN.DATA(X * 3)) + CInt(PIN.DATA(X * 3 + 1)) * 256 + CInt(PIN.DATA(X * 3 + 2)) * 65536 Next X If (PIN.PID2 And 1) = 0 Then ' spectrum + status For X = 0 To 63 STATUS.RAW(X) = PIN.DATA(X + SPECTRUM.Channels * 3) Next X Call Process_Status(STATUS) RequestScopeData(STATUS.SCOPE_DR) End If Call Plot_Spectrum(picMCAPlot, SPECTRUM, optScaleType(0).Checked, optPlotType(1).Checked) cmdSaveSpectrum.Enabled = True UpdateStatusDisplay(STATUS) End Sub Private Sub ProcessScopeDataEx(ByRef PIN As Packet_In, ByRef DppState As DppStateType) Dim X As Short Dim colPlotColor As Color colPlotColor = Color.Red For X = 0 To 2047 Scope(X) = PIN.DATA(X) Next X 'Scope_Packet_Received = True Call Plot_Scope(picScope, Scope, colPlotColor) ArmScope() End Sub Private Sub ProcessTextDataEx(ByRef PIN As Packet_In, ByRef DppState As DppStateType) Dim X As Short txtMiscData.Text = "" For X = 0 To 511 MiscData(X) = PIN.DATA(X) txtMiscData.Text = txtMiscData.Text & Chr(MiscData(X)) Next X End Sub Private Sub ProcessDiagDataEx(ByRef PIN As Packet_In, ByRef DppState As DppStateType) Dim dd As New DiagDataType Dim strDiag As String = "" dd.Initialize() Call Process_Diagnostics(PIN, dd) strDiag = DiagnosticsToString(dd) txtRawStatus.Text = strDiag End Sub Private Sub ArmScope() If chkAutoRearm.CheckState = System.Windows.Forms.CheckState.Checked Then SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_ARM_DIGITAL_OSCILLOSCOPE) 'Call btnArmTrigger_Click End Sub Private Sub RequestScopeData(ByRef ScopeDataReady As Boolean) If ScopeDataReady Then SendCommand(modDP5_Protocol.TRANSMIT_PACKET_TYPE.XMTPT_SEND_SCOPE_DATA) End Sub Public Sub SendCommand(ByRef XmtCmd As modDP5_Protocol.TRANSMIT_PACKET_TYPE) Dim HaveBuffer As Boolean Dim SentPkt As Boolean HaveBuffer = DP5_CMD(BufferOUT, XmtCmd) If (HaveBuffer) Then Select Case s.CurrentInterface Case USB SentPkt = SendPacketUSB(DppWinUSB, BufferOUT, PacketIn) If (s.CurrentInterface = USB) Then If (SentPkt) Then RemCallParsePacket(PacketIn) Else Timer2.Enabled = False End If End If End Select End If End Sub Public Sub SendCommandData(ByRef XmtCmd As modDP5_Protocol.TRANSMIT_PACKET_TYPE, ByRef DataOut As Object) Dim HaveBuffer As Boolean Dim SentPkt As Boolean HaveBuffer = DP5_CMD_Data(BufferOUT, XmtCmd, DataOut) If (HaveBuffer) Then Select Case s.CurrentInterface Case USB SentPkt = SendPacketUSB(DppWinUSB, BufferOUT, PacketIn) If (s.CurrentInterface = USB) Then If (SentPkt) Then RemCallParsePacket(PacketIn) Else Timer2.Enabled = False End If End If End Select End If End Sub Private Sub EnableDppCmdControls(ByRef EnableCmd As Boolean) '---- Configuration ----------------------------- cmdShowConfiguration.Enabled = EnableCmd '---- Acquisition ------------------------------- cmdStartAcquisition.Enabled = EnableCmd cmdStopAcquisition.Enabled = EnableCmd cmdSingleUpdate.Enabled = EnableCmd cmdClearData.Enabled = EnableCmd '---- MCA Spectrum File ------------------------- cmdSaveSpectrum.Enabled = EnableCmd '---- Digital Oscilloscope ---------------------- cmdArmTrigger.Enabled = EnableCmd '---- DPP Diagnostic Data ----------------------- cmdDiagnostics.Enabled = EnableCmd '---- 512-Byte Miscellaneous Data Block --------- cmdReadMiscData.Enabled = EnableCmd cmdWriteMiscData.Enabled = EnableCmd cmdClearMiscData.Enabled = EnableCmd s.isDppConnected = EnableCmd End Sub Private Function CountDP5WinusbDevices2() As Integer Dim hKey As Integer Dim retCode As Integer Dim lRet As Integer Dim idxDP5 As Integer Dim DevicePath(MAXREGBUFFER - 1) As Byte Dim cbDevicePath As Integer Dim KeyName As String = "" Dim cbKeyName As Integer Dim ErrMsg As String Dim cbErrMsg As Integer Dim strDevicePath As String = "" Dim strMsg As String = "" Dim strValueName As String = "" Dim iRemNulls As Integer = 0 Dim strTest As String = "" TextBox1.Text = "" NumUSBDevices = 0 CountDP5WinusbDevices2 = 0 retCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WinUSBService, 0, KEY_QUERY_VALUE, hKey) If (retCode <> ERROR_SUCCESS) Then CountDP5WinusbDevices2 = 0 Exit Function End If KeyName = Space(MAX_PATH) ' Test ALL Keys (0,1,... are device paths, Count,NextInstance,(Default) have other info) For idxDP5 = 0 To (MAXDP5S + 3) - 1 'devs + 3 other keys cbKeyName = MAX_PATH cbDevicePath = MAXREGBUFFER retCode = RegEnumValue(hKey, idxDP5, KeyName, cbKeyName, 0, REG_NONE, DevicePath(0), cbDevicePath) If (retCode = ERROR_SUCCESS) Then strValueName = Trim(KeyName) strDevicePath = ByteArrayToString(DevicePath) If (Len(strValueName) = 0) Then 'do nothing ElseIf (StrComp(VB.Left(KeyName, 5), "Count", CompareMethod.Text) = 0) Then 'do nothing ElseIf (StrComp(VB.Left(KeyName, 12), "NextInstance", CompareMethod.Text) = 0) Then 'do nothing ElseIf (StrComp(VB.Left(strDevicePath, WinUsbDP5Size), WinUsbDP5, CompareMethod.Text) = 0) Then ' DP5 device path found iRemNulls = InStr(strValueName, Chr(0)) If (iRemNulls > 0) Then strValueName = VB.Left(strValueName, iRemNulls - 1) End If strMsg = strMsg & "KeyName " & strValueName & " " iRemNulls = InStr(strDevicePath, Chr(0)) If (iRemNulls > 0) Then strDevicePath = VB.Left(strDevicePath, iRemNulls - 1) End If strMsg = strMsg & strDevicePath & vbNewLine 'TRACE("DP5 device [%d]: %s=%s\r\n", (NumUSBDevices + 1), KeyName, DevicePath); NumUSBDevices = NumUSBDevices + 1 End If ElseIf (retCode = ERROR_NO_MORE_ITEMS) Then ' no more values to read strMsg = strMsg & CStr(idxDP5) & " : " & CStr((MAXDP5S + 3) - 1) & " ERROR_NO_MORE_ITEMS" & vbNewLine Exit For Else ' error reading values cbErrMsg = MAXERRBUFFER ErrMsg = Space(MAXERRBUFFER) lRet = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0, retCode, 0, ErrMsg, cbErrMsg, 0) If (lRet > 0) Then ErrMsg = VB.Left(ErrMsg, lRet) Else ErrMsg = "" strMsg = strMsg & "ErrMsg " & ErrMsg & vbNewLine Exit For End If Next RegCloseKey(hKey) TextBox1.Text = strMsg & "NumUSBDevices " & NumUSBDevices & vbNewLine CountDP5WinusbDevices2 = NumUSBDevices '/* return number of devices */ End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click CountDP5WinusbDevices2() End Sub End Class