Amptek Visual Basic Demonstration Application for DPP Devices Project

Amptek Visual Basic Demonstration Application for DPP Devices

This example demonstrates communications to Amptek devices using the WinUSB, Sockets and Serial Ports.

Copyright 2012-2017 Amptek Inc.

***********************************************************************
Software License Agreement

Licensor grants any person obtaining a copy of this software ("You") a worldwide, royalty-free, non-exclusive license, for the duration of the copyright, free of charge, to store and execute the Software in a computer system and to incorporate the Software or any portion of it in computer programs You write.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
***********************************************************************


References

FileName | Version | Description
VBA5.dll | 5.0 | Visual Basic For Applications
WINDOWS\system32\msvbvm50.dll\2 | 5.0 | Visual Basic runtime objects and procedures
VB5.OLB | 5.0 | Visual Basic objects and procedures
stdole2.tlb | 2.0 | OLE Automation
MSCOMM32.oca | 1.1 | Microsoft Comm Control 6.0
COMDLG32.oca | 1.2 | Microsoft Common Dialog Control 6.0 (SP6)
comctl32.oca | 1.3 | Microsoft Windows Common Controls 5.0 (SP2)
TABCTL32.oca | 1.1 | Microsoft Tabbed Dialog Control 6.0
RICHTX32.oca | 1.2 | Microsoft Rich Textbox Control 6.0 (SP6)
MSWINSCK.oca | 1.0 | Microsoft Winsock Control 6.0 (SP5)
comct232.oca | 1.1 | Microsoft Windows Common Controls-2 5.0 (SP2)


clsDppConfig Module

clsDppConfig Object


AccumulationTime Property

Public Property AccumulationTime

real time duration of present data acquisition interval

Type

A Double Value. The property is Read-Write

Syntax

Object.AccumulationTime [ = Double ]

The AccumulationTime Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Double | A Double Value. The property is Read-Write.


AcqMode Property

Public Property AcqMode

acquisition mode 0=MCA,1=MCS

Type

A Byte Value. The property is Read-Write

Syntax

Object.AcqMode [ = Byte ]

The AcqMode Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


AnalogOut Property

Public Property AnalogOut

dac enabled and DAC output type,(stobed peak,shaped pulse,dec inp,fast ch)

Type

A Byte Value. The property is Read-Write

Syntax

Object.AnalogOut [ = Byte ]

The AnalogOut Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


AudibleCounter Property

Public Property AudibleCounter

audio volume setting End Type

Type

A Byte Value. The property is Read-Write

Syntax

Object.AudibleCounter [ = Byte ]

The AudibleCounter Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


AuxOut Property

Public Property AuxOut

Aux output type

Type

A Byte Value. The property is Read-Write

Syntax

Object.AuxOut [ = Byte ]

The AuxOut Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


BaselineOn Property

Public Property BaselineOn

use autobaseline during detector reset

Type

A Byte Value. The property is Read-Write

Syntax

Object.BaselineOn [ = Byte ]

The BaselineOn Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


BLR Property

Public Property BLR

Baseline Restoration, see udBLR.Value notes for values

Type

A Byte Value. The property is Read-Write

Syntax

Object.BLR [ = Byte ]

The BLR Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


BoardTemp Property

Public Property BoardTemp

board temperature monitor value

Type

A Double Value. The property is Read-Write

Syntax

Object.BoardTemp [ = Double ]

The BoardTemp Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Double | A Double Value. The property is Read-Write.


BootStatus Property

Public Property BootStatus

boot status byte (PwrBtnConfig,SwConfigRcvd,McaEnabled)

Type

A Byte Value. The property is Read-Write

Syntax

Object.BootStatus [ = Byte ]

The BootStatus Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


bSpectrumCfg Property

Public Property bSpectrumCfg

create dpp mca file config

Type

A Boolean Value. The property is Read-Write

Syntax

Object.bSpectrumCfg [ = Boolean ]

The bSpectrumCfg Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Boolean | A Boolean Value. The property is Read-Write.


BufferSelect Property

Public Property BufferSelect

Holds Buffer Sel A&B,Buffer Sel Hardware,see DPPBufferSelect

Type

A Byte Value. The property is Read-Write

Syntax

Object.BufferSelect [ = Byte ]

The BufferSelect Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


CfgReadBack Property

Public Property CfgReadBack

load dpp config into config editor

Type

A Boolean Value. The property is Read-Write

Syntax

Object.CfgReadBack [ = Boolean ]

The CfgReadBack Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Boolean | A Boolean Value. The property is Read-Write.


CoarseGain Property

Public Property CoarseGain

stores current coarse gain value

Type

A Byte Value. The property is Read-Write

Syntax

Object.CoarseGain [ = Byte ]

The CoarseGain Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


Decimation Property

Public Property Decimation

decimation setting for pulse shaping

Type

A Byte Value. The property is Read-Write

Syntax

Object.Decimation [ = Byte ]

The Decimation Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


DetReset Property

Public Property DetReset

detector reset lockout period

Type

A Byte Value. The property is Read-Write

Syntax

Object.DetReset [ = Byte ]

The DetReset Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


DisplayCfg Property

Public Property DisplayCfg

show dpp config in msgbox dialog

Type

A Boolean Value. The property is Read-Write

Syntax

Object.DisplayCfg [ = Boolean ]

The DisplayCfg Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Boolean | A Boolean Value. The property is Read-Write.


DisplaySCA Property

Public Property DisplaySCA

parse/load sca settings into SCA controls

Type

A Boolean Value. The property is Read-Write

Syntax

Object.DisplaySCA [ = Boolean ]

The DisplaySCA Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Boolean | A Boolean Value. The property is Read-Write.


FastCount Property

Public Property FastCount

fast channel count

Type

A Double Value. The property is Read-Write

Syntax

Object.FastCount [ = Double ]

The FastCount Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Double | A Double Value. The property is Read-Write.


FastThreshold Property

Public Property FastThreshold

Fast Ch Threshold, events w/fch amp below this are rejected

Type

A Byte Value. The property is Read-Write

Syntax

Object.FastThreshold [ = Byte ]

The FastThreshold Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


FineGain Property

Public Property FineGain

stores current fine gain value

Type

A Long Value. The property is Read-Write

Syntax

Object.FineGain [ = Long ]

The FineGain Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Long | A Long Value. The property is Read-Write.


Firmware Property

Public Property Firmware

firmware revision

Type

A Double Value. The property is Read-Write

Syntax

Object.Firmware [ = Double ]

The Firmware Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Double | A Double Value. The property is Read-Write.


FlatTop Property

Public Property FlatTop

flatop register setting

Type

A Byte Value. The property is Read-Write

Syntax

Object.FlatTop [ = Byte ]

The FlatTop Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


FPGA Property

Public Property FPGA

FPGA

Type

A Double Value. The property is Read-Write

Syntax

Object.FPGA [ = Double ]

The FPGA Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Double | A Double Value. The property is Read-Write.


HV Property

Public Property HV

high voltage setting value

Type

A Long Value. The property is Read-Write

Syntax

Object.HV [ = Long ]

The HV Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Long | A Long Value. The property is Read-Write.


HVEnabled Property

Public Property HVEnabled

high voltage setting enable

Type

A Byte Value. The property is Read-Write

Syntax

Object.HVEnabled [ = Byte ]

The HVEnabled Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


HVMonitor Property

Public Property HVMonitor

high voltage monitor value

Type

A Double Value. The property is Read-Write

Syntax

Object.HVMonitor [ = Double ]

The HVMonitor Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Double | A Double Value. The property is Read-Write.


InputOffset Property

Public Property InputOffset

input offset

Type

A Long Value. The property is Read-Write

Syntax

Object.InputOffset [ = Long ]

The InputOffset Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Long | A Long Value. The property is Read-Write.


InputPolarity Property

Public Property InputPolarity

use InvertEnable during detector reset

Type

A Byte Value. The property is Read-Write

Syntax

Object.InputPolarity [ = Byte ]

The InputPolarity Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


MCAChannels Property

Public Property MCAChannels

number of channels 0=256,1=512,2=1024,3=2048,4=4096,5=8192

Type

A Byte Value. The property is Read-Write

Syntax

Object.MCAChannels [ = Byte ]

The MCAChannels Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


MCSDone Property

Public Property MCSDone

MCS done flag 1=finished, 0=not finished

Type

A Byte Value. The property is Read-Write

Syntax

Object.MCSDone [ = Byte ]

The MCSDone Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


MCSTimebase Property

Public Property MCSTimebase

MCS timebase value (0-15) see CAcqMode

Type

A Byte Value. The property is Read-Write

Syntax

Object.MCSTimebase [ = Byte ]

The MCSTimebase Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


OutputOffset Property

Public Property OutputOffset

Output DAC offset, -64…+63,(signed)(D7-D1) (-500mV to +492mV)

Type

A Byte Value. The property is Read-Write

Syntax

Object.OutputOffset [ = Byte ]

The OutputOffset Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


PoleZero Property

Public Property PoleZero

pole zero adjust value

Type

A Long Value. The property is Read-Write

Syntax

Object.PoleZero [ = Long ]

The PoleZero Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Long | A Long Value. The property is Read-Write.


PreampPower Property

Public Property PreampPower

preamp power select value (5v or 8.5v)

Type

A Byte Value. The property is Read-Write

Syntax

Object.PreampPower [ = Byte ]

The PreampPower Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


PresetCount Property

Public Property PresetCount

preset count in selected channels, ch are set in SCA8 Public SCA(0 To 7) As Long ' SCA values, LL, UL, and Enable are stored together

Type

A Long Value. The property is Read-Write

Syntax

Object.PresetCount [ = Long ]

The PresetCount Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Long | A Long Value. The property is Read-Write.


PresetCountExpired Property

Public Property PresetCountExpired

indicates presets counts have been reached

Type

A Byte Value. The property is Read-Write

Syntax

Object.PresetCountExpired [ = Byte ]

The PresetCountExpired Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


PresetTime Property

Public Property PresetTime

var holds preset time, used in usb

Type

A Long Value. The property is Read-Write

Syntax

Object.PresetTime [ = Long ]

The PresetTime Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Long | A Long Value. The property is Read-Write.


PUREnable Property

Public Property PUREnable

pile-up rejection enabled

Type

A Byte Value. The property is Read-Write

Syntax

Object.PUREnable [ = Byte ]

The PUREnable Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


PwrBtnConfig Property

Public Property PwrBtnConfig

dpp has loaded config from power button

Type

A Byte Value. The property is Read-Write

Syntax

Object.PwrBtnConfig [ = Byte ]

The PwrBtnConfig Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


RTDFast Property

Public Property RTDFast

RTD Time Threshold,Events w/HWHM wider than this are rejected

Type

A Byte Value. The property is Read-Write

Syntax

Object.RTDFast [ = Byte ]

The RTDFast Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


RTDOn Property

Public Property RTDOn

Turns RTD on, and sets the amplitude and timing thresholds

Type

A Byte Value. The property is Read-Write

Syntax

Object.RTDOn [ = Byte ]

The RTDOn Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


RTDSlow Property

Public Property RTDSlow

Risetime Discrimination slow threshold

Type

A Byte Value. The property is Read-Write

Syntax

Object.RTDSlow [ = Byte ]

The RTDSlow Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


ScaReadBack Property

Public Property ScaReadBack

parse/load sca settings into SCA controls

Type

A Boolean Value. The property is Read-Write

Syntax

Object.ScaReadBack [ = Boolean ]

The ScaReadBack Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Boolean | A Boolean Value. The property is Read-Write.


ScaReadReady Property

Public Property ScaReadReady

sca readback ready

Type

A Boolean Value. The property is Read-Write

Syntax

Object.ScaReadReady [ = Boolean ]

The ScaReadReady Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Boolean | A Boolean Value. The property is Read-Write.


SerialNumber Property

Public Property SerialNumber

unit serial number

Type

A Double Value. The property is Read-Write

Syntax

Object.SerialNumber [ = Double ]

The SerialNumber Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Double | A Double Value. The property is Read-Write.


SetFastThreshDone Property

Public Property SetFastThreshDone

DPP tune fast thresh has successfully done

Type

A Byte Value. The property is Read-Write

Syntax

Object.SetFastThreshDone [ = Byte ]

The SetFastThreshDone Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


SetInputOffsetDone Property

Public Property SetInputOffsetDone

DPP tune input offset has successfully done

Type

A Byte Value. The property is Read-Write

Syntax

Object.SetInputOffsetDone [ = Byte ]

The SetInputOffsetDone Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


SetSlowThreshDone Property

Public Property SetSlowThreshDone

DPP tune slow thresh has successfully done

Type

A Byte Value. The property is Read-Write

Syntax

Object.SetSlowThreshDone [ = Byte ]

The SetSlowThreshDone Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


SlowCount Property

Public Property SlowCount

slow channel count

Type

A Double Value. The property is Read-Write

Syntax

Object.SlowCount [ = Double ]

The SlowCount Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Double | A Double Value. The property is Read-Write.


SlowThreshold Property

Public Property SlowThreshold

Slow ch threshold, Events w/amp lower not added to spectrum

Type

A Byte Value. The property is Read-Write

Syntax

Object.SlowThreshold [ = Byte ]

The SlowThreshold Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


StatDevInd Property

Public Property StatDevInd

device indicator from status block (0=dp4,1=px4)

Type

A Byte Value. The property is Read-Write

Syntax

Object.StatDevInd [ = Byte ]

The StatDevInd Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


StatMcaEnabled Property

Public Property StatMcaEnabled

mca enabled status, high during acq, preset time resets flag

Type

A Byte Value. The property is Read-Write

Syntax

Object.StatMcaEnabled [ = Byte ]

The StatMcaEnabled Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


SwConfigRcvd Property

Public Property SwConfigRcvd

software has sent valid config to unit since startup

Type

A Byte Value. The property is Read-Write

Syntax

Object.SwConfigRcvd [ = Byte ]

The SwConfigRcvd Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


TEC Property

Public Property TEC

TEC temperature setting (displayed in Kelvin)

Type

A Long Value. The property is Read-Write

Syntax

Object.TEC [ = Long ]

The TEC Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Long | A Long Value. The property is Read-Write.


TECMonitor Property

Public Property TECMonitor

TEC temperature monitor value (displayed in Kelvin)

Type

A Double Value. The property is Read-Write

Syntax

Object.TECMonitor [ = Double ]

The TECMonitor Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Double | A Double Value. The property is Read-Write.


TimeToPeak Property

Public Property TimeToPeak

TimeToPeak register setting

Type

A Byte Value. The property is Read-Write

Syntax

Object.TimeToPeak [ = Byte ]

The TimeToPeak Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


TTLGate Property

Public Property TTLGate

gate input settings, determines events included/excluded from spectrum, see DPPGate

Type

A Byte Value. The property is Read-Write

Syntax

Object.TTLGate [ = Byte ]

The TTLGate Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsDppConfig.
Byte | A Byte Value. The property is Read-Write.


clsProfile Module

clsProfile Object


SendCoarseFineGain Property

Public Property SendCoarseFineGain

Type

A Boolean Value. The property is Read-Write

Syntax

Object.SendCoarseFineGain [ = Boolean ]

The SendCoarseFineGain Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type clsProfile.
Boolean | A Boolean Value. The property is Read-Write.


CSCommon Module

CSCommon Object


ComPort Property

Public Property ComPort

Serial Port Settings

Type

A Long Value. The property is Read-Write

Syntax

Object.ComPort [ = Long ]

The ComPort Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Long | A Long Value. The property is Read-Write.


cstrRawCfgIn Property

Public Property cstrRawCfgIn

Type

A String Value. The property is Read-Write

Syntax

Object.cstrRawCfgIn [ = String ]

The cstrRawCfgIn Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
String | A String Value. The property is Read-Write.


cstrRawScaCfgIn Property

Public Property cstrRawScaCfgIn

Type

A String Value. The property is Read-Write

Syntax

Object.cstrRawScaCfgIn [ = String ]

The cstrRawScaCfgIn Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
String | A String Value. The property is Read-Write.


cstrSockAddr Property

Public Property cstrSockAddr

Type

A String Value. The property is Read-Write

Syntax

Object.cstrSockAddr [ = String ]

The cstrSockAddr Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
String | A String Value. The property is Read-Write.


CurrentInterface Property

Public Property CurrentInterface

selected communications interface (0=RS232/1=USB/2=ETHERNET)

Type

A Byte Value. The property is Read-Write

Syntax

Object.CurrentInterface [ = Byte ]

The CurrentInterface Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Byte | A Byte Value. The property is Read-Write.


Dp5CmdList Property

Public Property Dp5CmdList

Type

A New Collection Object. The property is Read-Write

Syntax

[Set] Object.Dp5CmdList [ = New Collection ]

The Dp5CmdList Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
New Collection | A New Collection Object. The property is Read-Write.


DppConfig Property

Public Property DppConfig

Type

A New clsDppConfig Object. The property is Read-Write

Syntax

[Set] Object.DppConfig [ = New clsDppConfig ]

The DppConfig Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
New clsDppConfig | A New clsDppConfig Object. The property is Read-Write.


HwCfgDP5 Property

Public Property HwCfgDP5

Type

A String Value. The property is Read-Write

Syntax

Object.HwCfgDP5 [ = String ]

The HwCfgDP5 Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
String | A String Value. The property is Read-Write.


HwCfgDP5Out Property

Public Property HwCfgDP5Out

Type

A String Value. The property is Read-Write

Syntax

Object.HwCfgDP5Out [ = String ]

The HwCfgDP5Out Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
String | A String Value. The property is Read-Write.


HwCfgExReady Property

Public Property HwCfgExReady

Type

A Boolean Value. The property is Read-Write

Syntax

Object.HwCfgExReady [ = Boolean ]

The HwCfgExReady Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Boolean | A Boolean Value. The property is Read-Write.


HwCfgReady Property

Public Property HwCfgReady

Type

A Boolean Value. The property is Read-Write

Syntax

Object.HwCfgReady [ = Boolean ]

The HwCfgReady Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Boolean | A Boolean Value. The property is Read-Write.


HwRdBkDP5Out Property

Public Property HwRdBkDP5Out

Type

A String Value. The property is Read-Write

Syntax

Object.HwRdBkDP5Out [ = String ]

The HwRdBkDP5Out Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
String | A String Value. The property is Read-Write.


HwScaCfgDP5 Property

Public Property HwScaCfgDP5

Type

A String Value. The property is Read-Write

Syntax

Object.HwScaCfgDP5 [ = String ]

The HwScaCfgDP5 Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
String | A String Value. The property is Read-Write.


HwScaCfgReady Property

Public Property HwScaCfgReady

Type

A Boolean Value. The property is Read-Write

Syntax

Object.HwScaCfgReady [ = Boolean ]

The HwScaCfgReady Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Boolean | A Boolean Value. The property is Read-Write.


InetPort Property

Public Property InetPort

Type

A Long Value. The property is Read-Write

Syntax

Object.InetPort [ = Long ]

The InetPort Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Long | A Long Value. The property is Read-Write.


isDppConnected Property

Public Property isDppConnected

CurrentInterface selected and device found

Type

A Boolean Value. The property is Read-Write

Syntax

Object.isDppConnected [ = Boolean ]

The isDppConnected Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Boolean | A Boolean Value. The property is Read-Write.


NetfinderActive Property

Public Property NetfinderActive

Type

A Boolean Value. The property is Read-Write

Syntax

Object.NetfinderActive [ = Boolean ]

The NetfinderActive Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Boolean | A Boolean Value. The property is Read-Write.


profile Property

Public Property profile

Type

A New clsProfile Object. The property is Read-Write

Syntax

[Set] Object.profile [ = New clsProfile ]

The profile Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
New clsProfile | A New clsProfile Object. The property is Read-Write.


SCAEnabled Property

Public Property SCAEnabled

Type

A Boolean Value. The property is Read-Write

Syntax

Object.SCAEnabled [ = Boolean ]

The SCAEnabled Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Boolean | A Boolean Value. The property is Read-Write.


SockAddr Property

Public Property SockAddr

Type

A Long Value. The property is Read-Write

Syntax

Object.SockAddr [ = Long ]

The SockAddr Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type CSCommon.
Long | A Long Value. The property is Read-Write.


modControls Module


modControls Consts

Consts

Scope | Name | Type | Value | Description
Private | cmdArrowWidth | Long | 285 |
Public | colorAmptekBlue | Long | &HFCCE7A |
Public | colorBlue | Long | &HFF0000 |
Public | colorGreen | String | &H8000& |
Public | colorLightGray | Long | &HD3D3D3 |
Public | colorLightSlateGray | Long | &H998877 |
Public | colorLightSteelBlue | Long | &HDEC4B0 |
Public | colorRed | String | &HFF& |
Public | colorSilver | Long | &HC0C0C0 |
Public | colorWhite | Long | &HFFFFFF |
Public | colorYellow | String | &HFFFF& |
Public | dlgCFG_Filter | String | "Amptek Config File (*.cfg)|*.cfg|All Files (*.*)|*.*" |
Public | dlgCSV_Filter | String | "Comma Separated Value (*.csv)|*.csv|All Files (*.*)|*.*" |
Public | dlgMCA_Filter | String | "Amptek Spectrum File (*.mca)|*.mca|All Files (*.*)|*.*" |
Public | dlgTXT_Filter | String | "Text File (*.txt)|*.txt|All Files (*.*)|*.*" |
Public | dlgXL_Filter | String | "Excel Files (*.xls)|*.xls|All Files (*.*)|*.*" |
Private | GWL_EXSTYLE | String | (-20) |
Private | GWL_STYLE | String | (-16) |
Private | WS_EX_RIGHT | Long | &H1000 | Alignment use extended sytle


GetWindowLong Method

Private Declaration GetWindowLong

Library

user32

Alias

GetWindowLongA

Type Return

A Long Value

Syntax

GetWindowLong ( hwnd, nIndex)

The GetWindowLong Declaration syntax has these parts:

Part | Description
hwnd | Required. A Long Value.
nIndex | Required. A Long Value.


SetWindowLong Method

Private Declaration SetWindowLong

Library

user32

Alias

SetWindowLongA

Type Return

A Long Value

Syntax

SetWindowLong ( hwnd, nIndex, dwNewLong)

The SetWindowLong Declaration syntax has these parts:

Part | Description
hwnd | Required. A Long Value.
nIndex | Required. A Long Value.
dwNewLong | Required. A Long Value.


AlignTextBoxToComboBox Method

Public Method AlignTextBoxToComboBox

Type Return

None

Syntax

Object.AlignTextBoxToComboBox Combo1, Text1

The AlignTextBoxToComboBox Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modControls.
Combo1 | Required. A ComboBox Object.
Text1 | Required. A TextBox Object.


ClickTxtComboGroup Method

Public Method ClickTxtComboGroup

Type Return

A Boolean Value

Syntax

Object.ClickTxtComboGroup ( Combo1, Text1)

The ClickTxtComboGroup Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modControls.
Combo1 | Required. A ComboBox Object.
Text1 | Required. A TextBox Object.


dlgOpen Method

Public Method dlgOpen

Type Return

A Boolean Value

Syntax

Object.dlgOpen ( CmnDlgFIO, strFileFilters)

The dlgOpen Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modControls.
CmnDlgFIO | Required. A CommonDialog Object.
strFileFilters | Required. A String Value.


dlgSave Method

Public Method dlgSave

Type Return

A Boolean Value

Syntax

Object.dlgSave ( CmnDlgFIO, strFileFilters)

The dlgSave Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modControls.
CmnDlgFIO | Required. A Object Object.
strFileFilters | Required. A String Value.


GetDefaultFileWildcard Method

Private Method GetDefaultFileWildcard

Type Return

A String Value

Syntax

Object.GetDefaultFileWildcard ( strFilter)

The GetDefaultFileWildcard Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modControls.
strFilter | Required. A String Value.


SaveLastDir Method

Public Method SaveLastDir

Type Return

None

Syntax

Object.SaveLastDir CmnDlgFIO

The SaveLastDir Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modControls.
CmnDlgFIO | Required. A CommonDialog Object.


SetComboRight Method

Public Method SetComboRight

Type Return

None

Syntax

Object.SetComboRight frm

The SetComboRight Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modControls.
frm | Required. A Form Object.


SetStyle Method

Public Method SetStyle

Type Return

None

Syntax

Object.SetStyle lHWnd, lStyleFlags, bState, [bExtended]

The SetStyle Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modControls.
lHWnd | Required. A Long Value.
lStyleFlags | Required. A Long Value.
bState | Required. A Boolean Value.
bExtended | Optional. A Boolean = False Object.


modDP5CfgControls Module


modDP5CfgControls Consts

Consts

Scope | Name | Type | Value | Description
Private | CB_FINDSTRINGEXACT | Long | &H158 |
Private | CB_FINDSTRING | Long | &H14C |
Private | HasComboCtrl | Long | &H1 |
Private | HasTextCtrl | Long | &H2 |
Public | LastCCI | String | CtrlInfoIndex.ciiMask |
Public | LB_ERR | String | (-1) |
Private | LB_FINDSTRINGEXACT | Long | &H1A2 |
Private | LB_FINDSTRING | Long | &H18F |
Public | strDecValueChars | String | "+-.0123456789" |
Private | WM_USER | Long | &H400 |


SendMessageFind Method

Private Declaration SendMessageFind

Library

user32

Alias

SendMessageA

Type Return

A Long Value

Syntax

SendMessageFind ( hwnd, wMsg, wParam, lParam)

The SendMessageFind Declaration syntax has these parts:

Part | Description
hwnd | Required. A Long Value.
wMsg | Required. A Long Value.
wParam | Required. A Integer Value.
lParam | Required. A String Value.


AddDP5ListCmd Method

Public Method AddDP5ListCmd

Type Return

A Long Value

Syntax

Object.AddDP5ListCmd ( lstDP5Cmds, strCmd, CtrlType)

The AddDP5ListCmd Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
lstDP5Cmds | Required. A ListBox Object.
strCmd | Required. A String Value.
CtrlType | Required. A DP5CmdCtrls Value.


CboTxtCtrlVis Method

Public Method CboTxtCtrlVis

Type Return

None

Syntax

Object.CboTxtCtrlVis frm, strTag, isVisible

The CboTxtCtrlVis Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
strTag | Required. A String Value.
isVisible | Required. A Boolean Value.


DP5CmdCtrlType Method

Public Method DP5CmdCtrlType

Type Return

A Long Value

Syntax

Object.DP5CmdCtrlType ( ctrl)

The DP5CmdCtrlType Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
ctrl | Required. A Control Object.


DP5CmdLblType Method

Public Method DP5CmdLblType

Type Return

A Long Value

Syntax

Object.DP5CmdLblType ( ctrl, strLabel)

The DP5CmdLblType Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
ctrl | Required. A Control Object.
strLabel | Required. A String Value.


DP5UnitsFromData Method

Public Method DP5UnitsFromData

Type Return

A Boolean Value

Syntax

Object.DP5UnitsFromData ( varUnitsArray, strData, strRetData, strUnit)

The DP5UnitsFromData Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
varUnitsArray | Required. A Variant Value.
strData | Required. A String Value.
strRetData | Required. A String Value.
strUnit | Required. A String Value.


FindCboIdxExact Method

Public Method FindCboIdxExact

Type Return

A Long Value

Syntax

Object.FindCboIdxExact ( cboCtrl, strVal)

The FindCboIdxExact Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
cboCtrl | Required. A ComboBox Object.
strVal | Required. A String Value.


FindCboIdx Method

Public Method FindCboIdx

Type Return

A Long Value

Syntax

Object.FindCboIdx ( cboCtrl, strVal)

The FindCboIdx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
cboCtrl | Required. A ComboBox Object.
strVal | Required. A String Value.


FindCboMask Method

Public Method FindCboMask

Type Return

A Long Value

Syntax

Object.FindCboMask ( cboCtrl)

The FindCboMask Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
cboCtrl | Required. A ComboBox Object.


GetCtrlIdxByNameTag Method

Public Method GetCtrlIdxByNameTag

Type Return

A Long Value

Syntax

Object.GetCtrlIdxByNameTag ( frm, strName, strTag)

The GetCtrlIdxByNameTag Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
strName | Required. A String Value.
strTag | Required. A String Value.


GetDP5CmdCtrlInfo Method

Public Method GetDP5CmdCtrlInfo

Type Return

A String Value

Syntax

Object.GetDP5CmdCtrlInfo ( frm, lstDP5Commands, varCmdCtrls, idxCmd)

The GetDP5CmdCtrlInfo Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
lstDP5Commands | Required. A ListBox Object.
varCmdCtrls | Required. A Variant Value.
idxCmd | Required. A Long Value.


GetDP5CmdGroups Method

Public Method GetDP5CmdGroups

Type Return

None

Syntax

Object.GetDP5CmdGroups frm, varCmdCtrls, SSTab1

The GetDP5CmdGroups Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
varCmdCtrls | Required. A Variant Value.
SSTab1 | Required. A SSTab Object.


GetDP5Control Method

Public Method GetDP5Control

Type Return

A Control Object

Syntax

Object.GetDP5Control ( frm, varCmdCtrls, idxCmd, CtrlType, [SetGlobalFind])

The GetDP5Control Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
varCmdCtrls | Required. A Variant Value.
idxCmd | Required. A Long Value.
CtrlType | Required. A DP5CmdCtrls Value.
SetGlobalFind | Optional. A Boolean = False Object.


GetDP5ListCmd Method

Public Method GetDP5ListCmd

Type Return

A Long Value

Syntax

Object.GetDP5ListCmd ( lstDP5Cmds, strCmd)

The GetDP5ListCmd Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
lstDP5Cmds | Required. A ListBox Object.
strCmd | Required. A String Value.


GetSSTabName Method

Public Method GetSSTabName

Type Return

A String Value

Syntax

Object.GetSSTabName ( CmdCtrl, SSTab1)

The GetSSTabName Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
CmdCtrl | Required. A Control Object.
SSTab1 | Required. A SSTab Object.


GetTextBoxIndexByTag Method

Public Method GetTextBoxIndexByTag

Type Return

A Long Value

Syntax

Object.GetTextBoxIndexByTag ( varCmdCtrls, strTag)

The GetTextBoxIndexByTag Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
varCmdCtrls | Required. A Variant Value.
strTag | Required. A String Value.


GetValByCmd Method

Public Method GetValByCmd

Type Return

A Variant Value

Syntax

Object.GetValByCmd ( strCmdIn, varCmdVal)

The GetValByCmd Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
strCmdIn | Required. A String Value.
varCmdVal | Required. A Variant Value.


MakeUnitsArray Method

Public Method MakeUnitsArray

Type Return

A Variant Value

Syntax

Object.MakeUnitsArray ()

The MakeUnitsArray Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.


ReadDP5Settings Method

Public Method ReadDP5Settings

Type Return

None

Syntax

Object.ReadDP5Settings frm, lstDP5Commands, varCmdCtrls, varConfig

The ReadDP5Settings Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
lstDP5Commands | Required. A ListBox Object.
varCmdCtrls | Required. A Variant Value.
varConfig | Required. A Variant Value.


ReadDP5Text Method

Public Method ReadDP5Text

Type Return

None

Syntax

Object.ReadDP5Text frm, lstDP5Commands, varCmdCtrls, varValues

The ReadDP5Text Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
lstDP5Commands | Required. A ListBox Object.
varCmdCtrls | Required. A Variant Value.
varValues | Required. A Variant Value.


SetCboListIdx Method

Public Method SetCboListIdx

Type Return

A Long Value

Syntax

Object.SetCboListIdx ( frm, varCmdCtrls, idxCmd, strVal)

The SetCboListIdx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
varCmdCtrls | Required. A Variant Value.
idxCmd | Required. A Long Value.
strVal | Required. A String Value.


SetCboMaskIdx Method

Public Method SetCboMaskIdx

Type Return

A Long Value

Syntax

Object.SetCboMaskIdx ( frm, varCmdCtrls, idxCmd)

The SetCboMaskIdx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
varCmdCtrls | Required. A Variant Value.
idxCmd | Required. A Long Value.


SetupCmdCtrls Method

Public Method SetupCmdCtrls

Type Return

A Variant Value

Syntax

Object.SetupCmdCtrls ( frm, lstDP5Commands)

The SetupCmdCtrls Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
lstDP5Commands | Required. A ListBox Object.


SetupStartupCboTxt Method

Public Method SetupStartupCboTxt

Type Return

None

Syntax

Object.SetupStartupCboTxt frm, varCmdCtrls

The SetupStartupCboTxt Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
varCmdCtrls | Required. A Variant Value.


UnPressButtons Method

Public Method UnPressButtons

Type Return

None

Syntax

Object.UnPressButtons Toolbar1

The UnPressButtons Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
Toolbar1 | Required. A ComctlLib.Toolbar Object.


UpdateDP5Ctrls Method

Public Method UpdateDP5Ctrls

Type Return

None

Syntax

Object.UpdateDP5Ctrls frm, lstDP5Commands, varCmdCtrls, varConfig, varUnitsArray

The UpdateDP5Ctrls Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
lstDP5Commands | Required. A ListBox Object.
varCmdCtrls | Required. A Variant Value.
varConfig | Required. A Variant Value.
varUnitsArray | Required. A Variant Value.


UpdateDP5TextCtrls Method

Public Method UpdateDP5TextCtrls

Type Return

None

Syntax

Object.UpdateDP5TextCtrls frm, lstDP5Commands, varCmdCtrls, varValues, varUnitsArray

The UpdateDP5TextCtrls Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
frm | Required. A Form Object.
lstDP5Commands | Required. A ListBox Object.
varCmdCtrls | Required. A Variant Value.
varValues | Required. A Variant Value.
varUnitsArray | Required. A Variant Value.


LoadingCfg Property

Public Property LoadingCfg

Type

A Boolean Value. The property is Read-Write

Syntax

Object.LoadingCfg [ = Boolean ]

The LoadingCfg Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
Boolean | A Boolean Value. The property is Read-Write.


strFindCtrl Property

Public Property strFindCtrl

Type

A String Value. The property is Read-Write

Syntax

Object.strFindCtrl [ = String ]

The strFindCtrl Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
String | A String Value. The property is Read-Write.


strFindIdx Property

Public Property strFindIdx

Type

A String Value. The property is Read-Write

Syntax

Object.strFindIdx [ = String ]

The strFindIdx Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
String | A String Value. The property is Read-Write.


strFindTab Property

Public Property strFindTab

Type

A String Value. The property is Read-Write

Syntax

Object.strFindTab [ = String ]

The strFindTab Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5CfgControls.
String | A String Value. The property is Read-Write.


CompareMethod Enumeration

Public CompareMethod enumeration

Members

Name | Value | Description
Binary | 0 |
Text | 1 |
Database | 2 |


CtrlInfoIndex Enumeration

Public CtrlInfoIndex enumeration

Members

Name | Value | Description
ciiTag | 0 |
ciiText | 1 |
ciiNameLC | 2 |
ciiIndexLC | 3 |
ciiNameTC | 4 |
ciiIndexTC | 5 |
ciiCtrlType | 6 |
ciiCtrlGroup | 7 |
ciiLblDescription | 8 |
ciiLblLimits | 9 |
ciiLblUnits | 10 |
ciiUnits | 11 |
ciiSendCmd | 12 |
ciiMask | 13 |


DP5CmdCtrls Enumeration

Public DP5CmdCtrls enumeration

Members

Name | Value | Description
ccsNone | 0 |
ccsCbo | 1 |
ccsTxt | 2 |
ccsCboTxt | 3 |


DP5CmdLbls Enumeration

Public DP5CmdLbls enumeration

Members

Name | Value | Description
clsNone | 0 |
clsDescription | 1 |
clsLimit | 2 |
clsUnit | 3 |


Public HwConfigType udt

Members

Name | Type | Description
Command | String |
Value | String |
Comment | String |


modDP5Configuration Module


AppendCmdDesc Method

Public Method AppendCmdDesc

Type Return

A String Value

Syntax

Object.AppendCmdDesc ( cstrCmd, cstrCfgData)

The AppendCmdDesc Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
cstrCmd | Required. A String Value.
cstrCfgData | Required. A String Value.


CreateFullReadBackCmdMCA8000D Method

Public Method CreateFullReadBackCmdMCA8000D

Type Return

A String Value

Syntax

Object.CreateFullReadBackCmdMCA8000D ()

The CreateFullReadBackCmdMCA8000D Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.


CreateFullReadBackCmd Method

Public Method CreateFullReadBackCmd

Type Return

A String Value

Syntax

Object.CreateFullReadBackCmd ()

The CreateFullReadBackCmd Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.


CreateResTestReadBackCmd Method

Public Method CreateResTestReadBackCmd

Type Return

A String Value

Syntax

Object.CreateResTestReadBackCmd ( bSendCoarseFineGain)

The CreateResTestReadBackCmd Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
bSendCoarseFineGain | Required. A Boolean Value.


GetCmdChunk Method

Public Method GetCmdChunk

Type Return

A Long Value

Syntax

Object.GetCmdChunk ( strCmd)

The GetCmdChunk Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
strCmd | Required. A String Value.


GetCmdData Method

Public Method GetCmdData

Type Return

A String Value

Syntax

Object.GetCmdData ( cstrCmd, cstrCfgData)

The GetCmdData Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
cstrCmd | Required. A String Value.
cstrCfgData | Required. A String Value.


GetCmdDesc Method

Public Method GetCmdDesc

Type Return

A String Value

Syntax

Object.GetCmdDesc ( strCmd)

The GetCmdDesc Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
strCmd | Required. A String Value.


MakeDp5CmdListMCA8000D Method

Public Method MakeDp5CmdListMCA8000D

Type Return

None

Syntax

Object.MakeDp5CmdListMCA8000D strCfgArr

The MakeDp5CmdListMCA8000D Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
strCfgArr | Required. A Collection Object.


MakeDp5CmdList Method

Public Method MakeDp5CmdList

Type Return

None

Syntax

Object.MakeDp5CmdList strCfgArr

The MakeDp5CmdList Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
strCfgArr | Required. A Collection Object.


RemoveCmdByDeviceType Method

Public Method RemoveCmdByDeviceType

Type Return

A String Value

Syntax

Object.RemoveCmdByDeviceType ( strCfgDataIn, PC5_PRESENT, DppType, isDP5_RevDxGains, DPP_ECO)

The RemoveCmdByDeviceType Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
strCfgDataIn | Required. A String Value.
PC5_PRESENT | Required. A Boolean Value.
DppType | Required. A Byte Value.
isDP5_RevDxGains | Required. A Boolean Value.
DPP_ECO | Required. A Byte Value.


RemoveCmd Method

Public Method RemoveCmd

Type Return

A String Value

Syntax

Object.RemoveCmd ( cstrCmd, cstrCfgData)

The RemoveCmd Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
cstrCmd | Required. A String Value.
cstrCfgData | Required. A String Value.


Remove_MCA8000D_Cmds Method

Public Method Remove_MCA8000D_Cmds

Type Return

A String Value

Syntax

Object.Remove_MCA8000D_Cmds ( strCfgDataIn, DppType)

The Remove_MCA8000D_Cmds Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
strCfgDataIn | Required. A String Value.
DppType | Required. A Byte Value.


ReplaceCmdDesc Method

Public Method ReplaceCmdDesc

Type Return

A String Value

Syntax

Object.ReplaceCmdDesc ( cstrCmd, cstrCfgData)

The ReplaceCmdDesc Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
cstrCmd | Required. A String Value.
cstrCfgData | Required. A String Value.


ReplaceText Method

Public Method ReplaceText

Type Return

A String Value

Syntax

Object.ReplaceText ( strInTextIn, strFrom, strTo)

The ReplaceText Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
strInTextIn | Required. A String Value.
strFrom | Required. A String Value.
strTo | Required. A String Value.


s Property

Public Property s

Type

A New CSCommon Object. The property is Read-Write

Syntax

[Set] Object.s [ = New CSCommon ]

The s Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5Configuration.
New CSCommon | A New CSCommon Object. The property is Read-Write.


modDP5_Protocol Module


modDP5_Protocol Consts

Consts

Scope | Name | Type | Value | Description
Public | ACK | Long | 0 |
Public | ETHERNET_KEEPALIVE | Long | 1500 | send a keep-alive after 1.5s of interface inactivity
Public | ETHERNET | Long | 2 |
Public | ETHERNET_TIMEOUT | Long | 1000 | default timeout of 1000mS
Public | INTERNET_TIMEOUT | Long | 3000 | 3 seconds if DP5 is on different subnet than this PC
Public | Retries | Long | 2 | total of 3 attempts
Public | RS232 | Long | 0 |
Public | RS232_TIMEOUT | Long | 2500 | default timeout of 2500mS (8K spectrum ~2.2s)
Public | SYNC1_ | Long | &HF5 |
Public | SYNC2_ | Long | &HFA |
Public | USB | Long | 1 |
Public | USB_TIMEOUT | Long | 500 | default timeout of 500mS


timeGetTime Method

Public Declaration timeGetTime

timeGetTimeVB

Library

winmm.dll

Type Return

A Long Value

Syntax

timeGetTime ()

The timeGetTime Declaration syntax has these parts:

Part Description


msDelay Method

Public Method msDelay

Type Return

A Boolean Value

Syntax

Object.msDelay ( MSec)

The msDelay Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
MSec | Required. A Long Value.


msTimeDiff Method

Public Method msTimeDiff

Type Return

A Currency Value

Syntax

Object.msTimeDiff ( curStartTime)

The msTimeDiff Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
curStartTime | Required. A Currency Value.


msTimeExpired Method

Public Method msTimeExpired

Type Return

A Boolean Value

Syntax

Object.msTimeExpired ( curStartTimeMS, curDelayTimeMS)

The msTimeExpired Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
curStartTimeMS | Required. A Currency Value.
curDelayTimeMS | Required. A Currency Value.


msTimeStart Method

Public Method msTimeStart

Type Return

A Currency Value

Syntax

Object.msTimeStart ()

The msTimeStart Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.


SendPacketUSB Method

Public Method SendPacketUSB

Type Return

A Variant Value

Syntax

Object.SendPacketUSB ( DppWinUSB, Buffer, PacketIn)

The SendPacketUSB Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
DppWinUSB | Required. A WinUsbDevice Value.
Buffer | Required. A Byte Value.
PacketIn | Required. A Byte Value.


timeGetTimeVB Method

Public Method timeGetTimeVB

Type Return

A Double Value

Syntax

Object.timeGetTimeVB ()

The timeGetTimeVB Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.


BufferOUT Property

Public Property BufferOUT

Type

A Byte Value. The property is Read-Write

Syntax

Object.BufferOUT [ = Byte ]

The BufferOUT Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Byte | A Byte Value. The property is Read-Write.


CommError Property

Public Property CommError

Type

A Boolean Value. The property is Read-Write

Syntax

Object.CommError [ = Boolean ]

The CommError Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Boolean | A Boolean Value. The property is Read-Write.


InPacketType Property

Public Property InPacketType

Type

A Integer Value. The property is Read-Write

Syntax

Object.InPacketType [ = Integer ]

The InPacketType Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Integer | A Integer Value. The property is Read-Write.


MiscData Property

Public Property MiscData

Type

A Byte Value. The property is Read-Write

Syntax

Object.MiscData [ = Byte ]

The MiscData Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Byte | A Byte Value. The property is Read-Write.


OutStr Property

Public Property OutStr

Type

A String Value. The property is Read-Write

Syntax

Object.OutStr [ = String ]

The OutStr Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
String | A String Value. The property is Read-Write.


PacketIn Property

Public Property PacketIn

largest possible IN packet

Type

A Byte Value. The property is Read-Write

Syntax

Object.PacketIn [ = Byte ]

The PacketIn Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Byte | A Byte Value. The property is Read-Write.


Packet_Received Property

Public Property Packet_Received

Type

A Boolean Value. The property is Read-Write

Syntax

Object.Packet_Received [ = Boolean ]

The Packet_Received Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Boolean | A Boolean Value. The property is Read-Write.


PIN Property

Public Property PIN

Type

A Packet_In Value. The property is Read-Write

Syntax

Object.PIN [ = Packet_In ]

The PIN Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Packet_In | A Packet_In Value. The property is Read-Write.


PlotColor Property

Public Property PlotColor

Type

A Long Value. The property is Read-Write

Syntax

Object.PlotColor [ = Long ]

The PlotColor Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Long | A Long Value. The property is Read-Write.


Scope Property

Public Property Scope

make this a structure, with scope info?

Type

A Byte Value. The property is Read-Write

Syntax

Object.Scope [ = Byte ]

The Scope Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Byte | A Byte Value. The property is Read-Write.


ScopeOverFlow Property

Public Property ScopeOverFlow

Type

A Boolean Value. The property is Read-Write

Syntax

Object.ScopeOverFlow [ = Boolean ]

The ScopeOverFlow Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Boolean | A Boolean Value. The property is Read-Write.


SPECTRUM Property

Public Property SPECTRUM

Type

A Spec Value. The property is Read-Write

Syntax

Object.SPECTRUM [ = Spec ]

The SPECTRUM Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Spec | A Spec Value. The property is Read-Write.


STATUS Property

Public Property STATUS

Type

A Stat Value. The property is Read-Write

Syntax

Object.STATUS [ = Stat ]

The STATUS Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Stat | A Stat Value. The property is Read-Write.


strCommStatus Property

Public Property strCommStatus

Type

A String Value. The property is Read-Write

Syntax

Object.strCommStatus [ = String ]

The strCommStatus Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
String | A String Value. The property is Read-Write.


UDP_offset Property

Public Property UDP_offset

Type

A Integer Value. The property is Read-Write

Syntax

Object.UDP_offset [ = Integer ]

The UDP_offset Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Integer | A Integer Value. The property is Read-Write.


USBDeviceTest Property

Public Property USBDeviceTest

Type

A Boolean Value. The property is Read-Write

Syntax

Object.USBDeviceTest [ = Boolean ]

The USBDeviceTest Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Boolean | A Boolean Value. The property is Read-Write.


USB_Default_Timeout Property

Public Property USB_Default_Timeout

Type

A Boolean Value. The property is Read-Write

Syntax

Object.USB_Default_Timeout [ = Boolean ]

The USB_Default_Timeout Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modDP5_Protocol.
Boolean | A Boolean Value. The property is Read-Write.


PID1_TYPE Enumeration

Public PID1_TYPE enumeration

Members

Name | Value | Description
PID1_REQ_STATUS | &H1 |
PID1_REQ_SPECTRUM | &H2 |
PID1_REQ_SCOPE_MISC | &H3 |
PID1_REQ_SCA | &H4 |
PID1_REQ_CONFIG | &H20 |
PID1_REQ_FPGA_UC | &H30 |
PID1_RCV_STATUS | &H80 |
PID1_RCV_SPECTRUM | &H81 |
PID1_RCV_SCOPE_MISC | &H82 |
PID1_RCV_SCA | &H83 |
PID1_VENDOR_REQ | &HF0 |
PID1_ACK | &HFF |


PID2_ACK_TYPE Enumeration

Public PID2_ACK_TYPE enumeration

Members

Name | Value | Description
PID2_ACK_OK | &H0 |
PID2_ACK_SYNC_ERROR | &H1 |
PID2_ACK_PID_ERROR | &H2 |
PID2_ACK_LEN_ERROR | &H3 |
PID2_ACK_CHECKSUM_ERROR | &H4 |
PID2_ACK_BAD_PARAM | &H5 |
PID2_ACK_BAD_HEX_REC | &H6 |
PID2_ACK_UNRECOG | &H7 |
PID2_ACK_FPGA_ERROR | &H8 |
PID2_ACK_CP2201_NOT_FOUND | &H9 |
PID2_ACK_SCOPE_DATA_NOT_AVAIL | &HA |
PID2_ACK_PC5_NOT_PRESENT | &HB |
PID2_ACK_OK_ETHERNET_SHARE_REQ | &HC |
PID2_ACK_ETHERNET_BUSY | &HD |


PID2_RCV_SCA_TYPE Enumeration

Public PID2_RCV_SCA_TYPE enumeration

Members

Name | Value | Description
RCVPT_SCA | &H1 |


PID2_RCV_SCOPE_MISC_TYPE Enumeration

Public PID2_RCV_SCOPE_MISC_TYPE enumeration

Members

Name | Value | Description
RCVPT_SCOPE_DATA | &H1 |
RCVPT_512_BYTE_MISC_DATA | &H2 |
RCVPT_SCOPE_DATA_WITH_OVERFLOW | &H3 |
RCVPT_ETHERNET_SETTINGS | &H4 |
RCVPT_DIAGNOSTIC_DATA | &H5 |
RCVPT_HARDWARE_DESCRIPTION | &H6 |
RCVPT_CONFIG_READBACK | &H7 |
RCVPT_NETFINDER_READBACK | &H8 |


PID2_RCV_SPECTRUM_TYPE Enumeration

Public PID2_RCV_SPECTRUM_TYPE enumeration

Members

Name | Value | Description
RCVPT_256_CHANNEL_SPECTRUM | &H1 |
RCVPT_256_CHANNEL_SPECTRUM_STATUS | &H2 |
RCVPT_512_CHANNEL_SPECTRUM | &H3 |
RCVPT_512_CHANNEL_SPECTRUM_STATUS | &H4 |
RCVPT_1024_CHANNEL_SPECTRUM | &H5 |
RCVPT_1024_CHANNEL_SPECTRUM_STATUS | &H6 |
RCVPT_2048_CHANNEL_SPECTRUM | &H7 |
RCVPT_2048_CHANNEL_SPECTRUM_STATUS | &H8 |
RCVPT_4096_CHANNEL_SPECTRUM | &H9 |
RCVPT_4096_CHANNEL_SPECTRUM_STATUS | &HA |
RCVPT_8192_CHANNEL_SPECTRUM | &HB |
RCVPT_8192_CHANNEL_SPECTRUM_STATUS | &HC |


PID2_RCV_STATUS_TYPE Enumeration

Public PID2_RCV_STATUS_TYPE enumeration

Members

Name | Value | Description
RCVPT_DP4_STYLE_STATUS | &H1 |


PID2_REQ_CONFIG_TYPE Enumeration

Public PID2_REQ_CONFIG_TYPE enumeration

Members

Name | Value | Description
PID2_PX4_STYLE_CONFIG_PACKET | &H1 |
PID2_TEXT_CONFIG_PACKET | &H2 |
PID2_CONFIG_READBACK_PACKET | &H3 |


PID2_REQ_FPGA_UC_TYPE Enumeration

Public PID2_REQ_FPGA_UC_TYPE enumeration

Members

Name | Value | Description
PID2_ERASE_FPGA_IMAGE | &H1 |
PID2_UPLOAD_PACKET_FPGA | &H2 |
PID2_REINITIALIZE_FPGA | &H3 |
PID2_ERASE_UC_IMAGE_0 | &H4 |
PID2_ERASE_UC_IMAGE_1 | &H5 |
PID2_ERASE_UC_IMAGE_2 | &H6 |
PID2_UPLOAD_PACKET_UC | &H7 |
PID2_SWITCH_TO_UC_IMAGE_0 | &H8 |
PID2_SWITCH_TO_UC_IMAGE_1 | &H9 |
PID2_SWITCH_TO_UC_IMAGE_2 | &HA | PID2_UC_FPGA_CHECKSUMS


PID2_REQ_SCA_TYPE Enumeration

Public PID2_REQ_SCA_TYPE enumeration

Members

Name | Value | Description
PID2_SEND_SCA | &H1 |
PID2_LATCH_SEND_SCA | &H2 |
PID2_LATCH_CLEAR_SEND_SCA | &H3 |


PID2_REQ_SCOPE_MISC_TYPE Enumeration

Public PID2_REQ_SCOPE_MISC_TYPE enumeration

Members

Name | Value | Description
PID2_SEND_SCOPE_DATA | &H1 |
PID2_SEND_512_BYTE_MISC_DATA | &H2 |
PID2_SEND_SCOPE_DATA_REARM | &H3 |
PID2_SEND_ETHERNET_SETTINGS | &H4 |
PID2_SEND_DIAGNOSTIC_DATA | &H5 |
PID2_SEND_HARDWARE_DESCRIPTION | &H6 |
PID2_SEND_NETFINDER_READBACK | &H7 |


PID2_REQ_SPECTRUM_TYPE Enumeration

Public PID2_REQ_SPECTRUM_TYPE enumeration

Members

Name | Value | Description
PID2_SEND_SPECTRUM | &H1 |
PID2_SEND_CLEAR_SPECTRUM | &H2 |
PID2_SEND_SPECTRUM_STATUS | &H3 |
PID2_SEND_CLEAR_SPECTRUM_STATUS | &H4 | PID2_BUFFER_SPECTRUM PID2_BUFFER_CLEAR_SPECTRUM PID2_SEND_BUFFER PID2_SEND_CONFIG


PID2_REQ_STATUS_TYPE Enumeration

Public PID2_REQ_STATUS_TYPE enumeration

Members

Name | Value | Description
PID2_SEND_DP4_STYLE_STATUS | &H1 |


PID2_VENDOR_REQ_TYPE Enumeration

Public PID2_VENDOR_REQ_TYPE enumeration

Members

Name | Value | Description
PID2_CLEAR_SPECTRUM_BUFFER | &H1 |
PID2_ENABLE_MCA_MCS | &H2 |
PID2_DISABLE_MCA_MCS | &H3 |
PID2_ARM_DIGITAL_OSCILLOSCOPE | &H4 |
PID2_AUTOSET_INPUT_OFFSET | &H5 |
PID2_AUTOSET_FAST_THRESHOLD | &H6 |
PID2_READ_IO3_0 | &H7 |
PID2_WRITE_IO3_0 | &H8 |
PID2_WRITE_512_BYTE_MISC_DATA | &H9 |
PID2_SET_DCAL | &HA |
PID2_SET_PZ_CORRECTION_UC_TEMP_CAL_PZ | &HB |
PID2_SET_PZ_CORRECTION_UC_TEMP_CAL_UC | &HC |
PID2_SET_BOOT_FLAGS | &HD | PID2_SET_HV_DP4_EMULATION PID2_SET_TEC_DP4_EMULATION PID2_SET_INPUT_OFFSET_DP4_EMULATION
PID2_SET_ADC_CAL_GAIN_OFFSET | &HE | PID2_SET_SPECTRUM_OFFSET PID2_REQ_SCOPE_DATA_MISC_DATA_SCA_PACKETS
PID2_SET_SERIAL_NUMBER | &HF |
PID2_CLEAR_GP_COUNTER | &H10 |
PID2_SET_ETHERNET_SETTINGS | &H11 | PID2_SWITCH_SUPPLIES
PID2_ETHERNET_ALLOW_SHAREING | &H20 |
PID2_ETHERNET_NO_SHARING | &H21 |
PID2_ETHERNET_LOCK_IP | &H22 |


PX5_OPTIONS Enumeration

Public PX5_OPTIONS enumeration

Members

Name | Value | Description
PX5_OPTION_NONE | 0 |
PX5_OPTION_HPGe_HVPS | 1 |
PX5_OPTION_TEST_TEK | 4 |
PX5_OPTION_TEST_MOX | 5 |
PX5_OPTION_TEST_AMP | 6 |
PX5_OPTION_TEST_MODE_1 | 8 |
PX5_OPTION_TEST_MODE_2 | 9 |


TRANSMIT_PACKET_TYPE Enumeration

Public TRANSMIT_PACKET_TYPE enumeration

Members

Name | Value | Description
XMTPT_SEND_STATUS | 0 |
XMTPT_SEND_SPECTRUM | 1 |
XMTPT_SEND_CLEAR_SPECTRUM | 2 |
XMTPT_SEND_SPECTRUM_STATUS | 3 |
XMTPT_SEND_CLEAR_SPECTRUM_STATUS | 4 |
XMTPT_BUFFER_SPECTRUM | 5 |
XMTPT_BUFFER_CLEAR_SPECTRUM | 6 |
XMTPT_SEND_BUFFER | 7 |
XMTPT_SEND_DP4_STYLE_STATUS | 8 |
XMTPT_SEND_PX4_CONFIG | 9 |
XMTPT_SEND_SCOPE_DATA | 10 |
XMTPT_SEND_512_BYTE_MISC_DATA | 11 |
XMTPT_SEND_SCOPE_DATA_REARM | 12 |
XMTPT_SEND_ETHERNET_SETTINGS | 13 |
XMTPT_SEND_DIAGNOSTIC_DATA | 14 |
XMTPT_SEND_NETFINDER_PACKET | 15 |
XMTPT_SEND_HARDWARE_DESCRIPTION | 16 |
XMTPT_SEND_SCA | 17 |
XMTPT_LATCH_SEND_SCA | 18 |
XMTPT_LATCH_CLEAR_SEND_SCA | 19 |
XMTPT_SEND_ROI_OR_FIXED_BLOCK | 20 |
XMTPT_PX4_STYLE_CONFIG_PACKET | 21 |
XMTPT_SEND_CONFIG_PACKET_EX | 22 |
XMTPT_SEND_CONFIG_PACKET_TO_HW | 23 |
XMTPT_READ_CONFIG_PACKET | 24 |
XMTPT_FULL_READ_CONFIG_PACKET | 25 |
XMTPT_ERASE_FPGA_IMAGE | 26 |
XMTPT_UPLOAD_PACKET_FPGA | 27 |
XMTPT_REINITIALIZE_FPGA | 28 |
XMTPT_ERASE_UC_IMAGE_0 | 29 |
XMTPT_ERASE_UC_IMAGE_1 | 30 |
XMTPT_ERASE_UC_IMAGE_2 | 31 |
XMTPT_UPLOAD_PACKET_UC | 32 |
XMTPT_SWITCH_TO_UC_IMAGE_0 | 33 |
XMTPT_SWITCH_TO_UC_IMAGE_1 | 34 |
XMTPT_SWITCH_TO_UC_IMAGE_2 | 35 |
XMTPT_UC_FPGA_CHECKSUMS | 36 |
 | 37 | VENDOR_REQUESTS_TO_DP5
XMTPT_CLEAR_SPECTRUM_BUFFER | 38 |
XMTPT_ENABLE_MCA_MCS | 39 |
XMTPT_DISABLE_MCA_MCS | 40 |
XMTPT_ARM_DIGITAL_OSCILLOSCOPE | 41 |
XMTPT_AUTOSET_INPUT_OFFSET | 42 |
XMTPT_AUTOSET_FAST_THRESHOLD | 43 |
XMTPT_READ_IO3_0 | 44 |
XMTPT_WRITE_IO3_0 | 45 |
XMTPT_WRITE_512_BYTE_MISC_DATA | 46 |
XMTPT_SET_DCAL | 47 |
XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL_PZ | 48 |
XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL_UC | 49 |
XMTPT_SET_BOOT_FLAGS | 50 |
XMTPT_SET_HV_DP4_EMULATION | 51 |
XMTPT_SET_TEC_DP4_EMULATION | 52 |
XMTPT_SET_INPUT_OFFSET_DP4_EMULATION | 53 |
XMTPT_SET_ADC_CAL_GAIN_OFFSET | 54 |
XMTPT_SET_SPECTRUM_OFFSET | 55 |
XMTPT_REQ_SCOPE_DATA_MISC_DATA_SCA_PACKETS | 56 |
XMTPT_SET_SERIAL_NUMBER | 57 |
XMTPT_CLEAR_GP_COUNTER | 58 |
XMTPT_SWITCH_SUPPLIES | 59 |
XMTPT_SEND_TEST_PACKET | 61 |


Public Packet_In udt

Members

Name | Type | Description
PID1 | Byte |
PID2 | Byte |
LEN | Integer | signed, but data payload always less than 32768
STATUS | Byte |
DATA(32768) | Byte |
CheckSum | Long |


Public Packet_Out udt

Members

Name | Type | Description
PID1 | Byte |
PID2 | Byte |
LEN | Integer | signed, but data payload always less than 32768
EXPECTEDRESPONSE | Byte |
DATA(514) | Byte |


Public Spec udt

Members

Name | Type | Description
DATA() | Long | this keeps total of static data under 64K VB limit
Channels | Integer |


Public Stat udt

Members

Name | Type | Description
RAW(64) | Byte |
SerialNumber | Long |
FastCount | Double |
SlowCount | Double |
FPGA | Byte |
Firmware | Byte |
Build | Byte |
AccumulationTime | Double |
HV | Double |
DET_TEMP | Double |
DP5_TEMP | Double |
PX4 | Boolean |
AFAST_LOCKED | Boolean |
MCA_EN | Boolean |
PresetCountDone | Boolean |
PresetRtDone | Boolean |
PresetLtDone | Boolean |
SUPPLIES_ON | Boolean |
SCOPE_DR | Boolean |
DP5_CONFIGURED | Boolean |
GP_COUNTER | Double |
AOFFSET_LOCKED | Boolean |
MCS_DONE | Boolean |
DCAL | Double |
PZCORR | Byte | or single?
UC_TEMP_OFFSET | Byte |
AN_IN | Double |
VREF_IN | Double |
PC5_SerialNumber | Long |
PC5_PRESENT | Boolean |
PC5_HV_POL | Boolean |
PC5_8_5V | Boolean |
LiveTime | Double |
RealTime | Double |
BOOT_FLAG_LSB | Byte |
BOOT_FLAG_MSB | Byte |
BOOT_HV | Double |
BOOT_TEC | Double |
BOOT_INPOFFSET | Double | or long?
ADC_GAIN_CAL | Double |
ADC_OFFSET_CAL | Byte |
SPECTRUM_OFFSET | Long | or single?
 | Variant |
b80MHzMode | Boolean |
bFPGAAutoClock | Boolean |
DEVICE_ID | Byte | 0=DP5, 1=PX5, 2=DP5G, 3=MCA8000D, 4=TB5
strDeviceID | String |
ReBootFlag | Boolean | FW6.05 and later
DPP_options | Byte | 1=HPGe HVPS
HPGe_HV_INH | Boolean |
HPGe_HV_INH_POL | Boolean |
TEC_Voltage | Double |
DPP_ECO | Byte |
AU34_2 | Boolean |
isAscInstalled | Boolean |
isAscEnabled | Boolean |
bScintHas80MHzOption | Boolean |
isDP5_RevDxGains | Boolean |


modFindPortWin32 Module


modFindPortWin32 Consts

Consts

Scope | Name | Type | Value | Description
Private | FILE_ATTRIBUTE_NORMAL | Long | &H80 |
Private | FILE_SHARE_READ | Long | &H1 |
Private | FILE_SHARE_WRITE | Long | &H2 |
Private | FirstComPort | Long | 1 |
Private | INVALID_HANDLE_VALUE | Long | -1 |
Private | LastComPort | Long | 16 |
Private | OPEN_ALWAYS | Long | &H4 |
Private | OPEN_EXISTING | Long | &H3 |


CloseHandle Method

Private Declaration CloseHandle

Library

kernel32.dll

Type Return

A Long Value

Syntax

CloseHandle ( hObject)

The CloseHandle Declaration syntax has these parts:

Part | Description
hObject | Required. A Long Value.


CreateFile Method

Private Declaration CreateFile

Library

kernel32.dll

Alias

CreateFileA

Type Return

A Long Value

Syntax

CreateFile ( lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)

The CreateFile Declaration syntax has these parts:

Part | Description
lpFileName | Required. A String Value.
dwDesiredAccess | Required. A Long Value.
dwShareMode | Required. A Long Value.
lpSecurityAttributes | Required. A SECURITY_ATTRIBUTES Value.
dwCreationDisposition | Required. A Long Value.
dwFlagsAndAttributes | Required. A Long Value.
hTemplateFile | Required. A Long Value.


CreateComPortResource Method

Public Method CreateComPortResource

Type Return

None

Syntax

Object.CreateComPortResource lstComPortList

The CreateComPortResource Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modFindPortWin32.
lstComPortList | Required. A Object Object.


GetBaudRate Method

Public Method GetBaudRate

Type Return

A String Value

Syntax

Object.GetBaudRate ( strSettings)

The GetBaudRate Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modFindPortWin32.
strSettings | Required. A String Value.


GetFirstComPort Method

Public Method GetFirstComPort

Type Return

A Integer Value

Syntax

Object.GetFirstComPort ()

The GetFirstComPort Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modFindPortWin32.


GetPortListIndex Method

Public Method GetPortListIndex

Type Return

A Integer Value

Syntax

Object.GetPortListIndex ( lstComPortList, iComPort)

The GetPortListIndex Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modFindPortWin32.
lstComPortList | Required. A Object Object.
iComPort | Required. A Integer Value.


isAnyComPort Method

Public Method isAnyComPort

Type Return

A Boolean Value

Syntax

Object.isAnyComPort ()

The isAnyComPort Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modFindPortWin32.


isComPortAvailable Method

Public Method isComPortAvailable

Type Return

A Boolean Value

Syntax

Object.isComPortAvailable ( iComPort)

The isComPortAvailable Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modFindPortWin32.
iComPort | Required. A Integer Value.


IsPortInList Method

Public Method IsPortInList

Type Return

A Boolean Value

Syntax

Object.IsPortInList ( lstComPortList, iComPort)

The IsPortInList Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modFindPortWin32.
lstComPortList | Required. A Object Object.
iComPort | Required. A Integer Value.


ToggleBaudRate Method

Public Method ToggleBaudRate

Type Return

A String Value

Syntax

Object.ToggleBaudRate ( strSettings)

The ToggleBaudRate Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modFindPortWin32.
strSettings | Required. A String Value.


Private SECURITY_ATTRIBUTES udt

Members

Name | Type | Description
nLength | Long |
lpSecurityDescriptor | Long |
bInheritHandle | Long |


modIniFile Module


modIniFile Consts

Consts

Scope | Name | Type | Value | Description
Public | IniSectionApp | String | "DP5 Application Settings" |
Public | IniSectionCfg | String | "DP5 Configuration File" |
Public | IniSectionVal | String | "DP5 Configuration Values" |


GetPrivateProfileSectionNames Method

Private Declaration GetPrivateProfileSectionNames

Library

kernel32

Alias

GetPrivateProfileSectionNamesA

Type Return

A Long Value

Syntax

GetPrivateProfileSectionNames ( lpReturnBuffer, nSize, lpFileName)

The GetPrivateProfileSectionNames Declaration syntax has these parts:

Part | Description
lpReturnBuffer | Required. A String Value.
nSize | Required. A Long Value.
lpFileName | Required. A String Value.


GetPrivateProfileSection Method

Private Declaration GetPrivateProfileSection

Library

kernel32

Alias

GetPrivateProfileSectionA

Type Return

A Long Value

Syntax

GetPrivateProfileSection ( lpAppName, lpReturnedString, nSize, lpFileName)

The GetPrivateProfileSection Declaration syntax has these parts:

Part | Description
lpAppName | Required. A String Value.
lpReturnedString | Required. A String Value.
nSize | Required. A Long Value.
lpFileName | Required. A String Value.


GetPrivateProfileString Method

Private Declaration GetPrivateProfileString

Library

kernel32

Alias

GetPrivateProfileStringA

Type Return

A Long Value

Syntax

GetPrivateProfileString ( lpApplicationName, lpKeyName, lpDefault, lpReturnedString, nSize, lpFileName)

The GetPrivateProfileString Declaration syntax has these parts:

Part | Description
lpApplicationName | Required. A String Value.
lpKeyName | Required. A Any Value.
lpDefault | Required. A String Value.
lpReturnedString | Required. A String Value.
nSize | Required. A Long Value.
lpFileName | Required. A String Value.


WritePrivateProfileSection Method

Private Declaration WritePrivateProfileSection

Library

kernel32

Alias

WritePrivateProfileSectionA

Type Return

A Long Value

Syntax

WritePrivateProfileSection ( lpAppName, lpString, lpFileName)

The WritePrivateProfileSection Declaration syntax has these parts:

Part | Description
lpAppName | Required. A String Value.
lpString | Required. A String Value.
lpFileName | Required. A String Value.


WritePrivateProfileString Method

Private Declaration WritePrivateProfileString

Library

kernel32

Alias

WritePrivateProfileStringA

Type Return

A Long Value

Syntax

WritePrivateProfileString ( lpApplicationName, lpKeyName, lpString, lpFileName)

The WritePrivateProfileString Declaration syntax has these parts:

Part | Description
lpApplicationName | Required. A String Value.
lpKeyName | Required. A Any Value.
lpString | Required. A Any Value.
lpFileName | Required. A String Value.


AppendDP5Comments Method

Public Method AppendDP5Comments

Appends comments to INI data array. Returns the Command Key (Field 0) and the Data (Field 1) with comments and semicolons.

Type Return

A Variant Value

Syntax

Object.AppendDP5Comments ( varConfig, varComments)

The AppendDP5Comments Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
varConfig | Required. A Variant Value. INI configuration data array.
varComments | Required. A Variant Value. INI comment data array.


AppendSemicolonsToConfig Method

Public Method AppendSemicolonsToConfig

Appends semicolons to configuration data array. Returns updated configuration array.

Type Return

A Variant Value

Syntax

Object.AppendSemicolonsToConfig ( varConfig)

The AppendSemicolonsToConfig Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
varConfig | Required. A Variant Value. INI configuration data array.


ClearConfigData Method

Public Method ClearConfigData

Clears configuration data. Returns updated configuration array.

Type Return

A Variant Value

Syntax

Object.ClearConfigData ( varConfig)

The ClearConfigData Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
varConfig | Required. A Variant Value. INI configuration data array.


ConfigToUCASE Method

Public Method ConfigToUCASE

Sets configuration data array keys and data to upper case. Returns updated configuration array.

Type Return

A Variant Value

Syntax

Object.ConfigToUCASE ( varConfig)

The ConfigToUCASE Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
varConfig | Required. A Variant Value. INI configuration data array.


CopyIniArr Method

Public Method CopyIniArr

Creates INI data array of existing array size. Optional copy of existing data. Returns a INI data array.

Type Return

A Variant Value

Syntax

Object.CopyIniArr ( varData, [bCopyEmpty])

The CopyIniArr Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
varData | Required. A Variant Value. INI configuration data array.
bCopyEmpty | Optional. A Boolean = True Object.


CreateIniArr Method

Public Method CreateIniArr

Creates INI data array of existing array size. Optional copy of existing data. Returns a INI data array.

Type Return

A Variant Value

Syntax

Object.CreateIniArr ( varData, [bCopyData])

The CreateIniArr Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
varData | Required. A Variant Value. INI configuration data array.
bCopyData | Optional. A Boolean = True Object. Copy existing data array.


DataArrayString Method

Public Method DataArrayString

Creates a formatted display string of a INI data array.

Type Return

A String Value

Syntax

Object.DataArrayString ( strSection, varData)

The DataArrayString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strSection | Required. A String Value. INI file Section.
varData | Required. A Variant Value. INI data array.


DeleteIniSettingEx Method

Public Method DeleteIniSettingEx

Type Return

A Variant Value

Syntax

Object.DeleteIniSettingEx ( strFilename, Section, [Key])

The DeleteIniSettingEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
Section | Required. A String Value.
Key | Optional. A String Value.


DeleteIniSetting Method

Public Method DeleteIniSetting

Type Return

A Variant Value

Syntax

Object.DeleteIniSetting ( strFilename, Section, [Key])

The DeleteIniSetting Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
Section | Required. A String Value.
Key | Optional. A String Value.


FindIniData Method

Public Method FindIniData

Find Data for given Key in INI data array. Returns the Data (Field 1).

Type Return

A String Value

Syntax

Object.FindIniData ( strKey, varData)

The FindIniData Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strKey | Required. A Variant Value. INI item Key.
varData | Required. A Variant Value. INI data array.


GetAllIniSettingsEx Method

Public Method GetAllIniSettingsEx

Type Return

A Variant Value

Syntax

Object.GetAllIniSettingsEx ( strFilename, Section)

The GetAllIniSettingsEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
Section | Required. A String Value.


GetAllIniSettings Method

Public Method GetAllIniSettings

Type Return

A Variant Value

Syntax

Object.GetAllIniSettings ( strFilename, Section)

The GetAllIniSettings Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
Section | Required. A String Value.


GetDP5Commands Method

Public Method GetDP5Commands

Removes comments from INI section data. Returns the Command Key (Field 0) and the Command Setting (Field 1) without semicolons.

Type Return

A Variant Value

Syntax

Object.GetDP5Commands ( varData)

The GetDP5Commands Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
varData | Required. A Variant Value. INI Section array.

Remarks

The comment whitespace is not trimmed.


GetDP5Comments Method

Public Method GetDP5Comments

Extracts comments from INI section data. Returns the Command Key (Field 0) and the Comments (Field 1) without semicolons.

Type Return

A Variant Value

Syntax

Object.GetDP5Comments ( varData)

The GetDP5Comments Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
varData | Required. A Variant Value. INI Section array.

Remarks

The comment whitespace is not trimmed.


GetDP5ConfigSection Method

Public Method GetDP5ConfigSection

Read INI configuration data and comments array from file. Returns INI configuration data array as return value and comments array as parameter.

Type Return

A Variant Value

Syntax

Object.GetDP5ConfigSection ( strFilename, strSection, varComments)

The GetDP5ConfigSection Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value. INI Filename.
strSection | Required. A String Value. INI file Section.
varComments | Required. A Variant Value. INI comment data array.


GetFromIniEx Method

Public Method GetFromIniEx

Type Return

A String Value

Syntax

Object.GetFromIniEx ( strFilename, strSection, strKey, [strDefault])

The GetFromIniEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
strSection | Required. A String Value.
strKey | Required. A String Value.
strDefault | Optional. A String Value.


GetFromIni Method

Public Method GetFromIni

Type Return

A String Value

Syntax

Object.GetFromIni ( strFilename, strSection, strKey, [strDefault])

The GetFromIni Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
strSection | Required. A String Value.
strKey | Required. A String Value.
strDefault | Optional. A String Value.


GetIniListEx2 Method

Public Method GetIniListEx2

Reads Ini Section, saves to List control.

Type Return

None

Syntax

Object.GetIniListEx2 strFilename, strSection, objList, bRemComments

The GetIniListEx2 Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value. INI Filename.
strSection | Required. A String Value. INI Section requested.
objList | Required. A Object Object. INI Section display list.
bRemComments | Required. A Boolean Value. Remove comments from section data.


GetIniList Method

Public Method GetIniList

Type Return

None

Syntax

Object.GetIniList strFilename, strSection, objList

The GetIniList Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
strSection | Required. A String Value.
objList | Required. A Object Object.


GetSectionNames Method

Public Method GetSectionNames

Returns the INI file section names.

Type Return

A Variant Value

Syntax

Object.GetSectionNames ( strFilename)

The GetSectionNames Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value. INI Filename.


IniFileString Method

Public Method IniFileString

Creates a formatted display string of INI file.

Type Return

A String Value

Syntax

Object.IniFileString ( strFilename)

The IniFileString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value. INI Filename.


LoadApplicationSettings Method

Public Method LoadApplicationSettings

Type Return

None

Syntax

Object.LoadApplicationSettings frm, [AppSet], [CfgSet], [ComSet]

The LoadApplicationSettings Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
frm | Required. A Form Object.
AppSet | Optional. A Boolean = True Object.
CfgSet | Optional. A Boolean = True Object.
ComSet | Optional. A Boolean = True Object.


SaveAllIniSettingsEx Method

Public Method SaveAllIniSettingsEx

Type Return

None

Syntax

Object.SaveAllIniSettingsEx strFilename, Section, Settings

The SaveAllIniSettingsEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
Section | Required. A String Value.
Settings | Required. A Variant Value.


SaveApplicationSettings Method

Public Method SaveApplicationSettings

Type Return

None

Syntax

Object.SaveApplicationSettings frm, [AppSet], [CfgSet], [ComSet]

The SaveApplicationSettings Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
frm | Required. A Form Object.
AppSet | Optional. A Boolean = True Object.
CfgSet | Optional. A Boolean = True Object.
ComSet | Optional. A Boolean = True Object.


SaveDP5ConfigSection Method

Public Method SaveDP5ConfigSection

Saves INI data array to file with optional append comments to configuration

Type Return

None

Syntax

Object.SaveDP5ConfigSection strFilename, strSection, varConfig, [varComments]

The SaveDP5ConfigSection Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value. INI Filename.
strSection | Required. A String Value. INI file Section.
varConfig | Required. A Variant Value. INI configuration data array.
varComments | Optional. A Variant Value. INI comment data array.


SaveIniDataArray Method

Public Method SaveIniDataArray

Saves INI data array to file.

Type Return

None

Syntax

Object.SaveIniDataArray strFilename, strSection, varData

The SaveIniDataArray Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value. INI Filename.
strSection | Required. A String Value. INI file Section.
varData | Required. A Variant Value. INI data array.


SaveToIniEx Method

Public Method SaveToIniEx

Type Return

None

Syntax

Object.SaveToIniEx strFilename, strSection, strKey, strData

The SaveToIniEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
strSection | Required. A String Value.
strKey | Required. A String Value.
strData | Required. A String Value.


SaveToIni Method

Public Method SaveToIni

Type Return

None

Syntax

Object.SaveToIni strFilename, strSection, strKey, strData

The SaveToIni Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.
strSection | Required. A String Value.
strKey | Required. A String Value.
strData | Required. A String Value.


SectionString Method

Public Method SectionString

Creates a formatted display string of INI file Section.

Type Return

A String Value

Syntax

Object.SectionString ( strFilename, strSection)

The SectionString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value. INI Filename.
strSection | Required. A String Value. INI file Section.


ValidFilename Method

Public Method ValidFilename

Type Return

A String Value

Syntax

Object.ValidFilename ( strFilename)

The ValidFilename Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
strFilename | Required. A String Value.


strIniFilename Property

Public Property strIniFilename

Type

A String Value. The property is Read-Write

Syntax

Object.strIniFilename [ = String ]

The strIniFilename Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
String | A String Value. The property is Read-Write.


varCmdCtrls Property

Public Property varCmdCtrls

Type

A Variant Value. The property is Read-Write

Syntax

Object.varCmdCtrls [ = Variant ]

The varCmdCtrls Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
Variant | A Variant Value. The property is Read-Write.


varComments Property

Public Property varComments

Type

A Variant Value. The property is Read-Write

Syntax

Object.varComments [ = Variant ]

The varComments Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
Variant | A Variant Value. The property is Read-Write.


varConfig Property

Public Property varConfig

INI File Utilities for DP5 Configurations.

Type

A Variant Value. The property is Read-Write

Syntax

Object.varConfig [ = Variant ]

The varConfig Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
Variant | A Variant Value. The property is Read-Write.


varUnitsArray Property

Public Property varUnitsArray

Type

A Variant Value. The property is Read-Write

Syntax

Object.varUnitsArray [ = Variant ]

The varUnitsArray Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
Variant | A Variant Value. The property is Read-Write.


varValComments Property

Public Property varValComments

Type

A Variant Value. The property is Read-Write

Syntax

Object.varValComments [ = Variant ]

The varValComments Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
Variant | A Variant Value. The property is Read-Write.


varValues Property

Public Property varValues

Type

A Variant Value. The property is Read-Write

Syntax

Object.varValues [ = Variant ]

The varValues Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modIniFile.
Variant | A Variant Value. The property is Read-Write.


modNetFinder Module

The Netfinder protocol allows a PC application to search for embedded systems on a network.
For USB, the NetFinder Packet is used to Identify DPP devices


modNetFinder Consts

Consts

Scope | Name | Type | Value | Description
Public | MAX_NETFINDER_ENTRIES | Long | 10 |
Public | MAX_NETFINDER_STRING | Long | 80 |
Public | NO_NETFINDER_ENTRIES | Long | -1 |


AddEntry Method

Public Method AddEntry

Type Return

None

Syntax

Object.AddEntry pEntry, Buffer, destPort

The AddEntry Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
pEntry | Required. A NETDISPLAY_ENTRY Value.
Buffer | Required. A Byte Value.
destPort | Required. A Long Value.


AddStr Method

Public Method AddStr

Type Return

None

Syntax

Object.AddStr strStr, str1, [str2], [AddNL]

The AddStr Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
strStr | Required. A String Value.
str1 | Required. A String Value.
str2 | Optional. A String = "" Object.
AddNL | Optional. A Boolean = True Object.


AlertByteToCOLORREF Method

Public Method AlertByteToCOLORREF

COLORREF

Type Return

A Long Value

Syntax

Object.AlertByteToCOLORREF ( alert_level)

The AlertByteToCOLORREF Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
alert_level | Required. A Byte Value.


AlertEntryToCOLORREF Method

Public Method AlertEntryToCOLORREF

COLORREF

Type Return

A Long Value

Syntax

Object.AlertEntryToCOLORREF ( pEntry)

The AlertEntryToCOLORREF Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
pEntry | Required. A NETDISPLAY_ENTRY Value.


EntryToStrUSB Method

Public Method EntryToStrUSB

Type Return

A String Value

Syntax

Object.EntryToStrUSB ( pEntry, strPort)

The EntryToStrUSB Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
pEntry | Required. A NETDISPLAY_ENTRY Value.
strPort | Required. A String Value.


EntryToStr Method

Public Method EntryToStr

Type Return

A String Value

Syntax

Object.EntryToStr ( pEntry)

The EntryToStr Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
pEntry | Required. A NETDISPLAY_ENTRY Value.


EventDays_ByteToULong Method

Private Method EventDays_ByteToULong

Type Return

A Variant Value

Syntax

Object.EventDays_ByteToULong ( Buffer, Index)

The EventDays_ByteToULong Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Buffer | Required. A Byte Value.
Index | Required. A Long Value.


FindEntry Method

Public Method FindEntry

Type Return

A Variant Value

Syntax

Object.FindEntry ( SockAddr, DppEntries)

The FindEntry Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
SockAddr | Required. A Long Value.
DppEntries | Required. A NETDISPLAY_ENTRY Value.


FormatNetFinderTime Method

Public Method FormatNetFinderTime

Type Return

A String Value

Syntax

Object.FormatNetFinderTime ( pEntry, NetFinderEvent)

The FormatNetFinderTime Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
pEntry | Required. A NETDISPLAY_ENTRY Value.
NetFinderEvent | Required. A Byte Value.


GetNetFinderString Method

Private Method GetNetFinderString

Type Return

A Variant Value

Syntax

Object.GetNetFinderString ( Buffer, Index)

The GetNetFinderString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Buffer | Required. A Byte Value.
Index | Required. A Long Value.


GetSerialNumber Method

Private Method GetSerialNumber

Type Return

A Long Value

Syntax

Object.GetSerialNumber ( str_type)

The GetSerialNumber Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
str_type | Required. A String Value.


inc Method

Private Method inc

Type Return

A Long Value

Syntax

Object.inc ( varIndex)

The inc Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
varIndex | Required. A Variant Value.


InitAllEntries Method

Public Method InitAllEntries

Type Return

None

Syntax

Object.InitAllEntries DppEntries

The InitAllEntries Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
DppEntries | Required. A NETDISPLAY_ENTRY Value.


InitEntry Method

Public Method InitEntry

Type Return

None

Syntax

Object.InitEntry pEntry

The InitEntry Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
pEntry | Required. A NETDISPLAY_ENTRY Value.


IpAddrConvert Method

Public Method IpAddrConvert

IpAddrConvert converts multiple IP address formats.

Returns:
IpAddrConvert convertions with ToByteArray = False
long to string
byte array to string
string to long

IpAddrConvert convertions with ToByteArray = True
long to byte array
byte array to string (no change)
string to byte array

Type Return

A Variant Value

Syntax

Object.IpAddrConvert ( IPAddress, [ToByteArray])

The IpAddrConvert Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
IPAddress | Required. A Variant Value. IP Address to be converted.
ToByteArray | Optional. A Boolean = False Object. IP Address convertion function.


SockAddr_ByteToULong Method

Private Method SockAddr_ByteToULong

Type Return

A Variant Value

Syntax

Object.SockAddr_ByteToULong ( Buffer, Index)

The SockAddr_ByteToULong Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Buffer | Required. A Byte Value.
Index | Required. A Long Value.


DppEntries Property

Public Property DppEntries

Type

A NETDISPLAY_ENTRY Value. The property is Read-Write

Syntax

Object.DppEntries [ = NETDISPLAY_ENTRY ]

The DppEntries Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
NETDISPLAY_ENTRY | A NETDISPLAY_ENTRY Value. The property is Read-Write.


EthernetConnected Property

Public Property EthernetConnected

Type

A Boolean Value. The property is Read-Write

Syntax

Object.EthernetConnected [ = Boolean ]

The EthernetConnected Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Boolean | A Boolean Value. The property is Read-Write.


EthernetConnectionStatus Property

Public Property EthernetConnectionStatus

Type

A Integer Value. The property is Read-Write

Syntax

Object.EthernetConnectionStatus [ = Integer ]

The EthernetConnectionStatus Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Integer | A Integer Value. The property is Read-Write.


EthernetConnectionTicker Property

Public Property EthernetConnectionTicker

Type

A Integer Value. The property is Read-Write

Syntax

Object.EthernetConnectionTicker [ = Integer ]

The EthernetConnectionTicker Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Integer | A Integer Value. The property is Read-Write.


InetLockDpp Property

Public Property InetLockDpp

Type

A Boolean Value. The property is Read-Write

Syntax

Object.InetLockDpp [ = Boolean ]

The InetLockDpp Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Boolean | A Boolean Value. The property is Read-Write.


InetShareDpp Property

Public Property InetShareDpp

Type

A Boolean Value. The property is Read-Write

Syntax

Object.InetShareDpp [ = Boolean ]

The InetShareDpp Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Boolean | A Boolean Value. The property is Read-Write.


isDppFound Property

Public Property isDppFound

Type

A Boolean Value. The property is Read-Write

Syntax

Object.isDppFound [ = Boolean ]

The isDppFound Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Boolean | A Boolean Value. The property is Read-Write.


NetfinderUnit Property

Public Property NetfinderUnit

Type

A Integer Value. The property is Read-Write

Syntax

Object.NetfinderUnit [ = Integer ]

The NetfinderUnit Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Integer | A Integer Value. The property is Read-Write.


Netfinder_active Property

Public Property Netfinder_active

Type

A Boolean Value. The property is Read-Write

Syntax

Object.Netfinder_active [ = Boolean ]

The Netfinder_active Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Boolean | A Boolean Value. The property is Read-Write.


Netfinder_Seq Property

Public Property Netfinder_Seq

Type

A Integer Value. The property is Read-Write

Syntax

Object.Netfinder_Seq [ = Integer ]

The Netfinder_Seq Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Integer | A Integer Value. The property is Read-Write.


NewNetfinderRequest Property

Public Property NewNetfinderRequest

Type

A Boolean Value. The property is Read-Write

Syntax

Object.NewNetfinderRequest [ = Boolean ]

The NewNetfinderRequest Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Boolean | A Boolean Value. The property is Read-Write.


NfPktEntries Property

Public Property NfPktEntries

RS232,USB,ETHERNET,SPARE

Type

A NETDISPLAY_ENTRY Value. The property is Read-Write

Syntax

Object.NfPktEntries [ = NETDISPLAY_ENTRY ]

The NfPktEntries Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
NETDISPLAY_ENTRY | A NETDISPLAY_ENTRY Value. The property is Read-Write.


SearchIp Property

Public Property SearchIp

Type

A Long Value. The property is Read-Write

Syntax

Object.SearchIp [ = Long ]

The SearchIp Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Long | A Long Value. The property is Read-Write.


UnitIP Property

Public Property UnitIP

capture up to 16 IPs per Netfinder?

Type

A Variant Value. The property is Read-Write

Syntax

Object.UnitIP [ = Variant ]

The UnitIP Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modNetFinder.
Variant | A Variant Value. The property is Read-Write.


Public NETDISPLAY_ENTRY udt

Members

Name | Type | Description
alert_level | Byte |
event1_days | Long |
event1_hours | Byte |
event1_minutes | Byte |
event1_seconds | Byte |
event2_days | Long |
event2_hours | Byte |
event2_minutes | Byte |
event2_seconds | Byte |
mac(6) | Byte |
ip(4) | Byte |
port | Integer |
subnet(4) | Byte |
gateway(4) | Byte |
str_type | String |
str_description | String |
str_ev1 | String |
str_ev2 | String |
str_display | String |
ccConnectRGB | Long | COLORREF
HasData | Boolean |
SockAddr | Long |
SerNum | Long |


modParsePacket Module


modParsePacket Consts

Consts

Scope | Name | Type | Value | Description
Public | preqProcessAck | String | &H4000& |
Public | preqProcessCfgRead | String | &H200& |
Public | preqProcessDiagData | String | &H80& |
Public | preqProcessError | String | &H8000& |
Public | preqProcessHwDesc | String | &H100& |
Public | preqProcessInetSettings | String | &H40& |
Public | preqProcessNetFindRead | String | &H400& |
Public | preqProcessNone | String | &H0& |
Public | preqProcessSCAData | String | &H2000& |
Public | preqProcessScopeDataOverFlow | String | &H20& |
Public | preqProcessScopeData | String | &H8& |
Public | preqProcessSpectrum | String | &H2& |
Public | preqProcessStatus | String | &H1& |
Public | preqProcessTextData | String | &H10& |
Public | preqRequestScopeData | String | &H4& |
Public | USB_DiagDataDelayMS | Long | 2500& |


DiagnosticsToString Method

Public Method DiagnosticsToString

Type Return

A String Value

Syntax

Object.DiagnosticsToString ( dd)

The DiagnosticsToString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
dd | Required. A DiagDataType Value.


DP5_Dx_OptionFlags Method

Public Method DP5_Dx_OptionFlags

Type Return

A String Value

Syntax

Object.DP5_Dx_OptionFlags ( DP5_Dx_Options)

The DP5_Dx_OptionFlags Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
DP5_Dx_Options | Required. A Byte Value.


FmtHex Method

Public Method FmtHex

Type Return

A String Value

Syntax

Object.FmtHex ( DecNum, HexDig)

The FmtHex Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
DecNum | Required. A Long Value.
HexDig | Required. A Long Value.


IsAorB Method

Public Method IsAorB

Type Return

A String Value

Syntax

Object.IsAorB ( bIsA, strA, strB)

The IsAorB Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
bIsA | Required. A Boolean Value.
strA | Required. A String Value.
strB | Required. A String Value.


LongWordToDouble Method

Private Method LongWordToDouble

Type Return

A Variant Value

Syntax

Object.LongWordToDouble ( lwStart, Buffer)

The LongWordToDouble Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
lwStart | Required. A Long Value.
Buffer | Required. A Byte Value.


OnOffStr Method

Public Method OnOffStr

Type Return

A String Value

Syntax

Object.OnOffStr ( bOnOff)

The OnOffStr Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
bOnOff | Required. A Boolean Value.


ParsePacketStatus Method

Public Method ParsePacketStatus

Type Return

None

Syntax

Object.ParsePacketStatus P, PIN

The ParsePacketStatus Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
P | Required. A Byte Value.
PIN | Required. A Packet_In Value.


ParsePacket Method

Public Method ParsePacket

Type Return

A Variant Value

Syntax

Object.ParsePacket ( P, PIN)

The ParsePacket Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
P | Required. A Byte Value.
PIN | Required. A Packet_In Value.


PID2_TextToString Method

Public Method PID2_TextToString

Type Return

A String Value

Syntax

Object.PID2_TextToString ( strPacketSource, PID2)

The PID2_TextToString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
strPacketSource | Required. A String Value.
PID2 | Required. A Byte Value.


Process_Diagnostics Method

Public Method Process_Diagnostics

Type Return

None

Syntax

Object.Process_Diagnostics PIN, dd

The Process_Diagnostics Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
PIN | Required. A Packet_In Value.
dd | Required. A DiagDataType Value.


Process_Status Method

Public Method Process_Status

Type Return

None

Syntax

Object.Process_Status STATUS

The Process_Status Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
STATUS | Required. A Stat Value.


VersionToStr Method

Public Method VersionToStr

Type Return

A String Value

Syntax

Object.VersionToStr ( bVersion)

The VersionToStr Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
bVersion | Required. A Byte Value.


ACK_Received Property

Public Property ACK_Received

Type

A Boolean Value. The property is Read-Write

Syntax

Object.ACK_Received [ = Boolean ]

The ACK_Received Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
Boolean | A Boolean Value. The property is Read-Write.


DppState Property

Public Property DppState

Type

A DppStateType Value. The property is Read-Write

Syntax

Object.DppState [ = DppStateType ]

The DppState Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
DppStateType | A DppStateType Value. The property is Read-Write.


Timeout_flag Property

Public Property Timeout_flag

Type

A Boolean Value. The property is Read-Write

Syntax

Object.Timeout_flag [ = Boolean ]

The Timeout_flag Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modParsePacket.
Boolean | A Boolean Value. The property is Read-Write.


CommType Enumeration

Public CommType enumeration

Members

Name | Value | Description
commRS232 | 0 |
commUSB | 1 |
commSockets | 2 |
commNone | 3 |


DP5_DPP_TYPES Enumeration

Public DP5_DPP_TYPES enumeration

Members

Name | Value | Description
dppDP5 | 0 |
dppPX5 | 1 |
dppDP5G | 2 |
dppMCA8000D | 3 |
dppTB5 | 4 |
dppDP5X | 5 |


Public DiagDataType udt

Members

Name | Type | Description
ADC_V(12) | Single |
PC5_V(4) | Single |
PC5_PRESENT | Boolean |
PC5_SerialNumber | Long |
Firmware | Byte |
FPGA | Byte |
SRAMTestPass | Boolean |
SRAMTestData | Long |
TempOffset | Integer |
strTempRaw | String |
strTempCal | String |
PC5Initialized | Boolean |
PC5DCAL | Single |
IsPosHV | Boolean |
Is8_5VPreAmp | Boolean |
Sup9VOn | Boolean |
PreAmpON | Boolean |
HVOn | Boolean |
TECOn | Boolean |
DiagData(192) | Byte |


Public DppStateType udt

Members

Name | Type | Description
Interface | CommType |
strPort | String |
ReqProcess | Long |
HaveScopeData | Boolean |
ScopeAutoRearm | Boolean |


modPlot Module


Plot_Scope Method

Public Method Plot_Scope

Type Return

None

Syntax

Object.Plot_Scope picScope, Scope, PlotColor

The Plot_Scope Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modPlot.
picScope | Required. A VB.PictureBox Object.
Scope | Required. A Byte Value.
PlotColor | Required. A Long Value.


Plot_Spectrum Method

Public Method Plot_Spectrum

Type Return

None

Syntax

Object.Plot_Spectrum picMCAPlot, SPECTRUM, isLinear, isLines

The Plot_Spectrum Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modPlot.
picMCAPlot | Required. A VB.PictureBox Object.
SPECTRUM | Required. A Spec Value.
isLinear | Required. A Boolean Value.
isLines | Required. A Boolean Value.


RgbToQbColor Method

Public Method RgbToQbColor

Type Return

A Variant Value

Syntax

Object.RgbToQbColor ( PlotColor)

The RgbToQbColor Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modPlot.
PlotColor | Required. A Long Value.


WriteTextFile Method

Public Method WriteTextFile

Type Return

None

Syntax

Object.WriteTextFile strFilename, strData, [OverWrite]

The WriteTextFile Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modPlot.
strFilename | Required. A String Value.
strData | Required. A String Value.
OverWrite | Optional. A Boolean = False Object.


modProject Module


modSCA Module


modSCA Consts

Consts

Scope | Name | Type | Value | Description
Public | CFG_SECTION | String | "DP5 Configuration File" |
Public | SCA_SECTION | String | "DP5 SCA Configuration" |


GetNextCMD Method

Public Method GetNextCMD

Type Return

A Boolean Value

Syntax

Object.GetNextCMD ( strCMDList, strCmd)

The GetNextCMD Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
strCMDList | Required. A String Value.
strCmd | Required. A String Value.


GetSCASettingsINI Method

Public Method GetSCASettingsINI

Type Return

None

Syntax

Object.GetSCASettingsINI sca, Index

The GetSCASettingsINI Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.
Index | Required. A Long Value.


GetSCASetupINI Method

Public Method GetSCASetupINI

Type Return

None

Syntax

Object.GetSCASetupINI sca

The GetSCASetupINI Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.


InitSCA Method

Public Method InitSCA

Type Return

None

Syntax

Object.InitSCA

The InitSCA Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.


ReadSCASetting Method

Public Method ReadSCASetting

Type Return

None

Syntax

Object.ReadSCASetting sca, strSCAInfo

The ReadSCASetting Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.
strSCAInfo | Required. A String Value.


SaveSCASettingsINI Method

Public Method SaveSCASettingsINI

Type Return

None

Syntax

Object.SaveSCASettingsINI sca, Index

The SaveSCASettingsINI Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.
Index | Required. A Long Value.


SaveSCASetupINI Method

Public Method SaveSCASetupINI

Type Return

None

Syntax

Object.SaveSCASetupINI sca

The SaveSCASetupINI Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.


SCACfgParser Method

Public Method SCACfgParser

Type Return

None

Syntax

Object.SCACfgParser sca, strSCASettings

The SCACfgParser Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.
strSCASettings | Required. A String Value.


SCASettingsString Method

Public Method SCASettingsString

Type Return

A Variant Value

Syntax

Object.SCASettingsString ( sca, Index, [bDppMsg])

The SCASettingsString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.
Index | Required. A Long Value.
bDppMsg | Optional. A Boolean = True Object.


SCASetupString Method

Public Method SCASetupString

Type Return

A Variant Value

Syntax

Object.SCASetupString ( sca, [bDppMsg])

The SCASetupString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.
bDppMsg | Optional. A Boolean = True Object.


SCAStringALLDisplay Method

Public Method SCAStringALLDisplay

Type Return

A Variant Value

Syntax

Object.SCAStringALLDisplay ( sca)

The SCAStringALLDisplay Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.


SCAStringALL Method

Public Method SCAStringALL

Type Return

A Variant Value

Syntax

Object.SCAStringALL ( sca, [bDppMsg])

The SCAStringALL Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
sca | Required. A scaSetup Value.
bDppMsg | Optional. A Boolean = True Object.


SCAString Method

Public Method SCAString

Type Return

A Variant Value

Syntax

Object.SCAString ( strCmd, strData, [bDppMsg])

The SCAString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
strCmd | Required. A String Value.
strData | Required. A String Value.
bDppMsg | Optional. A Boolean Value.


SplitData Method

Public Method SplitData

Type Return

A Boolean Value

Syntax

Object.SplitData ( strData, varValue, strDefault)

The SplitData Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
strData | Required. A String Value.
varValue | Required. A Variant Value.
strDefault | Required. A Variant Value.


varValueToIndex Method

Public Method varValueToIndex

Type Return

A Long Value

Syntax

Object.varValueToIndex ( varData)

The varValueToIndex Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
varData | Required. A Variant Value.


sca Property

Public Property sca

Type

A scaSetup Value. The property is Read-Write

Syntax

Object.sca [ = scaSetup ]

The sca Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSCA.
scaSetup | A scaSetup Value. The property is Read-Write.


Public scaRegister udt

Members

Name | Type | Description
Index | Variant |
Low | Variant |
High | Variant |
OutPut | Variant |


Public scaSetup udt

Members

Name | Type | Description
strIniFilename | String |
Channels | Variant |
HaveChannels | Boolean |
Index | Variant |
HaveIndex | Boolean |
PulseWidth | Variant |
sca(15) | scaRegister |


modSendCommand Module


modSendCommand Consts

Consts

Scope | Name | Type | Value | Description
Public | DP4_PX4_OLD_CFG_SIZE | Long | 64 |


DP5_CMD_Data Method

Public Method DP5_CMD_Data

Type Return

A Variant Value

Syntax

Object.DP5_CMD_Data ( Buffer, XmtCmd, DataOut)

The DP5_CMD_Data Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSendCommand.
Buffer | Required. A Byte Value.
XmtCmd | Required. A TRANSMIT_PACKET_TYPE Value.
DataOut | Required. A Variant Value.


DP5_CMD Method

Public Method DP5_CMD

Type Return

A Variant Value

Syntax

Object.DP5_CMD ( Buffer, XmtCmd)

The DP5_CMD Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSendCommand.
Buffer | Required. A Byte Value.
XmtCmd | Required. A TRANSMIT_PACKET_TYPE Value.


POUT_Buffer Method

Public Method POUT_Buffer

Type Return

A Variant Value

Syntax

Object.POUT_Buffer ( POUT, Buffer)

The POUT_Buffer Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSendCommand.
POUT | Required. A Packet_Out Value.
Buffer | Required. A Byte Value.


Whitespace Property

Public Property Whitespace

Type

A String Value. The property is Read-Write

Syntax

Object.Whitespace [ = String ]

The Whitespace Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSendCommand.
String | A String Value. The property is Read-Write.


modShaping Module


modShaping Consts

Consts

Scope | Name | Type | Value | Description
Public | MAXPEAKINGTIMES_20MHZ | String | MAXPEAKINGTIMES - 2 |
Public | MAXPEAKINGTIMES_80MHZ | String | MAXPEAKINGTIMES |
Public | MAXPEAKINGTIMES | Long | 26 |


cboRiseUpdate Method

Public Method cboRiseUpdate

Type Return

None

Syntax

Object.cboRiseUpdate cboRise, cboFlatTop, is80MHz

The cboRiseUpdate Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
cboRise | Required. A ComboBox Object.
cboFlatTop | Required. A ComboBox Object.
is80MHz | Required. A Boolean Value.


CheckRangeCDbl Method

Public Method CheckRangeCDbl

Type Return

A Variant Value

Syntax

Object.CheckRangeCDbl ( TestVal, MinVal, MaxVal)

The CheckRangeCDbl Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
TestVal | Required. A Single Value.
MinVal | Required. A Single Value.
MaxVal | Required. A Single Value.


GetFlattopValues Method

Public Method GetFlattopValues

Type Return

None

Syntax

Object.GetFlattopValues cboFlatTop, DecimationIn, FlatTop, is80MHz

The GetFlattopValues Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
cboFlatTop | Required. A ComboBox Object.
DecimationIn | Required. A Integer Value.
FlatTop | Required. A Integer Value.
is80MHz | Required. A Boolean Value.


GetFPGAClockMode Method

Public Method GetFPGAClockMode

Type Return

A Boolean Value

Syntax

Object.GetFPGAClockMode ( strCLCK, strTPEA)

The GetFPGAClockMode Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
strCLCK | Required. A String Value.
strTPEA | Required. A String Value.


GetRiseTextValue Method

Private Method GetRiseTextValue

Type Return

A String Value

Syntax

Object.GetRiseTextValue ( RiseIndex, is80MHz, isRiseAveCalc)

The GetRiseTextValue Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
RiseIndex | Required. A Long Value.
is80MHz | Required. A Boolean Value.
isRiseAveCalc | Required. A Boolean Value.


LoadPeakingValues Method

Public Method LoadPeakingValues

Type Return

None

Syntax

Object.LoadPeakingValues cboRise, cboFlatTop, is80MHz

The LoadPeakingValues Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
cboRise | Required. A ComboBox Object.
cboFlatTop | Required. A ComboBox Object.
is80MHz | Required. A Boolean Value.


SetComboRiseValues Method

Public Method SetComboRiseValues

Type Return

None

Syntax

Object.SetComboRiseValues cboRise, is80MHz

The SetComboRiseValues Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
cboRise | Required. A ComboBox Object.
is80MHz | Required. A Boolean Value.


SetRiseAndAvg Method

Public Method SetRiseAndAvg

Type Return

A Integer Value

Syntax

Object.SetRiseAndAvg ( RiseIndex, is80MHz)

The SetRiseAndAvg Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
RiseIndex | Required. A Long Value.
is80MHz | Required. A Boolean Value.


SetShapingIndex Method

Public Method SetShapingIndex

Type Return

None

Syntax

Object.SetShapingIndex cboShaping, strShapingIn

The SetShapingIndex Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
cboShaping | Required. A ComboBox Object.
strShapingIn | Required. A String Value.


b80MHzModeCfg Property

Public Property b80MHzModeCfg

Type

A Boolean Value. The property is Read-Write

Syntax

Object.b80MHzModeCfg [ = Boolean ]

The b80MHzModeCfg Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
Boolean | A Boolean Value. The property is Read-Write.


b80MHzModeCfg_old Property

Public Property b80MHzModeCfg_old

Type

A Boolean Value. The property is Read-Write

Syntax

Object.b80MHzModeCfg_old [ = Boolean ]

The b80MHzModeCfg_old Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modShaping.
Boolean | A Boolean Value. The property is Read-Write.


modSpectrumFile Module


GetSpectrumFilename Method

Public Method GetSpectrumFilename

Type Return

A Boolean Value

Syntax

Object.GetSpectrumFilename ( strFilename, cmnDlg)

The GetSpectrumFilename Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSpectrumFile.
strFilename | Required. A String Value.
cmnDlg | Required. A CommonDialog Object.


LogEvent Method

Public Method LogEvent

Type Return

None

Syntax

Object.LogEvent strEvent, [bOverWrite]

The LogEvent Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSpectrumFile.
strEvent | Required. A String Value.
bOverWrite | Optional. A Boolean = False Object.


ProcessSpectrumCfgForFile Method

Public Method ProcessSpectrumCfgForFile

Type Return

A String Value

Syntax

Object.ProcessSpectrumCfgForFile ( strCfgIn, Dp5CmdList)

The ProcessSpectrumCfgForFile Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSpectrumFile.
strCfgIn | Required. A String Value.
Dp5CmdList | Required. A Collection Object.


SaveSpectrum Method

Public Method SaveSpectrum

Type Return

None

Syntax

Object.SaveSpectrum strFilename, SPECTRUM, strCfg, STATUS, strTag, strDescription, dateStart

The SaveSpectrum Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSpectrumFile.
strFilename | Required. A String Value.
SPECTRUM | Required. A Spec Value.
strCfg | Required. A String Value.
STATUS | Required. A Stat Value.
strTag | Required. A String Value.
strDescription | Required. A String Value.
dateStart | Required. A Date Value.


ShowStatusValueStrings Method

Public Method ShowStatusValueStrings

Type Return

A String Value

Syntax

Object.ShowStatusValueStrings ( m_DP5_Status)

The ShowStatusValueStrings Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modSpectrumFile.
m_DP5_Status | Required. A Stat Value.


modWinUSB Module

Windows DDK WinUSB API and Setup API Converted to Visual Basic 5/6
Note: WinUSB Index represents CurrentControlSet device index
MultiUSB Index represents Index of stored WinUsbDevice for multiple DPP devices


modWinUSB Consts

Consts

Scope | Name | Type | Value | Description
Public | BUFFER_SIZE | Long | 1024 |
Public | DBT_DEVICEARRIVAL | Long | 32768 |
Public | DBT_DEVICEREMOVECOMPLETE | Long | 32772 |
Public | DBT_DEVTYP_DEVICEINTERFACE | Long | 5 |
Public | DEVICE_NOTIFY_WINDOW_HANDLE | Long | 0 |
Public | DIGCF_DEVICEINTERFACE | Integer | &H10 |
Public | DIGCF_PRESENT | Integer | &H2 |
Public | ERROR_NO_MORE_ITEMS | String | 259& |
Public | ERROR_SUCCESS | String | 0& |
Public | FILE_ATTRIBUTE_NORMAL | Integer | &H80 |
Public | FILE_FLAG_OVERLAPPED | Long | &H40000000 |
Public | FILE_SHARE_READ | Integer | &H1 |
Public | FILE_SHARE_WRITE | Integer | &H2 |
Public | FORMAT_MESSAGE_FROM_SYSTEM | Long | &H1000 |
Public | GENERIC_READ | Long | &H80000000 |
Public | GENERIC_WRITE | Long | &H40000000 |
Public | GWL_WNDPROC | String | (-4) |
Public | HKEY_LOCAL_MACHINE | Long | &H80000002 |
Public | KEY_QUERY_VALUE | Long | &H1 |
Public | MAXDP5S | Long | 128 | max number of devices
Public | MAXERRBUFFER | Long | 256 |
Public | MAXREGBUFFER | Long | 128 |
Public | MAX_DEVPATH_LENGTH | Long | 256 |
Public | MAX_PATH | Long | 260 |
Public | NUM_ASYNCH_IO | Long | 100 |
Public | OPEN_EXISTING | Integer | 3 |
Public | REG_DWORD | Long | 4 | 32-bit number
Public | REG_NONE | Long | 0 | No value type
Public | WinUsbDP5Size | Long | 21 |
Public | WinUsbDP5 | String | "USB\Vid_10c4&Pid_842a" |
Public | WinUSBService | String | "SYSTEM\CurrentControlSet\Services\WinUSB\Enum" |
Public | WM_DEVICECHANGE | Long | &H219 |


CallWindowProc Method

Public Declaration CallWindowProc

CopyMemory (RtlMoveMemory) moves memory either forward or backward, _ aligned or unaligned, in 4-byte blocks, followed by any remaining bytes.

Library

user32

Alias

CallWindowProcA

Type Return

A Long Value

Syntax

CallWindowProc ( lpPrevWndFunc, hwnd, Msg, wParam, lParam)

The CallWindowProc Declaration syntax has these parts:

Part | Description
lpPrevWndFunc | Required. A Long Value.
hwnd | Required. A Long Value.
Msg | Required. A Long Value.
wParam | Required. A Long Value.
lParam | Required. A Long Value.

Remarks

The (Source + Length) can overlap the Destination range passed in to CopyMemory (RtlMoveMemory).


CloseHandle Method

Public Declaration CloseHandle

Library

kernel32.dll

Type Return

A Boolean Value

Syntax

CloseHandle ( hObject)

The CloseHandle Declaration syntax has these parts:

Part | Description
hObject | Required. A Long Value.


CopyMemory Method

Public Declaration CopyMemory

CopyMemory (RtlMoveMemory) moves memory either forward or backward, _ aligned or unaligned, in 4-byte blocks, followed by any remaining bytes.

Library

kernel32

Alias

RtlMoveMemory

Type Return

A None Object

Syntax

CopyMemory Destination, Source, Length

The CopyMemory Declaration syntax has these parts:

Part | Description
Destination | Required. A Any Value. Points to the destination of the move.
Source | Required. A Any Value. Points to the memory to be copied.
Length | Required. A Long Value. Specifies the number of bytes to be copied.

Remarks

The (Source + Length) can overlap the Destination range passed in to CopyMemory (RtlMoveMemory).


CreateFile Method

Public Declaration CreateFile

Library

kernel32.dll

Alias

CreateFileA

Type Return

A Long Value

Syntax

CreateFile ( lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile)

The CreateFile Declaration syntax has these parts:

Part | Description
lpFileName | Required. A String Value.
dwDesiredAccess | Required. A Long Value.
dwShareMode | Required. A Long Value.
lpSecurityAttributes | Required. A SECURITY_ATTRIBUTES Value.
dwCreationDisposition | Required. A Long Value.
dwFlagsAndAttributes | Required. A Long Value.
hTemplateFile | Required. A Long Value.


FormatMessage Method

Public Declaration FormatMessage

Library

kernel32

Alias

FormatMessageA

Type Return

A Long Value

Syntax

FormatMessage ( dwFlags, lpSource, dwMessageId, dwLanguageZId, lpBuffer, nSize, Arguments)

The FormatMessage Declaration syntax has these parts:

Part | Description
dwFlags | Required. A Long Value.
lpSource | Required. A Any Value.
dwMessageId | Required. A Long Value.
dwLanguageZId | Required. A Long Value.
lpBuffer | Required. A String Value.
nSize | Required. A Long Value.
Arguments | Required. A Long Value.


GetWindowLong Method

Public Declaration GetWindowLong

Library

user32

Alias

GetWindowLongA

Type Return

A Long Value

Syntax

GetWindowLong ( hwnd, nIndex)

The GetWindowLong Declaration syntax has these parts:

Part | Description
hwnd | Required. A Long Value.
nIndex | Required. A Long Value.


RegCloseKey Method

Public Declaration RegCloseKey

Library

advapi32.dll

Type Return

A Long Value

Syntax

RegCloseKey ( hKey)

The RegCloseKey Declaration syntax has these parts:

Part | Description
hKey | Required. A Long Value.


RegEnumValue Method

Public Declaration RegEnumValue

Library

advapi32.dll

Alias

RegEnumValueA

Type Return

A Long Value

Syntax

RegEnumValue ( hKey, dwIndex, lpValueName, lpcbValueName, lpReserved, lpType, lpData, lpcbData)

The RegEnumValue Declaration syntax has these parts:

Part | Description
hKey | Required. A Long Value.
dwIndex | Required. A Long Value.
lpValueName | Required. A String Value.
lpcbValueName | Required. A Long Value.
lpReserved | Required. A Long Value.
lpType | Required. A Long Value.
lpData | Required. A Any Value.
lpcbData | Required. A Long Value.


RegisterDeviceNotification Method

Public Declaration RegisterDeviceNotification

Library

user32.dll

Alias

RegisterDeviceNotificationA

Type Return

A Long Value

Syntax

RegisterDeviceNotification ( hRecipient, NotificationFilter, Flags)

The RegisterDeviceNotification Declaration syntax has these parts:

Part | Description
hRecipient | Required. A Long Value.
NotificationFilter | Required. A Any Value.
Flags | Required. A Long Value.


RegOpenKeyEx Method

Public Declaration RegOpenKeyEx

Library

advapi32.dll

Alias

RegOpenKeyExA

Type Return

A Long Value

Syntax

RegOpenKeyEx ( hKey, lpSubKey, ulOptions, samDesired, phkResult)

The RegOpenKeyEx Declaration syntax has these parts:

Part | Description
hKey | Required. A Long Value.
lpSubKey | Required. A String Value.
ulOptions | Required. A Long Value.
samDesired | Required. A Long Value.
phkResult | Required. A Long Value.


RtlMoveMemory Method

Public Declaration RtlMoveMemory

Library

kernel32

Type Return

A Long Value

Syntax

RtlMoveMemory ( Dest, src, Count)

The RtlMoveMemory Declaration syntax has these parts:

Part | Description
Dest | Required. A Any Value.
src | Required. A Any Value.
Count | Required. A Long Value.


SetupDiDestroyDeviceInfoList Method

Public Declaration SetupDiDestroyDeviceInfoList

Library

setupapi.dll

Type Return

A Long Value

Syntax

SetupDiDestroyDeviceInfoList ( DeviceInfoSet)

The SetupDiDestroyDeviceInfoList Declaration syntax has these parts:

Part | Description
DeviceInfoSet | Required. A Long Value.


SetupDiEnumDeviceInterfaces Method

Public Declaration SetupDiEnumDeviceInterfaces

Library

setupapi.dll

Type Return

A Boolean Value

Syntax

SetupDiEnumDeviceInterfaces ( DeviceInfoSet, DeviceInfoData, InterfaceClassGuid, MemberIndex, DeviceInterfaceData)

The SetupDiEnumDeviceInterfaces Declaration syntax has these parts:

Part | Description
DeviceInfoSet | Required. A Long Value.
DeviceInfoData | Required. A Long Value.
InterfaceClassGuid | Required. A Guid Value.
MemberIndex | Required. A Long Value.
DeviceInterfaceData | Required. A SP_DEVICE_INTERFACE_DATA Value.


SetupDiGetClassDevs Method

Public Declaration SetupDiGetClassDevs

Library

setupapi.dll

Alias

SetupDiGetClassDevsA

Type Return

A Long Value

Syntax

SetupDiGetClassDevs ( ClassGuid, Enumerator, hwndParent, Flags)

The SetupDiGetClassDevs Declaration syntax has these parts:

Part | Description
ClassGuid | Required. A Guid Value.
Enumerator | Required. A String Value.
hwndParent | Required. A Long Value.
Flags | Required. A Long Value.


SetupDiGetDeviceInterfaceDetail Method

Public Declaration SetupDiGetDeviceInterfaceDetail

Library

setupapi.dll

Alias

SetupDiGetDeviceInterfaceDetailA

Type Return

A Boolean Value

Syntax

SetupDiGetDeviceInterfaceDetail ( DeviceInfoSet, DeviceInterfaceData, DeviceInterfaceDetailData, DeviceInterfaceDetailDataSize, RequiredSize, DeviceInfoData)

The SetupDiGetDeviceInterfaceDetail Declaration syntax has these parts:

Part | Description
DeviceInfoSet | Required. A Long Value.
DeviceInterfaceData | Required. A SP_DEVICE_INTERFACE_DATA Value.
DeviceInterfaceDetailData | Required. A Long Value.
DeviceInterfaceDetailDataSize | Required. A Long Value.
RequiredSize | Required. A Long Value.
DeviceInfoData | Required. A Long Value.


SetWindowLong Method

Public Declaration SetWindowLong

Library

user32

Alias

SetWindowLongA

Type Return

A Long Value

Syntax

SetWindowLong ( hwnd, nIndex, dwNewLong)

The SetWindowLong Declaration syntax has these parts:

Part | Description
hwnd | Required. A Long Value.
nIndex | Required. A Long Value.
dwNewLong | Required. A Long Value.


UnregisterDeviceNotification Method

Public Declaration UnregisterDeviceNotification

Library

user32.dll

Type Return

A Boolean Value

Syntax

UnregisterDeviceNotification ( Handle)

The UnregisterDeviceNotification Declaration syntax has these parts:

Part | Description
Handle | Required. A Long Value.


WinUsb_AbortPipe Method

Public Declaration WinUsb_AbortPipe

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_AbortPipe ( InterfaceHandle, PipeId)

The WinUsb_AbortPipe Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.
PipeId | Required. A Byte Value.


WinUsb_FlushPipe Method

Public Declaration WinUsb_FlushPipe

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_FlushPipe ( InterfaceHandle, PipeId)

The WinUsb_FlushPipe Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.
PipeId | Required. A Byte Value.


WinUsb_Free Method

Public Declaration WinUsb_Free

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_Free ( InterfaceHandle)

The WinUsb_Free Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.


WinUsb_Initialize Method

Public Declaration WinUsb_Initialize

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_Initialize ( DeviceHandle, InterfaceHandle)

The WinUsb_Initialize Declaration syntax has these parts:

Part | Description
DeviceHandle | Required. A Long Value.
InterfaceHandle | Required. A Long Value.


WinUsb_QueryInterfaceSettings Method

Public Declaration WinUsb_QueryInterfaceSettings

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_QueryInterfaceSettings ( InterfaceHandle, AlternateInterfaceNumber, UsbAltInterfaceDescriptor)

The WinUsb_QueryInterfaceSettings Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.
AlternateInterfaceNumber | Required. A Byte Value.
UsbAltInterfaceDescriptor | Required. A USB_INTERFACE_DESCRIPTOR Value.


WinUsb_QueryPipe Method

Public Declaration WinUsb_QueryPipe

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_QueryPipe ( InterfaceHandle, AlternateInterfaceNumber, PipeIndex, PipeInformation)

The WinUsb_QueryPipe Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.
AlternateInterfaceNumber | Required. A Byte Value.
PipeIndex | Required. A Byte Value.
PipeInformation | Required. A WINUSB_PIPE_INFORMATION Value.


WinUsb_ReadPipe Method

Public Declaration WinUsb_ReadPipe

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_ReadPipe ( InterfaceHandle, PipeId, Buffer, BufferLength, LengthTransferred, Overlapped)

The WinUsb_ReadPipe Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.
PipeId | Required. A Byte Value.
Buffer | Required. A Byte Value.
BufferLength | Required. A Long Value.
LengthTransferred | Required. A Long Value.
Overlapped | Required. A Long Value.


WinUsb_ResetPipe Method

Public Declaration WinUsb_ResetPipe

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_ResetPipe ( InterfaceHandle, PipeId)

The WinUsb_ResetPipe Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.
PipeId | Required. A Byte Value.


WinUsb_SetPipePolicy1 Method

Public Declaration WinUsb_SetPipePolicy1

Library

winusb.dll

Alias

WinUsb_SetPipePolicy

Type Return

A Boolean Value

Syntax

WinUsb_SetPipePolicy1 ( InterfaceHandle, PipeId, PolicyType, ValueLength, Value)

The WinUsb_SetPipePolicy1 Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.
PipeId | Required. A Byte Value.
PolicyType | Required. A Long Value.
ValueLength | Required. A Long Value.
Value | Required. A Long Value.


WinUsb_SetPipePolicy Method

Public Declaration WinUsb_SetPipePolicy

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_SetPipePolicy ( InterfaceHandle, PipeId, PolicyType, ValueLength, Value)

The WinUsb_SetPipePolicy Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.
PipeId | Required. A Byte Value.
PolicyType | Required. A Long Value.
ValueLength | Required. A Long Value.
Value | Required. A Byte Value.


WinUsb_WritePipe Method

Public Declaration WinUsb_WritePipe

Library

winusb.dll

Type Return

A Boolean Value

Syntax

WinUsb_WritePipe ( InterfaceHandle, PipeId, Buffer, BufferLength, LengthTransferred, Overlapped)

The WinUsb_WritePipe Declaration syntax has these parts:

Part | Description
InterfaceHandle | Required. A Long Value.
PipeId | Required. A Byte Value.
Buffer | Required. A Byte Value.
BufferLength | Required. A Long Value.
LengthTransferred | Required. A Long Value.
Overlapped | Required. A Long Value.


ByteArrayToString Method

Public Method ByteArrayToString

Type Return

A Variant Value

Syntax

Object.ByteArrayToString ( byteArray)

The ByteArrayToString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
byteArray | Required. A Byte Value.


CloseDeviceHandle Method

Public Method CloseDeviceHandle

Closes the device handle obtained with CreateFile and frees resources.

Type Return

None

Syntax

Object.CloseDeviceHandle DppWinUSB

The CloseDeviceHandle Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
DppWinUSB | Required. A WinUsbDevice Value.


CopyWinUsbDevice Method

Public Method CopyWinUsbDevice

Copies WinUsbDevice storage.

Type Return

None

Syntax

Object.CopyWinUsbDevice Source, Destination

The CopyWinUsbDevice Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Source | Required. A WinUsbDevice Value. WinUsbDevice storage to be saved
Destination | Required. A WinUsbDevice Value. WinUsbDevice storage copy


CountDP5WinusbDevices Method

Public Method CountDP5WinusbDevices

Counts the number of WinUSB DPP device connected

Type Return

A Variant Value

Syntax

Object.CountDP5WinusbDevices ()

The CountDP5WinusbDevices Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.


DeviceConnectedDisplay Method

Public Method DeviceConnectedDisplay

Type Return

None

Syntax

Object.DeviceConnectedDisplay rtbStatus, isDetected

The DeviceConnectedDisplay Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
rtbStatus | Required. A RichTextLib.RichTextBox Object.
isDetected | Required. A Boolean Value.


DeviceNameMatch Method

Public Method DeviceNameMatch

Compares two device path names. Used to find out if the device name of a recently attached or removed device matches the name of a device the application is communicating with.

Returns True if the names match, False if not.

Type Return

A Boolean Value

Syntax

Object.DeviceNameMatch ( m, DevicePathName)

The DeviceNameMatch Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
m | Required. A Message Value. A WM_DEVICECHANGE message. A call to RegisterDeviceNotification causes WM_DEVICECHANGE messages to be passed to an OnDeviceChange routine..
DevicePathName | Required. A String Value. A device pathname returned by SetupDiGetDeviceInterfaceDetail in an SP_DEVICE_INTERFACE_DETAIL_DATA structure.


FindDeviceFromGuid Method

Public Method FindDeviceFromGuid

Use SetupDi (Setup Device Installation) API functions to retrieve the device path name of an attached device that belongs to a device interface class.

Returns True if a device is found, False if not.

Type Return

A Boolean Value

Syntax

Object.FindDeviceFromGuid ( TestGuid, DevicePathName, MemberIndex)

The FindDeviceFromGuid Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
TestGuid | Required. A Guid Value. Interface class GUID.
DevicePathName | Required. A String Value. A pointer to the device path name of an attached device.
MemberIndex | Required. A Long Value.


GetDeviceHandle Method

Public Method GetDeviceHandle

Requests a handle with CreateFile.
Returns The handle.

Type Return

A Boolean Value

Syntax

Object.GetDeviceHandle ( DppWinUSB, DevicePathName)

The GetDeviceHandle Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
DppWinUSB | Required. A WinUsbDevice Value.
DevicePathName | Required. A String Value. Returned by SetupDiGetDeviceInterfaceDetail in an SP_DEVICE_INTERFACE_DETAIL_DATA structure.


GetErrorString Method

Public Method GetErrorString

Returns the error message for the last error. Adapted from Dan Appleman's "Win32 API Puzzle Book"

Type Return

A String Value

Syntax

Object.GetErrorString ( LastError)

The GetErrorString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
LastError | Required. A Long Value.


InitializeDevice Method

Public Method InitializeDevice

Initializes a device interface and obtains information about it. Calls these winusb API functions: WinUsb_Initialize,WinUsb_QueryInterfaceSettings, WinUsb_QueryPipe
Returns True on success, False on failure.

Type Return

A Boolean Value

Syntax

Object.InitializeDevice ( DppWinUSB)

The InitializeDevice Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
DppWinUSB | Required. A WinUsbDevice Value. DPP WinUSB device information


OpenDevice Method

Public Method OpenDevice

Type Return

A Boolean Value

Syntax

Object.OpenDevice ( hwnd, DppWinUSB, DeviceConnected, DevicePathName, MemberIndex)

The OpenDevice Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
hwnd | Required. A Long Value.
DppWinUSB | Required. A WinUsbDevice Value.
DeviceConnected | Required. A Boolean Value.
DevicePathName | Required. A String Value.
MemberIndex | Required. A Long Value.


ProcessError Method

Public Method ProcessError

Returns and/or displays process error messages

Type Return

A Variant Value

Syntax

Object.ProcessError ( errError, [errSource], [errControl])

The ProcessError Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
errError | Required. A ErrObject Object.
errSource | Optional. A String = "" Object.
errControl | Optional. A ERRORLEVEL = elevSrcDescReturn Object.


RegisterForDeviceNotifications Method

Public Method RegisterForDeviceNotifications

Requests to receive a notification when a device is attached or removed.

Returns True on success, False otherwise.

Type Return

A Boolean Value

Syntax

Object.RegisterForDeviceNotifications ( DevicePathName, formHandle, ClassGuid, deviceNotificationHandle)

The RegisterForDeviceNotifications Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
DevicePathName | Required. A String Value. Handle to a device.
formHandle | Required. A Long Value. Handle to the window that will receive device events.
ClassGuid | Required. A Guid Value. Device interface GUID.
deviceNotificationHandle | Required. A Long Value. Returned device notification handle.


SetPipePolicy1 Method

Public Method SetPipePolicy1

Sets pipe policy. Used when the value parameter is a long (PIPE_TRANSFER_TIMEOUT only).
Returns True on success, False on failure.

Type Return

A Boolean Value

Syntax

Object.SetPipePolicy1 ( DppWinUSB, PipeId, PolicyType, Value)

The SetPipePolicy1 Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
DppWinUSB | Required. A WinUsbDevice Value.
PipeId | Required. A Byte Value. Pipe to set a policy for.
PolicyType | Required. A Long Value. PIPE_POLICY_TYPE member.
Value | Required. A Long Value. Policy value.


SetPipePolicy Method

Private Method SetPipePolicy

Sets pipe policy. Used when the value parameter is a byte (all except PIPE_TRANSFER_TIMEOUT).
Returns True on success, False on failure.

Type Return

A Boolean Value

Syntax

Object.SetPipePolicy ( DppWinUSB, PipeId, PolicyType, Value)

The SetPipePolicy Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
DppWinUSB | Required. A WinUsbDevice Value.
PipeId | Required. A Byte Value. Pipe to set a policy for.
PolicyType | Required. A Long Value. PIPE_POLICY_TYPE member.
Value | Required. A Boolean Value. Policy value.


StatusList Method

Public Method StatusList

Type Return

None

Syntax

Object.StatusList rtbStatus, strStatus, clrColor, [bNL]

The StatusList Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
rtbStatus | Required. A RichTextLib.RichTextBox Object.
strStatus | Required. A String Value.
clrColor | Required. A Long Value.
bNL | Optional. A Boolean = True Object.


UpdateStatusList Method

Public Method UpdateStatusList

Type Return

None

Syntax

Object.UpdateStatusList rtbStatus, strStatus, [clrColor]

The UpdateStatusList Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
rtbStatus | Required. A RichTextLib.RichTextBox Object.
strStatus | Required. A String Value.
clrColor | Optional. A Long = vbBlack Object.


UsbEndpointDirectionIn Method

Private Method UsbEndpointDirectionIn

Is the endpoint's direction IN (device to host)
Returns True if IN (device to host), False if OUT (host to device)

Type Return

A Boolean Value

Syntax

Object.UsbEndpointDirectionIn ( addr)

The UsbEndpointDirectionIn Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
addr | Required. A Long Value. The endpoint address.


UsbEndpointDirectionOut Method

Private Method UsbEndpointDirectionOut

Is the endpoint's direction OUT (host to device)
Returns True if OUT (host to device, False if IN (device to host)

Type Return

A Boolean Value

Syntax

Object.UsbEndpointDirectionOut ( addr)

The UsbEndpointDirectionOut Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
addr | Required. A Long Value. The endpoint address.


VbBool Method

Public Method VbBool

Converts any C boolean type to a VB boolean type

Type Return

A Boolean Value

Syntax

Object.VbBool ( bBool)

The VbBool Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
bBool | Required. A Variant Value.


WndProc Method

Public Method WndProc

Overrides WndProc to enable checking for and handling WM_DEVICECHANGE messages.

Type Return

A Long Value

Syntax

Object.WndProc ( hwnd, Msg, wParam, lParam)

The WndProc Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
hwnd | Required. A Long Value.
Msg | Required. A Long Value.
wParam | Required. A Long Value.
lParam | Required. A Long Value.


CurrentUSBDevice Property

Public Property CurrentUSBDevice

WinUSB

Type

A Long Value. The property is Read-Write

Syntax

Object.CurrentUSBDevice [ = Long ]

The CurrentUSBDevice Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Long | A Long Value. The property is Read-Write.


DppWinUSB Property

Public Property DppWinUSB

DppWinUSB device information

Type

A WinUsbDevice Value. The property is Read-Write

Syntax

Object.DppWinUSB [ = WinUsbDevice ]

The DppWinUSB Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
WinUsbDevice | A WinUsbDevice Value. The property is Read-Write.


EmptyWinUSB Property

Public Property EmptyWinUSB

DppWinUSB device information

Type

A WinUsbDevice Value. The property is Read-Write

Syntax

Object.EmptyWinUSB [ = WinUsbDevice ]

The EmptyWinUSB Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
WinUsbDevice | A WinUsbDevice Value. The property is Read-Write.


glngPrevWndProc Property

Public Property glngPrevWndProc

Type

A Long Value. The property is Read-Write

Syntax

Object.glngPrevWndProc [ = Long ]

The glngPrevWndProc Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Long | A Long Value. The property is Read-Write.


MultiWinUSB Property

Public Property MultiWinUSB

Multiple WinUSB device information, 0-4

Type

A WinUsbDevice Value. The property is Read-Write

Syntax

Object.MultiWinUSB [ = WinUsbDevice ]

The MultiWinUSB Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
WinUsbDevice | A WinUsbDevice Value. The property is Read-Write.


MUSB_Idx Property

Public Property MUSB_Idx

multiusb serial numbers read from file

Type

A MUSB_SN_TO_INDEX Value. The property is Read-Write

Syntax

Object.MUSB_Idx [ = MUSB_SN_TO_INDEX ]

The MUSB_Idx Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
MUSB_SN_TO_INDEX | A MUSB_SN_TO_INDEX Value. The property is Read-Write.


MUSB_LAST_INDEX Property

Public Property MUSB_LAST_INDEX

last index is read fron vbDP5_MultiUSB.ini file

Type

A Long Value. The property is Read-Write

Syntax

Object.MUSB_LAST_INDEX [ = Long ]

The MUSB_LAST_INDEX Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Long | A Long Value. The property is Read-Write.


MUSB_MAX_INDEX Property

Public Property MUSB_MAX_INDEX

max index is 4 for five devices 0-4

Type

A Long Value. The property is Read-Write

Syntax

Object.MUSB_MAX_INDEX [ = Long ]

The MUSB_MAX_INDEX Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Long | A Long Value. The property is Read-Write.


MUSB_SN Property

Public Property MUSB_SN

multiusb serial numbers read from file

Type

A Long Value. The property is Read-Write

Syntax

Object.MUSB_SN [ = Long ]

The MUSB_SN Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Long | A Long Value. The property is Read-Write.


NumMultiDpp Property

Public Property NumMultiDpp

number of multiusb devices

Type

A Long Value. The property is Read-Write

Syntax

Object.NumMultiDpp [ = Long ]

The NumMultiDpp Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Long | A Long Value. The property is Read-Write.


NumUSBDevices Property

Public Property NumUSBDevices

Type

A Long Value. The property is Read-Write

Syntax

Object.NumUSBDevices [ = Long ]

The NumUSBDevices Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Long | A Long Value. The property is Read-Write.


USBDeviceConnected Property

Public Property USBDeviceConnected

Type

A Boolean Value. The property is Read-Write

Syntax

Object.USBDeviceConnected [ = Boolean ]

The USBDeviceConnected Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Boolean | A Boolean Value. The property is Read-Write.


USBDeviceNotificationHandle Property

Public Property USBDeviceNotificationHandle

Type

A Long Value. The property is Read-Write

Syntax

Object.USBDeviceNotificationHandle [ = Long ]

The USBDeviceNotificationHandle Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
Long | A Long Value. The property is Read-Write.


USBDevicePathName Property

Public Property USBDevicePathName

Type

A String Value. The property is Read-Write

Syntax

Object.USBDevicePathName [ = String ]

The USBDevicePathName Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type modWinUSB.
String | A String Value. The property is Read-Write.


ERRORLEVEL Enumeration

Public ERRORLEVEL enumeration

Members

Name | Value | Description
elevCodeReturn | 0 | Return error code.
elevDescReturn | 1 | Return error description string.
elevSrcDescReturn | 2 | Return error description string and error source string.
elevMsgBox | 3 | Return/Display error description string and error source string.


PIPE_POLICY_TYPE Enumeration

Public PIPE_POLICY_TYPE enumeration

Members

Name | Value | Description
SHORT_PACKET_TERMINATE | &H1 |
AUTO_CLEAR_STALL | 2 |
PIPE_TRANSFER_TIMEOUT | 3 |
IGNORE_SHORT_PACKETS | 4 |
ALLOW_PARTIAL_READS | 5 |
AUTO_FLUSH | 6 |
RAW_IO | 7 |
MAXIMUM_TRANSFER_SIZE | 8 |


USBD_PIPE_TYPE Enumeration

Public USBD_PIPE_TYPE enumeration

Members

Name | Value | Description
UsbdPipeTypeControl | 0 |
UsbdPipeTypeIsochronous | 1 |
UsbdPipeTypeBulk | 2 |
UsbdPipeTypeInterrupt | 3 |


Public DEV_BROADCAST_DEVICEINTERFACE2 udt

Members

Name | Type | Description
dbcc_size | Long |
dbcc_devicetype | Long |
dbcc_reserved | Long |
dbcc_classguid | Guid |
dbcc_name | String * 1024 |


Public DEV_BROADCAST_DEVICEINTERFACE udt

Members

Name | Type | Description
dbcc_size | Long |
dbcc_devicetype | Long |
dbcc_reserved | Long |
dbcc_classguid | Guid |
dbcc_name | Long |


Public DEV_BROADCAST_HDR udt

Members

Name | Type | Description
dbch_size | Long |
dbch_devicetype | Long |
dbch_reserved | Long |


Public Guid udt

Members

Name | Type | Description
D1 | Long |
D2 | Integer |
D3 | Integer |
D4(7) | Byte |


Public Message udt

Enumerates the error levels returned by ProcessError.

Members

Name | Type | Description
hwnd | Long | Handle of window.
Msg | Long | Message.
wParam | Long | First message parameter.
lParam | Long | Second message parameter.


Public MUSB_SN_TO_INDEX udt

MultiUSB Index to DPP Serial Number storage type.

Members

Name | Type | Description
Index | Long | WinUSB Device Information Array Index for Device
SerNum | Long | DPP Device Serial Number


Public SECURITY_ATTRIBUTES udt

Members

Name | Type | Description
nLength | Long |
lpSecurityDescriptor | Long |
bInheritHandle | Long |


Public SP_DEVICE_INTERFACE_DATA udt

Members

Name | Type | Description
cbSize | Long |
InterfaceClassGuid | Guid |
Flags | Long |
Reserved | Long |


Public SP_DEVICE_INTERFACE_DETAIL_DATA udt

Members

Name | Type | Description
cbSize | Long |
DevicePath | Byte | DataPath(256) As Byte


Public USB_INTERFACE_DESCRIPTOR udt

Members

Name | Type | Description
bLength | Byte |
bDescriptorType | Byte |
bInterfaceNumber | Byte |
bAlternateSetting | Byte |
bNumEndpoints | Byte |
bInterfaceClass | Byte |
bInterfaceSubClass | Byte |
bInterfaceProtocol | Byte |
iInterface | Byte |


Public WinUsbDevice udt

DPP WinUSB device information data type.

Members

Name | Type | Description
DeviceHandle | Long | Communications device resource handle.
winUsbHandle | Long | WinUSB interface handle.
bulkInPipe | Long | Bulk IN pipe id.
bulkOutPipe | Long | Bulk OUT pipe id.
interruptInPipe | Long | Interrupt IN pipe id.
interruptOutPipe | Long | Interrupt OUT pipe id.
devicespeed | Long | Device speed indicator.
SerNum | Long | dpp serial number
idxUSB | Long | WinUSB device index (1-NumDevices)
idxMUSB | Long | MUSB array index


Public WINUSB_PIPE_INFORMATION udt

Members

Name | Type | Description
PipeType | USBD_PIPE_TYPE |
PipeId | Byte |
MaximumPacketSize | Integer |
Interval | Byte |


mod_vbDP5 Module


mod_vbDP5 Consts

Consts

Scope | Name | Type | Value | Description
Public | MAX_DISPLAY_ENTRIES | Long | 4 |


EntryToStrRS232 Method

Public Method EntryToStrRS232

Type Return

A String Value

Syntax

Object.EntryToStrRS232 ( pEntry, strPort)

The EntryToStrRS232 Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type mod_vbDP5.
pEntry | Required. A NETDISPLAY_ENTRY Value.
strPort | Required. A String Value.


GetWinSockStateString Method

Public Method GetWinSockStateString

Type Return

A String Value

Syntax

Object.GetWinSockStateString ( wSock)

The GetWinSockStateString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type mod_vbDP5.
wSock | Required. A Winsock Object.


NetFinderSearch Method

Public Method NetFinderSearch

DP5 Netfinder Search

Type Return

None

Syntax

Object.NetFinderSearch

The NetFinderSearch Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type mod_vbDP5.


SendPacketInet Method

Public Method SendPacketInet

Type Return

A Variant Value

Syntax

Object.SendPacketInet ( IntCtrl, Buffer, PacketIn)

The SendPacketInet Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type mod_vbDP5.
IntCtrl | Required. A Object Object.
Buffer | Required. A Byte Value.
PacketIn | Required. A Byte Value.


SendPacketRS232 Method

Public Method SendPacketRS232

Type Return

A Variant Value

Syntax

Object.SendPacketRS232 ( IntCtrl, Buffer, PacketIn)

The SendPacketRS232 Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type mod_vbDP5.
IntCtrl | Required. A Object Object.
Buffer | Required. A Byte Value.
PacketIn | Required. A Byte Value.


RS232ComPortTest Property

Public Property RS232ComPortTest

Type

A Boolean Value. The property is Read-Write

Syntax

Object.RS232ComPortTest [ = Boolean ]

The RS232ComPortTest Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type mod_vbDP5.
Boolean | A Boolean Value. The property is Read-Write.


RS232HeaderReceived Property

Public Property RS232HeaderReceived

Type

A Boolean Value. The property is Read-Write

Syntax

Object.RS232HeaderReceived [ = Boolean ]

The RS232HeaderReceived Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type mod_vbDP5.
Boolean | A Boolean Value. The property is Read-Write.


RS232PacketPtr Property

Public Property RS232PacketPtr

Type

A Integer Value. The property is Read-Write

Syntax

Object.RS232PacketPtr [ = Integer ]

The RS232PacketPtr Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type mod_vbDP5.
Integer | A Integer Value. The property is Read-Write.


Form3 Module

Form3 Form


btnAccept_Click Method

Private Method btnAccept_Click

Type Return

None

Syntax

Object.btnAccept_Click

The btnAccept_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type Form3.


btnIgnore_Click Method

Private Method btnIgnore_Click

Type Return

None

Syntax

Object.btnIgnore_Click

The btnIgnore_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type Form3.


Form_Load Method

Private Method Form_Load

Type Return

None

Syntax

Object.Form_Load

The Form_Load Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type Form3.


Timer1_Timer Method

Private Method Timer1_Timer

Type Return

None

Syntax

Object.Timer1_Timer

The Timer1_Timer Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type Form3.


frmControls Module

frmControls Form


frmDP5 Module

frmDP5 Form


InitCommonControls Method

Private Declaration InitCommonControls

Library

comctl32.dll

Type Return

A None Object

Syntax

InitCommonControls

The InitCommonControls Declaration syntax has these parts:

Part Description


Load Method

Private Declaration Load

Library

ary Lib "kernel32

Alias

LoadLibraryA

Type Return

A Long Value

Syntax

Load ( lpLibFileName)

The Load Declaration syntax has these parts:

Part | Description
lpLibFileName | Required. A String Value.


Sleep Method

Private Declaration Sleep

Library

kernel32

Type Return

A None Object

Syntax

Sleep dwMilliseconds

The Sleep Declaration syntax has these parts:

Part | Description
dwMilliseconds | Required. A Long Value.


ArmScope Method

Private Method ArmScope

Type Return

None

Syntax

Object.ArmScope

The ArmScope Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


CloseProgram Method

Public Method CloseProgram

Type Return

None

Syntax

Object.CloseProgram

The CloseProgram Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdArmTrigger_Click Method

Private Method cmdArmTrigger_Click

Type Return

None

Syntax

Object.cmdArmTrigger_Click

The cmdArmTrigger_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdClearData_Click Method

Private Method cmdClearData_Click

Type Return

None

Syntax

Object.cmdClearData_Click

The cmdClearData_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdClearMiscData_Click Method

Private Method cmdClearMiscData_Click

Type Return

None

Syntax

Object.cmdClearMiscData_Click

The cmdClearMiscData_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdColor_Click Method

Private Method cmdColor_Click

Type Return

None

Syntax

Object.cmdColor_Click

The cmdColor_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdDiagnostics_Click Method

Private Method cmdDiagnostics_Click

Type Return

None

Syntax

Object.cmdDiagnostics_Click

The cmdDiagnostics_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdEditConfiguration_Click Method

Private Method cmdEditConfiguration_Click

Type Return

None

Syntax

Object.cmdEditConfiguration_Click

The cmdEditConfiguration_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdReadMiscData_Click Method

Private Method cmdReadMiscData_Click

Type Return

None

Syntax

Object.cmdReadMiscData_Click

The cmdReadMiscData_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdRS232ComPortTest Method

Public Method cmdRS232ComPortTest

Type Return

None

Syntax

Object.cmdRS232ComPortTest

The cmdRS232ComPortTest Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdSaveSpectrum_Click Method

Private Method cmdSaveSpectrum_Click

Type Return

None

Syntax

Object.cmdSaveSpectrum_Click

The cmdSaveSpectrum_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdSelectCommunications_Click Method

Private Method cmdSelectCommunications_Click

Type Return

None

Syntax

Object.cmdSelectCommunications_Click

The cmdSelectCommunications_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdShowConfiguration_Click Method

Private Method cmdShowConfiguration_Click

Type Return

None

Syntax

Object.cmdShowConfiguration_Click

The cmdShowConfiguration_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdShowSCASettings_Click Method

Public Method cmdShowSCASettings_Click

Type Return

None

Syntax

Object.cmdShowSCASettings_Click

The cmdShowSCASettings_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdSingleUpdate_Click Method

Private Method cmdSingleUpdate_Click

Type Return

None

Syntax

Object.cmdSingleUpdate_Click

The cmdSingleUpdate_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdStartAcquisition_Click Method

Private Method cmdStartAcquisition_Click

Type Return

None

Syntax

Object.cmdStartAcquisition_Click

The cmdStartAcquisition_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdStopAcquisition_Click Method

Private Method cmdStopAcquisition_Click

Type Return

None

Syntax

Object.cmdStopAcquisition_Click

The cmdStopAcquisition_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdUSBDeviceTest Method

Public Method cmdUSBDeviceTest

Type Return

None

Syntax

Object.cmdUSBDeviceTest

The cmdUSBDeviceTest Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


cmdWriteMiscData_Click Method

Private Method cmdWriteMiscData_Click

Type Return

None

Syntax

Object.cmdWriteMiscData_Click

The cmdWriteMiscData_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


DisplayError Method

Private Method DisplayError

Type Return

None

Syntax

Object.DisplayError PIN, DppState

The DisplayError Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


DppComm_OnComm Method

Private Method DppComm_OnComm

Type Return

None

Syntax

Object.DppComm_OnComm

The DppComm_OnComm Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


DppWinsock_DataArrival Method

Private Method DppWinsock_DataArrival

Type Return

None

Syntax

Object.DppWinsock_DataArrival bytesTotal

The DppWinsock_DataArrival Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
bytesTotal | Required. A Long Value.


EnableDppCmdControls Method

Private Method EnableDppCmdControls

Type Return

None

Syntax

Object.EnableDppCmdControls EnableCmd

The EnableDppCmdControls Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
EnableCmd | Required. A Boolean Value.


Form_Initialize Method

Private Method Form_Initialize

Type Return

None

Syntax

Object.Form_Initialize

The Form_Initialize Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


Form_Load Method

Private Method Form_Load

Type Return

None

Syntax

Object.Form_Load

The Form_Load Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


Form_Unload Method

Private Method Form_Unload

Type Return

None

Syntax

Object.Form_Unload Cancel

The Form_Unload Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
Cancel | Required. A Integer Value.


GetMcaFileCfg Method

Private Method GetMcaFileCfg

Type Return

A String Value

Syntax

Object.GetMcaFileCfg ()

The GetMcaFileCfg Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


NetFinderWinSock_DataArrival Method

Private Method NetFinderWinSock_DataArrival

Type Return

None

Syntax

Object.NetFinderWinSock_DataArrival bytesTotal

The NetFinderWinSock_DataArrival Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
bytesTotal | Required. A Long Value.


OnDeviceChange Method

Public Method OnDeviceChange

Type Return

None

Syntax

Object.OnDeviceChange hwnd, Msg, wParam, lParam

The OnDeviceChange Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
hwnd | Required. A Long Value.
Msg | Required. A Long Value.
wParam | Required. A Long Value.
lParam | Required. A Long Value.


ParsePacketEx Method

Private Method ParsePacketEx

Type Return

None

Syntax

Object.ParsePacketEx PIN, DppState

The ParsePacketEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


picScope_DblClick Method

Private Method picScope_DblClick

Type Return

None

Syntax

Object.picScope_DblClick

The picScope_DblClick Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


ProcessAck Method

Private Method ProcessAck

Type Return

None

Syntax

Object.ProcessAck PID2

The ProcessAck Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PID2 | Required. A Byte Value.


ProcessCfgReadEx Method

Private Method ProcessCfgReadEx

Type Return

None

Syntax

Object.ProcessCfgReadEx PIN, DppState

The ProcessCfgReadEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


ProcessDiagDataEx Method

Private Method ProcessDiagDataEx

Type Return

None

Syntax

Object.ProcessDiagDataEx PIN, DppState

The ProcessDiagDataEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


ProcessInetSettingsEx Method

Private Method ProcessInetSettingsEx

Type Return

None

Syntax

Object.ProcessInetSettingsEx PIN, DppState

The ProcessInetSettingsEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


ProcessNetFindReadEx Method

Private Method ProcessNetFindReadEx

Type Return

None

Syntax

Object.ProcessNetFindReadEx PIN, DppState

The ProcessNetFindReadEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


ProcessSCADataEx Method

Private Method ProcessSCADataEx

Type Return

None

Syntax

Object.ProcessSCADataEx PIN, DppState

The ProcessSCADataEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


ProcessScopeDataEx Method

Private Method ProcessScopeDataEx

Type Return

None

Syntax

Object.ProcessScopeDataEx PIN, DppState

The ProcessScopeDataEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


ProcessSpectrumEx Method

Private Method ProcessSpectrumEx

Type Return

None

Syntax

Object.ProcessSpectrumEx PIN, DppState

The ProcessSpectrumEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


ProcessStatusEx Method

Private Method ProcessStatusEx

Type Return

None

Syntax

Object.ProcessStatusEx PIN, DppState

The ProcessStatusEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


ProcessTextDataEx Method

Private Method ProcessTextDataEx

Type Return

None

Syntax

Object.ProcessTextDataEx PIN, DppState

The ProcessTextDataEx Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PIN | Required. A Packet_In Value.
DppState | Required. A DppStateType Value.


RemCallParsePacket Method

Public Method RemCallParsePacket

Type Return

None

Syntax

Object.RemCallParsePacket PacketIn

The RemCallParsePacket Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
PacketIn | Required. A Byte Value.


RequestSCASettings Method

Public Method RequestSCASettings

Type Return

None

Syntax

Object.RequestSCASettings

The RequestSCASettings Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


RequestScopeData Method

Private Method RequestScopeData

Type Return

None

Syntax

Object.RequestScopeData ScopeDataReady

The RequestScopeData Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
ScopeDataReady | Required. A Boolean Value.


RightJustify Method

Private Method RightJustify

Type Return

A Variant Value

Syntax

Object.RightJustify ( strParam, sTxtWidth)

The RightJustify Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
strParam | Required. A String Value.
sTxtWidth | Required. A Single Value.


rtbStatus_Click Method

Private Method rtbStatus_Click

Type Return

None

Syntax

Object.rtbStatus_Click

The rtbStatus_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


SendCommandData Method

Public Method SendCommandData

Type Return

None

Syntax

Object.SendCommandData XmtCmd, DataOut

The SendCommandData Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
XmtCmd | Required. A TRANSMIT_PACKET_TYPE Value.
DataOut | Required. A Variant Value.


SendCommand Method

Public Method SendCommand

Type Return

None

Syntax

Object.SendCommand XmtCmd

The SendCommand Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
XmtCmd | Required. A TRANSMIT_PACKET_TYPE Value.


Timer1_Timer Method

Private Method Timer1_Timer

Type Return

None

Syntax

Object.Timer1_Timer

The Timer1_Timer Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


Timer2_Timer Method

Private Method Timer2_Timer

Type Return

None

Syntax

Object.Timer2_Timer

The Timer2_Timer Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


Timer3_Timer Method

Private Method Timer3_Timer

Type Return

None

Syntax

Object.Timer3_Timer

The Timer3_Timer Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.


UpdateStatusDisplay Method

Private Method UpdateStatusDisplay

Type Return

None

Syntax

Object.UpdateStatusDisplay STATUS

The UpdateStatusDisplay Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
STATUS | Required. A Stat Value.


datStartAcqTime Property

Public Property datStartAcqTime

Type

A Date Value. The property is Read-Write

Syntax

Object.datStartAcqTime [ = Date ]

The datStartAcqTime Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
Date | A Date Value. The property is Read-Write.


pnlStatus Property

Public Property pnlStatus

displays status

Type

A Panel Object. The property is Read-Write

Syntax

[Set] Object.pnlStatus [ = Panel ]

The pnlStatus Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
Panel | A Panel Object. The property is Read-Write.


frmDP5CFG Module

frmDP5CFG Form


BLRQuickSet Method

Private Method BLRQuickSet

Type Return

None

Syntax

Object.BLRQuickSet cstrMode, cstrDown, cstrUp

The BLRQuickSet Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
cstrMode | Required. A String Value.
cstrDown | Required. A String Value.
cstrUp | Required. A String Value.


cboCLCK_Update Method

Private Method cboCLCK_Update

Type Return

None

Syntax

Object.cboCLCK_Update Index

The cboCLCK_Update Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
Index | Required. A Integer Value.


cboControl_Click Method

Private Method cboControl_Click

Type Return

None

Syntax

Object.cboControl_Click Index

The cboControl_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
Index | Required. A Integer Value.


cboFlatTop_Click Method

Private Method cboFlatTop_Click

Type Return

None

Syntax

Object.cboFlatTop_Click

The cboFlatTop_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cboInputRange_Click Method

Private Method cboInputRange_Click

Type Return

None

Syntax

Object.cboInputRange_Click

The cboInputRange_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cboMCAC_Click Method

Private Method cboMCAC_Click

Type Return

None

Syntax

Object.cboMCAC_Click

The cboMCAC_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cboPUR_MCA8000D_Click Method

Private Method cboPUR_MCA8000D_Click

Type Return

None

Syntax

Object.cboPUR_MCA8000D_Click

The cboPUR_MCA8000D_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cboRise_Click Method

Private Method cboRise_Click

Type Return

None

Syntax

Object.cboRise_Click

The cboRise_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cboSCAI_Click Method

Private Method cboSCAI_Click

Type Return

None

Syntax

Object.cboSCAI_Click

The cboSCAI_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cboSCAO_Select_Click Method

Private Method cboSCAO_Select_Click

Type Return

None

Syntax

Object.cboSCAO_Select_Click

The cboSCAO_Select_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cboSCAW_Click Method

Private Method cboSCAW_Click

Type Return

None

Syntax

Object.cboSCAW_Click

The cboSCAW_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


chkEnableSCA_Click Method

Private Method chkEnableSCA_Click

Type Return

None

Syntax

Object.chkEnableSCA_Click

The chkEnableSCA_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdApply_Click Method

Private Method cmdApply_Click

Type Return

None

Syntax

Object.cmdApply_Click

The cmdApply_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdBLRQuickset_Click Method

Private Method cmdBLRQuickset_Click

Type Return

None

Syntax

Object.cmdBLRQuickset_Click

The cmdBLRQuickset_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdCancel_Click Method

Private Method cmdCancel_Click

Type Return

None

Syntax

Object.cmdCancel_Click

The cmdCancel_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdDefaults_Click Method

Private Method cmdDefaults_Click

Type Return

None

Syntax

Object.cmdDefaults_Click Index

The cmdDefaults_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
Index | Required. A Integer Value.


cmdEnterFineGain_Click Method

Private Method cmdEnterFineGain_Click

Type Return

None

Syntax

Object.cmdEnterFineGain_Click

The cmdEnterFineGain_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdFindCmd_Click Method

Private Method cmdFindCmd_Click

Type Return

None

Syntax

Object.cmdFindCmd_Click

The cmdFindCmd_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdGainCfToTotal_Click Method

Private Method cmdGainCfToTotal_Click

Type Return

None

Syntax

Object.cmdGainCfToTotal_Click

The cmdGainCfToTotal_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdGainTotalToCf_Click Method

Private Method cmdGainTotalToCf_Click

Type Return

None

Syntax

Object.cmdGainTotalToCf_Click

The cmdGainTotalToCf_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdHelp_Click Method

Private Method cmdHelp_Click

Type Return

None

Syntax

Object.cmdHelp_Click

The cmdHelp_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdOK_Click Method

Private Method cmdOK_Click

Type Return

None

Syntax

Object.cmdOK_Click

The cmdOK_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdOutputQuickset_Click Method

Private Method cmdOutputQuickset_Click

Type Return

None

Syntax

Object.cmdOutputQuickset_Click Index

The cmdOutputQuickset_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
Index | Required. A Integer Value.


cmdReadCfg_Click Method

Private Method cmdReadCfg_Click

Type Return

None

Syntax

Object.cmdReadCfg_Click

The cmdReadCfg_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdReadHwCfg_Click Method

Private Method cmdReadHwCfg_Click

Type Return

None

Syntax

Object.cmdReadHwCfg_Click

The cmdReadHwCfg_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdSaveCfg_Click Method

Private Method cmdSaveCfg_Click

Type Return

None

Syntax

Object.cmdSaveCfg_Click

The cmdSaveCfg_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdSendCfgToHwNoEdit_Click Method

Private Method cmdSendCfgToHwNoEdit_Click

Type Return

None

Syntax

Object.cmdSendCfgToHwNoEdit_Click

The cmdSendCfgToHwNoEdit_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


cmdSendCfgToHw_Click Method

Private Method cmdSendCfgToHw_Click

Type Return

None

Syntax

Object.cmdSendCfgToHw_Click

The cmdSendCfgToHw_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


EnableCfgControls Method

Private Method EnableCfgControls

Type Return

None

Syntax

Object.EnableCfgControls isEnabled

The EnableCfgControls Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
isEnabled | Required. A Boolean Value.


EnableCommandsByDeviceType Method

Private Method EnableCommandsByDeviceType

Type Return

None

Syntax

Object.EnableCommandsByDeviceType

The EnableCommandsByDeviceType Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


fix_sca_limits Method

Private Method fix_sca_limits

Type Return

None

Syntax

Object.fix_sca_limits

The fix_sca_limits Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


Form_Initialize Method

Private Method Form_Initialize

Type Return

None

Syntax

Object.Form_Initialize

The Form_Initialize Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


Form_Load Method

Private Method Form_Load

Type Return

None

Syntax

Object.Form_Load

The Form_Load Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


Form_Unload Method

Private Method Form_Unload

Type Return

None

Syntax

Object.Form_Unload Cancel

The Form_Unload Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
Cancel | Required. A Integer Value.


GetCboIndex Method

Private Method GetCboIndex

Type Return

A Long Value

Syntax

Object.GetCboIndex ( strID, [lDefault], [bNumeric])

The GetCboIndex Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
strID | Required. A String Value.
lDefault | Optional. A Long = 0 Object.
bNumeric | Optional. A Boolean = False Object.


GetDP5ConfigString Method

Public Method GetDP5ConfigString

Read String configuration data and comments array from dpp config string. Returns INI configuration data array as return value and comments array as parameter.

Type Return

A Variant Value

Syntax

Object.GetDP5ConfigString ( strConfig, varComments)

The GetDP5ConfigString Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
strConfig | Required. A String Value. hardware configuration string.
varComments | Required. A Variant Value. INI comment data array.


GetTxtItem Method

Private Method GetTxtItem

Type Return

A String Value

Syntax

Object.GetTxtItem ( strID)

The GetTxtItem Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
strID | Required. A String Value.


InitAUX Method

Private Method InitAUX

Type Return

None

Syntax

Object.InitAUX

The InitAUX Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


InitCON Method

Private Method InitCON

Type Return

None

Syntax

Object.InitCON

The InitCON Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


InitFastPeakCombo Method

Private Method InitFastPeakCombo

Type Return

None

Syntax

Object.InitFastPeakCombo

The InitFastPeakCombo Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


InitGATE Method

Private Method InitGATE

Type Return

None

Syntax

Object.InitGATE

The InitGATE Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


InitPAPZ Method

Private Method InitPAPZ

Type Return

None

Syntax

Object.InitPAPZ

The InitPAPZ Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


InitPeakDetectModeCombo Method

Private Method InitPeakDetectModeCombo

Type Return

None

Syntax

Object.InitPeakDetectModeCombo

The InitPeakDetectModeCombo Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


InitPreampVoltageCombo Method

Private Method InitPreampVoltageCombo

Type Return

None

Syntax

Object.InitPreampVoltageCombo DeviceType

The InitPreampVoltageCombo Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
DeviceType | Required. A Byte Value.


InitPURE Method

Private Method InitPURE

Type Return

None

Syntax

Object.InitPURE

The InitPURE Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


init_sca Method

Private Method init_sca

Type Return

None

Syntax

Object.init_sca

The init_sca Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


LoadListAUO1 Method

Private Method LoadListAUO1

Type Return

None

Syntax

Object.LoadListAUO1 m_AUO1Combo, isNewList

The LoadListAUO1 Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
m_AUO1Combo | Required. A ComboBox Object.
isNewList | Required. A Boolean Value.


LoadListAUO2 Method

Private Method LoadListAUO2

Type Return

None

Syntax

Object.LoadListAUO2 m_AUO2Combo, isNewList

The LoadListAUO2 Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
m_AUO2Combo | Required. A ComboBox Object.
isNewList | Required. A Boolean Value.


lstDP5Commands_Click Method

Private Method lstDP5Commands_Click

Type Return

None

Syntax

Object.lstDP5Commands_Click

The lstDP5Commands_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


optDppDeviceType_Click Method

Private Method optDppDeviceType_Click

Type Return

None

Syntax

Object.optDppDeviceType_Click Index

The optDppDeviceType_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
Index | Required. A Integer Value.


OutputQuickset Method

Private Method OutputQuickset

Type Return

None

Syntax

Object.OutputQuickset strDAC, strOutputOffset, strAUX2, strAUX1, strCONN1, strCONN2

The OutputQuickset Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
strDAC | Required. A String Value.
strOutputOffset | Required. A String Value.
strAUX2 | Required. A String Value.
strAUX1 | Required. A String Value.
strCONN1 | Required. A String Value.
strCONN2 | Required. A String Value.


ReadSCACfgFromINI Method

Private Method ReadSCACfgFromINI

Type Return

None

Syntax

Object.ReadSCACfgFromINI strFilename

The ReadSCACfgFromINI Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
strFilename | Required. A String Value.


reset_sca_high Method

Private Method reset_sca_high

Type Return

None

Syntax

Object.reset_sca_high

The reset_sca_high Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


reset_sca_low Method

Private Method reset_sca_low

Type Return

None

Syntax

Object.reset_sca_low

The reset_sca_low Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


SaveSCACfgToINI Method

Private Method SaveSCACfgToINI

Type Return

None

Syntax

Object.SaveSCACfgToINI strFilename

The SaveSCACfgToINI Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
strFilename | Required. A String Value.


SetCboItem Method

Private Method SetCboItem

Type Return

None

Syntax

Object.SetCboItem strID, strVal

The SetCboItem Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
strID | Required. A String Value.
strVal | Required. A String Value.


SetCfgInstructions Method

Private Method SetCfgInstructions

Type Return

None

Syntax

Object.SetCfgInstructions [bDisplay]

The SetCfgInstructions Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
bDisplay | Optional. A Boolean = True Object.


SetFastPeakCombo Method

Private Method SetFastPeakCombo

Type Return

None

Syntax

Object.SetFastPeakCombo strTPFA

The SetFastPeakCombo Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
strTPFA | Required. A String Value.


SetGainFromInputRangeControl Method

Private Method SetGainFromInputRangeControl

Type Return

None

Syntax

Object.SetGainFromInputRangeControl

The SetGainFromInputRangeControl Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


SetInputRangeControlFromGain Method

Private Method SetInputRangeControlFromGain

Type Return

None

Syntax

Object.SetInputRangeControlFromGain

The SetInputRangeControlFromGain Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


SetMCA8000D_PUR_From_ShapingPUR Method

Private Method SetMCA8000D_PUR_From_ShapingPUR

Type Return

None

Syntax

Object.SetMCA8000D_PUR_From_ShapingPUR

The SetMCA8000D_PUR_From_ShapingPUR Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


SetShapingPUR_From_MCA8000D_PUR Method

Private Method SetShapingPUR_From_MCA8000D_PUR

Type Return

None

Syntax

Object.SetShapingPUR_From_MCA8000D_PUR

The SetShapingPUR_From_MCA8000D_PUR Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


SetTxtItem Method

Private Method SetTxtItem

Type Return

None

Syntax

Object.SetTxtItem strID, strVal

The SetTxtItem Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
strID | Required. A String Value.
strVal | Required. A String Value.


SSTab1_Click Method

Private Method SSTab1_Click

Type Return

None

Syntax

Object.SSTab1_Click PreviousTab

The SSTab1_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
PreviousTab | Required. A Integer Value.


strSOFF_INFO Method

Private Method strSOFF_INFO

Type Return

A Variant Value

Syntax

Object.strSOFF_INFO ()

The strSOFF_INFO Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


Timer1_Timer Method

Private Method Timer1_Timer

Type Return

None

Syntax

Object.Timer1_Timer

The Timer1_Timer Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


Toolbar1_ButtonClick Method

Private Method Toolbar1_ButtonClick

Type Return

None

Syntax

Object.Toolbar1_ButtonClick Button

The Toolbar1_ButtonClick Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
Button | Required. A ComctlLib.Button Object.


txtControl_Change Method

Private Method txtControl_Change

Type Return

None

Syntax

Object.txtControl_Change Index

The txtControl_Change Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
Index | Required. A Integer Value.


txtSCAH_Edit_Change Method

Private Method txtSCAH_Edit_Change

Type Return

None

Syntax

Object.txtSCAH_Edit_Change

The txtSCAH_Edit_Change Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


txtSCAL_Edit_Change Method

Private Method txtSCAL_Edit_Change

Type Return

None

Syntax

Object.txtSCAL_Edit_Change

The txtSCAL_Edit_Change Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


UpdateSCAEdit Method

Private Method UpdateSCAEdit

Type Return

None

Syntax

Object.UpdateSCAEdit

The UpdateSCAEdit Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.


VersionToDbl Method

Public Method VersionToDbl

Type Return

A Double Value

Syntax

Object.VersionToDbl ( bVersion, bBuild)

The VersionToDbl Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
bVersion | Required. A Byte Value.
bBuild | Required. A Byte Value.


bFormLoading Property

Private Property bFormLoading

Type

A Boolean Value. The property is Read-Write

Syntax

Object.bFormLoading [ = Boolean ]

The bFormLoading Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5CFG.
Boolean | A Boolean Value. The property is Read-Write.


frmDP5_Connect Module

frmDP5_Connect Form


btnFindIP_Click Method

Private Method btnFindIP_Click

Type Return

None

Syntax

Object.btnFindIP_Click

The btnFindIP_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


btnOK_Click Method

Private Method btnOK_Click

Type Return

None

Syntax

Object.btnOK_Click

The btnOK_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


cboRS232Comm_Click Method

Private Method cboRS232Comm_Click

Type Return

None

Syntax

Object.cboRS232Comm_Click

The cboRS232Comm_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


chkLock_Click Method

Private Method chkLock_Click

Type Return

None

Syntax

Object.chkLock_Click

The chkLock_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


chkShare_Click Method

Private Method chkShare_Click

Type Return

None

Syntax

Object.chkShare_Click

The chkShare_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


cmdCloseDevice_Click Method

Private Method cmdCloseDevice_Click

Type Return

None

Syntax

Object.cmdCloseDevice_Click

The cmdCloseDevice_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


cmdCountDevices_Click Method

Private Method cmdCountDevices_Click

Type Return

None

Syntax

Object.cmdCountDevices_Click

The cmdCountDevices_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


cmdDisableUSBNotify_Click Method

Private Method cmdDisableUSBNotify_Click

Type Return

None

Syntax

Object.cmdDisableUSBNotify_Click

The cmdDisableUSBNotify_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


cmdDoNotConnect_Click Method

Private Method cmdDoNotConnect_Click

Type Return

None

Syntax

Object.cmdDoNotConnect_Click

The cmdDoNotConnect_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


cmdFindDevice_Click Method

Public Method cmdFindDevice_Click

Type Return

None

Syntax

Object.cmdFindDevice_Click

The cmdFindDevice_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


cmdRequestDataAndStatus_Click Method

Private Method cmdRequestDataAndStatus_Click

Type Return

None

Syntax

Object.cmdRequestDataAndStatus_Click

The cmdRequestDataAndStatus_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


cmdSelectIP_Click Method

Private Method cmdSelectIP_Click

Type Return

None

Syntax

Object.cmdSelectIP_Click Index

The cmdSelectIP_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
Index | Required. A Integer Value.


EnableCommControls Method

Private Method EnableCommControls

Type Return

None

Syntax

Object.EnableCommControls CurrentInterface

The EnableCommControls Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
CurrentInterface | Required. A Byte Value.


EnableINETControls Method

Private Method EnableINETControls

Type Return

None

Syntax

Object.EnableINETControls [EnInetCmds]

The EnableINETControls Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
EnInetCmds | Optional. A Boolean Value.


EnableRS232Controls Method

Private Method EnableRS232Controls

Type Return

None

Syntax

Object.EnableRS232Controls [EnRS232Cmds], [EnRS232StatusCmd]

The EnableRS232Controls Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
EnRS232Cmds | Optional. A Boolean Value.
EnRS232StatusCmd | Optional. A Boolean = False Object.


EnableUSBControls Method

Private Method EnableUSBControls

Type Return

None

Syntax

Object.EnableUSBControls [EnUSBCmds]

The EnableUSBControls Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
EnUSBCmds | Optional. A Boolean Value.


EthernetConnect Method

Private Method EthernetConnect

this is Public so Form2 can call it

Type Return

None

Syntax

Object.EthernetConnect

The EthernetConnect Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


Form_Load Method

Private Method Form_Load

Type Return

None

Syntax

Object.Form_Load

The Form_Load Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


Form_Paint Method

Private Method Form_Paint

Type Return

None

Syntax

Object.Form_Paint

The Form_Paint Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


Form_Unload Method

Private Method Form_Unload

Type Return

None

Syntax

Object.Form_Unload Cancel

The Form_Unload Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
Cancel | Required. A Integer Value.


lblIpId_Click Method

Private Method lblIpId_Click

Type Return

None

Syntax

Object.lblIpId_Click Index

The lblIpId_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
Index | Required. A Integer Value.


lblUnit_Click Method

Private Method lblUnit_Click

Type Return

None

Syntax

Object.lblUnit_Click Index

The lblUnit_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
Index | Required. A Integer Value.


optComm_Click Method

Private Method optComm_Click

Type Return

None

Syntax

Object.optComm_Click Index

The optComm_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
Index | Required. A Integer Value.


SetComPort Method

Private Method SetComPort

Type Return

A Integer Value

Syntax

Object.SetComPort ()

The SetComPort Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


udSelectDevice_Change Method

Private Method udSelectDevice_Change

Type Return

None

Syntax

Object.udSelectDevice_Change

The udSelectDevice_Change Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.


bDoNotConnect Property

Public Property bDoNotConnect

Type

A Boolean Value. The property is Read-Write

Syntax

Object.bDoNotConnect [ = Boolean ]

The bDoNotConnect Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5_Connect.
Boolean | A Boolean Value. The property is Read-Write.


frmDppConfigDisplay Module

frmDppConfigDisplay Form


cmdOK_Click Method

Private Method cmdOK_Click

Type Return

None

Syntax

Object.cmdOK_Click

The cmdOK_Click Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDppConfigDisplay.


Form_Load Method

Private Method Form_Load

Type Return

None

Syntax

Object.Form_Load

The Form_Load Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDppConfigDisplay.


SetMessage Method

Private Method SetMessage

Type Return

None

Syntax

Object.SetMessage cstrMsg, cstrDelimiter

The SetMessage Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDppConfigDisplay.
cstrMsg | Required. A String Value.
cstrDelimiter | Required. A String Value.


m_strDelimiter Property

Public Property m_strDelimiter

Type

A String Value. The property is Read-Write

Syntax

Object.m_strDelimiter [ = String ]

The m_strDelimiter Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDppConfigDisplay.
String | A String Value. The property is Read-Write.


m_strMessage Property

Public Property m_strMessage

Type

A String Value. The property is Read-Write

Syntax

Object.m_strMessage [ = String ]

The m_strMessage Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDppConfigDisplay.
String | A String Value. The property is Read-Write.


m_strTitle Property

Public Property m_strTitle

Type

A String Value. The property is Read-Write

Syntax

Object.m_strTitle [ = String ]

The m_strTitle Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDppConfigDisplay.
String | A String Value. The property is Read-Write.


frmIPConfiguration Module

frmIPConfiguration Form


frmTest Module

frmTest Form


frCommunications_DragDrop Method

Private Method frCommunications_DragDrop

Type Return

None

Syntax

Object.frCommunications_DragDrop Source, X, Y

The frCommunications_DragDrop Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmTest.
Source | Required. A Control Object.
X | Required. A Single Value.
Y | Required. A Single Value.


clsDppConfig Source Code

Option Explicit

Public CfgReadBack As Boolean       'load dpp config into config editor
Public DisplayCfg As Boolean        'show dpp config in msgbox dialog
Public bSpectrumCfg As Boolean      'create dpp mca file config
Public ScaReadBack As Boolean       'parse/load sca settings into SCA controls
Public ScaReadReady As Boolean      'sca readback ready
Public DisplaySCA As Boolean       'parse/load sca settings into SCA controls

'' --------------------------------------------------------------------------------------
''  DppConfigSettingsType
'' --------------------------------------------------------------------------------------
'Public Type DPP_CONFIG_SETTINGS
    ' MCA Properties
    Public AcqMode As Byte           ' acquisition mode 0=MCA,1=MCS
    Public MCSTimebase As Byte       ' MCS timebase value (0-15) see CAcqMode
    Public MCAChannels As Byte       ' number of channels 0=256,1=512,2=1024,3=2048,4=4096,5=8192
    Public BufferSelect As Byte      ' Holds Buffer Sel A&B,Buffer Sel Hardware,see DPPBufferSelect
    Public TTLGate As Byte           ' gate input settings, determines events included/excluded from spectrum, see DPPGate
    Public SlowThreshold As Byte     ' Slow ch threshold, Events w/amp lower not added to spectrum
    Public PresetTime As Long        ' var holds preset time, used in usb
    Public PresetCount As Long       ' preset count in selected channels, ch are set in SCA8
    'Public SCA(0 To 7) As Long       ' SCA values, LL, UL, and Enable are stored together

    ' Shaping Properties
    Public TimeToPeak As Byte        ' TimeToPeak register setting
    Public Decimation As Byte        ' decimation setting for pulse shaping
    Public FlatTop As Byte           ' flatop register setting
    Public PUREnable As Byte         ' pile-up rejection enabled
    Public FastThreshold As Byte     ' Fast Ch Threshold, events w/fch amp below this are rejected
    Public RTDSlow As Byte           ' Risetime Discrimination slow threshold
    Public RTDOn As Byte             ' Turns RTD on, and sets the amplitude and timing thresholds
    Public RTDFast As Byte           ' RTD Time Threshold,Events w/HWHM wider than this are rejected
    Public BLR As Byte               ' Baseline Restoration, see udBLR.Value notes for values
    Public BaselineOn As Byte        ' use autobaseline during detector reset

    ' Gain PZ Properties
    Public CoarseGain As Byte        ' stores current coarse gain value
    Public FineGain As Long          ' stores current fine gain value
    Public PoleZero As Long          ' pole zero adjust value
    Public InputOffset As Long       ' input offset
    Public InputPolarity As Byte     ' use InvertEnable during detector reset
    Public DetReset As Byte          ' detector reset lockout period

    ' Power Properties
    Public TEC As Long               ' TEC temperature setting (displayed in Kelvin)
    Public HVEnabled As Byte         ' high voltage setting enable
    Public HV As Long                ' high voltage setting value
    Public PreampPower As Byte       ' preamp power select value (5v or 8.5v)

    ' Misc Properties
    Public AnalogOut As Byte         ' dac enabled and DAC output type,(stobed peak,shaped pulse,dec inp,fast ch)
    Public OutputOffset As Byte      ' Output DAC offset, -64…+63,(signed)(D7-D1) (-500mV to +492mV)
    Public AuxOut As Byte            ' Aux output type
    Public AudibleCounter As Byte    ' audio volume setting
'End Type

'' --------------------------------------------------------------------------------------
''  DppStatusType (DPP_STATUS) DPP Status Storage Type
'' --------------------------------------------------------------------------------------
'Public Type DPP_STATUS

    ' Identification
    Public FPGA As Double              ' FPGA
    Public Firmware As Double          ' firmware revision
    Public SerialNumber As Double      ' unit serial number
    Public StatDevInd As Byte          ' device indicator from status block (0=dp4,1=px4)

    ' Configuration
    Public BootStatus As Byte          ' boot status byte (PwrBtnConfig,SwConfigRcvd,McaEnabled)
    Public PwrBtnConfig As Byte        ' dpp has loaded config from power button
    Public SwConfigRcvd As Byte        ' software has sent valid config to unit since startup

    ' Tuning
    Public SetFastThreshDone As Byte   ' DPP tune fast thresh has successfully done
    Public SetSlowThreshDone As Byte   ' DPP tune slow thresh has successfully done
    Public SetInputOffsetDone As Byte  ' DPP tune input offset has successfully done

    ' Monitors
    Public BoardTemp As Double         ' board temperature monitor value
    Public HVMonitor As Double         ' high voltage monitor value
    Public TECMonitor As Double        ' TEC temperature monitor value (displayed in Kelvin)

    ' Acquisition Parameters
    Public FastCount As Double         ' fast channel count
    Public SlowCount As Double         ' slow channel count
    Public AccumulationTime As Double  ' real time duration of present data acquisition interval

    ' Acquisition Mode
    Public StatMcaEnabled As Byte      ' mca enabled status, high during acq, preset time resets flag
    Public MCSDone As Byte             ' MCS done flag 1=finished, 0=not finished
    Public PresetCountExpired As Byte  ' indicates presets counts have been reached

'End Type


clsProfile Source Code

Option Explicit

Public SendCoarseFineGain As Boolean


CSCommon Source Code

Option Explicit

Public DppConfig As New clsDppConfig

Public profile As New clsProfile
Public HwCfgDP5 As String
Public cstrRawCfgIn As String
Public HwCfgReady As Boolean
Public HwCfgExReady As Boolean
Public Dp5CmdList As New Collection
Public HwCfgDP5Out As String
Public HwRdBkDP5Out As String

Public SCAEnabled As Boolean
Public HwScaCfgDP5 As String
Public cstrRawScaCfgIn As String
Public HwScaCfgReady As Boolean

' Shared Communications Interface Settings
Public CurrentInterface As Byte         ' selected communications interface (0=RS232/1=USB/2=ETHERNET)
Public isDppConnected As Boolean        ' CurrentInterface selected and device found
Public ComPort As Long                  ' Serial Port Settings

' Ethernet Settings
Public NetfinderActive As Boolean
Public SockAddr As Long
Public cstrSockAddr As String
Public InetPort As Long


Form3 Source Code

Private Sub btnAccept_Click()
    'Call frmDP5.btnDisconnect_Click  ' disconnect, so the other interface can connect
    Unload Form3
End Sub

Private Sub btnIgnore_Click()
    Unload Form3    ' unload the form without disconnecting
End Sub

Private Sub Form_Load()
    Timer1.Enabled = True ' start the timer
End Sub

Private Sub Timer1_Timer()
    If ProgressBar1.Value < ProgressBar1.Max Then
        ProgressBar1.Value = ProgressBar1.Value + 1
    Else
        Call btnAccept_Click
    End If
End Sub


frmControls Source Code

Option Explicit


frmDP5 Source Code

Option Explicit

Private Declare Sub InitCommonControls Lib "comctl32.dll" ()
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Public pnlStatus As Panel        'displays status
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public datStartAcqTime As Date

Private Sub cmdArmTrigger_Click()
    SendCommand XMTPT_ARM_DIGITAL_OSCILLOSCOPE
End Sub

Private Sub cmdClearData_Click()
    SendCommand XMTPT_SEND_CLEAR_SPECTRUM_STATUS
End Sub

Private Sub cmdClearMiscData_Click()
    txtMiscData = ""
End Sub

Private Sub cmdEditConfiguration_Click()
    Load frmDP5CFG
    frmDP5CFG.Show vbModal
End Sub

Private Sub cmdReadMiscData_Click()
    SendCommand XMTPT_SEND_512_BYTE_MISC_DATA
End Sub

Private Sub cmdShowConfiguration_Click()
    If (s.isDppConnected) Then
        s.DppConfig.DisplayCfg = True
        SendCommand XMTPT_FULL_READ_CONFIG_PACKET
    End If
End Sub

Public Sub cmdShowSCASettings_Click()
    If (s.isDppConnected) Then s.DppConfig.DisplaySCA = True
    RequestSCASettings
End Sub

Public Sub RequestSCASettings()
    If (s.isDppConnected) Then
        's.HwRdBkDP5Out = "SCAI=?;"
        's.HwRdBkDP5Out = ""
        s.HwRdBkDP5Out = "MCAC=?;SCAW=?;"
        s.HwRdBkDP5Out = s.HwRdBkDP5Out & "SCAI=1;SCAL=?;SCAH=?;SCAO=?;"
        s.HwRdBkDP5Out = s.HwRdBkDP5Out & "SCAI=2;SCAL=?;SCAH=?;SCAO=?;"
        s.HwRdBkDP5Out = s.HwRdBkDP5Out & "SCAI=3;SCAL=?;SCAH=?;SCAO=?;"
        s.HwRdBkDP5Out = s.HwRdBkDP5Out & "SCAI=4;SCAL=?;SCAH=?;SCAO=?;"
        s.HwRdBkDP5Out = s.HwRdBkDP5Out & "SCAI=5;SCAL=?;SCAH=?;SCAO=?;"
        s.HwRdBkDP5Out = s.HwRdBkDP5Out & "SCAI=6;SCAL=?;SCAH=?;SCAO=?;"
        s.HwRdBkDP5Out = s.HwRdBkDP5Out & "SCAI=7;SCAL=?;SCAH=?;SCAO=?;"
        s.HwRdBkDP5Out = s.HwRdBkDP5Out & "SCAI=8;SCAL=?;SCAH=?;SCAO=?;"
        s.DppConfig.ScaReadReady = False
        s.DppConfig.ScaReadBack = True
        SendCommand XMTPT_READ_CONFIG_PACKET
    End If
End Sub

Private Sub cmdStartAcquisition_Click()
    datStartAcqTime = Now
    SendCommand XMTPT_ENABLE_MCA_MCS
    Timer2.Enabled = True
End Sub

Private Sub cmdColor_Click()
    PlotColor = RgbToQbColor(PlotColor)
End Sub

Private Sub cmdDiagnostics_Click()
    SendCommand XMTPT_SEND_DIAGNOSTIC_DATA
End Sub

Private Function GetMcaFileCfg() As String
    Dim bDelay As Boolean
    s.HwCfgDP5 = ""
    's.DppConfig.bSpectrumCfg = True
    s.DppConfig.CfgReadBack = True
    SendCommand XMTPT_FULL_READ_CONFIG_PACKET
    bDelay = msDelay(50)
    GetMcaFileCfg = s.HwCfgDP5
End Function

Private Sub cmdSaveSpectrum_Click()
    Dim strFilename As String
    Dim strCfg As String
    Dim strTag As String
    Dim strDescription As String
    Dim dateStart As Date
    Dim bHaveFilename As Boolean

    bHaveFilename = GetSpectrumFilename(strFilename, CommonDialog1)
    If (bHaveFilename) Then
        If (IsDate(datStartAcqTime)) Then
            dateStart = datStartAcqTime
        Else
            dateStart = Now
        End If
        Set s.Dp5CmdList = New Collection
        MakeDp5CmdList s.Dp5CmdList
        strTag = Trim(txtSpectrumTag)
        strDescription = Trim(txtSpectrumDescription)
        strCfg = GetMcaFileCfg()
        'MsgBox strCfg
        strCfg = ProcessSpectrumCfgForFile(strCfg, s.Dp5CmdList)
        Call SaveSpectrum(strFilename, SPECTRUM, strCfg, STATUS, strTag, strDescription, dateStart)
    End If
End Sub

Private Sub cmdSingleUpdate_Click()
    Timer2.Enabled = False
    cmdSingleUpdate.Enabled = False
    If (chkDeltaMode = vbChecked) Then
        SendCommand XMTPT_SEND_CLEAR_SPECTRUM_STATUS
    Else
        SendCommand XMTPT_SEND_SPECTRUM_STATUS
    End If
    cmdSingleUpdate.Enabled = True
End Sub

Public Sub cmdRS232ComPortTest()
    'SendCommand XMTPT_SEND_STATUS
    SendCommand XMTPT_SEND_NETFINDER_PACKET
End Sub

Public Sub cmdUSBDeviceTest()
    SendCommand XMTPT_SEND_NETFINDER_PACKET
End Sub

Private Sub cmdSelectCommunications_Click()
    Dim bStatusDone As Boolean
    On Error Resume Next
    cmdSelectCommunications.Enabled = False
    'start/clear netfinder search when form loaded
    NewNetfinderRequest = True
    NetfinderUnit = 0
    InitAllEntries DppEntries
    rtbStatus.Visible = False
    Load frmDP5_Connect
    frmDP5_Connect.Show vbModal
    If (Not frmDP5_Connect.bDoNotConnect) Then
        If (s.isDppConnected) Then
            SendCommand XMTPT_SEND_STATUS
            bStatusDone = msDelay(500)
        End If

        If (lblSelectCommunications.Caption <> "Select Communications") Then
            EnableDppCmdControls True
            If (s.CurrentInterface = USB) Then
                rtbStatus.Visible = True
            End If
        Else
            EnableDppCmdControls False
        End If
    Else
        lblSelectCommunications.Caption = "Select Communications"
        s.isDppConnected = False
        EnableDppCmdControls False
    End If
    cmdSelectCommunications.Enabled = True

End Sub

Private Sub cmdStopAcquisition_Click()
    SendCommand XMTPT_DISABLE_MCA_MCS
End Sub

Private Sub cmdWriteMiscData_Click()
    SendCommandData XMTPT_WRITE_512_BYTE_MISC_DATA, txtMiscData.Text
End Sub

Private Sub Form_Initialize()
    On Error Resume Next
    LoadLibrary "shell32.dll"
    InitCommonControls
    On Error GoTo 0
End Sub

Private Sub Form_Load()
    Dim bHaveComPort As Boolean
    CurrentUSBDevice = 1
    NumUSBDevices = 0

    InitSCA
    LoadApplicationSettings Me

'    CloseDeviceHandle DppWinUSB
'    If USBDeviceNotificationHandle <> 0 Then
'        Call UnregisterDeviceNotification(USBDeviceNotificationHandle) 'Stop receiving notification messages.
'    End If
'    USBDeviceConnected = False

    InitAllEntries NfPktEntries

    s.DppConfig.CfgReadBack = False
    s.DppConfig.DisplayCfg = False
    s.DppConfig.ScaReadBack = False
    s.DppConfig.ScaReadReady = False
    s.DppConfig.DisplaySCA = False

    Set s.Dp5CmdList = New Collection
    MakeDp5CmdList s.Dp5CmdList
    s.HwCfgDP5 = ""

    EnableDppCmdControls False
    RS232ComPortTest = False
    USBDeviceTest = False
    lblVersion.BorderStyle = vbBSNone
    Set pnlStatus = StatusBar1.Panels(1)        'set the status panel to the status bar panel
    Whitespace$ = Chr$(0) + Chr$(9) + Chr$(10) + Chr$(11) + Chr$(12) + Chr$(13) + Chr$(32)
    'frmDP5_Connect.cboRS232Comm.ListIndex = 0
    If (DppComm.PortOpen) Then DppComm.PortOpen = False
    If (s.CurrentInterface = RS232) Then
        bHaveComPort = isAnyComPort()
        If (bHaveComPort) Then
            If (isComPortAvailable(DppComm.CommPort)) Then
                    'ready to open port
            Else    'open an existing port
                DppComm.CommPort = GetFirstComPort()
            End If
            DppComm.PortOpen = True
            DppComm.InputMode = comInputModeBinary
            DppComm.RThreshold = 8  ' Call OnComm after header is received
            s.CurrentInterface = RS232
        Else
            s.CurrentInterface = USB
        End If
    End If
    PlotColor = &HFF&
    USBDevicePathName = ""
    USBDeviceConnected = False
    USBDeviceNotificationHandle = 0
    pnlStatus = "DP5 test application ready..."
    lblVersion.Caption = "DP5 SDK vbDP5 v" + Right(str(App.Major), 1) + "." + Right(str(App.Minor), 2)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    SaveApplicationSettings Me

    CloseDeviceHandle DppWinUSB
    If USBDeviceNotificationHandle <> 0 Then
        Call UnregisterDeviceNotification(USBDeviceNotificationHandle) 'Stop receiving notification messages.
    End If
    'pass control back to previous windows
    SetWindowLong Me.hwnd, GWL_WNDPROC, glngPrevWndProc
    DppWinsock.Close
    CloseProgram
End Sub

Public Sub CloseProgram()
    Dim frm As Form
    For Each frm In Forms
        Unload frm
    Next frm
End Sub

Private Sub DppComm_OnComm()
    Dim PIN_LEN As Integer
    Dim X As Long
    Dim Temp() As Byte
    Dim L As Integer

    Select Case DppComm.CommEvent
        Case comEventFrame   ' framing error
            CommError = True
        Case comEventOverrun   ' overrun error
            CommError = True
        Case comEventRxOver   ' receive buffer overflow
            CommError = True
        Case comEvReceive      ' at least RThreshold characters are in the receive buffer
            If RS232HeaderReceived Then
                DppComm.InputLen = 0    ' read the whole buffer - should be the rest of the transfer
                Temp() = DppComm.Input
                If ((UBound(Temp) + 8) > UBound(PacketIn)) Then
                    'the buffer is bigger than storage, this indicates an error
                    Exit Sub
                End If
                DppComm.RThreshold = 8
                For X = 0 To UBound(Temp(), 1)
                    PacketIn(X + 8) = Temp(X)   ' PacketIn should already have the header in it
                Next X
                RS232HeaderReceived = False
                DppState.ReqProcess = ParsePacket(PacketIn(), PIN)
                ParsePacketEx PIN, DppState
            Else
                DppComm.InputLen = 8    ' only read the first 8 bytes
                Temp() = DppComm.Input
                For X = 0 To 7
                    PacketIn(X) = Temp(X)
                Next X
                If (PacketIn(0) = SYNC1_) And (PacketIn(1) = SYNC2_) Then
                    PIN_LEN = (PacketIn(4) * 256) + PacketIn(5)   ' temporarily save the length field
                    If PIN_LEN > 0 Then
                        DppComm.RThreshold = PIN_LEN    ' additional bytes to read = data length
                        RS232HeaderReceived = True
                    Else
                        DppState.ReqProcess = ParsePacket(PacketIn(), PIN)
                        ParsePacketEx PIN, DppState
                    End If
                Else
                    DppComm.InputLen = 0    ' read the whole buffer
                    Temp() = DppComm.Input  ' flush the buffer by emptying it
                End If
            End If
    End Select
End Sub

'1440
Private Function RightJustify(strParam As String, sTxtWidth As Single)
    Dim sTxtLenSp As Single
    Dim sTxtLen As Single
    Dim sTxtFill As Single
    Dim strText As String
    Dim lSpace As Long

    sTxtLen = TextWidth(strParam)
    If (sTxtLen < sTxtWidth) Then
        strText = strParam
        sTxtLenSp = TextWidth(" ")
        sTxtFill = sTxtWidth - sTxtLen
        lSpace = sTxtFill \ sTxtLenSp
        strText = Space(lSpace) & strText
        RightJustify = strText
    Else
        RightJustify = strParam
    End If
End Function

'can also use TextWidth to format display
Private Sub UpdateStatusDisplay(STATUS As Stat)
    Dim H, m, s
    Dim strStatus As String
    Dim strParam As String
    Dim strValue As String
    Dim sTxtWidth As Single

    strStatus = ""
    sTxtWidth = lblStatusDisplay(0).Width - TextWidth("  ")

    strParam = strParam & RightJustify("Device Type: ", sTxtWidth) & vbNewLine
    strValue = STATUS.strDeviceID
    strStatus = strStatus & strValue & vbNewLine

    strParam = strParam & RightJustify("Serial Number: ", sTxtWidth) & vbNewLine
    strValue = CStr(STATUS.SerialNumber)
    strStatus = strStatus & strValue & vbNewLine

    strParam = strParam & RightJustify("Firmware: ", sTxtWidth) & vbNewLine
    strValue = "v" + Format(Fix(STATUS.Firmware / 16), "0") + "." + Format(STATUS.Firmware And 15, "00")
    strStatus = strStatus & strValue & vbNewLine

    strParam = strParam & RightJustify("FPGA: ", sTxtWidth) & vbNewLine
    strValue = "v" + Format(Fix(STATUS.FPGA / 16), "0") + "." + Format(STATUS.FPGA And 15, "00")
    strStatus = strStatus & strValue & vbNewLine

    strParam = strParam & RightJustify("Fast Count: ", sTxtWidth) & vbNewLine
    strValue = Format(STATUS.FastCount, "#,###,###,##0"),
    strStatus = strStatus & strValue & vbNewLine

    strParam = strParam & RightJustify("SlowCount: ", sTxtWidth) & vbNewLine
    strValue = Format(STATUS.SlowCount, "#,###,###,##0"),
    strStatus = strStatus & strValue & vbNewLine

    strParam = strParam & RightJustify("Accumulation Time: ", sTxtWidth) & vbNewLine
    If STATUS.AccumulationTime < 1000 Then
        strValue = 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 = Format(H, "###0h ") + Format(m, "#0m ") + Format(s, "#0.0s")
    End If
    strStatus = strStatus & strValue & vbNewLine

    strParam = strParam & RightJustify("PC5 Serial Number: ", sTxtWidth) & 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 <> dppDP5G) Then
        strParam = strParam & RightJustify("Detector HV: ", sTxtWidth) & vbNewLine
        strValue = Format(STATUS.HV, "###0V")             ' round to nearest volt
        strStatus = strStatus & strValue & vbNewLine
        strParam = strParam & RightJustify("Detector Temp: ", sTxtWidth) & vbNewLine
        strValue = Format(STATUS.DET_TEMP, "##0°C")     ' round to nearest degree
        strStatus = strStatus & strValue & vbNewLine
    End If

    strParam = strParam & RightJustify("DP5 Temp: ", sTxtWidth) & vbNewLine
    strValue = str(STATUS.DP5_TEMP) & "°C"
    strStatus = strStatus & strValue & vbNewLine

    strParam = strParam & RightJustify("G.P. Counter: ", sTxtWidth) & vbNewLine
    strValue = str(STATUS.GP_COUNTER)
    strStatus = strStatus & strValue & vbNewLine

    If (STATUS.DEVICE_ID = dppDP5) Then
        strParam = strParam & RightJustify("PC5 Present: ", sTxtWidth) & vbNewLine
        strValue = str(STATUS.PC5_PRESENT)
        strStatus = strStatus & strValue & vbNewLine

        If STATUS.PC5_PRESENT Then
            strParam = strParam & RightJustify("PC5 HV Polarity: ", sTxtWidth) & vbNewLine
            If (STATUS.PC5_HV_POL) Then
                strValue = "Positive"
            Else
                strValue = "Negative"
            End If
            strStatus = strStatus & strValue & vbNewLine

            strParam = strParam & RightJustify("PC5 Preamp: ", sTxtWidth) & vbNewLine
            If (STATUS.PC5_8_5V) Then
                strValue = "+/-8.5V"
            Else
                strValue = "+/-5V"
            End If
            strStatus = strStatus & strValue & vbNewLine
        End If

        strParam = strParam & RightJustify("DP5 Temp: ", sTxtWidth) & vbNewLine
        strValue = str(STATUS.DP5_TEMP) & "°C"
        strStatus = strStatus & strValue & vbNewLine
    ElseIf (STATUS.DEVICE_ID = dppDP5G) Then
        strParam = strParam & RightJustify("PC5G Present: ", sTxtWidth) & vbNewLine
        strValue = str(STATUS.PC5_PRESENT)
        strStatus = strStatus & strValue & vbNewLine
    ElseIf (STATUS.DEVICE_ID = 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 & RightJustify("PX5 Options: ", sTxtWidth) & 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 & RightJustify("HPGe HV: ", sTxtWidth) & 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 & RightJustify("INH Polarity: ", sTxtWidth) & vbNewLine
            If STATUS.HPGe_HV_INH_POL Then
                strValue = "high"
            Else
                strValue = "low"
            End If
            strStatus = strStatus & strValue & vbNewLine
        Else
            strParam = strParam & RightJustify("PX5 Options: ", sTxtWidth) & vbNewLine
            strValue = "No Options Installed"
            strStatus = strStatus & strValue & vbNewLine
        End If
    End If

    If STATUS.ReBootFlag Then
        strStatus = strStatus & "***Reboot detected***" & vbNewLine
    End If

    lblStatusDisplay(0) = strParam
    lblStatusDisplay(1) = strStatus
End Sub

Private Sub picScope_DblClick()
    picScope.Cls
End Sub

Private Sub rtbStatus_Click()
    rtbStatus.Text = ""
End Sub

Private Sub Timer1_Timer()
    DppComm.RThreshold = 8  ' 8 byte ACK packet expected
    Timer1.Enabled = False
End Sub

Private Sub Timer2_Timer()
    If (chkDeltaMode = vbChecked) Then
        SendCommand XMTPT_SEND_CLEAR_SPECTRUM_STATUS
    Else
        SendCommand XMTPT_SEND_SPECTRUM_STATUS
    End If
End Sub

Private Sub Timer3_Timer()
    Timeout_flag = True
    Netfinder_active = False
    Timer3.Enabled = False  ' is this right?
End Sub

'------------------------------------------------------------------------------
' Called when a WM_DEVICECHANGE message has arrived,
' indicating that a device has been attached or removed.
'------------------------------------------------------------------------------
' parameter "m" A public message with information about the device.
Public Sub OnDeviceChange(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long)
    Dim m As Message
    m.hwnd = hwnd
    m.Msg = Msg
    m.wParam = wParam
    m.lParam = lParam
    On Error GoTo OnDeviceChangeErr
    'Debug.Print " hWnd = " & hWnd & " Msg = " & Msg & " wParam = " & wParam & " lParam = " & lParam
    If (m.wParam = DBT_DEVICEARRIVAL) Then
        ' If WParam contains DBT_DEVICEARRIVAL, a device has been attached.
        ' Find out if it's the device we're communicating with.
        If DeviceNameMatch(m, USBDevicePathName) Then
            UpdateStatusList rtbStatus, "Device attached.", vbBlue
            UpdateStatusList rtbStatus, "Reconnecting to device...", RGB(128, 0, 128)
            UpdateStatusList frmDP5_Connect.rtbStatus, "Device attached.", vbBlue
            UpdateStatusList frmDP5_Connect.rtbStatus, "Reconnecting to device...", RGB(128, 0, 128)
            frmDP5_Connect.cmdFindDevice_Click
            USB_Default_Timeout = True     ' flag that default timeout is in use
        End If
    ElseIf (m.wParam = DBT_DEVICEREMOVECOMPLETE) Then
        ' If WParam contains DBT_DEVICEREMOVAL, a device has been removed.
        ' Find out if it's the device we're communicating with.
        If DeviceNameMatch(m, USBDevicePathName) Then
            UpdateStatusList rtbStatus, "Device removed.", vbRed
            UpdateStatusList frmDP5_Connect.rtbStatus, "Device removed.", vbRed
            ' Set DeviceConnected False so on the next data-transfer attempt,
            ' OpenDevice() will be called to look for the device
            ' and get a new handle.
            USBDeviceConnected = False
        End If
    End If
    Exit Sub
OnDeviceChangeErr:
    Call ProcessError(Err)
End Sub

Public Sub RemCallParsePacket(ByRef PacketIn() As Byte)
    DppState.ReqProcess = ParsePacket(PacketIn(), PIN)
    ParsePacketEx PIN, DppState
End Sub

Private Sub ParsePacketEx(PIN As Packet_In, 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(PIN As Packet_In, DppState As DppStateType)
    Dim Buffer(4095) As Byte    '0-4095, 4096 bytes
    Dim strDisplay As String

    Dim idxNfInfo As Integer
    For idxNfInfo = 0 To (PIN.LEN - 1)
        Buffer(idxNfInfo) = PIN.DATA(idxNfInfo)
    Next
    InitEntry NfPktEntries(DppState.Interface)
    AddEntry NfPktEntries(DppState.Interface), Buffer, 0
    If (RS232ComPortTest) Then
        RS232ComPortTest = False
        strDisplay = EntryToStrRS232(NfPktEntries(DppState.Interface), "RS232 - COM" & DppComm.CommPort)
        'MsgBox NfPktEntries(DppState.Interface).str_display
        frmDP5_Connect.txtRS232Status = ""
        frmDP5_Connect.txtRS232Status = strDisplay
        isDppFound(RS232) = True
        frmDP5_Connect.lblDppFound(RS232).Visible = True
        pnlStatus = "RS232 NetFind Found" + vbCrLf
    ElseIf (USBDeviceTest) Then
        USBDeviceTest = False
        strDisplay = EntryToStrUSB(NfPktEntries(DppState.Interface), "USB Device " & CurrentUSBDevice & " of " & NumUSBDevices)
        frmDP5_Connect.rtbStatus = ""
        frmDP5_Connect.rtbStatus = strDisplay
        isDppFound(USB) = True
        frmDP5_Connect.lblDppFound(USB).Visible = True
        pnlStatus = "USB NetFind Found" + vbCrLf
    End If

End Sub

Private Sub ProcessCfgReadEx(PIN As Packet_In, DppState As DppStateType)
    Dim cstrRawCfgIn As String
    'Dim cstrCh As String
    Dim cstrCmdData As String
    Dim cstrCmdD As String
    Dim strCfg As String
    Dim cstrDisplayCfgOut As String
    Dim idxCfg As Long
    Dim varCmd As Variant
    Dim strHwCfgDP5 As String

    cstrRawCfgIn = ""
    strHwCfgDP5 = ""
    ' =============================
    ' === Create Raw Configuration Buffer From Hardware ===
    For idxCfg = 0 To PIN.LEN - 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
    'MsgBox cstrRawCfgIn
    ' =============================

    If (s.DppConfig.DisplayCfg) Then
        s.DppConfig.DisplayCfg = False
        strCfg = cstrRawCfgIn
        cstrDisplayCfgOut = cstrRawCfgIn
        For Each varCmd In s.Dp5CmdList
            cstrCmdD = CStr(varCmd)
            If (Len(cstrCmdD) > 0) Then
                cstrDisplayCfgOut = ReplaceCmdDesc(cstrCmdD, cstrDisplayCfgOut)
            End If
        Next
'        CopyDp5CfgToClip(strCfg,cstrDisplayCfgOut);
        frmDppConfigDisplay.m_strMessage = cstrDisplayCfgOut
        'frmDppConfigDisplay.m_strMessage = cstrRawCfgIn

        frmDppConfigDisplay.m_strDelimiter = ";"
        Load frmDppConfigDisplay
        frmDppConfigDisplay.m_strTitle = "DPP Configuration"
        frmDppConfigDisplay.Show vbModal

        'Exit Sub
    ElseIf (s.DppConfig.CfgReadBack) Then
        s.DppConfig.CfgReadBack = False
        s.HwCfgDP5 = strHwCfgDP5
        s.cstrRawCfgIn = cstrRawCfgIn
        s.HwCfgReady = True
    ElseIf (s.DppConfig.ScaReadBack) Then
        s.DppConfig.ScaReadBack = False
        s.HwScaCfgDP5 = strHwCfgDP5
        s.cstrRawScaCfgIn = cstrRawCfgIn
        s.HwScaCfgReady = True
        If (s.DppConfig.DisplaySCA) Then
            SCACfgParser sca, s.HwScaCfgDP5
            MsgBox SCAStringALLDisplay(sca)
            'MsgBox s.HwScaCfgDP5 & vbNewLine & "++++" & vbNewLine & s.cstrRawScaCfgIn & vbNewLine
        End If
'    ElseIf (s.DppConfig.bSpectrumCfg) Then
'        s.DppConfig.bSpectrumCfg = False
'        cstrDisplayCfgOut = cstrRawCfgIn
'        For Each varCmd In s.Dp5CmdList
'            cstrCmdD = CStr(varCmd)
'            If (Len(cstrCmdD) > 0) Then
'                cstrDisplayCfgOut = AppendCmdDesc(cstrCmdD, cstrDisplayCfgOut)
'            End If
'        Next
'        s.HwCfgDP5 = cstrDisplayCfgOut
'        cstrRawCfgIn = cstrRawCfgIn
'        s.HwCfgReady = True

        'MsgBox strHwCfgDP5 & vbNewLine & "++++" & vbNewLine & cstrRawCfgIn & vbNewLine
        'MsgBox s.HwScaCfgDP5 & vbNewLine & "++++" & vbNewLine & s.cstrRawScaCfgIn & vbNewLine
        'WriteTextFile App.Path & "\scacfg.hm", s.HwScaCfgDP5
        'WriteTextFile App.Path & "\scacfg.hm", s.cstrRawScaCfgIn
        s.DppConfig.DisplaySCA = False
        s.DppConfig.ScaReadReady = True
    End If

    s.DppConfig.DisplayCfg = False
    s.DppConfig.CfgReadBack = False
    s.DppConfig.ScaReadBack = False
    s.DppConfig.DisplaySCA = False

'    cstrCmdData = GetCmdData("MCAS", cstrRawCfgIn) ' mca mode
'    If (Not cstrCmdData.CompareNoCase("MCS")) Then
'        s.profile->m_nAcquireMode = ACQ_MODE_MCS
'    Else
'        s.profile->m_nAcquireMode = ACQ_MODE_MCA
'    End If
'    If (S.DppConfig.isDeltaMode) Then
'        s.profile->m_nAcquireMode = ACQ_MODE_DELTA
'    End If

'    cstrCmdData = GetCmdData("MCAC", cstrRawCfgIn) ' channels
'    if ((atoi(cstrCmdData) > 0) && (atoi(cstrCmdData) <= 8192)) {
'        s.DppConfig.mcaCH = atoi(cstrCmdData);
'    else
'        s.DppConfig.mcaCH = 1024;
'    end if
'
'    cstrCmdData = GetCmdData("THSL",cstrRawCfgIn); ' LLD thresh
'    s.DppConfig.SlowThresholdPct = atof(cstrCmdData);
'
'    cstrCmdData = GetCmdData("THFA",cstrRawCfgIn); ' fast thresh
'    s.DppConfig.FastChThreshold = atoi(cstrCmdData);
'
'    cstrCmdData = GetCmdData("TPEA",cstrRawCfgIn); ' peak time
'    s.DppConfig.RiseUS = atof(cstrCmdData);
'
'    cstrCmdData = GetCmdData("GAIN",cstrRawCfgIn); ' gain
'    s.DppConfig.cstrGainDisplayValue = cstrCmdData + "x";
'
'    s.DppConfig.strPresetCmd = "";
'    s.DppConfig.strPresetVal = "";
'
'    cstrCmdData = GetCmdData("PREC",cstrRawCfgIn); 'preset count
'    s.DppConfig.PresetCount = atoi(cstrCmdData);
'    if (s.DppConfig.PresetCount > 0) {
'        if (s.DppConfig.strPresetCmd.GetLength() > 0) { s.DppConfig.strPresetCmd += "/"; }
'        if (s.DppConfig.strPresetVal.GetLength() > 0) { s.DppConfig.strPresetVal += "/"; }
'        s.DppConfig.strPresetCmd += "Cnt";
'        s.DppConfig.strPresetVal += cstrCmdData;
'    end if
'
'    cstrCmdData = GetCmdData("PRET",cstrRawCfgIn); 'preset actual time
'    s.DppConfig.PresetAcq = atof(cstrCmdData);
'    if (s.DppConfig.PresetAcq > 0) {
'        if (s.DppConfig.strPresetCmd.GetLength() > 0) { s.DppConfig.strPresetCmd += "/"; }
'        if (s.DppConfig.strPresetVal.GetLength() > 0) { s.DppConfig.strPresetVal += "/"; }
'        s.DppConfig.strPresetCmd += "Acq";
'        s.DppConfig.strPresetVal += cstrCmdData;
'    }
'
'    cstrCmdData = GetCmdData("PRER",cstrRawCfgIn); ' preset real time
'    s.DppConfig.PresetRt = atof(cstrCmdData);
'    if (s.DppConfig.PresetRt > 0) {
'        if (s.DppConfig.strPresetCmd.GetLength() > 0) { s.DppConfig.strPresetCmd += "/"; }
'        if (s.DppConfig.strPresetVal.GetLength() > 0) { s.DppConfig.strPresetVal += "/"; }
'        s.DppConfig.strPresetCmd += "Real";
'        s.DppConfig.strPresetVal += cstrCmdData;
'    end if
'
'    if (s.DppConfig.strPresetCmd.GetLength() = 0) {
'        s.DppConfig.strPresetCmd += "None";
'    end if
'    if (s.DppConfig.strPresetVal.GetLength() = 0) {
'        's.DppConfig.strPresetVal += "";
'    end if
'
'    cstrCmdData = GetCmdData("CLCK",cstrRawCfgIn); ' fpga clock mode
'    if (atoi(cstrCmdData) = 80) {
'        s.DppConfig.b80MHzMode = TRUE;
'    else
'        s.DppConfig.b80MHzMode = FALSE;
'    end if
'
'    ' DP5 oscilloscope support
'    cstrCmdData = GetCmdData("INOF",cstrRawCfgIn); ' osc. Input offset
'    s.DppConfig.cstrInputOffset = cstrCmdData;
'
'    cstrCmdData = GetCmdData("DACO",cstrRawCfgIn); ' osc. DAC output
'    s.DppConfig.cstrAnalogOut = cstrCmdData;
'
'    cstrCmdData = GetCmdData("DACF",cstrRawCfgIn); ' osc. DAC offset
'    s.DppConfig.cstrOutputOffset = cstrCmdData;
'
'    cstrCmdData = GetCmdData("AUO1",cstrRawCfgIn); ' osc. AUX_OUT1
'    s.DppConfig.cstrTriggerSource = cstrCmdData;
'
'    cstrCmdData = GetCmdData("SCOE",cstrRawCfgIn); ' osc. Scope trigger edge
'    s.DppConfig.cstrTriggerSlope = cstrCmdData;
'
'    cstrCmdData = GetCmdData("SCOT",cstrRawCfgIn); ' osc. Scope trigger position
'    s.DppConfig.cstrTriggerPosition = cstrCmdData;
'
'    cstrCmdData = GetCmdData("SCOG",cstrRawCfgIn); ' osc. Scope gain
'    s.DppConfig.cstrScopeGain = cstrCmdData;
'
'    cstrCmdData = GetCmdData("MCAS",cstrRawCfgIn); ' Acq Mode
'    s.DppConfig.AcqMode = 0;
'    s.DppConfig.cstrMcaMode = "MCA";
'    if (cstrCmdData = "NORM") {
'        s.DppConfig.cstrMcaMode = "MCA";
'    Elseif  (cstrCmdData = "MCS") {
'        s.DppConfig.cstrMcaMode = "MCS";
'        s.DppConfig.AcqMode = 1;
'    Elseif  (cstrCmdData.GetLength() > 0) {
'        s.DppConfig.cstrMcaMode = cstrCmdData;
'    }
'    s.DppConfig.UpdateScopeCfg = TRUE;
End Sub

Private Sub DisplayError(PIN As Packet_In, DppState As DppStateType)
    pnlStatus = PID2_TextToString("Received packet", CByte(PIN.STATUS))
    ' bad PID, assigned by ParsePacket
    If (PIN.STATUS = PID2_ACK_PID_ERROR) Then
        pnlStatus = "Received packet: PID1=0x" + FmtHex(PIN.PID1, 2) + ", PID2=0x" + FmtHex(PIN.PID2, 2) + ", LEN=" + str(PIN.LEN) + vbCrLf,
    End If
End Sub

Private Sub ProcessAck(PID2 As Byte)
    pnlStatus = PID2_TextToString("ACK", PID2)
End Sub

Private Sub ProcessStatusEx(PIN As Packet_In, DppState As DppStateType)
    Dim X As Integer
    For X = 0 To 63
        STATUS.RAW(X) = PIN.DATA(X)
    Next X
    Call Process_Status(STATUS)
    RequestScopeData STATUS.SCOPE_DR
    UpdateStatusDisplay STATUS
'    If (RS232ComPortTest) Then
'        frmDP5_Connect.txtRS232Status = ""
'        RS232ComPortTest = False
'        frmDP5_Connect.txtRS232Status = ShowStatusValueStrings(STATUS)
'        If (STATUS.SerialNumber > 0) Then
'            isDppFound(RS232) = True
'            frmDP5_Connect.lblDppFound(RS232).Visible = True
'        Else
'            isDppFound(RS232) = False
'            frmDP5_Connect.lblDppFound(RS232).Visible = False
'        End If
'    End If
    pnlStatus = "Status Received" + vbCrLf
End Sub

Private Sub ProcessSpectrumEx(PIN As Packet_In, DppState As DppStateType)
    Dim X As Integer

    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) = CLng(PIN.DATA(X * 3)) + CLng(PIN.DATA(X * 3 + 1)) * 256& + CLng(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).Value, optPlotType(1).Value)
    cmdSaveSpectrum.Enabled = True
    UpdateStatusDisplay STATUS

End Sub

Private Sub ProcessScopeDataEx(PIN As Packet_In, DppState As DppStateType)
    Dim X As Integer
    For X = 0 To 2047
        Scope(X) = PIN.DATA(X)
    Next X
    'Scope_Packet_Received = True
    Call Plot_Scope(picScope, Scope, PlotColor)
    ArmScope
End Sub

Private Sub ProcessTextDataEx(PIN As Packet_In, DppState As DppStateType)
    Dim X As Integer
    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 ProcessInetSettingsEx(PIN As Packet_In, DppState As DppStateType)
''''' Ethernet settings
''''                        If PIN.DATA(0) = &HFF Then
''''                            btnIPDynamic.Value = True
''''                        Else
''''                            btnIPStatic.Value = True
''''                        End If
''''
''''                        For X = 0 To 11
''''                            txtIP(X).Text = Trim(Str(PIN.DATA(X + 1)))
''''                        Next X
''''
''''                        ' Note: port isn't supported yet, but it's at PIN.DATA(17-18)
''''                        txtMAC.Text = ""
''''                        For X = 0 To 5
''''                            'txtMAC.Text = txtMAC.Text + H$(PIN.DATA(17 + X), 2)
''''                            txtMAC.Text = txtMAC.Text + H$(PIN.DATA(19 + X), 2)
''''                            If X < 5 Then
''''                                txtMAC.Text = txtMAC.Text + ":"
''''                            End If
''''                        Next X
'''    Dim X As Integer
'''    For X = 0 To 2047
'''        Scope(X) = PIN.DATA(X)
'''    Next X
'''    'Scope_Packet_Received = True
'''    Call Plot_Scope(picScope, Scope, PlotColor)
'''    ArmScope
End Sub

Private Sub ProcessDiagDataEx(PIN As Packet_In, DppState As DppStateType)
    Dim dd As DiagDataType
    Dim strDiag As String
    Call Process_Diagnostics(PIN, dd)
    strDiag = DiagnosticsToString(dd)
    txtRawStatus = strDiag

''''    Dim X As Integer
''''    For X = 0 To 2047
''''        Scope(X) = PIN.DATA(X)
''''    Next X
''''    'Scope_Packet_Received = True
''''    Call Plot_Scope(picScope, Scope, PlotColor)
''''    ArmScope
End Sub

Private Sub ProcessSCADataEx(PIN As Packet_In, DppState As DppStateType)

        'ElseIf ((PIN.PID1 = PID1_RCV_SCA) And (PIN.PID2 = RCVPT_SCA)) Then 'sca packet
            'ParsePacket = preqProcessSCAData

'                Case &H83   ' SCA packet
'                    If (PIN.PID2 = 1) Then
'                        For X = 0 To 15
'                            sca& = PIN.DATA(X * 4) + PIN.DATA(X * 4 + 1) * 256& + PIN.DATA(X * 4 + 2) * 65536 + PIN.DATA(X * 4 + 3) * 16777216
'                            txtSCACount(X).Text = Str(sca&)
'                        Next X
'                    End If

'Call Process_Diagnostics

''''    Dim X As Integer
''''    For X = 0 To 2047
''''        Scope(X) = PIN.DATA(X)
''''    Next X
''''    'Scope_Packet_Received = True
''''    Call Plot_Scope(picScope, Scope, PlotColor)
''''    ArmScope
End Sub

Private Sub ArmScope()
    If chkAutoRearm.Value = vbChecked Then SendCommand XMTPT_ARM_DIGITAL_OSCILLOSCOPE 'Call btnArmTrigger_Click
End Sub

Private Sub RequestScopeData(ScopeDataReady As Boolean)
    If ScopeDataReady Then SendCommand XMTPT_SEND_SCOPE_DATA
End Sub

Public Sub SendCommand(XmtCmd As TRANSMIT_PACKET_TYPE)
    Dim HaveBuffer As Boolean
    Dim SentPkt As Boolean

    HaveBuffer = DP5_CMD(BufferOUT, XmtCmd)
    If (HaveBuffer) Then
        Select Case s.CurrentInterface
            Case RS232
                SentPkt = SendPacketRS232(DppComm, BufferOUT, PacketIn())
            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
            Case ETHERNET
                SentPkt = SendPacketInet(DppWinsock, BufferOUT, PacketIn())
        End Select
    End If
End Sub

Public Sub SendCommandData(XmtCmd As TRANSMIT_PACKET_TYPE, DataOut As Variant)
    Dim HaveBuffer As Boolean
    Dim SentPkt As Boolean

    HaveBuffer = DP5_CMD_Data(BufferOUT, XmtCmd, DataOut)
    If (HaveBuffer) Then
        Select Case s.CurrentInterface
            Case RS232
                SentPkt = SendPacketRS232(DppComm, BufferOUT, PacketIn())
            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
            Case ETHERNET
                SentPkt = SendPacketInet(DppWinsock, BufferOUT, PacketIn())
        End Select
    End If
End Sub

Private Sub DppWinsock_DataArrival(ByVal bytesTotal As Long)
    Dim temp1() As Byte
    Dim LEN_temp As Integer
    Dim idxDataIn As Long

    DppWinsock.GetData temp1()
    If Netfinder_active Then
        If (temp1(0) = 1) And (Netfinder_Seq = (temp1(2) * 256 + temp1(3))) Then
            frmDP5_Connect.txtIP(0).Text = Trim(str(temp1(20)))
            frmDP5_Connect.txtIP(1).Text = Trim(str(temp1(21)))
            frmDP5_Connect.txtIP(2).Text = Trim(str(temp1(22)))
            frmDP5_Connect.txtIP(3).Text = Trim(str(temp1(23)))
            rtbStatus = "IP: " & str(temp1(20)) + "." & str(temp1(21)) + "." & str(temp1(22)) + "." & str(temp1(23)) & vbCrLf
        Else
            rtbStatus = "Bad version or Seq No" + vbCrLf
        End If
        Netfinder_active = False
    Else
        For idxDataIn = 0 To UBound(temp1()) '(bytesTotal - 1) - DppWinsock.BytesReceived
            PacketIn(idxDataIn + UDP_offset) = temp1(idxDataIn)
        Next idxDataIn
        UDP_offset = UDP_offset + UBound(temp1()) + 1 ' now UDP_offset = index of next empty location, and total # of bytes rcvd

        If DppWinsock.BytesReceived Then  ' another packet to get?
            DppWinsock.GetData temp1()
            For idxDataIn = 0 To UBound(temp1()) '(bytesTotal - 1) - DppWinsock.BytesReceived
                PacketIn(idxDataIn + UDP_offset) = temp1(idxDataIn)
            Next idxDataIn
            UDP_offset = UDP_offset + UBound(temp1()) + 1 ' now UDP_offset = index of next empty location, and total # of bytes rcvd
        End If

        If ((PacketIn(0) = &HF5) And (PacketIn(1) = &HFA)) Then
            LEN_temp = CInt(PacketIn(4)) * 256 + CInt(PacketIn(5))  ' only use LEN field if sync bytes are OK
        Else
            UDP_offset = 0  ' if sync bytes not OK, restart packet
        End If

        If ((PacketIn(0) = &HF5) And (PacketIn(1) = &HFA) And (UDP_offset >= (LEN_temp + 8))) Then
            DppState.ReqProcess = ParsePacket(PacketIn(), PIN)
            ParsePacketEx PIN, DppState
        End If

    End If
End Sub

Private Sub NetFinderWinSock_DataArrival(ByVal bytesTotal As Long)
    Dim idxEntry As Long
    Dim NetFinderData() As Byte
    Dim MoreNetfinder As Boolean
    Dim destPort As Long

    NetFinderWinSock.GetData NetFinderData()
    destPort = NetFinderWinSock.RemotePort
    If NewNetfinderRequest Then
        NetfinderUnit = 0
        NewNetfinderRequest = False
    End If

    Do
        If (NetfinderUnit >= 4) Then Exit Do
        If (NetFinderData(0) = 1) And (Netfinder_Seq = (NetFinderData(2) * 256 + NetFinderData(3))) Then
            InitEntry DppEntries(NetfinderUnit)
            AddEntry DppEntries(NetfinderUnit), NetFinderData, destPort
            frmDP5_Connect.lblUnit(NetfinderUnit) = DppEntries(NetfinderUnit).str_display
            frmDP5_Connect.lblUnit(NetfinderUnit).BackColor = AlertEntryToCOLORREF(DppEntries(NetfinderUnit))
            frmDP5_Connect.cmdSelectIP(NetfinderUnit).Visible = True
            If (SearchIp = DppEntries(NetfinderUnit).SockAddr) Then
                isDppFound(ETHERNET) = True
                frmDP5_Connect.lblDppFound(ETHERNET).Visible = True
                s.CurrentInterface = ETHERNET
                frmDP5_Connect.lblIpFound.Caption = IpAddrConvert(SearchIp)
            End If
            NetfinderUnit = NetfinderUnit + 1
        Else
            'TextLog txtLog, "Bad version or Seq No" + vbCrLf
        End If
        If NetFinderWinSock.BytesReceived > 0 Then
            NetFinderWinSock.GetData NetFinderData()
            MoreNetfinder = True
        Else
            MoreNetfinder = False
        End If
    Loop While MoreNetfinder And (NetfinderUnit < 4)
End Sub

Private Sub EnableDppCmdControls(EnableCmd As Boolean)
    '---- Communications ----------------------------
    'cmdSelectCommunications.Enabled = EnableCmd

    '---- Configuration -----------------------------
    'cmdEditConfiguration.Enabled = EnableCmd
    cmdShowConfiguration.Enabled = EnableCmd

    '---- Acquisition -------------------------------
    cmdStartAcquisition.Enabled = EnableCmd
    cmdStopAcquisition.Enabled = EnableCmd
    cmdSingleUpdate.Enabled = EnableCmd
    cmdClearData.Enabled = EnableCmd
    'cmdColor.Enabled = EnableCmd

    '---- MCA Spectrum File -------------------------
    cmdSaveSpectrum.Enabled = EnableCmd
    'cmdChangeSpectrumSavePath.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


frmDP5_Connect Source Code

Option Explicit

Public bDoNotConnect As Boolean

Private Sub btnOK_Click()
    Dim strSelectedComm As String
    bDoNotConnect = False
    strSelectedComm = "Select Communications"
    Select Case s.CurrentInterface    'if found display...
        Case RS232      'display com port
            If (isDppFound(RS232)) Then
                strSelectedComm = "RS232 - " & "COM" & frmDP5.DppComm.CommPort
                s.isDppConnected = True
            End If
        Case USB        'display WinUSB
            If (isDppFound(USB)) Then
                strSelectedComm = "USB - " & "WinUSB"
                s.isDppConnected = True
            End If
        Case ETHERNET   'display ip address
            If (isDppFound(ETHERNET)) Then
                strSelectedComm = "IP - " & frmDP5.DppWinsock.RemoteHost
                s.isDppConnected = True
            End If
        Case Else
            s.isDppConnected = False
    End Select
    frmDP5.lblSelectCommunications.Caption = strSelectedComm
    's.SockAddr =
    SaveApplicationSettings Me, True, False, True
    Unload Me
End Sub

Private Sub cboRS232Comm_Click()
    RS232ComPortTest = False    'turn comport test  off if running
    txtRS232Status.Text = ""
    lblDppFound(RS232).Visible = False
    isDppFound(RS232) = False

    If (cboRS232Comm.ListIndex >= 0) Then
        s.ComPort = cboRS232Comm.ItemData(cboRS232Comm.ListIndex)
        'Call SetComPort
    End If

    If (frmDP5.DppComm.PortOpen) Then
        cmdRequestDataAndStatus.Enabled = True
    Else
        cmdRequestDataAndStatus.Enabled = False
    End If
End Sub

Private Sub chkLock_Click()
    InetLockDpp = CBool(chkLock.Value)
    If (Not InetLockDpp) Then
        InetShareDpp = True
        chkShare.Enabled = True
    Else
        InetShareDpp = False
        chkShare.Enabled = False
    End If
End Sub

Private Sub chkShare_Click()
    InetShareDpp = CBool(chkShare.Value)
End Sub

Private Sub cmdCloseDevice_Click()
    If (USBDeviceConnected) Then
        CloseDeviceHandle DppWinUSB
        cmdDisableUSBNotify_Click
        USBDeviceConnected = False
    End If
End Sub

Private Sub cmdCountDevices_Click()
    NumUSBDevices = CountDP5WinusbDevices()
    lblNumUSBDevices = NumUSBDevices
    If (NumUSBDevices > 1) Then
        If (CurrentUSBDevice > NumUSBDevices) Then
            CurrentUSBDevice = NumUSBDevices
            udSelectDevice.Value = CurrentUSBDevice
        End If
        udSelectDevice.Max = NumUSBDevices
        udSelectDevice.Enabled = True
    Else    'disable spin and device selection
        udSelectDevice.Enabled = False
        CurrentUSBDevice = 1
        udSelectDevice.Value = 1
        udSelectDevice.Max = 1
    End If
End Sub

Private Sub cmdDisableUSBNotify_Click()
    If USBDeviceNotificationHandle <> 0 Then
        Call UnregisterDeviceNotification(USBDeviceNotificationHandle) 'Stop receiving notification messages.
    End If
    SetWindowLong Me.hwnd, GWL_WNDPROC, glngPrevWndProc             'pass control back to previous windows
End Sub

Private Sub EthernetConnect()    ' this is Public so Form2 can call it
    Dim P As Integer

    If frmDP5.DppWinsock.State > 0 Then
        frmDP5.DppWinsock.Close
    End If
    frmDP5.DppWinsock.RemoteHost = Trim(txtIP(0).Text) + "." + Trim(txtIP(1).Text) + "." + Trim(txtIP(2).Text) + "." + Trim(txtIP(3).Text)
    frmDP5.DppWinsock.RemotePort = txtUDPPort.Text
    s.CurrentInterface = ETHERNET
End Sub

Private Sub cmdDoNotConnect_Click()
    bDoNotConnect = True
    s.isDppConnected = False
    DoEvents
    frmDP5.lblSelectCommunications.Caption = "Select Communications"
    s.isDppConnected = False
    DoEvents
    Unload Me
End Sub

Private Sub cmdRequestDataAndStatus_Click()
    RS232ComPortTest = True
    txtRS232Status.Text = ""
    lblDppFound(RS232).Visible = False
    isDppFound(RS232) = False
    s.CurrentInterface = RS232
    Call SetComPort
    frmDP5.cmdRS232ComPortTest
End Sub

Private Sub cmdSelectIP_Click(Index As Integer)
    lblUnit_Click Index
End Sub

Private Sub Form_Load()
    Dim idxCommType As Long
    Dim byteSockAddr As Variant
    Dim idxIp As Long
    Dim iCurrentPort As Integer
    Dim bHaveComPort As Boolean

    bDoNotConnect = True
    iCurrentPort = 0
    bHaveComPort = False
    'The port must be closed to scan for available ports
    If (frmDP5.DppComm.PortOpen) Then
        frmDP5.DppComm.PortOpen = False
    End If
    CreateComPortResource cboRS232Comm

    If (cboRS232Comm.ListCount > 0) Then
        If (IsPortInList(cboRS232Comm, s.ComPort)) Then
            If (frmDP5.DppComm.CommPort <> s.ComPort) Then
                frmDP5.DppComm.CommPort = s.ComPort
            End If
            cboRS232Comm.ListIndex = GetPortListIndex(cboRS232Comm, s.ComPort)
            bHaveComPort = True
        Else        'have ports but not on list
            cboRS232Comm.ListIndex = 0
        End If
        If (bHaveComPort) Then
            'if ports available and port is closed open port
            If (Not frmDP5.DppComm.PortOpen) Then
                frmDP5.DppComm.PortOpen = True
            End If
        End If
    End If

    If (s.CurrentInterface = USB) Then
        cmdCloseDevice_Click
    End If

    For idxIp = 0 To 3
        lblIpId(idxIp).Caption = "I" & vbNewLine & "P" & vbNewLine & CStr(idxIp + 1)
        lblIpId(idxIp).BorderStyle = ccNone
        lblIpId(idxIp).Visible = False
    Next

    lblNetFinderErrors = ""

    'start/clear netfinder search when form loaded
    NewNetfinderRequest = True
    NetfinderUnit = 0
    InitAllEntries DppEntries

    LoadApplicationSettings Me, True, False, False

    strCommStatus = ""
    lblIpFound.BorderStyle = vbBSNone
    lblIpFound = ""

    For idxCommType = 0 To 2
        lblDppFound(idxCommType).BackColor = colorLightSteelBlue
        lblDppFound(idxCommType).ForeColor = colorLightSlateGray
        lblDppFound(idxCommType).Visible = False
        isDppFound(idxCommType) = False
    Next

    If (s.SockAddr <> 0) Then
        byteSockAddr = IpAddrConvert(s.SockAddr, True)
        txtIP(0) = (CStr(byteSockAddr(0)))
        txtIP(1) = (CStr(byteSockAddr(1)))
        txtIP(2) = (CStr(byteSockAddr(2)))
        txtIP(3) = (CStr(byteSockAddr(3)))
    End If

    If ((s.InetPort > 0) And (s.InetPort < &HFFFF)) Then
        txtUDPPort = CStr(s.InetPort)
    End If

    cmdCountDevices_Click

    Select Case s.CurrentInterface
        Case RS232
            optComm_Click RS232
        Case USB
            optComm_Click USB
        Case ETHERNET
            optComm_Click ETHERNET
        Case Else
            optComm_Click USB
    End Select

End Sub

Private Sub Form_Paint()
    DoEvents
End Sub

Private Sub Form_Unload(Cancel As Integer)
    On Error Resume Next
    'btnOK_Click
    Unload Me
End Sub

Private Sub lblIpId_Click(Index As Integer)
    lblUnit_Click Index
End Sub

Private Sub lblUnit_Click(Index As Integer)
    If (DppEntries(Index).SockAddr = 0) Then Exit Sub
    s.SockAddr = DppEntries(Index).SockAddr
    s.cstrSockAddr = IpAddrConvert(s.SockAddr)
    s.InetPort = CLng(Val(txtUDPPort.Text))
    If ((s.InetPort <= 0) Or (s.InetPort >= &HFFFF)) Then
        s.InetPort = 10001
    End If
    txtIP(0) = (CStr(DppEntries(Index).ip(0)))
    txtIP(1) = (CStr(DppEntries(Index).ip(1)))
    txtIP(2) = (CStr(DppEntries(Index).ip(2)))
    txtIP(3) = (CStr(DppEntries(Index).ip(3)))
    EthernetConnect
End Sub

Public Sub cmdFindDevice_Click()
' Search for a specific device.
    Dim isDetected As Boolean
    'On Error GoTo cmdFindDevice_ClickErr
    cmdFindDevice.Enabled = False
    'Uses DppWinUSB defined in DppWinUSB
    cmdCloseDevice_Click

    isDetected = OpenDevice(frmDP5.hwnd, DppWinUSB, USBDeviceConnected, USBDevicePathName, CurrentUSBDevice - 1)
    DeviceConnectedDisplay rtbStatus, USBDeviceConnected
    DeviceConnectedDisplay frmDP5.rtbStatus, USBDeviceConnected
    cmdFindDevice.Enabled = True
    If (USBDeviceConnected) Then
        lblDppFound(USB).Visible = True
        isDppFound(USB) = True
        s.CurrentInterface = USB
        USBDeviceTest = True
        frmDP5.cmdUSBDeviceTest
    Else
        lblDppFound(USB).Visible = False
        isDppFound(USB) = False
    End If
    Exit Sub
cmdFindDevice_ClickErr:
    Call ProcessError(Err)
End Sub

Private Sub btnFindIP_Click()
    Dim strSearchIp As String
    isDppFound(ETHERNET) = False
    lblDppFound(ETHERNET).Visible = False
    lblIpFound.Caption = ""
    strSearchIp = txtIP(0).Text + "." + txtIP(1).Text + "." + txtIP(2).Text + "." + txtIP(3).Text
    SearchIp = IpAddrConvert(strSearchIp)
    NetFinderSearch
End Sub

Private Function SetComPort() As Integer
    On Error Resume Next
    Dim OldCommPort As Integer
    Dim iPort As Integer

    iPort = cboRS232Comm.ItemData(cboRS232Comm.ListIndex)
    If (cboRS232Comm.ListCount > 0) Then
        If (iPort < 1) Then
            cboRS232Comm.ListIndex = 0
            iPort = cboRS232Comm.ItemData(cboRS232Comm.ListIndex)
        End If
    End If

    OldCommPort = frmDP5.DppComm.CommPort       'Save the current port
    SetComPort = 0
    If (iPort <> OldCommPort) Then      'the port is not set, update the port number
        If (frmDP5.DppComm.PortOpen) Then frmDP5.DppComm.PortOpen = False      'close port if open
        frmDP5.DppComm.CommPort = iPort                                 'set the port
        If (Not frmDP5.DppComm.PortOpen) Then frmDP5.DppComm.PortOpen = True    'reopen the port
        If (Err.Number <> 0) Then   'port error
            MsgBox Err.Description & vbNewLine & " Setting to old port COM" & OldCommPort
            Err.Clear
            If (frmDP5.DppComm.PortOpen) Then frmDP5.DppComm.PortOpen = False
            frmDP5.DppComm.CommPort = OldCommPort
            If (Not frmDP5.DppComm.PortOpen) Then frmDP5.DppComm.PortOpen = True
            If (Err.Number <> 0) Then   'port error
                MsgBox Err.Description & vbNewLine & " Cannot set COM Port."
                Err.Clear
            Else
                SetComPort = OldCommPort
            End If
        Else
            SetComPort = iPort
        End If
    Else    'open the port if closed
        If (Not frmDP5.DppComm.PortOpen) Then frmDP5.DppComm.PortOpen = True
        If (Err.Number <> 0) Then   'port error
            MsgBox "SetComPort Error: " & Err.Description
            Err.Clear
        Else
            SetComPort = iPort
        End If
    End If
    Debug.Print "SetComPort = " & iPort
End Function

Private Sub EnableRS232Controls(Optional EnRS232Cmds As Boolean, Optional EnRS232StatusCmd As Boolean = False)
    Dim bPortOpen As Boolean
    bPortOpen = frmDP5.DppComm.PortOpen
    cboRS232Comm.Enabled = EnRS232Cmds
    txtRS232Status.Enabled = EnRS232Cmds
    cmdRequestDataAndStatus.Enabled = EnRS232StatusCmd And bPortOpen
    If (EnRS232Cmds) Then
        txtRS232Status.BackColor = &H80000005
    Else
        txtRS232Status.BackColor = &H8000000F
    End If
    lblDppFound(RS232).Enabled = EnRS232Cmds
End Sub

Private Sub EnableUSBControls(Optional EnUSBCmds As Boolean)
    cmdFindDevice.Enabled = EnUSBCmds
    cmdDisableUSBNotify.Enabled = EnUSBCmds
    rtbStatus.Enabled = EnUSBCmds
    lblDppFound(USB).Enabled = EnUSBCmds

    cmdCountDevices.Enabled = EnUSBCmds
    lblNumUSBDevices.Enabled = EnUSBCmds
    lblSelectDevice.Enabled = EnUSBCmds
    udSelectDevice.Enabled = EnUSBCmds
    lblCurrentDevice.Enabled = EnUSBCmds
    cmdCloseDevice.Enabled = EnUSBCmds

End Sub

Private Sub EnableINETControls(Optional EnInetCmds As Boolean)
    Dim idxComm As Long

    For idxComm = 0 To 3
        txtIP(idxComm).Enabled = EnInetCmds
        lblUnit(idxComm).Enabled = EnInetCmds
        cmdSelectIP(idxComm).Enabled = EnInetCmds
        If (EnInetCmds) Then
            txtIP(idxComm).BackColor = &H80000005   'white
            If (DppEntries(idxComm).SockAddr <> 0) Then
                lblUnit(idxComm).BackColor = AlertEntryToCOLORREF(DppEntries(idxComm))
            Else
                lblUnit(idxComm).BackColor = &H80000005   'white
            End If
        Else
            lblUnit(idxComm).BackColor = &H8000000F   'buttonface
            txtIP(idxComm).BackColor = &H8000000F   'buttonface
        End If
    Next
    txtUDPPort.Enabled = EnInetCmds
    btnFindIP.Enabled = EnInetCmds
    lblInet_IPAddress.Enabled = EnInetCmds
    chkLock.Enabled = EnInetCmds
    chkShare.Enabled = EnInetCmds
    lblInet_Port.Enabled = EnInetCmds
    lblIpFound.Enabled = EnInetCmds
    lblDppFound(ETHERNET).Enabled = EnInetCmds

    cmdSelectIP(0).Enabled = EnInetCmds
    cmdSelectIP(1).Enabled = EnInetCmds
    cmdSelectIP(2).Enabled = EnInetCmds
    cmdSelectIP(3).Enabled = EnInetCmds

    If (EnInetCmds) Then
        txtUDPPort.BackColor = &H80000005
    Else
        txtUDPPort.BackColor = &H8000000F
    End If
End Sub

Private Sub EnableCommControls(CurrentInterface As Byte)
    Dim idxIp As Long

    txtRS232Status.Visible = False
    rtbStatus.Visible = False
    For idxIp = 0 To 3
        lblUnit(idxIp).Visible = False
        lblIpId(idxIp).Visible = False
    Next

    EnableRS232Controls False
    EnableUSBControls False
    EnableINETControls False
    s.CurrentInterface = CurrentInterface
    Select Case CurrentInterface
        Case RS232
            EnableRS232Controls True
            txtRS232Status.Visible = True
        Case USB
            EnableUSBControls True
            rtbStatus.Visible = True
        Case ETHERNET
            EnableINETControls True
            For idxIp = 0 To 3
                lblUnit(idxIp).Visible = True
                lblIpId(idxIp).Visible = True
            Next
    End Select
End Sub

'frmDP5.lblSelectCommunications
Private Sub optComm_Click(Index As Integer)
    Dim idxComm As Long
    RS232ComPortTest = False    'turn comport test  off if running
    USBDeviceTest = False
    optComm(Index).Value = True
    Select Case Index
        Case RS232
            EnableCommControls RS232            's.CurrentInterface = RS232
            idxComm = SetComPort()
            If (idxComm > 0) Then
                strCommStatus = "RS232 COM" & idxComm
                DppState.Interface = commRS232
            Else
                strCommStatus = "RS232 COM NOT SET"
                DppState.Interface = commNone
            End If
            If (frmDP5.DppComm.PortOpen) Then
                cmdRequestDataAndStatus.Enabled = True
            Else
                cmdRequestDataAndStatus.Enabled = False
            End If
            Call cmdRequestDataAndStatus_Click
        Case USB
            EnableCommControls USB              's.CurrentInterface = USB
            strCommStatus = "USB"
            Call cmdFindDevice_Click
            DppState.Interface = commUSB
        Case ETHERNET
            EnableCommControls ETHERNET         's.CurrentInterface = ETHERNET
            DppState.Interface = commSockets
            strCommStatus = "ETHERNET"
            If frmDP5.DppWinsock.State > 0 Then
                frmDP5.DppWinsock.Close
            End If
            frmDP5.DppWinsock.RemoteHost = txtIP(0).Text + "." + txtIP(1).Text + "." + txtIP(2).Text + "." + txtIP(3).Text
            frmDP5.DppWinsock.RemotePort = txtUDPPort.Text
            'DppWinsock.LocalPort = txtUDPPort.Text
            Netfinder_active = False
            Call btnFindIP_Click
    End Select
End Sub

Private Sub udSelectDevice_Change()
    CurrentUSBDevice = udSelectDevice.Value
    lblCurrentDevice = CurrentUSBDevice
End Sub


frmDP5CFG Source Code

Option Explicit

Private Declare Sub InitCommonControls Lib "comctl32.dll" ()
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private bFormLoading As Boolean

Private Sub cboControl_Click(Index As Integer)
    Dim idxTxt As Long
    Dim isVisible As Boolean

    If (IsEmpty(varCmdCtrls)) Then Exit Sub
    idxTxt = GetTextBoxIndexByTag(varCmdCtrls, cboControl(Index).Tag)
    If (idxTxt >= 0) Then
        isVisible = ClickTxtComboGroup(cboControl(Index), txtControl(idxTxt))
        CboTxtCtrlVis Me, cboControl(Index).Tag, isVisible
    End If
    'update the fpga clock labels
    If (cboControl(Index).Tag = "CLCK") Then cboCLCK_Update Index

    If (STATUS.DEVICE_ID = dppMCA8000D) Then
        If ("PURE" = cboControl(Index).Tag) Then  'set the MCA8000D PUR Control
            SetMCA8000D_PUR_From_ShapingPUR
        End If
    End If

End Sub

Private Sub cboCLCK_Update(Index As Integer)
    Dim cstrClck As String
    Dim cstrOldClck As String
    Dim lClck As Long

    cstrClck = cboControl(Index).Text
    lClck = CLng(Val(cstrClck))
    If (lClck = 20) Then
        b80MHzModeCfg = False
    ElseIf (lClck = 80) Then
        b80MHzModeCfg = True
    End If
    lblFPGAClk(1).Visible = False
    lblFPGAClk(2).Visible = False
    If (b80MHzModeCfg_old <> b80MHzModeCfg) Then
        If (s.isDppConnected) Then
            lblFPGAClk(1).Visible = True
        Else
            lblFPGAClk(2).Visible = True
        End If
    End If
End Sub

Private Sub cboFlatTop_Click()
    Dim idxCtrl As Long
    idxCtrl = GetCtrlIdxByNameTag(Me, "txtControl", "TFLA")
    txtControl(idxCtrl) = cboFlatTop.Text
End Sub

Private Sub cboInputRange_Click()
    'GAIA -> one plus the combobox index (1=1V,2=10V)
    'GAIF -> ignored
    '---- OR
    'GAIN -> 1 or 10 only
    SetGainFromInputRangeControl
    'MsgBox "cboInputRange_Click"
End Sub

Private Sub cboPUR_MCA8000D_Click()
    SetShapingPUR_From_MCA8000D_PUR
    'MsgBox "cboPUR_MCA8000D_Click"
End Sub

Private Sub cboRise_Click()
    Dim idxCtrl As Long
    cboRiseUpdate cboRise, cboFlatTop, b80MHzModeCfg
    idxCtrl = GetCtrlIdxByNameTag(Me, "txtControl", "TPEA")
    txtControl(idxCtrl) = cboRise.Text
End Sub

Private Sub chkEnableSCA_Click()
    s.SCAEnabled = CBool(chkEnableSCA.Value = vbChecked)
    fraSingleChannelAnalyzer.Visible = s.SCAEnabled
    If (bFormLoading) Then Exit Sub
    If (Not s.isDppConnected) Then Exit Sub
    If (s.SCAEnabled) Then
'        LoadingCfg = False
'        s.HwScaCfgReady = False                'clear cfg ready flag
'        s.HwScaCfgDP5 = ""                     'clear config readback string
'        s.cstrRawScaCfgIn = ""
'        TimeExpired = False
'        lblPleaseWait.Visible = True
'        'curStart = msTimeStart()               'keep using the old 5sec timer
'        s.DppConfig.ScaReadBack = True      'set request config readback flag
'        frmDP5.cmdShowSCASettings_Click
'        'frmDP5.SendCommand XMTPT_FULL_READ_CONFIG_PACKET    'request dpp config
'        Do                                  'wait until s.HwCfgReady or timeout
'            DoEvents
'            curElapsed = msTimeDiff(curStart)
'            TimeExpired = msTimeExpired(curStart, 5000)    '1000 milliseconds max wait
'        Loop Until (TimeExpired Or s.HwScaCfgReady)
'        If ((Len(s.HwScaCfgDP5) = 0) Or (Not s.HwScaCfgReady)) Then
'            strMsg = ""
'            MsgBox "Please try again."
'            lblPleaseWait.Visible = False
'            Exit Sub
'        Else
'            MsgBox s.HwScaCfgDP5 & vbNewLine & "++++" & vbNewLine & s.cstrRawScaCfgIn & vbNewLine
'        End If
    End If
End Sub

Private Sub cmdApply_Click()
'
End Sub

Private Sub BLRQuickSet(cstrMode As String, cstrDown As String, cstrUp As String)
    Dim idxCtrl As Long
    Dim idxList As Long
    Dim cstrVal As String

    idxCtrl = GetCtrlIdxByNameTag(Me, "cboControl", "BLRM")
    cstrVal = cstrMode
    idxList = FindCboIdxExact(cboControl(idxCtrl), cstrVal)
    If (idxList = LB_ERR) Then
        idxList = FindCboIdx(cboControl(idxCtrl), cstrVal)
    End If
    If (idxList = LB_ERR) Then     'not found default to 0
        idxList = 0
    End If
    cboControl(idxCtrl).ListIndex = idxList
    idxCtrl = GetCtrlIdxByNameTag(Me, "txtControl", "BLRD")
    If (idxCtrl >= 0) Then txtControl(idxCtrl) = cstrDown
    idxCtrl = GetCtrlIdxByNameTag(Me, "txtControl", "BLRU")
    If (idxCtrl >= 0) Then txtControl(idxCtrl) = cstrUp
End Sub

' this function replaces blr quickset 20110504, 20140813 vb version
Private Sub cmdBLRQuickset_Click()
    Call BLRQuickSet("1", "3", "0")
End Sub

Private Sub cmdCancel_Click()
    Unload Me
End Sub

Private Sub cmdEnterFineGain_Click()

End Sub

Private Sub cmdFindCmd_Click()
    Dim btn As Button

    If (Len(strFindTab) = 0) Then Exit Sub
    If (Len(strFindCtrl) = 0) Then Exit Sub
    If (Len(strFindIdx) = 0) Then Exit Sub
    Set btn = Toolbar1.Buttons(strFindTab)
    Toolbar1_ButtonClick btn
    Controls(strFindCtrl)(strFindIdx).SetFocus
End Sub

Private Sub cmdGainCfToTotal_Click()

End Sub

Private Sub cmdGainTotalToCf_Click()

End Sub

Private Sub cmdHelp_Click()
'
End Sub

Private Sub cmdOK_Click()
    Unload Me
End Sub

'Read a configuration.
Private Sub cmdReadCfg_Click()
    Dim strCLCK As String
    Dim strTPEA As String
    Dim strTFLA As String
    Dim strTPFA As String

    If (dlgOpen(cmnDlg, dlgTXT_Filter)) Then
        strIniFilename = cmnDlg.filename
        '=========================
        EnableCommandsByDeviceType
        '=========================
        LoadingCfg = True
        varValues = GetDP5ConfigSection(strIniFilename, IniSectionVal, varValComments)    'get saved values
        UpdateDP5TextCtrls Me, lstDP5Commands, varCmdCtrls, varValues, varUnitsArray
        varConfig = GetDP5ConfigSection(strIniFilename, IniSectionCfg, varComments)    'get config
        UpdateDP5Ctrls Me, lstDP5Commands, varCmdCtrls, varConfig, varUnitsArray
        'if reading cfg from file, will base all controls on file info
        strCLCK = GetValByCmd("CLCK", varConfig)
        strTPEA = GetValByCmd("TPEA", varConfig)
        strTFLA = GetValByCmd("TFLA", varConfig)
        strTPFA = GetValByCmd("TPFA", varConfig)

        b80MHzModeCfg = GetFPGAClockMode(strCLCK, strTPEA)
        b80MHzModeCfg_old = b80MHzModeCfg

        'update TPEA
        LoadPeakingValues cboRise, cboFlatTop, b80MHzModeCfg
        SetShapingIndex cboRise, strTPEA

        cboRiseUpdate cboRise, cboFlatTop, b80MHzModeCfg
        SetShapingIndex cboFlatTop, strTFLA

        'Set the Fast Channel Threshold
        InitFastPeakCombo
        SetFastPeakCombo strTPFA

        If (b80MHzModeCfg) Then
            lblFPGAClk(0) = "80MHz"
            b80MHzModeCfg_old = True
        Else
            lblFPGAClk(0) = "20MHz"
            b80MHzModeCfg_old = False
        End If

        lblFPGAClk(1).Visible = False
        lblFPGAClk(2).Visible = False

        LoadingCfg = False
        EnableCfgControls True

        If (s.SCAEnabled) Then
            ReadSCACfgFromINI strIniFilename
        End If
        SetCfgInstructions False         ' hide configuration dialog start instructions
    Else
        'a file was not selected
    End If

End Sub

'Purpose: Read String configuration data and comments array from dpp config string.
'Returns INI configuration data array as return value and comments array as parameter.
'Parameter: strConfig hardware configuration string.
'Parameter: varComments INI comment data array.
Public Function GetDP5ConfigString(strConfig As String, ByRef varComments As Variant) As Variant
    Dim varConfig As Variant
    Dim idxCmd As Long
    Dim DppCfg() As HwConfigType
    Dim lPos As Long
    Dim lCmd As Long
    Dim lSep As Long
    Dim cfgLen As Long
    Dim strHwCfg As String
    Dim strItem As String
    Dim strData() As String

    strHwCfg = strConfig
    cfgLen = Len(strHwCfg)                  'extract all config data, append comments
    If (cfgLen < 7) Then Exit Function           'must be at least CCCC=V; (7 chars long)
    idxCmd = -1
    Do
        lPos = InStr(strHwCfg, ";")
        If (lPos > 0) Then
            strItem = ""
            strItem = Trim(Left(strHwCfg, lPos))
            lCmd = Len(strItem)
            lSep = InStr(strItem, "=")
            If ((lCmd >= 7) And (5 = lSep)) Then 'test for CCCC=V; (7 chars long)
                idxCmd = idxCmd + 1                 'inc index
                ReDim Preserve DppCfg(idxCmd)       'create storage
                DppCfg(idxCmd).Command = Left(strItem, 4)
                DppCfg(idxCmd).Value = Trim(Mid(strItem, 6))
                DppCfg(idxCmd).Comment = GetCmdDesc(DppCfg(idxCmd).Command)
                strHwCfg = Mid(strHwCfg, lPos + 1)
            Else
                strHwCfg = Mid(strHwCfg, lPos + 1)  'skip this command
            End If
        End If
    Loop Until ((lPos = 0) Or (idxCmd > (cfgLen / 5)) Or (Len(strHwCfg) = 0))
    ReDim strData(UBound(DppCfg), 1)
    For idxCmd = 0 To UBound(DppCfg)
        strData(idxCmd, 0) = DppCfg(idxCmd).Command
        strData(idxCmd, 1) = DppCfg(idxCmd).Value & "    " & DppCfg(idxCmd).Comment
    Next
    varConfig = GetDP5Commands(strData)                     'remove the comments
    varComments = GetDP5Comments(strData)                   'save the comments
    GetDP5ConfigString = varConfig
End Function

Private Sub cmdReadHwCfg_Click()
    Dim curStart As Currency            'start time from system time in milliseconds
    Dim TimeExpired As Boolean          'time expired flag
    Dim curElapsed As Currency          'Elapsed time from start time in milliseconds
    Dim varCmd As Variant
    Dim cstrDisplayCfgOut As String
    Dim strMsg As String

    If (Not s.isDppConnected) Then Exit Sub             'exit if no dpp connect
    LoadingCfg = False
    s.HwCfgReady = False                'clear cfg ready flag
    s.HwCfgDP5 = ""                     'clear config readback string
    s.cstrRawCfgIn = ""
    TimeExpired = False
    lblPleaseWait.Visible = True
    curStart = msTimeStart()
    s.DppConfig.CfgReadBack = True      'set request config readback flag
    frmDP5.SendCommand XMTPT_FULL_READ_CONFIG_PACKET    'request dpp config
    Do                                  'wait until s.HwCfgReady or timeout
        DoEvents
        curElapsed = msTimeDiff(curStart)
        TimeExpired = msTimeExpired(curStart, 5000)    '1000 milliseconds max wait
    Loop Until (TimeExpired Or s.HwCfgReady)

    'read cfg in s.HwCfgDP5
    If ((Len(s.HwCfgDP5) = 0) Or (Not s.HwCfgReady)) Then
        strMsg = ""
'        If (TimeExpired) Then strMsg = strMsg & "Config Readback Time Expired" & vbNewLine
'        If (Len(s.HwCfgDP5) = 0) Then strMsg = strMsg & "No Config Readback Received" & vbNewLine
'        If (Not s.HwCfgReady) Then strMsg = strMsg & "Config Readback No Ready" & vbNewLine
'        MsgBox strMsg
        MsgBox "Please try again."
        lblPleaseWait.Visible = False
        Exit Sub
    End If

''    Dim strTestFile As String
''    strTestFile = App.Path & "\_TestCfgIn.hm"
''    WriteTextFile strTestFile, s.HwCfgDP5

    If (s.SCAEnabled And s.isDppConnected) Then
        LoadingCfg = False
        s.HwScaCfgReady = False                'clear cfg ready flag
        s.HwScaCfgDP5 = ""                     'clear config readback string
        s.cstrRawScaCfgIn = ""
        TimeExpired = False
        lblPleaseWait.Visible = True
        'curStart = msTimeStart()               'keep using the old 5sec timer
        s.DppConfig.ScaReadBack = True      'set request config readback flag
        frmDP5.RequestSCASettings
        'frmDP5.SendCommand XMTPT_FULL_READ_CONFIG_PACKET    'request dpp config
        Do                                  'wait until s.HwCfgReady or timeout
            DoEvents
            curElapsed = msTimeDiff(curStart)
            TimeExpired = msTimeExpired(curStart, 5000)    '1000 milliseconds max wait
        Loop Until (TimeExpired Or s.HwScaCfgReady)
        If ((Len(s.HwScaCfgDP5) = 0) Or (Not s.HwScaCfgReady)) Then
            strMsg = ""
            MsgBox "Please try again."
            lblPleaseWait.Visible = False
            Exit Sub
        Else
            'MsgBox SCAStringALL(sca, True)
            'MsgBox s.HwScaCfgDP5 & vbNewLine & "++++" & vbNewLine & s.cstrRawScaCfgIn & vbNewLine
            SCACfgParser sca, s.HwScaCfgDP5
            cboMCAC.ListIndex = varValueToIndex(sca.Channels)
            cboSCAW.ListIndex = varValueToIndex(sca.PulseWidth)
            cboSCAI.ListIndex = varValueToIndex(sca.Index)
            cboSCAI_Click
            UpdateSCAEdit
            sca.Index = 1
            cboSCAI.ListIndex = varValueToIndex(sca.Index)
            UpdateSCAEdit
            'MsgBox SCAStringALL(sca, True)
        End If
    End If

    If (chkDisplayConfigurationOnRead.Value = vbChecked) Then
        ''===========================================================================
        ''uncomment the following block to display the configuration on dpp readback
        ''===========================================================================
        cstrDisplayCfgOut = s.cstrRawCfgIn
        For Each varCmd In s.Dp5CmdList
            cstrDisplayCfgOut = ReplaceCmdDesc(CStr(varCmd), cstrDisplayCfgOut)
        Next
        frmDppConfigDisplay.m_strMessage = cstrDisplayCfgOut
        frmDppConfigDisplay.m_strDelimiter = ";"
        Load frmDppConfigDisplay
        frmDppConfigDisplay.m_strTitle = "DPP Configuration"
        frmDppConfigDisplay.Show vbModal
        ''===========================================================================
    End If

    'convert config string to control data
    Dim strCLCK As String
    Dim strTPEA As String
    Dim strTFLA As String
    Dim strTPFA As String

    '=========================
    EnableCommandsByDeviceType
    '=========================
    LoadingCfg = True
    varConfig = GetDP5ConfigString(s.HwCfgDP5, varComments)    'get config
    UpdateDP5Ctrls Me, lstDP5Commands, varCmdCtrls, varConfig, varUnitsArray
    'if reading cfg from file, will base all controls on file info
    strCLCK = GetValByCmd("CLCK", varConfig)
    strTPEA = GetValByCmd("TPEA", varConfig)
    strTFLA = GetValByCmd("TFLA", varConfig)
    strTPFA = GetValByCmd("TPFA", varConfig)

    b80MHzModeCfg = GetFPGAClockMode(strCLCK, strTPEA)
    b80MHzModeCfg_old = b80MHzModeCfg

    'update TPEA
    LoadPeakingValues cboRise, cboFlatTop, b80MHzModeCfg
    SetShapingIndex cboRise, strTPEA

    cboRiseUpdate cboRise, cboFlatTop, b80MHzModeCfg
    SetShapingIndex cboFlatTop, strTFLA

    'Set the Fast Channel Threshold
    InitFastPeakCombo
    SetFastPeakCombo strTPFA

    If (b80MHzModeCfg) Then
        lblFPGAClk(0) = "80MHz"
        b80MHzModeCfg_old = True
    Else
        lblFPGAClk(0) = "20MHz"
        b80MHzModeCfg_old = False
    End If

    lblFPGAClk(1).Visible = False
    lblFPGAClk(2).Visible = False

    LoadingCfg = False
    lblPleaseWait.Visible = False
    SetCfgInstructions False         ' hide configuration dialog start instructions
    EnableCfgControls True
End Sub

Private Sub cmdSaveCfg_Click()
    Dim varNotEmptyVal As Variant

    If (dlgSave(cmnDlg, dlgTXT_Filter)) Then
        strIniFilename = cmnDlg.filename
        '-------- Save Text Values To Section --------------------------------------------------------------
        ReadDP5Text Me, lstDP5Commands, varCmdCtrls, varValues  '1. Scan all TextBoxes for Values
        varNotEmptyVal = CopyIniArr(varValues, False)           '2. Remove Empty Values
        Call DeleteIniSetting(strIniFilename, IniSectionVal)       '3. Clear the Value Section
        Call SaveDP5ConfigSection(strIniFilename, IniSectionVal, varNotEmptyVal, varValComments)   '4. Save Values with comments
        '---------------------------------------------------------------------------------------------------
        ReadDP5Settings Me, lstDP5Commands, varCmdCtrls, varConfig  '1. Scan all TextBoxes for Values
        Call SaveDP5ConfigSection(strIniFilename, IniSectionCfg, varConfig, varComments)   '2. Save Values with comments
        If (s.SCAEnabled) Then
            SaveSCACfgToINI strIniFilename
        End If
    Else
        'a file was not selected
    End If
End Sub

Private Sub cmdSendCfgToHw_Click()
    Dim idxCmd As Long
    Dim strCfg As String
    Dim strDisplay As String
    Dim strCmd As String
    Dim curStart As Currency            'start time from system time in milliseconds
    Dim TimeExpired As Boolean          'time expired flag
    Dim curElapsed As Currency          'Elapsed time from start time in milliseconds
    Dim lCfgLen As Long                 'ASCII Configuration Command String Length
    Dim idxSplitCfg As Long             'Configuration split position, only if necessary
    Dim bSplitCfg As Boolean            'Configuration split flag
    Dim strSplitCfg As String           'Configuration split string second buffer

    bSplitCfg = False
    If (Not s.isDppConnected) Then Exit Sub             'exit if no dpp connect
    ReadDP5Settings Me, lstDP5Commands, varCmdCtrls, varConfig  '1. Scan all TextBoxes for Values
    strDisplay = ""
    If (IsEmpty(varConfig)) Then Exit Sub    'not initialized
    strCfg = TypeName(varConfig)             'test variant data type
    If (strCfg = "String()") Then           ('have data
        strCfg = ""                         'clear cfg storage
    Else
        Exit Sub                            'no data
    End If
    For idxCmd = 0 To UBound(varConfig, 1)
        strCmd = varConfig(idxCmd, 0) & "=" & varConfig(idxCmd, 1) & ";"
        If (Not (InStr(strCmd, "RESC") > 0)) Then
            If (Len(Trim(varConfig(idxCmd, 1))) > 0) Then
                strCfg = strCfg & strCmd
                strDisplay = strDisplay & strCmd & vbNewLine
            Else
                strDisplay = strDisplay & ";" & strCmd & vbNewLine
            End If
        End If
    Next
    strCfg = "RESC=YES;" & strCfg
    strCfg = UCase(strCfg)
    strCfg = RemoveCmdByDeviceType(strCfg, STATUS.PC5_PRESENT, STATUS.DEVICE_ID, STATUS.isDP5_RevDxGains, STATUS.DPP_ECO)
    Clipboard.SetText strCfg
    strDisplay = "RESC=YES;" & vbNewLine & strDisplay
    strDisplay = UCase(strDisplay)
    txtSendCfgToHwNoEdit = strDisplay

    'Test configuration size
    lCfgLen = Len(strCfg)
    If (lCfgLen > 512) Then     'configuration is too large, try to reduce
        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 = Left(strCfg, idxSplitCfg)
        End If
    End If

    'MsgBox strCfg
    'MsgBox strSplitCfg

    lblCfgLenValue = CStr(Len(strCfg))
    s.HwCfgReady = False
    s.HwCfgExReady = False
    s.HwCfgDP5Out = strCfg
    If (Len(strCfg) > 0) Then
        s.HwCfgReady = True
        frmDP5.SendCommand XMTPT_SEND_CONFIG_PACKET_TO_HW
        s.HwCfgReady = False
    End If

    If (bSplitCfg) Then             'send second configuration block
        TimeExpired = False
        lblPleaseWait.Visible = True
        curStart = msTimeStart()
        Do                          'wait for cfg packet to be processed
            DoEvents
            curElapsed = msTimeDiff(curStart)
            TimeExpired = msTimeExpired(curStart, 200)    '200 milliseconds wait
        Loop Until (TimeExpired)
        lblPleaseWait.Visible = False
        s.HwCfgReady = False
        s.HwCfgExReady = False
        s.HwCfgDP5Out = strSplitCfg
        If (Len(strCfg) > 0) Then
            s.HwCfgReady = True
            frmDP5.SendCommand XMTPT_SEND_CONFIG_PACKET_TO_HW
            s.HwCfgReady = False
        End If
    End If

    If (s.SCAEnabled And s.isDppConnected) Then
        TimeExpired = False
        lblPleaseWait.Visible = True
        curStart = msTimeStart()
        Do                          'wait for cfg packet to be processed
            DoEvents
            curElapsed = msTimeDiff(curStart)
            TimeExpired = msTimeExpired(curStart, 200)    '200 milliseconds wait
        Loop Until (TimeExpired)
        lblPleaseWait.Visible = False
        strCfg = SCAStringALL(sca, True)
        s.HwCfgReady = False
        s.HwCfgExReady = False
        s.HwCfgDP5Out = strCfg
        If (Len(strCfg) > 0) Then
            s.HwCfgReady = True
            frmDP5.SendCommand XMTPT_SEND_CONFIG_PACKET_TO_HW
            s.HwCfgReady = False
        End If
    End If

End Sub

'Function InstrCount(StringToSearch As String, StringToFind As String) As Long
'    If Len(StringToFind) Then
'        InstrCount = UBound(Split(StringToSearch, StringToFind))
'    End If
'End Function

Private Sub cmdSendCfgToHwNoEdit_Click()
    Dim idxCfg As Integer
    Dim varCfgHw As Variant
    Dim varCommentsHw As Variant
    Dim strCfg As String
    Dim strDisplay As String
    Dim strCmd As String

    strDisplay = ""
    On Error GoTo cmdSendCfgToHwNoEditErr
    If (dlgOpen(cmnDlg, dlgTXT_Filter)) Then
        strIniFilename = cmnDlg.filename
        varCfgHw = GetDP5ConfigSection(strIniFilename, IniSectionCfg, varCommentsHw) 'read ini config from file
        If (IsEmpty(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
        txtSendCfgToHwNoEdit = strDisplay
        lblCfgLenValue = CStr(Len(strCfg))
    Else
        'a file was not selected
    End If
    Exit Sub
cmdSendCfgToHwNoEditErr:

End Sub

'Enable XP Styles Manifest for VB5/VB6 Controls
Private Sub Form_Initialize()
    On Error Resume Next
    LoadLibrary "shell32.dll"
    InitCommonControls
    On Error GoTo 0
End Sub

'tell the operator how to start the configuration dialog
Private Sub SetCfgInstructions(Optional bDisplay As Boolean = True)
    Dim strStart As String
    strStart = "To begin, Read Hardware Configuration OR " & vbNewLine
    strStart = strStart & "Select DPP Device Type, then Open Configuration File"
    lblStartCfg = strStart
    lblStartCfg.Visible = bDisplay
End Sub

Private Sub Form_Load()
    Dim idxTab As Long
    bFormLoading = True
    SetCfgInstructions          ' display configuration dialog start instructions

    lblPleaseWait.Visible = False
    fraPREL.Top = fraPRET.Top
    fraPREL.Left = fraPRET.Left
    LoadApplicationSettings Me, True, False, False

    '===========================================================================
    '==== This Configuration Dialog has controls to configure GAIN only
    '===========================================================================
    's.profile.SendCoarseFineGain = True     'removes GAIN cmd (sends GAIA,GAIF)
    s.profile.SendCoarseFineGain = False     'removes GAIA,GAIF cmd (sends GAIN)

    If (s.SCAEnabled) Then
        chkEnableSCA.Value = vbChecked
    Else
        chkEnableSCA.Value = vbUnchecked
    End If
    fraSingleChannelAnalyzer.Visible = s.SCAEnabled

    If (Not s.isDppConnected) Then
        fraDppDeviceType.Enabled = True   'enable select device type
        optDppDeviceType(0).Enabled = True
        optDppDeviceType(1).Enabled = True
        optDppDeviceType(2).Enabled = True
        optDppDeviceType(3).Enabled = True
        optDppDeviceType(4).Enabled = True
        If ((STATUS.DEVICE_ID >= dppDP5) And (STATUS.DEVICE_ID <= dppTB5)) Then 'set device type
            'value is ok
        Else
            STATUS.DEVICE_ID = CByte(dppDP5)
        End If
        optDppDeviceType(STATUS.DEVICE_ID).Value = True
    Else
        fraDppDeviceType.Enabled = False   'disable select device type
        optDppDeviceType(0).Enabled = False
        optDppDeviceType(1).Enabled = False
        optDppDeviceType(2).Enabled = False
        optDppDeviceType(3).Enabled = False
        optDppDeviceType(4).Enabled = False
        If ((STATUS.DEVICE_ID >= dppDP5) And (STATUS.DEVICE_ID <= dppTB5)) Then 'set device type
            optDppDeviceType(STATUS.DEVICE_ID).Value = True 'value is ok
        End If
    End If

    EnableCommandsByDeviceType

    lblFPGAClk(0).BackColor = colorLightSteelBlue
    lblFPGAClk(0).ForeColor = colorLightSlateGray
    lblFPGAClk(1).BackColor = &H8000000F
    lblFPGAClk(1).ForeColor = colorRed
    lblFPGAClk(2).BackColor = &H8000000F
    lblFPGAClk(2).ForeColor = colorBlue

    Toolbar1.Buttons("General").Value = tbrPressed
    Toolbar1.Top = 0
    Toolbar1.Left = 0
    For idxTab = 0 To SSTab1.Tabs - 1
        lblTab(idxTab).BorderStyle = vbBSNone
        lblTab(idxTab).Caption = SSTab1.TabCaption(idxTab)
    Next
    SSTab1.Tab = 0
    varUnitsArray = MakeUnitsArray()
    LoadingCfg = True
    varCmdCtrls = SetupCmdCtrls(Me, lstDP5Commands)
    Timer1.Enabled = True   'run GetDP5CmdGroups
    LoadingCfg = False
    SSTab1.Tab = 0

'    Shape1.Move 60, 360, SSTab1.Width - 60 - 60, SSTab1.Height - 360 - 60
'    Shape1.ZOrder 1
    For idxTab = 0 To SSTab1.Tabs - 1
        Shape_ssTabBg(idxTab).Move 60, 360, SSTab1.Width - 60 - 60, SSTab1.Height - 360 - 60
        Shape_ssTabBg(idxTab).ZOrder 1
    Next
    SetComboRight Me
    'update all combo txt control groups
    SetupStartupCboTxt Me, varCmdCtrls
    SSTab1.Enabled = True

    EnableCfgControls False     'disable all controls to start

    txtSendCfgToHwNoEdit.Enabled = s.isDppConnected
    cmdSendCfgToHwNoEdit.Enabled = s.isDppConnected
    lblCfgToHwLength.Enabled = s.isDppConnected
    lblCfgLenValue.Enabled = s.isDppConnected
    cmdReadHwCfg.Enabled = s.isDppConnected
    cmdSendCfgToHw.Enabled = s.isDppConnected

    bFormLoading = False
End Sub

Private Sub Form_Unload(Cancel As Integer)
    SaveApplicationSettings Me, True, True, False
End Sub

Private Sub lstDP5Commands_Click()
    Dim idxLst As Long

    cmdFindCmd.Enabled = False
    If LoadingCfg Then Exit Sub
    idxLst = lstDP5Commands.ListIndex
    'Debug.Print GetDP5CmdCtrtType(lstDP5Commands, idxLst)
    txtCmdInfo = GetDP5CmdCtrlInfo(Me, lstDP5Commands, varCmdCtrls, idxLst)
    If (Len(strFindTab) = 0) Then Exit Sub
    If (Len(strFindCtrl) = 0) Then Exit Sub
    If (Len(strFindIdx) = 0) Then Exit Sub
    cmdFindCmd.Enabled = True
End Sub

Private Sub optDppDeviceType_Click(Index As Integer)
    'set the status flags for configuration without a DPP Device
    Dim idxButton As Long
    STATUS.DEVICE_ID = CByte(Index)
    EnableCommandsByDeviceType
'    If (STATUS.DEVICE_ID = dppMCA8000D) Then
'        For idxButton = 2 To Toolbar1.Buttons.Count
'            Toolbar1.Buttons(idxButton).Enabled = False
'        Next
'    End If
End Sub

Private Sub SSTab1_Click(PreviousTab As Integer)
    Dim btn As Button
    If LoadingCfg Then Exit Sub
    If (Toolbar1.Buttons(SSTab1.Tab + 1).Value <> tbrPressed) Then
        Set btn = Toolbar1.Buttons(SSTab1.Tab + 1)
        Toolbar1_ButtonClick btn
    End If
End Sub

Private Sub Timer1_Timer()
    Timer1.Enabled = False
    LoadingCfg = True
    GetDP5CmdGroups Me, varCmdCtrls, SSTab1
    LoadingCfg = False
End Sub

Private Sub Toolbar1_ButtonClick(ByVal Button As ComctlLib.Button)
    UnPressButtons Toolbar1
    Button.Value = tbrPressed
    SSTab1.Tab = Button.Index - 1
End Sub

Private Function strSOFF_INFO()
    Dim cstrSoffInfo As String
    cstrSoffInfo = "  SOFF - Set Spectrum Offset                (Default=OFF)" & vbNewLine & vbNewLine
    cstrSoffInfo = cstrSoffInfo & "  Range Depends on MCA/MCS Channels (MCAC): " & vbNewLine
    cstrSoffInfo = cstrSoffInfo & Space(16) & " 256 ch: -256 to +255.992 ch; 1/128 ch precision " & vbNewLine
    cstrSoffInfo = cstrSoffInfo & Space(16) & " 512 ch: -512 to +511.984 ch; 1/64 ch precision " & vbNewLine
    cstrSoffInfo = cstrSoffInfo & Space(16) & " 1024 ch: -1024 to +1023.969 ch; 1/32 ch precision " & vbNewLine
    cstrSoffInfo = cstrSoffInfo & Space(16) & " 2048 ch: -2048 to +2047.937 ch; 1/16 ch precision " & vbNewLine
    cstrSoffInfo = cstrSoffInfo & Space(16) & " 4096 ch: -4096 to +4095.875 ch; 1/8 ch precision " & vbNewLine
    cstrSoffInfo = cstrSoffInfo & Space(16) & " 8192 ch: -8192 to +8191.75 ch; 1/4 ch precision " & vbNewLine
    strSOFF_INFO = cstrSoffInfo
End Function

'============================================================
'============================================================
'==== SCA Start =============================================
'============================================================
'============================================================

Private Sub cboMCAC_Click()
    sca.Channels = cboMCAC.Text
    sca.HaveChannels = False
    fix_sca_limits
End Sub

Private Sub cboSCAI_Click()
    If (sca.Index <> (cboSCAI.ListIndex + 1)) Then
        sca.Index = (cboSCAI.ListIndex + 1)
        UpdateSCAEdit
    End If
End Sub

Private Sub UpdateSCAEdit()
    If (sca.Index < 1) Then sca.Index = 1
    lblSCAGroupIndex = "SCA " & sca.Index
    txtSCAL_Edit = sca.sca(sca.Index - 1).Low
    txtSCAH_Edit = sca.sca(sca.Index - 1).High
    If (sca.Index <= 8) Then
        cboSCAO_Select.ListIndex = varValueToIndex(sca.sca(sca.Index - 1).OutPut)
    End If
End Sub

Private Sub cboSCAO_Select_Click()
    If (cboSCAO_Select.ListIndex >= 0) Then sca.sca(sca.Index - 1).OutPut = cboSCAO_Select.Text
End Sub

Private Sub cboSCAW_Click()
    If (cboSCAW.ListIndex >= 0) Then sca.PulseWidth = cboSCAW.Text
End Sub

Private Sub cmdDefaults_Click(Index As Integer)
    Select Case Index
        Case 0
            init_sca
        Case 1
            reset_sca_low
        Case 2
            reset_sca_high
        Case Else
    End Select
    UpdateSCAEdit
End Sub

Private Sub ReadSCACfgFromINI(strFilename As String)
    Dim idxSCA As Long

    sca.strIniFilename = strFilename
    GetSCASetupINI sca
    cboMCAC.ListIndex = varValueToIndex(sca.Channels)
    cboSCAW.ListIndex = varValueToIndex(sca.PulseWidth)
    cboSCAI.ListIndex = varValueToIndex(sca.Index)
    For idxSCA = 1 To 8
        GetSCASettingsINI sca, idxSCA
    Next
    cboSCAI_Click
    UpdateSCAEdit
End Sub

Private Sub SaveSCACfgToINI(strFilename As String)
    Dim idxSCA As Long
    sca.strIniFilename = strFilename
    SaveSCASetupINI sca
    For idxSCA = 1 To 8
        SaveSCASettingsINI sca, idxSCA
    Next
End Sub

Private Sub init_sca()
    Dim idxSCA As Long
    sca.strIniFilename = ""
    sca.HaveChannels = False
    cboMCAC.ListIndex = 2
    sca.Channels = cboMCAC.Text
    cboSCAI.ListIndex = 0
    sca.Index = cboSCAI.ListIndex + 1
    cboSCAW.ListIndex = 0
    sca.PulseWidth = cboSCAW.Text
    For idxSCA = 0 To 15
        sca.sca(idxSCA).Low = 0
        sca.sca(idxSCA).High = 8191
        If (idxSCA < 8) Then
            sca.sca(idxSCA).OutPut = "OFF"
        End If
    Next
End Sub

Private Sub reset_sca_low()
    Dim idxSCA As Long
    For idxSCA = 0 To 15
        sca.sca(idxSCA).Low = 0
    Next
End Sub

Private Sub reset_sca_high()
    Dim idxSCA As Long
    For idxSCA = 0 To 15
        sca.sca(idxSCA).High = sca.Channels - 1
    Next
End Sub

Private Sub fix_sca_limits()
    Dim idxSCA As Long

    For idxSCA = 0 To 15
        If (Val(sca.sca(idxSCA).Low) > Val(sca.Channels)) Then
            sca.sca(idxSCA).Low = 1
        End If
        If (Val(sca.sca(idxSCA).High) > Val(sca.Channels)) Then
            sca.sca(idxSCA).High = sca.Channels
        End If
    Next
End Sub

Private Sub txtSCAL_Edit_Change()
    sca.sca(sca.Index - 1).Low = txtSCAL_Edit
End Sub

Private Sub txtSCAH_Edit_Change()
    sca.sca(sca.Index - 1).High = txtSCAH_Edit
End Sub

'============================================================
'============================================================
'==== SCA End ===============================================
'============================================================
'============================================================

Public Function VersionToDbl(bVersion As Byte, bBuild As Byte) As Double
    Dim VersionToStr As String
    VersionToStr = Trim(str((bVersion And &HF0) / 16)) + "." + Format((bVersion And &HF), "00") + Format(bBuild, "00")
    VersionToDbl = Val(VersionToStr)
End Function

'Enable/Disable all controls
Private Sub EnableCfgControls(isEnabled As Boolean)
    Dim idxTab As Long
    For idxTab = 0 To SSTab1.Tabs - 1
        Toolbar1.Buttons(idxTab + 1).Enabled = isEnabled
    Next
    If (STATUS.DEVICE_ID = dppMCA8000D) Then
        For idxTab = 3 To Toolbar1.Buttons.Count
            Toolbar1.Buttons(idxTab).Enabled = False
        Next
        fraCmdInfo.Visible = False
    Else
        fraCmdInfo.Visible = True
    End If

    fraResetConfiguration.Enabled = isEnabled
    lstDP5Commands.Enabled = isEnabled
    lblCmdList(0).Enabled = isEnabled
    fraCmdInfo.Enabled = isEnabled
    If (Not isEnabled) Then SSTab1.Tab = 0
End Sub

'Enable/Disable controls by DPP Device Type
Private Sub EnableCommandsByDeviceType()
    Dim dblFirmware As Double
    Dim bEnable As Boolean

    dblFirmware = 6#
    If (s.isDppConnected) Then
        dblFirmware = VersionToDbl(STATUS.Firmware, STATUS.Build)
    End If

    If (STATUS.DEVICE_ID = dppDP5G) Then
        b80MHzModeCfg = False
    End If

    fraFPGAClock.Visible = Not CBool(STATUS.DEVICE_ID = dppDP5G)
    fraHV.Visible = Not CBool(STATUS.DEVICE_ID = dppDP5G)

    '==========================================================================
    'Enable ASCII Command Editing By Firmware Version and DPP Device Type
    'Command Firmware  DPP Device  Enable Reason   SDK/DppMCA Supported
    '==========================================================================

    '[x] SCTC 6.08.01   G:T FW:Device   Yes     20140805
    fraScintillatorTimeConstant.Visible = False
    If (dblFirmware >= 6.0801) Then
        bEnable = CBool(STATUS.DEVICE_ID = dppDP5G) Or CBool(STATUS.DEVICE_ID = dppTB5)
        fraScintillatorTimeConstant.Visible = bEnable
    End If

    '[x] TPFA <6.07.05  FW  Yes     20140805
    '[x] TPFA 6.07.05   FW  Yes     20140805
        'InitFastPeakCombo - Changes Control Selections

    '[x] INOF ALL D:P Device  Yes   20140805
    fraInputOffset.Visible = False
    If (STATUS.DEVICE_ID <= dppPX5) Then
        fraInputOffset.Visible = True
    End If

    '[] AUO1 <6.08.02  FW  Yes
    '[] AUO1 6.08.02  FW  Yes
    '[] AUO2 <6.08.02  FW  Yes
    '[] AUO2 6.08.02  FW  Yes
    InitAUX
        'LoadListAUO1
        'LoadListAUO2

    '[] BOOT ALL D   Device  Yes
    '[] PAPS ALL D:P Device:DP5  Yes
    '[] PAPS ALL D:P Device:NotHPGe  Yes
    '[] PAPS ALL D:P Device:HPGeOnly Yes ' removed using fraPC5Control for BOOT and PAPS
    InitPreampVoltageCombo STATUS.DEVICE_ID

    '[] CON1 6.03 P:G FW:Device   Yes
    '[] CON2 6.03 P:G FW:Device   Yes
    InitCON

    '[] GATE ALL D   Device  Yes
    InitGATE

    '[] PAPZ 6.05 P   FW:Device:NotHPGe   Yes
    '[] PAPZ 6.05       P   FW:Device:HPGeOnly  Yes
    InitPAPZ

    '[] PDMD ALL       D:P:G   Device  Yes
    '[] PDMD ALL       M   Device  Yes
    InitPeakDetectModeCombo

    '[] PRER '0-4294967.29
    '[] PREL 6.07.00 M   FW:Device   Yes
    '[] PRET ALL       D:P:G   Device  Yes
    If ((CBool(STATUS.DEVICE_ID = dppMCA8000D)) And (dblFirmware >= 6.07)) Then
        fraPREL.Visible = True
        fraPRET.Visible = False
    Else
        fraPREL.Visible = False
        fraPRET.Visible = True
    End If

    '[] PURE ALL       D:P:G:T Device  Yes  '[ON|OF{F}|MA{X}|###.###] uS
    '[] PURE ALL       M   Device  Yes      '[HI{GH}| LO{W}|OF{F}]
    'fraPileUpReject  ***** needs full selections for all device types
    InitPURE

    '[] TECS ALL       D:P Device:PC5Only  Yes
    fraCoolerTemperature.Visible = False
    If ((STATUS.DEVICE_ID = dppDP5) Or (STATUS.DEVICE_ID = dppPX5)) Then
        fraCoolerTemperature.Visible = True  'cooler and hv if not dp5g
    End If

    '[] VOLU ALL       P   Device  Yes
    fraPX5Speaker.Visible = CBool(STATUS.DEVICE_ID = dppPX5)

    If (STATUS.DEVICE_ID = dppMCA8000D) Then    'setup MCA8000D controls on MCA Tab
        fraSOFF.Top = 2400
        cboInputRange.ListIndex = 0
        fraInputRange.Visible = True
        fraPUR_MCA8000D.Visible = True
    Else
        fraSOFF.Top = 4920
        fraInputRange.Visible = False
        fraPUR_MCA8000D.Visible = False
    End If

End Sub

Private Sub InitPURE()
    Dim idxCtrlPURE As Long
    Dim idxCtrlPURELBL As Long
    Dim idxCtrlPUREUnits As Long
    Dim idxCtrlPUREText As Long
    Dim m_PileUpRejectCombo As ComboBox
    Dim m_PileUpRejectLabel As Label
    Dim m_PileUpRejectUnits As Label
    Dim m_PileUpRejectText As TextBox

    idxCtrlPURE = GetCtrlIdxByNameTag(Me, "cboControl", "PURE")
    Set m_PileUpRejectCombo = cboControl(idxCtrlPURE)
    idxCtrlPURELBL = GetCtrlIdxByNameTag(Me, "lblValueLimits", "PURE")
    Set m_PileUpRejectLabel = lblValueLimits(idxCtrlPURELBL)
    idxCtrlPUREUnits = GetCtrlIdxByNameTag(Me, "lblValueUnits", "PURE")
    Set m_PileUpRejectUnits = lblValueUnits(idxCtrlPUREUnits)
'    idxCtrlPUREText = GetCtrlIdxByNameTag(Me, "txtControl", "PURE")
'    Set m_PileUpRejectText = txtControl(idxCtrlPUREText)

    m_PileUpRejectCombo.Clear
    If (STATUS.DEVICE_ID = dppMCA8000D) Then
        m_PileUpRejectCombo.AddItem "HIGH"
        m_PileUpRejectCombo.AddItem "LOW"
        m_PileUpRejectCombo.AddItem "OFF"
        m_PileUpRejectCombo.ListIndex = 2
        m_PileUpRejectUnits.Visible = False
    Else
        m_PileUpRejectCombo.AddItem "ON"
        m_PileUpRejectCombo.AddItem "OFF"
        m_PileUpRejectCombo.AddItem "Max"
        m_PileUpRejectCombo.AddItem "###.###"
        m_PileUpRejectCombo.ListIndex = 1
        m_PileUpRejectUnits.Visible = True
        m_PileUpRejectLabel.Caption = ""
    End If

End Sub

Private Sub InitPeakDetectModeCombo()
    Dim idxCtrl As Long
    Dim m_PeakDetectModeCombo As ComboBox

    idxCtrl = GetCtrlIdxByNameTag(Me, "cboControl", "PDMD")
    Set m_PeakDetectModeCombo = cboControl(idxCtrl)

    m_PeakDetectModeCombo.Clear
    If (CBool(STATUS.DEVICE_ID = dppMCA8000D)) Then
        m_PeakDetectModeCombo.AddItem "NORM"
        m_PeakDetectModeCombo.AddItem "MIN"
        m_PeakDetectModeCombo.AddItem "ABS"
        m_PeakDetectModeCombo.AddItem "CLK"
        m_PeakDetectModeCombo.AddItem "INT"
        m_PeakDetectModeCombo.ListIndex = 0
    Else
        m_PeakDetectModeCombo.AddItem "NORM"
        m_PeakDetectModeCombo.AddItem "MIN"
        m_PeakDetectModeCombo.ListIndex = 0
    End If
End Sub

Private Sub InitPAPZ()
    Dim idxCtrlPAPZ As Long
    Dim idxCtrlPAPZLBL As Long
    Dim idxCtrlPAPZUnits As Long
    Dim idxCtrlPAPZText As Long
    Dim m_PreampPoleZeroCombo As ComboBox
    Dim m_PreampPoleZeroLabel As Label
    Dim m_PreampPoleZeroUnits As Label
    Dim m_PreampPoleZeroText As TextBox
    Dim isHPGe As Boolean

    idxCtrlPAPZ = GetCtrlIdxByNameTag(Me, "cboControl", "PAPZ")
    Set m_PreampPoleZeroCombo = cboControl(idxCtrlPAPZ)
    idxCtrlPAPZLBL = GetCtrlIdxByNameTag(Me, "lblValueLimits", "PAPZ")
    Set m_PreampPoleZeroLabel = lblValueLimits(idxCtrlPAPZLBL)
    idxCtrlPAPZUnits = GetCtrlIdxByNameTag(Me, "lblValueUnits", "PAPZ")
    Set m_PreampPoleZeroUnits = lblValueUnits(idxCtrlPAPZUnits)
    idxCtrlPAPZText = GetCtrlIdxByNameTag(Me, "txtControl", "PAPZ")
    Set m_PreampPoleZeroText = txtControl(idxCtrlPAPZText)

    m_PreampPoleZeroCombo.Enabled = False
    m_PreampPoleZeroLabel.Enabled = False
    m_PreampPoleZeroUnits.Enabled = False
    m_PreampPoleZeroText.Enabled = False

    If (STATUS.DEVICE_ID = dppPX5) Then
        m_PreampPoleZeroCombo.Enabled = True
        m_PreampPoleZeroLabel.Enabled = True
        m_PreampPoleZeroUnits.Enabled = True
        m_PreampPoleZeroText.Enabled = True
        isHPGe = False
        If (s.isDppConnected) Then
            If ((STATUS.DPP_options And 15) = 1) Then       '"PX5 HPGe"
                isHPGe = True
            End If
        End If
        m_PreampPoleZeroCombo.ListIndex = 1
        If (isHPGe) Then
            m_PreampPoleZeroText.Text = "34.5-103.5 uS"
        Else
            m_PreampPoleZeroText.Text = "34.5-4387 uS"
        End If
    End If
End Sub

Private Sub InitGATE()
    Dim idxCtrlGATE As Long
    Dim m_GATECombo As ComboBox

    idxCtrlGATE = GetCtrlIdxByNameTag(Me, "cboControl", "GATE")
    Set m_GATECombo = cboControl(idxCtrlGATE)
    m_GATECombo.Enabled = False
    fraGateControl.Enabled = False
    If ((STATUS.DEVICE_ID = dppDP5) Or (STATUS.DEVICE_ID = dppMCA8000D)) Then
        m_GATECombo.Enabled = True
        fraGateControl.Enabled = True
        m_GATECombo.ListIndex = 0
    End If
End Sub

Private Sub InitCON()
    Dim idxCtrl1 As Long
    Dim m_CON1Combo As ComboBox
    Dim idxCtrl1Label As Long
    Dim m_CON1Label As Label

    Dim idxCtrl2 As Long
    Dim m_CON2Combo As ComboBox
    Dim idxCtrl2Label As Long
    Dim m_CON2Label As Label

    Dim dblFirmware As Double
    Dim isInitCON As Boolean

    idxCtrl1 = GetCtrlIdxByNameTag(Me, "cboControl", "CON1")
    Set m_CON1Combo = cboControl(idxCtrl1)          '[DAC|AUXOUT1|AUXIN1]
    idxCtrl1Label = GetCtrlIdxByNameTag(Me, "lblControlName", "CON1")
    Set m_CON1Label = lblControlName(idxCtrl1Label)
    idxCtrl2 = GetCtrlIdxByNameTag(Me, "cboControl", "CON2")
    Set m_CON2Combo = cboControl(idxCtrl2)          '[AUXOUT2|AUXIN2|GATEH|GATEL]
    idxCtrl2Label = GetCtrlIdxByNameTag(Me, "lblControlName", "CON2")
    Set m_CON2Label = lblControlName(idxCtrl2Label)
    m_CON1Combo.Enabled = False
    m_CON1Label.Enabled = False
    m_CON2Combo.Enabled = False
    m_CON2Label.Enabled = False
    dblFirmware = 6#
    If (s.isDppConnected) Then
        isInitCON = CBool(STATUS.DEVICE_ID = dppPX5) Or CBool(STATUS.DEVICE_ID = dppDP5G) Or CBool(STATUS.DEVICE_ID = dppTB5)
        dblFirmware = VersionToDbl(STATUS.Firmware, STATUS.Build)
        If ((dblFirmware >= 6.03) And isInitCON) Then
            m_CON1Combo.Enabled = True
            m_CON1Label.Enabled = True
            m_CON2Combo.Enabled = True
            m_CON2Label.Enabled = True
            If (STATUS.DEVICE_ID = dppPX5) Then     'set defaults
                m_CON1Combo.ListIndex = 0           'DAC (PX5)
                m_CON2Combo.ListIndex = 0           'AUXOUT2 (PX5)
            Else
                m_CON1Combo.ListIndex = 2           'AUXIN1 (DP5G,TB5)
                m_CON2Combo.ListIndex = 1           'AUXIN2 (DP5G,TB5)
            End If
        End If
    End If

End Sub

Private Sub InitPreampVoltageCombo(DeviceType As Byte)
    Dim idxCtrlPAPS As Long
    Dim idxCtrlPAPSLBL As Long
    Dim idxCtrlPAPSUnits As Long
    Dim idxCtrlBOOT As Long
    Dim idxCtrlBOOTLBL As Long
    Dim m_PreampVoltageCombo As ComboBox
    Dim m_PreampVoltageLabel As Label
    Dim m_PreampVoltageUnits As Label
    Dim m_PC5OnAtStartUpCombo As ComboBox
    Dim m_PC5OnAtStartUpLabel As Label
    Dim isHPGe As Boolean

    isHPGe = False
    If (s.isDppConnected) Then
        If (STATUS.DEVICE_ID = dppPX5) Then
            If ((STATUS.DPP_options And 15) = 1) Then       '"PX5 HPGe"
                isHPGe = True
            End If
        End If
    End If

    idxCtrlPAPS = GetCtrlIdxByNameTag(Me, "cboControl", "PAPS")
    Set m_PreampVoltageCombo = cboControl(idxCtrlPAPS)
    idxCtrlPAPSLBL = GetCtrlIdxByNameTag(Me, "lblControlName", "PAPS")
    Set m_PreampVoltageLabel = lblControlName(idxCtrlPAPSLBL)
    idxCtrlPAPSUnits = GetCtrlIdxByNameTag(Me, "lblValueUnits", "PAPS")
    Set m_PreampVoltageUnits = lblValueUnits(idxCtrlPAPSUnits)
    idxCtrlBOOT = GetCtrlIdxByNameTag(Me, "cboControl", "BOOT")
    Set m_PC5OnAtStartUpCombo = cboControl(idxCtrlBOOT)
    idxCtrlBOOTLBL = GetCtrlIdxByNameTag(Me, "lblControlName", "BOOT")
    Set m_PC5OnAtStartUpLabel = lblControlName(idxCtrlBOOTLBL)
    m_PreampVoltageUnits.Enabled = False
    If (DeviceType = dppPX5) Then
        fraPC5Control.Visible = True
        If (isHPGe) Then                '[OFF|ON] [PX5 with HPGe HVPS option]
            m_PreampVoltageCombo.Clear
            m_PreampVoltageCombo.AddItem "OFF"
            m_PreampVoltageCombo.AddItem "ON"
            m_PreampVoltageUnits.Enabled = False
            'm_PreampVoltageCombo.ListIndex = 1
        Else                            '[8.5|5|OFF] [PX5]
            m_PreampVoltageCombo.Clear
            m_PreampVoltageCombo.AddItem "8.5"
            m_PreampVoltageCombo.AddItem "5"
            m_PreampVoltageCombo.AddItem "OFF"
            m_PreampVoltageUnits.Enabled = True
            'm_PreampVoltageCombo.ListIndex = 1
        End If
        m_PC5OnAtStartUpCombo.Enabled = False
        m_PC5OnAtStartUpLabel.Enabled = False
    ElseIf (DeviceType = dppDP5) Then   '[8.5|5|OFF|ON] [DP5]
        fraPC5Control.Visible = True
        m_PC5OnAtStartUpCombo.Enabled = True
        m_PC5OnAtStartUpLabel.Enabled = True
        m_PreampVoltageUnits.Enabled = True
        m_PreampVoltageCombo.Clear
        m_PreampVoltageCombo.AddItem "8.5"
        m_PreampVoltageCombo.AddItem "5"
        m_PreampVoltageCombo.AddItem "OFF"
        m_PreampVoltageCombo.AddItem "ON"
        'm_PreampVoltageCombo.ListIndex = 1
    Else
        m_PC5OnAtStartUpCombo.Enabled = False
        m_PC5OnAtStartUpLabel.Enabled = False
        m_PreampVoltageCombo.Enabled = False
        m_PreampVoltageLabel.Enabled = False
        m_PreampVoltageUnits.Enabled = False
    End If
End Sub

Private Sub InitAUX()
    Dim idxCtrl1 As Long
    Dim idxCtrl2 As Long
    Dim m_AUO1Combo As ComboBox
    Dim m_AUO2Combo As ComboBox
    Dim dblFirmware As Double
    Dim isNewList As Boolean

    dblFirmware = 6#
    If (s.isDppConnected) Then
        dblFirmware = VersionToDbl(STATUS.Firmware, STATUS.Build)
    End If
    isNewList = False
    If (dblFirmware >= 6.0802) Then isNewList = True

    idxCtrl1 = GetCtrlIdxByNameTag(Me, "cboControl", "AUO1")
    Set m_AUO1Combo = cboControl(idxCtrl1)
    m_AUO1Combo.Clear
    idxCtrl2 = GetCtrlIdxByNameTag(Me, "cboControl", "AUO2")
    Set m_AUO2Combo = cboControl(idxCtrl2)
    LoadListAUO1 m_AUO1Combo, isNewList
    LoadListAUO2 m_AUO2Combo, isNewList
End Sub

Private Sub LoadListAUO1(m_AUO1Combo As ComboBox, isNewList As Boolean)
    m_AUO1Combo.Clear
    If (isNewList) Then
        m_AUO1Combo.AddItem "ICR"
        m_AUO1Combo.AddItem "PILEUP"
        m_AUO1Combo.AddItem "MCSTB"
        m_AUO1Combo.AddItem "ONESH"
        m_AUO1Combo.AddItem "DETRES"
        m_AUO1Combo.AddItem "MCAEN"
        m_AUO1Combo.AddItem "PEAKH"
        m_AUO1Combo.AddItem "SCA8"
        m_AUO1Combo.AddItem "RTDOS"
        m_AUO1Combo.AddItem "RTDREJ"
        m_AUO1Combo.AddItem "VETO"
        m_AUO1Combo.AddItem "LIVE"
        m_AUO1Combo.ListIndex = 0
    Else
        m_AUO1Combo.AddItem "#"
        m_AUO1Combo.AddItem "ICR"
        m_AUO1Combo.AddItem "PILEUP"
        m_AUO1Combo.AddItem "MCSTB"
        m_AUO1Combo.AddItem "ONESH"
        m_AUO1Combo.AddItem "DETRES"
        m_AUO1Combo.AddItem "MCAEN"
        m_AUO1Combo.AddItem "PEAKH"
        m_AUO1Combo.AddItem "SCA8"
        m_AUO1Combo.ListIndex = 1
    End If
End Sub

Private Sub LoadListAUO2(m_AUO2Combo As ComboBox, isNewList As Boolean)
    m_AUO2Combo.Clear
    If (isNewList) Then
        m_AUO2Combo.AddItem "ICR"
        m_AUO2Combo.AddItem "PILEUP"
        m_AUO2Combo.AddItem "MCSTB"
        m_AUO2Combo.AddItem "ONESH"
        m_AUO2Combo.AddItem "DETRES"
        m_AUO2Combo.AddItem "MCAEN"
        m_AUO2Combo.AddItem "PEAKH"
        m_AUO2Combo.AddItem "SCA8"
        m_AUO2Combo.AddItem "RTDOS"
        m_AUO2Combo.AddItem "RTDREJ"
        m_AUO2Combo.AddItem "VETO"
        m_AUO2Combo.AddItem "LIVE"
        m_AUO2Combo.AddItem "STREAM"
        m_AUO2Combo.ListIndex = 0
    Else
        m_AUO2Combo.AddItem "#"
        m_AUO2Combo.AddItem "ICR"
        m_AUO2Combo.AddItem "DIAG"
        m_AUO2Combo.AddItem "PEAKH"
        m_AUO2Combo.AddItem "ONESH"
        m_AUO2Combo.AddItem "RTDOS"
        m_AUO2Combo.AddItem "RTDREJ"
        m_AUO2Combo.AddItem "LIVE"
        m_AUO2Combo.AddItem "VETO"
        m_AUO2Combo.AddItem "STREAM"
        m_AUO2Combo.ListIndex = 1
    End If
End Sub

Private Sub InitFastPeakCombo()
    Dim idxCtrl As Long
    Dim m_FastPeakCombo As ComboBox
    Dim dblFirmware As Double

    dblFirmware = 6#
    If (s.isDppConnected) Then
        dblFirmware = VersionToDbl(STATUS.Firmware, STATUS.Build)
    End If

    idxCtrl = GetCtrlIdxByNameTag(Me, "cboControl", "TPFA")
    Set m_FastPeakCombo = cboControl(idxCtrl)

    m_FastPeakCombo.Clear
    If (b80MHzModeCfg) Then
        m_FastPeakCombo.AddItem "50"
        m_FastPeakCombo.AddItem "100"
        If (dblFirmware >= 6.0705) Then m_FastPeakCombo.AddItem "200"
        m_FastPeakCombo.AddItem "400"
        If (dblFirmware >= 6.0705) Then m_FastPeakCombo.AddItem "800"
        m_FastPeakCombo.ListIndex = 1
    Else
        m_FastPeakCombo.AddItem "200"
        m_FastPeakCombo.AddItem "400"
        If (dblFirmware >= 6.0705) Then m_FastPeakCombo.AddItem "800"
        m_FastPeakCombo.AddItem "1600"
        If (dblFirmware >= 6.0705) Then m_FastPeakCombo.AddItem "3200"
        m_FastPeakCombo.ListIndex = 1
    End If
End Sub

Private Sub SetFastPeakCombo(strTPFA As String)
    Dim idxCtrl As Long
    Dim m_FastPeakCombo As ComboBox
    Dim ListIndex As Long

    If (Not IsNumeric(strTPFA)) Then Exit Sub
    idxCtrl = GetCtrlIdxByNameTag(Me, "cboControl", "TPFA")
    Set m_FastPeakCombo = cboControl(idxCtrl)
    ListIndex = FindCboIdxExact(m_FastPeakCombo, strTPFA)     'search for exact value
    If (ListIndex = LB_ERR) Then
        ListIndex = FindCboIdx(m_FastPeakCombo, strTPFA)      'search for similar value
    End If
    If (ListIndex <> LB_ERR) Then        'if found set the value
        m_FastPeakCombo.ListIndex = ListIndex
    End If
End Sub

Private Sub SetCboItem(strID As String, strVal As String)
    Dim idxCtrl As Long
    Dim m_Combo As ComboBox
    Dim ListIndex As Long

    idxCtrl = GetCtrlIdxByNameTag(Me, "cboControl", strID)
    Set m_Combo = cboControl(idxCtrl)
    ListIndex = FindCboIdxExact(m_Combo, strVal)     'search for exact value
    If (ListIndex = LB_ERR) Then
        ListIndex = FindCboIdx(m_Combo, strVal)      'search for similar value
    End If
    If (ListIndex <> LB_ERR) Then        'if found set the value
        m_Combo.ListIndex = ListIndex
    End If
End Sub

Private Sub SetTxtItem(strID As String, strVal As String)
    Dim idxCtrl As Long
    Dim m_Text As TextBox
    Dim ListIndex As Long

    idxCtrl = GetCtrlIdxByNameTag(Me, "txtControl", strID)
    Set m_Text = txtControl(idxCtrl)
    m_Text.Text = strVal
End Sub

Private Function GetTxtItem(strID As String) As String
    Dim idxCtrl As Long
    Dim m_Text As TextBox
    Dim ListIndex As Long
    Dim strVal As String

    idxCtrl = GetCtrlIdxByNameTag(Me, "txtControl", strID)
    Set m_Text = txtControl(idxCtrl)
    strVal = m_Text.Text
    GetTxtItem = strVal
End Function

Private Sub OutputQuickset(strDAC As String, _
                            strOutputOffset As String, _
                            strAUX2 As String, _
                            strAUX1 As String, _
                            strCONN1 As String, _
                            strCONN2 As String)
    SetCboItem "DACO", strDAC
    SetTxtItem "DACF", strOutputOffset
    SetCboItem "AUO2", strAUX2
    SetCboItem "AUO1", strAUX1
    SetCboItem "CON1", strCONN1
    SetCboItem "CON2", strCONN2
End Sub

Private Sub cmdOutputQuickset_Click(Index As Integer)
    Select Case Index
        Case 0
            '1. Shaped Output:  DAC=SHAPED, output offset=50 mV, AUX2 = ICR, AUX1 = SCA8, CONN1 = DAC, CONN2 = AUXOUT2
            Call OutputQuickset("SHAPED", "50", "ICR", "SCA8", "DAC", "AUXOUT2")
        Case 1
            '2. ADC Input:  DAC=INPUT, output offset=0 mV, AUX2 = ICR, AUX1 = SCA8, CONN1 = DAC, CONN2 = AUXOUT2
            Call OutputQuickset("INPUT", "0", "ICR", "SCA8", "DAC", "AUXOUT2")
        Case 2
            '3. Pile-Up:  DAC=FAST, output offset=50 mV, AUX2 = ICR, AUX1 = PILEUP, CONN1 = DAC, CONN2 = AUXOUT2
            Call OutputQuickset("FAST", "50", "ICR", "PILEUP", "DAC", "AUXOUT2")
    End Select
End Sub

Private Sub txtControl_Change(Index As Integer)
    If (STATUS.DEVICE_ID = dppMCA8000D) Then
        If ("GAIN" = txtControl(Index).Tag) Then  'set the MCA8000D Input Range Control
            SetInputRangeControlFromGain
        End If
    End If
End Sub

Private Sub SetInputRangeControlFromGain()
    Dim strRange As String
    Dim lngRange As Long
    Dim idxRange As Long
    Dim idxRangeNew As Long

    idxRange = cboInputRange.ListIndex
    strRange = GetTxtItem("GAIN")
    lngRange = CLng(Val(strRange))
    If (lngRange < 10) Then
        idxRangeNew = 0
    Else
        idxRangeNew = 1
    End If
    'only set if necessary
    'setting cbo will trigger cbo click event
    'setting txt will trigger txt change event
    'limit here to avoid recursive loop
    If (idxRange <> idxRangeNew) Then
        cboInputRange.ListIndex = idxRangeNew
    End If
End Sub

Private Sub SetGainFromInputRangeControl()
    Dim strRange As String
    Dim lngRangeNew As Long
    Dim lngRange As Long
    Dim idxRangeNew As Long
    Dim idxRange As Long

    lngRangeNew = 1                             'get new range
    idxRangeNew = cboInputRange.ListIndex
    If (idxRangeNew <> 0) Then lngRangeNew = 10
    strRange = GetTxtItem("GAIN")
    lngRange = CLng(Val(strRange))
    'only set if necessary
    'setting cbo will trigger cbo click event
    'setting txt will trigger txt change event
    'limit here to avoid recursive loop
    If (lngRange <> lngRangeNew) Then
        strRange = CStr(lngRangeNew)
        SetTxtItem "GAIN", strRange
    End If
End Sub

Private Function GetCboIndex(strID As String, Optional lDefault As Long = 0, Optional bNumeric As Boolean = False) As Long
    Dim idxCtrl As Long
    Dim m_Combo As ComboBox
    Dim ListIndex As Long
    Dim strMask As String

    ListIndex = lDefault
    idxCtrl = GetCtrlIdxByNameTag(Me, "cboControl", strID)
    Set m_Combo = cboControl(idxCtrl)
    ListIndex = m_Combo.ListIndex

    If (ListIndex = LB_ERR) Then
        ListIndex = lDefault
    Else
        If (Not bNumeric) Then
            strMask = m_Combo.List(ListIndex)
            If (InStr(strMask, "#") > 0) Then
                ListIndex = lDefault
            End If
        End If
    End If
    GetCboIndex = ListIndex
End Function

Private Sub SetMCA8000D_PUR_From_ShapingPUR()
    Dim idxPileUp As Long
    Dim idxPileUpNew As Long

    idxPileUp = cboPUR_MCA8000D.ListIndex
    idxPileUpNew = GetCboIndex("PURE", 2, False)        'default 2-OFF
    'only set if necessary
    'setting cbo will trigger cbo click event
    'setting txt will trigger txt change event
    'limit here to avoid recursive loop
    If (idxPileUp <> idxPileUpNew) Then
        cboPUR_MCA8000D.ListIndex = idxPileUpNew
    End If
End Sub

Private Sub SetShapingPUR_From_MCA8000D_PUR()
    Dim idxPileUpNew As Long
    Dim idxPileUp As Long
    Dim strPileUp As String

    idxPileUpNew = cboPUR_MCA8000D.ListIndex
    idxPileUp = GetCboIndex("PURE", 2, False)        'default 2-OFF
    'only set if necessary
    'setting cbo will trigger cbo click event
    'setting txt will trigger txt change event
    'limit here to avoid recursive loop
    If (idxPileUp <> idxPileUpNew) Then
        strPileUp = cboPUR_MCA8000D.List(idxPileUpNew)
        SetCboItem "PURE", strPileUp
    End If
End Sub


frmDppConfigDisplay Source Code

Option Explicit

Public m_strMessage As String
Public m_strTitle As String
Public m_strDelimiter As String

Private Sub cmdOK_Click()
    Unload Me
End Sub

Private Sub Form_Load()
    txtCfg(0).BackColor = Me.BackColor
    txtCfg(1).BackColor = Me.BackColor
    If (Len(Trim(m_strTitle)) > 0) Then
        Me.Caption = m_strTitle
    End If
    If (Len(Trim(m_strDelimiter)) = 0) Then m_strDelimiter = vbNewLine
    SetMessage m_strMessage, m_strDelimiter
End Sub

Private Sub SetMessage(cstrMsg As String, cstrDelimiter As String)
    Dim iHalf As Long
    Dim iDelimiter As Long   ' \r\n ms win
    If (Len(cstrMsg) = 0) Then Exit Sub
    If (Len(cstrMsg) < 100) Then
        txtCfg(0).Text = cstrMsg
        txtCfg(1).Text = ""
    Else
        iHalf = CLng(Len(cstrMsg) / 2)
        iDelimiter = InStr(iHalf, cstrMsg, cstrDelimiter)
        If (iDelimiter >= iHalf) Then         ' try to find next \r\n
            txtCfg(0).Text = Left(cstrMsg, iDelimiter + 1)
            txtCfg(1).Text = Mid(cstrMsg, iDelimiter + 3)
        End If
    End If
End Sub


frmIPConfiguration Source Code

Option Explicit


frmTest Source Code

Option Explicit

'Private Sub btnSendPacket_Click()
'    Dim X As Long
'    Dim Packet() As Byte
'    Dim PktLen As Integer
'
'    PktLen = 8 + udLen.Value
'    ReDim Packet(PktLen - 1)
'    For X = 0 To 5
'        Packet(X) = Val(txtOut(X).Text)
'    Next X
'    If udLen > 0 Then
'        For X = 6 To 6 + udLen.Value - 1
'            Packet(X) = Val(txtOut(X).Text)
'        Next X
'    End If
'    For X = 10 To 11
'        Packet(X - (4 - udLen.Value)) = Val(txtOut(X).Text)
'    Next X
'    SendCommandData XMTPT_SEND_TEST_PACKET, Packet
'End Sub

'Private Sub txtOut_Change(Index As Integer)
'    Dim X As Long
'
'    If Index < 10 Then
'        Dim Sum As Long
'        Sum = 0
'        For X = 0 To 5
'            Sum = Sum + Val(txtOut(X).Text)  ' add first 6 bytes to checksum
'        Next X
'        If udLen > 0 Then
'            For X = 6 To 6 + udLen.Value - 1
'                Sum = Sum + Val(txtOut(X).Text)  ' add byte to checksum
'            Next X
'        End If
'
'        Sum = &H1000000 - Sum
'        txtOut(10).Text = "&H" + Hex((Sum And &HFF00&) / 256)   ' MSB first!
'        txtOut(11).Text = "&H" + Hex(Sum And &HFF&)
'    End If
'End Sub

'Private Sub udLen_Change()
'    Dim idxTxt As Integer
'    txtOut(5).Text = Str(udLen.Value)
'    For idxTxt = 6 To 9
'        txtOut(idxTxt).Visible = CBool(idxTxt < (6 + udLen.Value))
'    Next idxTxt
'End Sub

Private Sub frCommunications_DragDrop(Source As Control, X As Single, Y As Single)

End Sub


mod_vbDP5 Source Code

Option Explicit

Public RS232HeaderReceived As Boolean
Public RS232PacketPtr As Integer
Public RS232ComPortTest As Boolean
Public Const MAX_DISPLAY_ENTRIES = 4

Public Sub NetFinderSearch()  ' DP5 Netfinder Search
    Dim idxEntry As Long
    Dim IdRequest(5) As Byte    'Broadcast Identity Request (Note: Silicon Labs = 4 bytes, Amptek = 6 bytes)

    On Error GoTo NetFinderSearchErr

    'If (NetFinderWinSockError) Then Exit Sub
    'NetFinderWinSock.RemoteHost = "255.255.255.255" ' this gets set to the responding IP, so reset it each time
    Netfinder_Seq = Rnd * 32767 ' 15-bit random seq number, so don't have to screw around with signed INT
    IdRequest(0) = 0            ' Netfinder version/type
    IdRequest(1) = 0            ' reserved
    IdRequest(2) = (Netfinder_Seq And &HFF00) \ 256  'MSB
    IdRequest(3) = Netfinder_Seq And 255 ' LSB
    IdRequest(4) = &HF4         ' append validation bytes
    IdRequest(5) = &HFA

    For idxEntry = 0 To 3   'initialize entries
        frmDP5_Connect.cmdSelectIP(idxEntry).Visible = False
        frmDP5_Connect.lblUnit(idxEntry).Caption = ""
        frmDP5_Connect.lblUnit(idxEntry).BackColor = &H80000005
        frmDP5_Connect.lblUnit(idxEntry).ForeColor = &H80000012
        InitEntry DppEntries(idxEntry)
    Next

    NewNetfinderRequest = True
    frmDP5.NetFinderWinSock.RemoteHost = "255.255.255.255"  'this gets set to the responding IP, so reset it each time

    frmDP5.NetFinderWinSock.SendData IdRequest()            'send 3 times - DP5 will respond to only first one it sees
    frmDP5_Connect.lblNetFinderErrors.Caption = ""
    Exit Sub
NetFinderSearchErr:
    frmDP5_Connect.lblNetFinderErrors.Caption = "Net Finder Socket Error:" & vbNewLine & Err.Description

End Sub

Public Function SendPacketRS232(IntCtrl As Object, ByRef Buffer() As Byte, ByRef PacketIn() As Byte) As Boolean
    Dim bytesWritten As Long, bytesRead As Long
    Dim success As Boolean
    Dim curStartTime As Currency
    Dim isExpired As Boolean
    Dim strLog As String
    Dim i As Long
    Dim PLen As Long

    PLen = (Buffer(4) * 256) + Buffer(5) + 7

    ACK_Received = False
    Packet_Received = False ' a response packet is always expected
    PIN.STATUS = &HFF   ' packet invalid - will be overwritten soon by response/ACK packet

    ' send the packet
    'For i = 0 To POUT.LEN + 7
    For i = 0 To PLen
        IntCtrl.OutPut = Chr(Buffer(i))
    Next i
    Timeout_flag = False
    curStartTime = msTimeStart()
    Do
        DoEvents    ' receive bytes and parse packet
        isExpired = msTimeExpired(curStartTime, 1000)
        If (isExpired) Then Timeout_flag = True
    Loop While (PIN.STATUS = &HFF) And (Timeout_flag = False)  ' wait for ACK or timeout
    If Timeout_flag Then
        strLog = strLog + "Timeout: no response packet!" + vbCrLf
        SendPacketRS232 = False
    Else
        SendPacketRS232 = True
    End If
End Function

Public Function SendPacketInet(IntCtrl As Object, ByRef Buffer() As Byte, ByRef PacketIn() As Byte) As Boolean
    Dim bytesWritten As Long, bytesRead As Long
    Dim success As Boolean
    Dim curStartTime As Currency
    Dim isExpired As Boolean
    Dim strLog As String
    Dim idxData As Long
    Dim PLen As Long
    Dim Buffer_Eth() As Byte
    On Error GoTo SendPacketInetErr

    UDP_offset = 0  ' start at the beginning of InPacket()
    PLen = (Buffer(4) * 256) + Buffer(5) + 7
    ReDim Buffer_Eth(PLen)  'make a buffer the size of the data
    ACK_Received = False
    Packet_Received = False ' a response packet is always expected
    PIN.STATUS = &HFF   ' packet invalid - will be overwritten soon by response/ACK packet

    For idxData = 0 To PLen
        Buffer_Eth(idxData) = Buffer(idxData)
    Next
    IntCtrl.SendData Buffer_Eth()
    SendPacketInet = True

    Exit Function
SendPacketInetErr:
    SendPacketInet = False
End Function

Public Function EntryToStrRS232(ByRef pEntry As NETDISPLAY_ENTRY, strPort As String) As String
    Dim cstrAlertLevel As String
    Dim strDeviceType As String
    Dim cstrIpAddress As String
    Dim cstrEvent1, cstrEvent2 As String
    Dim cstrAdditionalDesc As String
    Dim cstrMacAddress As String
    Dim cstrEntry As String
    Dim temp_str, temp_str2 As String
    Dim idxVal As Long
    Dim strSep As String

    cstrAlertLevel = "Connection: "
    cstrAlertLevel = cstrAlertLevel & strPort
    strDeviceType = pEntry.str_type      ' Device Name/Type
    ' IP Address String
    cstrIpAddress = "IP Address: " & IpAddrConvert(pEntry.SockAddr)
    cstrAdditionalDesc = pEntry.str_description   ' Additional Description
    ' MacAddress
    cstrMacAddress = "MAC Address: "
    strSep = ""
    For idxVal = 0 To 5
        cstrMacAddress = cstrMacAddress & strSep & FmtHex(pEntry.mac(idxVal), 2)
        strSep = "-"
    Next
    ' Event1 Time
    temp_str = pEntry.str_ev1 + " "
    temp_str2 = FormatNetFinderTime(pEntry, 1)
    cstrEvent1 = temp_str + temp_str2
    ' Event2 Time
    temp_str = pEntry.str_ev2 + " "
    temp_str2 = FormatNetFinderTime(pEntry, 2)
    cstrEvent2 = temp_str + temp_str2

    cstrEntry = strDeviceType & vbNewLine
    cstrEntry = cstrEntry + cstrAlertLevel & vbNewLine
    cstrEntry = cstrEntry + cstrAdditionalDesc & vbNewLine
    cstrEntry = cstrEntry + cstrEvent1 & vbNewLine
    EntryToStrRS232 = cstrEntry
End Function

Public Function GetWinSockStateString(wSock As Winsock) As String
    Select Case wSock.State
        Case sckClosed  '0 Default.
            GetWinSockStateString = "Closed"
        Case sckOpen   '1
            GetWinSockStateString = "Open"
        Case sckListening   '2
            GetWinSockStateString = "Listening"
        Case sckConnectionPending    '3
            GetWinSockStateString = "Connection pending"
        Case sckResolvingHost    '4
            GetWinSockStateString = "Resolving host"
        Case sckHostResolved    '5
            GetWinSockStateString = "Host resolved"
        Case sckConnecting    '6
            GetWinSockStateString = "Connecting"
        Case sckConnected    '7
            GetWinSockStateString = "Connected"
        Case sckClosing    '8
            GetWinSockStateString = "Peer is closing the connection"
        Case sckError    '9
            GetWinSockStateString = "Error"
        Case Else
            GetWinSockStateString = "Unknown"
    End Select

End Function


modControls Source Code

Option Explicit

' From X11Color.h : header file
Public Const colorAmptekBlue = &HFCCE7A
Public Const colorBlue = &HFF0000
Public Const colorGreen = &H8000&
Public Const colorLightGray = &HD3D3D3
Public Const colorLightSlateGray = &H998877
Public Const colorLightSteelBlue = &HDEC4B0
Public Const colorRed = &HFF&
Public Const colorWhite = &HFFFFFF
Public Const colorYellow = &HFFFF&
Public Const colorSilver = &HC0C0C0

'dialog box file filters for file extensions
Public Const dlgTXT_Filter As String = "Text File (*.txt)|*.txt|All Files (*.*)|*.*"
Public Const dlgCFG_Filter As String = "Amptek Config File (*.cfg)|*.cfg|All Files (*.*)|*.*"
Public Const dlgCSV_Filter As String = "Comma Separated Value (*.csv)|*.csv|All Files (*.*)|*.*"
Public Const dlgMCA_Filter As String = "Amptek Spectrum File (*.mca)|*.mca|All Files (*.*)|*.*"
Public Const dlgXL_Filter As String = "Excel Files (*.xls)|*.xls|All Files (*.*)|*.*"

Private Const cmdArrowWidth = 285
Private Const WS_EX_RIGHT = &H1000 ' Alignment use extended sytle
Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE = (-16)
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

'Set Control Style
Public Sub SetStyle(ByVal lHWnd As Long, ByVal lStyleFlags As Long, ByVal bState As Boolean, Optional ByVal bExtended As Boolean = False)
    Dim lGWLType As Long
    Dim lStyle As Long

    lGWLType = IIf(bExtended, GWL_EXSTYLE, GWL_STYLE)
    lStyle = GetWindowLong(lHWnd, lGWLType)
    If (bState) Then
        lStyle = lStyle Or lStyleFlags
    Else
        lStyle = lStyle And Not lStyleFlags
    End If
    SetWindowLong lHWnd, lGWLType, lStyle
End Sub

'Set ComboBox text to right of drop arrow for all comboboxes
Public Sub SetComboRight(ByRef frm As Form)
    Dim ctl As Control
    For Each ctl In frm.Controls
        If (TypeName(ctl) = "ComboBox") Then
            SetStyle ctl.hwnd, WS_EX_RIGHT, True, True
        End If
    Next ctl
End Sub

'Aligns TextBox ComboBox Group Controls
Public Sub AlignTextBoxToComboBox(Combo1 As ComboBox, Text1 As TextBox)
    Text1.Top = Combo1.Top
    Text1.Left = Combo1.Left + cmdArrowWidth
    Text1.Width = Combo1.Width - cmdArrowWidth
    Text1.Height = Combo1.Height
End Sub

'Manages TextBox Display of TextBox ComboBox Control  Group
Public Function ClickTxtComboGroup(Combo1 As ComboBox, Text1 As TextBox) As Boolean
    If (InStr(Combo1.Text, "#") > 0) Then
        Text1.Visible = True
        Text1.ZOrder 0
    Else
        Text1.Visible = False
        Text1.ZOrder 1
    End If
    ClickTxtComboGroup = Text1.Visible
End Function

'================================================================================
' Common Dialog Box Functions
'
' This module contains the common dialog box functions and filters
'================================================================================

'================================================================================
'==== Example Usage ====
'================================================================================
'    If (dlgOpen(cmnDlg, dlgMCA_Filter)) Then
'        FileToOpen = cmnDlg.Filename
'    Else
'        'a file was not selected
'    End If
'
'    If (dlgSave(cmnDlg, dlgCSV_Filter)) Then
'        FileToSave = cmnDlg.Filename
'    Else
'        'a file was not selected
'    End If
'================================================================================

'creates an open common dialog, returns true is a file was selected, false otherwise
Public Function dlgOpen(CmnDlgFIO As CommonDialog, strFileFilters As String) As Boolean
    On Error GoTo ErrHandlerOpen
    dlgOpen = False
    CmnDlgFIO.CancelError = True    'create error on cancel
    CmnDlgFIO.FilterIndex = 1
    CmnDlgFIO.Filter = strFileFilters
    'CmnDlgFIO.Flags = cdlOFNHideReadOnly    'cdlOFNFileMustExist + cdlOFNHideReadOnly
    CmnDlgFIO.Flags = cdlOFNFileMustExist Or cdlOFNHideReadOnly Or cdlOFNExplorer Or cdlOFNLongNames
    CmnDlgFIO.filename = GetDefaultFileWildcard(strFileFilters)
    CmnDlgFIO.ShowOpen
    dlgOpen = True
    Exit Function

ErrHandlerOpen:
    If (Err.Number = cdlCancel) Then    'If (error = cdlCancel) user pressed Cancel button.
        '------ message from dlgbox to exit ------
    Else
        MsgBox Err.Description & " (" & Err.Number & ")")
    End If
    Exit Function
End Function

'creates a save common dialog, returns true if the file was saved, false otherwise
Public Function dlgSave(CmnDlgFIO As Object, strFileFilters As String) As Boolean
    On Error GoTo ErrHandlerSave
    dlgSave = False
    CmnDlgFIO.CancelError = True    'create error on cancel
    CmnDlgFIO.FilterIndex = 1
    CmnDlgFIO.Filter = strFileFilters
    CmnDlgFIO.Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt
    CmnDlgFIO.filename = GetDefaultFileWildcard(strFileFilters)
    CmnDlgFIO.ShowSave
    dlgSave = True
    Exit Function

ErrHandlerSave:
    If (Err.Number = cdlCancel) Then    'If (error = cdlCancel) user pressed Cancel button.
        'message from dlgbox to exit
    Else
        MsgBox Err.Description & " (" & Err.Number & ")")
    End If
    Exit Function
End Function

Private Function GetDefaultFileWildcard(strFilter As String) As String
    Dim extBegin As Integer
    Dim extEnd As Integer
    Dim strExt As String

    GetDefaultFileWildcard = ""
    'find starting bar, read until next bar or end of string
    extBegin = InStr(strFilter, "|")
    If (extBegin < 1) Then Exit Function
    extEnd = InStr(extBegin + 1, strFilter, "|")
    If ((extEnd - 1) < extBegin) Then
        extEnd = Len(strFilter)
    Else
        extEnd = extEnd - 1
    End If
    strExt = Trim(Mid(strFilter, extBegin + 1, extEnd - extBegin))
    If (Len(strExt) < 1) Then Exit Function
    GetDefaultFileWildcard = strExt
End Function

Public Sub SaveLastDir(CmnDlgFIO As CommonDialog)
    CmnDlgFIO.InitDir = Left$(CmnDlgFIO.filename, Len(CmnDlgFIO.filename) - Len(CmnDlgFIO.FileTitle) - 1)
End Sub


modDP5_Protocol Source Code

Option Explicit

Public strCommStatus As String
Public Declare Function timeGetTime Lib "winmm.dll" () As Long  'timeGetTimeVB
Public Packet_Received As Boolean
Public PacketIn(24648) As Byte ' largest possible IN packet
Public PIN As Packet_In
Public UDP_offset As Integer
Public USB_Default_Timeout As Boolean

Public USBDeviceTest As Boolean

Public Enum TRANSMIT_PACKET_TYPE
     'REQUEST_PACKETS_TO_DP5
    XMTPT_SEND_STATUS
    XMTPT_SEND_SPECTRUM
    XMTPT_SEND_CLEAR_SPECTRUM
    XMTPT_SEND_SPECTRUM_STATUS
    XMTPT_SEND_CLEAR_SPECTRUM_STATUS
    XMTPT_BUFFER_SPECTRUM
    XMTPT_BUFFER_CLEAR_SPECTRUM
    XMTPT_SEND_BUFFER
    XMTPT_SEND_DP4_STYLE_STATUS
    XMTPT_SEND_PX4_CONFIG
    XMTPT_SEND_SCOPE_DATA
    XMTPT_SEND_512_BYTE_MISC_DATA
    XMTPT_SEND_SCOPE_DATA_REARM
    XMTPT_SEND_ETHERNET_SETTINGS
    XMTPT_SEND_DIAGNOSTIC_DATA
    XMTPT_SEND_NETFINDER_PACKET
    XMTPT_SEND_HARDWARE_DESCRIPTION
    XMTPT_SEND_SCA
    XMTPT_LATCH_SEND_SCA
    XMTPT_LATCH_CLEAR_SEND_SCA
    XMTPT_SEND_ROI_OR_FIXED_BLOCK
    XMTPT_PX4_STYLE_CONFIG_PACKET
    XMTPT_SEND_CONFIG_PACKET_EX
    XMTPT_SEND_CONFIG_PACKET_TO_HW
    XMTPT_READ_CONFIG_PACKET
    XMTPT_FULL_READ_CONFIG_PACKET
    XMTPT_ERASE_FPGA_IMAGE
    XMTPT_UPLOAD_PACKET_FPGA
    XMTPT_REINITIALIZE_FPGA
    XMTPT_ERASE_UC_IMAGE_0
    XMTPT_ERASE_UC_IMAGE_1
    XMTPT_ERASE_UC_IMAGE_2
    XMTPT_UPLOAD_PACKET_UC
    XMTPT_SWITCH_TO_UC_IMAGE_0
    XMTPT_SWITCH_TO_UC_IMAGE_1
    XMTPT_SWITCH_TO_UC_IMAGE_2
    XMTPT_UC_FPGA_CHECKSUMS

    'VENDOR_REQUESTS_TO_DP5
    XMTPT_CLEAR_SPECTRUM_BUFFER
    XMTPT_ENABLE_MCA_MCS
    XMTPT_DISABLE_MCA_MCS
    XMTPT_ARM_DIGITAL_OSCILLOSCOPE
    XMTPT_AUTOSET_INPUT_OFFSET
    XMTPT_AUTOSET_FAST_THRESHOLD
    XMTPT_READ_IO3_0
    XMTPT_WRITE_IO3_0
    XMTPT_WRITE_512_BYTE_MISC_DATA
    XMTPT_SET_DCAL
    XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL_PZ
    XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL_UC
    XMTPT_SET_BOOT_FLAGS
    XMTPT_SET_HV_DP4_EMULATION
    XMTPT_SET_TEC_DP4_EMULATION
    XMTPT_SET_INPUT_OFFSET_DP4_EMULATION
    XMTPT_SET_ADC_CAL_GAIN_OFFSET
    XMTPT_SET_SPECTRUM_OFFSET
    XMTPT_REQ_SCOPE_DATA_MISC_DATA_SCA_PACKETS
    XMTPT_SET_SERIAL_NUMBER
    XMTPT_CLEAR_GP_COUNTER
    XMTPT_SWITCH_SUPPLIES

    XMTPT_SEND_TEST_PACKET
End Enum  'TRANSMIT_PACKET_TYPE

Public Enum PID1_TYPE
    PID1_REQ_STATUS = &H1
    PID1_REQ_SPECTRUM = &H2
    PID1_REQ_SCOPE_MISC = &H3
    PID1_REQ_SCA = &H4
    PID1_REQ_CONFIG = &H20
    PID1_REQ_FPGA_UC = &H30
    PID1_RCV_STATUS = &H80
    PID1_RCV_SPECTRUM = &H81
    PID1_RCV_SCOPE_MISC = &H82
    PID1_RCV_SCA = &H83
    PID1_VENDOR_REQ = &HF0
    PID1_ACK = &HFF
End Enum  'PID1_TYPE

Public Enum PID2_REQ_STATUS_TYPE
    PID2_SEND_DP4_STYLE_STATUS = &H1
End Enum  'PID2_REQ_STATUS_TYPE

Public Enum PID2_REQ_SPECTRUM_TYPE
    ' REQUEST_PACKETS_TO_DP5
    PID2_SEND_SPECTRUM = &H1
    PID2_SEND_CLEAR_SPECTRUM = &H2
    PID2_SEND_SPECTRUM_STATUS = &H3
    PID2_SEND_CLEAR_SPECTRUM_STATUS = &H4
    'PID2_BUFFER_SPECTRUM
    'PID2_BUFFER_CLEAR_SPECTRUM
    'PID2_SEND_BUFFER
    'PID2_SEND_CONFIG
End Enum  'PID2_REQ_SPECTRUM_TYPE

Public Enum PID2_REQ_SCOPE_MISC_TYPE
    PID2_SEND_SCOPE_DATA = &H1
    PID2_SEND_512_BYTE_MISC_DATA = &H2
    PID2_SEND_SCOPE_DATA_REARM = &H3
    PID2_SEND_ETHERNET_SETTINGS = &H4
    PID2_SEND_DIAGNOSTIC_DATA = &H5
    PID2_SEND_HARDWARE_DESCRIPTION = &H6
    PID2_SEND_NETFINDER_READBACK = &H7
End Enum  'PID2_REQ_SCOPE_MISC_TYPE

Public Enum PID2_REQ_SCA_TYPE
    PID2_SEND_SCA = &H1
    PID2_LATCH_SEND_SCA = &H2
    PID2_LATCH_CLEAR_SEND_SCA = &H3
End Enum  'PID2_REQ_SCA_TYPE

Public Enum PID2_REQ_CONFIG_TYPE
    PID2_PX4_STYLE_CONFIG_PACKET = &H1
    PID2_TEXT_CONFIG_PACKET = &H2
    PID2_CONFIG_READBACK_PACKET = &H3
End Enum  'PID2_SEND_CONFIG_TYPE

Public Enum PID2_REQ_FPGA_UC_TYPE
    PID2_ERASE_FPGA_IMAGE = &H1
    PID2_UPLOAD_PACKET_FPGA = &H2
    PID2_REINITIALIZE_FPGA = &H3
    PID2_ERASE_UC_IMAGE_0 = &H4
    PID2_ERASE_UC_IMAGE_1 = &H5
    PID2_ERASE_UC_IMAGE_2 = &H6
    PID2_UPLOAD_PACKET_UC = &H7
    PID2_SWITCH_TO_UC_IMAGE_0 = &H8
    PID2_SWITCH_TO_UC_IMAGE_1 = &H9
    PID2_SWITCH_TO_UC_IMAGE_2 = &HA
    'PID2_UC_FPGA_CHECKSUMS
End Enum  'PID2_REQ_FPGA_UC_TYPE

Public Enum PID2_VENDOR_REQ_TYPE
    PID2_CLEAR_SPECTRUM_BUFFER = &H1
    PID2_ENABLE_MCA_MCS = &H2
    PID2_DISABLE_MCA_MCS = &H3
    PID2_ARM_DIGITAL_OSCILLOSCOPE = &H4
    PID2_AUTOSET_INPUT_OFFSET = &H5
    PID2_AUTOSET_FAST_THRESHOLD = &H6
    PID2_READ_IO3_0 = &H7
    PID2_WRITE_IO3_0 = &H8
    PID2_WRITE_512_BYTE_MISC_DATA = &H9
    PID2_SET_DCAL = &HA
    PID2_SET_PZ_CORRECTION_UC_TEMP_CAL_PZ = &HB
    PID2_SET_PZ_CORRECTION_UC_TEMP_CAL_UC = &HC
    PID2_SET_BOOT_FLAGS = &HD
    'PID2_SET_HV_DP4_EMULATION
    'PID2_SET_TEC_DP4_EMULATION
    'PID2_SET_INPUT_OFFSET_DP4_EMULATION
    PID2_SET_ADC_CAL_GAIN_OFFSET = &HE
    'PID2_SET_SPECTRUM_OFFSET
    'PID2_REQ_SCOPE_DATA_MISC_DATA_SCA_PACKETS
    PID2_SET_SERIAL_NUMBER = &HF
    PID2_CLEAR_GP_COUNTER = &H10
    PID2_SET_ETHERNET_SETTINGS = &H11
    'PID2_SWITCH_SUPPLIES
    PID2_ETHERNET_ALLOW_SHAREING = &H20
    PID2_ETHERNET_NO_SHARING = &H21
    PID2_ETHERNET_LOCK_IP = &H22
End Enum  'PID2_VENDOR_REQ_TYPE

Public Enum PID2_RCV_STATUS_TYPE
    RCVPT_DP4_STYLE_STATUS = &H1
End Enum  'PID2_RCV_STATUS_TYPE

Public Enum PID2_RCV_SPECTRUM_TYPE
    RCVPT_256_CHANNEL_SPECTRUM = &H1
    RCVPT_256_CHANNEL_SPECTRUM_STATUS = &H2
    RCVPT_512_CHANNEL_SPECTRUM = &H3
    RCVPT_512_CHANNEL_SPECTRUM_STATUS = &H4
    RCVPT_1024_CHANNEL_SPECTRUM = &H5
    RCVPT_1024_CHANNEL_SPECTRUM_STATUS = &H6
    RCVPT_2048_CHANNEL_SPECTRUM = &H7
    RCVPT_2048_CHANNEL_SPECTRUM_STATUS = &H8
    RCVPT_4096_CHANNEL_SPECTRUM = &H9
    RCVPT_4096_CHANNEL_SPECTRUM_STATUS = &HA
    RCVPT_8192_CHANNEL_SPECTRUM = &HB
    RCVPT_8192_CHANNEL_SPECTRUM_STATUS = &HC
End Enum  'PID2_RCV_SPECTRUM_TYPE

Public Enum PID2_RCV_SCOPE_MISC_TYPE
    RCVPT_SCOPE_DATA = &H1
    RCVPT_512_BYTE_MISC_DATA = &H2
    RCVPT_SCOPE_DATA_WITH_OVERFLOW = &H3
    RCVPT_ETHERNET_SETTINGS = &H4
    RCVPT_DIAGNOSTIC_DATA = &H5
    RCVPT_HARDWARE_DESCRIPTION = &H6
    RCVPT_CONFIG_READBACK = &H7
    RCVPT_NETFINDER_READBACK = &H8
End Enum  'PID2_REQ_SCOPE_MISC_TYPE

Public Enum PID2_RCV_SCA_TYPE
    RCVPT_SCA = &H1
End Enum  'PID2_REQ_SCA_TYPE

Public Enum PID2_ACK_TYPE  'PID1_ACK, PID2_ACK_TYPE)
    PID2_ACK_OK = &H0
    PID2_ACK_SYNC_ERROR = &H1
    PID2_ACK_PID_ERROR = &H2
    PID2_ACK_LEN_ERROR = &H3
    PID2_ACK_CHECKSUM_ERROR = &H4
    PID2_ACK_BAD_PARAM = &H5
    PID2_ACK_BAD_HEX_REC = &H6
    PID2_ACK_UNRECOG = &H7
    PID2_ACK_FPGA_ERROR = &H8
    PID2_ACK_CP2201_NOT_FOUND = &H9
    PID2_ACK_SCOPE_DATA_NOT_AVAIL = &HA
    PID2_ACK_PC5_NOT_PRESENT = &HB
    PID2_ACK_OK_ETHERNET_SHARE_REQ = &HC
    PID2_ACK_ETHERNET_BUSY = &HD
End Enum  'PID2_ACK_TYPE

Public Const ACK = 0
Public Const SYNC1_ = &HF5
Public Const SYNC2_ = &HFA

Public Const RS232 = 0
Public Const USB = 1
Public Const ETHERNET = 2

Public Const ETHERNET_TIMEOUT = 1000   ' default timeout of 1000mS
Public Const INTERNET_TIMEOUT = 3000   ' 3 seconds if DP5 is on different subnet than this PC
Public Const RS232_TIMEOUT = 2500      ' default timeout of 2500mS (8K spectrum ~2.2s)
Public Const USB_TIMEOUT = 500         ' default timeout of 500mS

Public Const ETHERNET_KEEPALIVE = 1500 ' send a keep-alive after 1.5s of interface inactivity
Public Const Retries = 2   ' total of 3 attempts

Public OutStr As String
Public InPacketType As Integer
Public PlotColor As Long
Public Scope(0 To 2047) As Byte  ' make this a structure, with scope info?
Public ScopeOverFlow As Boolean
Public MiscData(512) As Byte
Public CommError As Boolean

Public Type Packet_In
    PID1 As Byte
    PID2 As Byte
    LEN As Integer  ' signed, but data payload always less than 32768
    STATUS As Byte
    DATA(32768) As Byte
    CheckSum As Long
End Type

Public BufferOUT(520) As Byte

Public Type Packet_Out
    PID1 As Byte
    PID2 As Byte
    LEN As Integer  ' signed, but data payload always less than 32768
    EXPECTEDRESPONSE As Byte
    DATA(514) As Byte
End Type

Public Type Spec
    DATA() As Long  ' this keeps total of static data under 64K VB limit
    Channels As Integer
End Type

Public Enum PX5_OPTIONS
    PX5_OPTION_NONE = 0
    PX5_OPTION_HPGe_HVPS = 1
    PX5_OPTION_TEST_TEK = 4
    PX5_OPTION_TEST_MOX = 5
    PX5_OPTION_TEST_AMP = 6
    PX5_OPTION_TEST_MODE_1 = 8
    PX5_OPTION_TEST_MODE_2 = 9
End Enum

Public Type Stat
    RAW(64) As Byte
    SerialNumber As Long
    FastCount As Double
    SlowCount As Double
    FPGA As Byte
    Firmware As Byte
    Build As Byte
    AccumulationTime As Double
    HV As Double
    DET_TEMP As Double
    DP5_TEMP As Double
    PX4 As Boolean
    AFAST_LOCKED As Boolean
    MCA_EN As Boolean
    PresetCountDone As Boolean
    PresetRtDone As Boolean
    PresetLtDone As Boolean
    SUPPLIES_ON As Boolean
    SCOPE_DR As Boolean
    DP5_CONFIGURED As Boolean
    GP_COUNTER As Double
    AOFFSET_LOCKED As Boolean
    MCS_DONE As Boolean
    DCAL As Double
    PZCORR As Byte  ' or single?
    UC_TEMP_OFFSET As Byte
    AN_IN As Double
    VREF_IN As Double
    PC5_SerialNumber As Long
    PC5_PRESENT As Boolean
    PC5_HV_POL As Boolean
    PC5_8_5V As Boolean
    LiveTime As Double
    RealTime As Double
    BOOT_FLAG_LSB As Byte
    BOOT_FLAG_MSB As Byte
    BOOT_HV As Double
    BOOT_TEC As Double
    BOOT_INPOFFSET As Double    ' or long?
    ADC_GAIN_CAL As Double
    ADC_OFFSET_CAL As Byte
    SPECTRUM_OFFSET As Long     ' or single?

    b80MHzMode As Boolean
    bFPGAAutoClock As Boolean
    DEVICE_ID As Byte           ' 0=DP5, 1=PX5, 2=DP5G, 3=MCA8000D, 4=TB5
    strDeviceID As String
    ReBootFlag As Boolean       ' FW6.05 and later
    DPP_options As Byte         ' 1=HPGe HVPS
    HPGe_HV_INH As Boolean
    HPGe_HV_INH_POL As Boolean
    TEC_Voltage As Double
    DPP_ECO As Byte
    AU34_2 As Boolean
    isAscInstalled As Boolean
    isAscEnabled As Boolean
    bScintHas80MHzOption As Boolean
    isDP5_RevDxGains As Boolean
End Type

Public STATUS As Stat
Public SPECTRUM As Spec

Public Function timeGetTimeVB() As Double
    Dim lRawTime As Long
    Dim dblTemp As Double

    lRawTime = timeGetTime()    'timeGetTimeVB
    If (lRawTime < 0) Then      'convert to unsigned integer
        dblTemp = (CDbl(lRawTime) + 1#) + 4294967295#
    Else
        dblTemp = lRawTime
    End If
    timeGetTimeVB = dblTemp
End Function

Public Function msTimeExpired(curStartTimeMS As Currency, curDelayTimeMS As Currency) As Boolean
    Dim curNewTime As Currency
    curNewTime = timeGetTimeVB()
    If curStartTimeMS < 0 Then curStartTimeMS = curStartTimeMS + CCur(2 ^ 32)
    If ((curNewTime < 0) Or (curNewTime < curStartTimeMS)) Then
        curNewTime = curNewTime + CCur(2 ^ 32)
    End If
    msTimeExpired = CBool(curNewTime >= (curStartTimeMS + curDelayTimeMS))
End Function

Public Function msTimeStart() As Currency
    Dim curNewTime As Currency
    msTimeStart = timeGetTimeVB()
End Function

Public Function msTimeDiff(curStartTime As Currency) As Currency
    Dim curNewTime As Currency
    curNewTime = timeGetTimeVB()
    If (curNewTime < curStartTime) Then
        curStartTime = curStartTime
        curNewTime = curNewTime + (2 ^ 32)
        msTimeDiff = curNewTime - curStartTime
    Else
        msTimeDiff = curNewTime - curStartTime
    End If
End Function

Public Function msDelay(MSec As Long) As Boolean
    Dim curStart As Currency
    Dim TimeExpired As Boolean
    Dim i As Long
    TimeExpired = False
    curStart = msTimeStart()
    Do
        DoEvents
        TimeExpired = msTimeExpired(curStart, CCur(MSec))
    Loop While (Not TimeExpired)
    msDelay = TimeExpired
End Function

Public Function SendPacketUSB(DppWinUSB As WinUsbDevice, ByRef Buffer() As Byte, ByRef PacketIn() As Byte) As Boolean
    Dim bytesWritten As Long, bytesRead As Long
    Dim success As Boolean
    Dim strLog As String
    Dim i As Long
    Dim PLen As Long

    If ((Buffer(2) = PID1_REQ_SCOPE_MISC) And Buffer(3) = PID2_SEND_DIAGNOSTIC_DATA) Then
        ' Request Diagnostic Packet delay 'USB_DiagDataDelayMS
        Call SetPipePolicy1(DppWinUSB, CByte(DppWinUSB.bulkInPipe), CInt(PIPE_POLICY_TYPE.PIPE_TRANSFER_TIMEOUT), USB_DiagDataDelayMS)
        USB_Default_Timeout = False     ' flag that non-default timeout is in use
    Else
        If USB_Default_Timeout = False Then  ' change pipetimeout to default if it isn't already set that way
            Call SetPipePolicy1(DppWinUSB, CByte(DppWinUSB.bulkInPipe), CInt(PIPE_POLICY_TYPE.PIPE_TRANSFER_TIMEOUT), USB_TIMEOUT)
            USB_Default_Timeout = True     ' flag that default timeout is in use
        End If
    End If

    PLen = (Buffer(4) * 256) + Buffer(5) + 7

    ACK_Received = False
    Packet_Received = False ' a response packet is always expected
    PIN.STATUS = &HFF   ' packet invalid - will be overwritten soon by response/ACK packet

    success = WinUsb_WritePipe(DppWinUSB.winUsbHandle, CByte(DppWinUSB.bulkOutPipe), Buffer(0), PLen + 1, bytesWritten, 0&)
    success = VbBool(success)

    If (success) Then
        success = WinUsb_ReadPipe(DppWinUSB.winUsbHandle, CByte(DppWinUSB.bulkInPipe), PacketIn(0), 32767, bytesRead, 0&)
        strLog = strLog & "USB Req sent: PID1=" & str(Buffer(2)) & ", PID2=" & str(Buffer(3)) & ": OK" & vbCrLf,
        success = VbBool(success)
        If (success) Then
            strLog = strLog & "USB Response: PID1=" & str(PacketIn(2)) & ", PID2=" & str(PacketIn(3)) & ": OK (read " & str(bytesRead) & ")" & vbCrLf,
            SendPacketUSB = True
        Else
            strLog = strLog & "USB Response: FAIL (read " & str(bytesRead) & ")" & vbCrLf)
            SendPacketUSB = False
        End If
    Else
       strLog = strLog & "USB Req sent: FAIL" & vbCrLf
       SendPacketUSB = False
    End If
End Function


modDP5CfgControls Source Code

Option Explicit

Public Type HwConfigType
    Command As String
    Value As String
    Comment As String
End Type

Public Enum CompareMethod
    Binary
    Text
    Database
End Enum

Public Const strDecValueChars = "+-.0123456789"

Private Declare Function SendMessageFind Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As String) As Long
Private Const WM_USER = &H400
'constants for searching the ListBox/ComboBox
Public Const LB_ERR = (-1)
Private Const LB_FINDSTRING = &H18F
Private Const LB_FINDSTRINGEXACT = &H1A2
Private Const CB_FINDSTRING = &H14C
Private Const CB_FINDSTRINGEXACT = &H158

Private Const HasComboCtrl = &H1
Private Const HasTextCtrl = &H2

Public Enum CtrlInfoIndex
    ciiTag
    ciiText
    ciiNameLC
    ciiIndexLC
    ciiNameTC
    ciiIndexTC
    ciiCtrlType
    ciiCtrlGroup
    ciiLblDescription
    ciiLblLimits
    ciiLblUnits
    ciiUnits
    ciiSendCmd
    ciiMask
End Enum

Public Enum DP5CmdCtrls
    ccsNone
    ccsCbo
    ccsTxt
    ccsCboTxt
End Enum

Public Enum DP5CmdLbls
    clsNone
    clsDescription
    clsLimit
    clsUnit
End Enum

Public Const LastCCI = CtrlInfoIndex.ciiMask
Public LoadingCfg As Boolean
Public strFindTab As String
Public strFindCtrl As String
Public strFindIdx As String

Public Function SetCboListIdx(frm As Form, varCmdCtrls As Variant, idxCmd As Long, strVal As String) As Long
    Dim ListIndex As Long
    Dim ctrl As Control

    Set ctrl = GetDP5Control(frm, varCmdCtrls, idxCmd, ccsCbo)
    ListIndex = FindCboIdxExact(ctrl, strVal)
    If (ListIndex = LB_ERR) Then
        ListIndex = FindCboIdx(ctrl, strVal)
    End If
    ctrl.ListIndex = ListIndex
    SetCboListIdx = ListIndex
End Function

Public Function SetCboMaskIdx(frm As Form, varCmdCtrls As Variant, idxCmd As Long) As Long
    Dim ListIndex As Long
    Dim ctrl As Control

    Set ctrl = GetDP5Control(frm, varCmdCtrls, idxCmd, ccsCbo)
    ListIndex = FindCboMask(ctrl)
    ctrl.ListIndex = ListIndex
    SetCboMaskIdx = ListIndex
End Function

'TextBox or ComboBox
Public Function GetDP5Control(frm As Form, varCmdCtrls As Variant, idxCmd As Long, CtrlType As DP5CmdCtrls, Optional SetGlobalFind As Boolean = False) As Control
    Dim ciiName As CtrlInfoIndex
    Dim ciiIndex As CtrlInfoIndex
    Dim strName As String
    Dim idxCtrl As Long

    Select Case CtrlType
        Case DP5CmdCtrls.ccsCbo
            ciiName = ciiNameLC
            ciiIndex = ciiIndexLC
        Case DP5CmdCtrls.ccsTxt
            ciiName = ciiNameTC
            ciiIndex = ciiIndexTC
        Case Else
            Exit Function
    End Select
    strName = varCmdCtrls(idxCmd, ciiName)
    idxCtrl = varCmdCtrls(idxCmd, ciiIndex)
    If (SetGlobalFind) Then
        strFindTab = varCmdCtrls(idxCmd, ciiCtrlGroup)
        strFindCtrl = strName
        strFindIdx = idxCtrl
    End If
    Set GetDP5Control = frm.Controls(strName)(idxCtrl)
End Function

Public Function FindCboMask(cboCtrl As ComboBox) As Long
    Dim idxList As Long
    Dim strList As String
    FindCboMask = -1
    For idxList = 0 To cboCtrl.ListCount - 1
        strList = cboCtrl.List(idxList)
        If (InStr(strList, "#") > 0) Then
            FindCboMask = idxList
            Exit For
        End If
    Next
End Function

Public Function FindCboIdx(cboCtrl As ComboBox, strVal As String) As Long
    Dim lRet As Long
    lRet = SendMessageFind(cboCtrl.hwnd, CB_FINDSTRING, 0, (strVal))
    If lRet = LB_ERR Then
        FindCboIdx = -1
    Else
        FindCboIdx = lRet
    End If
End Function

Public Function FindCboIdxExact(cboCtrl As ComboBox, strVal As String) As Long
    Dim lRet As Long
    lRet = SendMessageFind(cboCtrl.hwnd, CB_FINDSTRINGEXACT, 0, (strVal))
    If lRet = LB_ERR Then
        FindCboIdxExact = -1
    Else
        FindCboIdxExact = lRet
    End If
End Function

Public Function AddDP5ListCmd(lstDP5Cmds As ListBox, strCmd As String, CtrlType As DP5CmdCtrls) As Long
    Dim lRet As Long
    Dim idxLst As Long
    lRet = SendMessageFind(lstDP5Cmds.hwnd, LB_FINDSTRING, 0, (strCmd))
    If lRet = LB_ERR Then
        lstDP5Cmds.AddItem strCmd
        lstDP5Cmds.ListIndex = lstDP5Cmds.NewIndex
    Else
        lstDP5Cmds.ListIndex = lRet
    End If
    idxLst = lstDP5Cmds.ListIndex
    lstDP5Cmds.ItemData(idxLst) = lstDP5Cmds.ItemData(idxLst) Or CLng(CtrlType)
    AddDP5ListCmd = idxLst
End Function

Public Function GetDP5ListCmd(lstDP5Cmds As ListBox, strCmd As String) As Long
    Dim lRet As Long
    lRet = SendMessageFind(lstDP5Cmds.hwnd, LB_FINDSTRING, 0, (strCmd))
    If lRet = LB_ERR Then
        GetDP5ListCmd = -1
    Else
        GetDP5ListCmd = lRet
    End If
End Function

Public Function GetSSTabName(CmdCtrl As Control, SSTab1 As SSTab) As String
    Dim idxTab As Long
    Dim CtrlFrame As Control

    GetSSTabName = ""
    If (Len(CmdCtrl.Tag) = 4) Then
        If (TypeName(CmdCtrl.Container)) = "Frame" Then
            Set CtrlFrame = CmdCtrl.Container
            If CtrlFrame.Container.Name = "SSTab1" Then
                For idxTab = 0 To SSTab1.Tabs - 1
                    SSTab1.Tab = idxTab
                    If (CtrlFrame.Left >= 0) Then
                        GetSSTabName = SSTab1.TabCaption(idxTab)
                        Exit For
                    End If
                Next
            End If
        End If
    End If
End Function

Public Sub GetDP5CmdGroups(frm As Form, varCmdCtrls As Variant, SSTab1 As SSTab)
    Dim idxCmd As Long
    Dim CtrlType As DP5CmdCtrls
    Dim CmdCtrl As Control
    Dim lTab As Long

    lTab = SSTab1.Tab
    For idxCmd = 0 To UBound(varCmdCtrls, 1)          'loop through cmd control sets
        CtrlType = varCmdCtrls(idxCmd, ciiCtrlType)
        Select Case CtrlType
            Case DP5CmdCtrls.ccsCbo, DP5CmdCtrls.ccsCboTxt
                Set CmdCtrl = GetDP5Control(frm, varCmdCtrls, idxCmd, ccsCbo)
                varCmdCtrls(idxCmd, ciiCtrlGroup) = GetSSTabName(CmdCtrl, SSTab1)
            Case DP5CmdCtrls.ccsTxt
                Set CmdCtrl = GetDP5Control(frm, varCmdCtrls, idxCmd, ccsTxt)
                varCmdCtrls(idxCmd, ciiCtrlGroup) = GetSSTabName(CmdCtrl, SSTab1)
        End Select
    Next
    SSTab1.Tab = lTab
End Sub

Public Sub UnPressButtons(Toolbar1 As ComctlLib.Toolbar)
    Dim btn As Button
    For Each btn In Toolbar1.Buttons
        btn.Value = tbrUnpressed
    Next btn
End Sub

Public Function DP5CmdLblType(ctrl As Control, ByRef strLabel As String) As Long
    Dim strTypeName As String
    Dim strCtrlName As String
    Dim strCtrlType As String
    Dim LblType As DP5CmdLbls

    DP5CmdLblType = clsNone
    LblType = clsNone
    strLabel = ""
    strTypeName = TypeName(ctrl)
    If (strTypeName = "Label") Then
        strCtrlName = ctrl.Name
        If (strCtrlName = "lblControlName") Then
            LblType = clsDescription
        ElseIf (strCtrlName = "lblValueLimits") Then
            LblType = clsLimit
        ElseIf (strCtrlName = "lblValueUnits") Then
            LblType = clsUnit
        End If
        If (LblType <> clsNone) Then
            If (Len(ctrl.Tag) = 4) Then
                strLabel = ctrl.Caption
                DP5CmdLblType = LblType
            End If
        End If
    End If
End Function

Public Function DP5CmdCtrlType(ctrl As Control) As Long
    Dim strTypeName As String
    Dim strCtrlType As String
    Dim CtrlType As DP5CmdCtrls

    DP5CmdCtrlType = ccsNone
    CtrlType = ccsNone
    strTypeName = TypeName(ctrl)
    If (strTypeName = "ComboBox") Then
        CtrlType = ccsCbo
    ElseIf (strTypeName = "TextBox") Then
        CtrlType = ccsTxt
    End If
    If (CtrlType <> ccsNone) Then
        If (Len(ctrl.Tag) = 4) Then
            DP5CmdCtrlType = CtrlType
        End If
    End If
End Function

Public Function GetDP5CmdCtrlInfo(frm As Form, lstDP5Commands As ListBox, varCmdCtrls As Variant, idxCmd As Long) As String
    Dim CtrlType As DP5CmdCtrls
    Dim strInfo As String
    Dim strLimits As String
    Dim strUnits As String
    Dim strSend As String
    Dim bOption As Boolean
    Dim strOption As String

    If (LoadingCfg) Then Exit Function
    GetDP5CmdCtrlInfo = ""
    strInfo = ""
    If (idxCmd >= 0) Then
        bOption = False
        strInfo = strInfo & varCmdCtrls(idxCmd, ciiLblDescription) & vbNewLine
        strInfo = strInfo & varCmdCtrls(idxCmd, ciiTag) & vbNewLine
        strInfo = strInfo & varCmdCtrls(idxCmd, ciiCtrlGroup) & " Tab" & vbNewLine
        If (True = lstDP5Commands.Selected(idxCmd)) Then
            strSend = "Send selected."
        Else
            strSend = "Send not selected."
        End If
        strInfo = strInfo & strSend & vbNewLine
        CtrlType = varCmdCtrls(idxCmd, ciiCtrlType)
        If ((CtrlType = ccsCbo) Or (CtrlType = ccsCboTxt)) Then
            strOption = GetDP5Control(frm, varCmdCtrls, idxCmd, ccsCbo, True).Text      'sets global find option
            If (InStr(strOption, "#") > 0) Then
                strInfo = strInfo & vbNewLine & vbNewLine
            Else
                bOption = True
                strInfo = strInfo & "Option " & strOption & vbNewLine
            End If
        End If
        If ((CtrlType = ccsTxt) Or (CtrlType = ccsCboTxt) And (Not bOption)) Then
            strLimits = varCmdCtrls(idxCmd, ciiLblLimits)
            If (Len(strLimits) > 0) Then strInfo = strInfo & strLimits & vbNewLine
            strInfo = strInfo & "Value " & GetDP5Control(frm, varCmdCtrls, idxCmd, ccsTxt, True).Text 'sets global find option
            strInfo = strInfo & " "
            strUnits = varCmdCtrls(idxCmd, ciiLblUnits)
            If (Len(strUnits) > 0) Then strInfo = strInfo & strUnits & vbNewLine
            strInfo = strInfo & vbNewLine
        End If
    End If
    GetDP5CmdCtrlInfo = strInfo
End Function

Public Function SetupCmdCtrls(frm As Form, lstDP5Commands As ListBox) As Variant
    Dim ctrl As Control
    Dim strControl() As String
    Dim idxIndex As Long
    Dim strTypeName As String
    Dim CtrlType As DP5CmdCtrls
    Dim LblType As DP5CmdLbls
    Dim strCmd As String
    Dim strLbl As String

    For Each ctrl In frm.Controls
        CtrlType = DP5CmdCtrlType(ctrl)
        If (CtrlType <> ccsNone) Then
            strCmd = ctrl.Tag
            idxIndex = AddDP5ListCmd(lstDP5Commands, strCmd, CtrlType)
        End If
    Next
    If (lstDP5Commands.ListCount > 0) Then
        ReDim strControl(lstDP5Commands.ListCount - 1, LastCCI)
        For idxIndex = 0 To lstDP5Commands.ListCount - 1
            strControl(idxIndex, ciiTag) = lstDP5Commands.List(idxIndex)
            strControl(idxIndex, ciiText) = ""
            strControl(idxIndex, ciiNameLC) = ""
            strControl(idxIndex, ciiIndexLC) = ""
            strControl(idxIndex, ciiNameTC) = ""
            strControl(idxIndex, ciiIndexTC) = ""
            strControl(idxIndex, ciiCtrlType) = lstDP5Commands.ItemData(idxIndex)
            strControl(idxIndex, ciiUnits) = ""
            strControl(idxIndex, ciiSendCmd) = ""
            strControl(idxIndex, ciiMask) = ""
        Next
        For Each ctrl In frm.Controls
            CtrlType = DP5CmdCtrlType(ctrl)
            If ((CtrlType = ccsCbo) Or (CtrlType = ccsTxt)) Then
                strCmd = ctrl.Tag
                idxIndex = GetDP5ListCmd(lstDP5Commands, strCmd)
                If (idxIndex >= 0) Then
                    If (CtrlType = ccsCbo) Then
                        strControl(idxIndex, ciiNameLC) = ctrl.Name
                        strControl(idxIndex, ciiIndexLC) = ctrl.Index
                    ElseIf (CtrlType = ccsTxt) Then
                        strControl(idxIndex, ciiNameTC) = ctrl.Name
                        strControl(idxIndex, ciiIndexTC) = ctrl.Index
                    End If
                End If
            Else
                LblType = DP5CmdLblType(ctrl, strLbl)
                If (LblType <> clsNone) Then
                    strCmd = ctrl.Tag
                    idxIndex = GetDP5ListCmd(lstDP5Commands, strCmd)
                    If (idxIndex >= 0) Then
                        Select Case LblType
                            Case clsDescription
                                strControl(idxIndex, ciiLblDescription) = strLbl
                            Case clsLimit
                                strControl(idxIndex, ciiLblLimits) = strLbl
                            Case clsUnit
                                strControl(idxIndex, ciiLblUnits) = strLbl
                        End Select
                    End If
                End If
            End If
        Next
        SetupCmdCtrls = strControl
    End If
End Function

Public Sub UpdateDP5TextCtrls(frm As Form, lstDP5Commands As ListBox, varCmdCtrls As Variant, varValues As Variant, varUnitsArray As Variant)
    Dim idxSetting As Long
    Dim strCmd As String
    Dim strVal As String
    Dim idxCmd As Long
    Dim CtrlType As DP5CmdCtrls
    Dim strRetData As String
    Dim strUnit As String

    If (IsEmpty(varValues)) Then Exit Sub

    For idxSetting = 0 To UBound(varValues, 1)          'loop through settings
        strCmd = varValues(idxSetting, 0)
        strVal = varValues(idxSetting, 1)
        idxCmd = GetDP5ListCmd(lstDP5Commands, strCmd)  'find ctrl idx
        If (idxCmd >= 0) Then
            lstDP5Commands.Selected(idxCmd) = True
            CtrlType = varCmdCtrls(idxCmd, ciiCtrlType)
            Select Case CtrlType
                Case DP5CmdCtrls.ccsTxt, DP5CmdCtrls.ccsCboTxt  'only update the text
                    'get value (parse for units), set value
                    If (DP5UnitsFromData(varUnitsArray, strVal, strRetData, strUnit)) Then 'find data
                        varCmdCtrls(idxCmd, ciiUnits) = strUnit             'if found, update storage data
                    End If
                    GetDP5Control(frm, varCmdCtrls, idxCmd, ccsTxt).Text = strRetData
            End Select
        End If
    Next
End Sub

Public Sub UpdateDP5Ctrls(frm As Form, lstDP5Commands As ListBox, varCmdCtrls As Variant, varConfig As Variant, varUnitsArray As Variant)
    Dim idxSetting As Long
    Dim strCmd As String
    Dim strVal As String
    Dim idxCmd As Long
    Dim CtrlType As DP5CmdCtrls
    Dim strRetData As String
    Dim strUnit As String

    For idxSetting = 0 To UBound(varConfig, 1)          'loop through settings
        strCmd = varConfig(idxSetting, 0)
        strVal = varConfig(idxSetting, 1)
        idxCmd = GetDP5ListCmd(lstDP5Commands, strCmd)  'find ctrl idx
        If (idxCmd >= 0) Then
            lstDP5Commands.Selected(idxCmd) = True
            CtrlType = varCmdCtrls(idxCmd, ciiCtrlType)
            Select Case CtrlType
                Case DP5CmdCtrls.ccsNone    'do nothing
                Case DP5CmdCtrls.ccsCbo     'set idx
                    If (DP5UnitsFromData(varUnitsArray, strVal, strRetData, strUnit)) Then 'find data
                        varCmdCtrls(idxCmd, ciiUnits) = strUnit             'if found, update storage data
                    End If
                    Call SetCboListIdx(frm, varCmdCtrls, idxCmd, strRetData)
                Case DP5CmdCtrls.ccsTxt     'get value (parse for units), set value
                    If (DP5UnitsFromData(varUnitsArray, strVal, strRetData, strUnit)) Then 'find data
                        varCmdCtrls(idxCmd, ciiUnits) = strUnit             'if found, update storage data
                    End If
                    GetDP5Control(frm, varCmdCtrls, idxCmd, ccsTxt).Text = strRetData
                Case DP5CmdCtrls.ccsCboTxt
                    'check the cbo for list item, if not there select mask, update text
                    If (SetCboListIdx(frm, varCmdCtrls, idxCmd, strVal) >= 0) Then
                        '   if data in list idx has been set, goto next control
                    ElseIf (SetCboMaskIdx(frm, varCmdCtrls, idxCmd) >= 0) Then  'find mask ,set to mask value item
                        '   get value (parse for units), set value,exit
                        If (DP5UnitsFromData(varUnitsArray, strVal, strRetData, strUnit)) Then 'find data
                            varCmdCtrls(idxCmd, ciiUnits) = strUnit             'if found, update storage data
                        End If
                        GetDP5Control(frm, varCmdCtrls, idxCmd, ccsTxt).Text = strRetData
                    End If
            End Select
        End If
    Next
End Sub

Public Sub ReadDP5Text(frm As Form, lstDP5Commands As ListBox, varCmdCtrls As Variant, ByRef varValues As Variant)
    Dim idxSetting As Long
    Dim strCmd As String
    Dim strVal As String
    Dim idxCmd As Long
    Dim CtrlType As DP5CmdCtrls
    Dim strUnit As String
    Dim Table() As String
    Dim Table2() As String

    'If (IsEmpty(varValues)) Then Exit Sub

    If (IsEmpty(varValues)) Then    'try to create table
        'create VarValues array
        idxSetting = -1
        For idxCmd = 0 To UBound(varCmdCtrls, 1)          'loop through settings
            CtrlType = varCmdCtrls(idxCmd, ciiCtrlType)
            Select Case CtrlType
                Case DP5CmdCtrls.ccsTxt, DP5CmdCtrls.ccsCboTxt     'get value (append units), set value
                    idxSetting = idxSetting + 1
                    ReDim Preserve Table(1, idxSetting)
                    Table(0, idxSetting) = varCmdCtrls(idxCmd, ciiTag)  'save the cmd
                    Table(1, idxSetting) = ""
            End Select
        Next
        If (idxSetting >= 0) Then
            ReDim Table2(idxSetting, 1)
            For idxCmd = 0 To idxSetting                'swap the table main index
                Table2(idxCmd, 0) = Table(0, idxCmd)
                Table2(idxCmd, 1) = Table(1, idxCmd)
            Next
            varValues = Table2                          'save the new table
        Else
            Exit Sub
        End If
    End If

    For idxSetting = 0 To UBound(varValues, 1)          'loop through settings
        strCmd = varValues(idxSetting, 0)
        idxCmd = GetDP5ListCmd(lstDP5Commands, strCmd)  'find ctrl idx
        If (idxCmd >= 0) Then
            lstDP5Commands.Selected(idxCmd) = True
            CtrlType = varCmdCtrls(idxCmd, ciiCtrlType)
            Select Case CtrlType
                Case DP5CmdCtrls.ccsNone, DP5CmdCtrls.ccsCbo
                    'do nothing
                Case DP5CmdCtrls.ccsTxt, DP5CmdCtrls.ccsCboTxt     'get value (append units), set value
                    strVal = Trim(GetDP5Control(frm, varCmdCtrls, idxCmd, ccsTxt).Text)
                    If (Len(strVal) > 0) Then 'find units
                        strUnit = varCmdCtrls(idxCmd, ciiUnits)         'if found, update storage data
                        strUnit = Trim(strUnit)
                        If (Len(strUnit) > 0) Then 'save units, force to uppercase
                            strUnit = UCase(strUnit)
                            strVal = strVal & strUnit
                        End If
                    End If
                    varValues(idxSetting, 1) = strVal
            End Select
        End If
    Next
End Sub

'==========================
' Save Settings
'==========================
Public Sub ReadDP5Settings(frm As Form, lstDP5Commands As ListBox, varCmdCtrls As Variant, varConfig As Variant)
    Dim idxSetting As Long
    Dim strCmd As String
    Dim strVal As String
    Dim idxCmd As Long
    Dim CtrlType As DP5CmdCtrls
    Dim strUnit As String

    For idxSetting = 0 To UBound(varConfig, 1)          'loop through settings
        strCmd = varConfig(idxSetting, 0)
        idxCmd = GetDP5ListCmd(lstDP5Commands, strCmd)  'find ctrl idx
        If (idxCmd >= 0) Then
            lstDP5Commands.Selected(idxCmd) = True
            CtrlType = varCmdCtrls(idxCmd, ciiCtrlType)
            Select Case CtrlType
                Case DP5CmdCtrls.ccsCbo
                    strVal = Trim(GetDP5Control(frm, varCmdCtrls, idxCmd, ccsCbo).Text)
                    If (Len(strVal) > 0) Then 'find units
                        strUnit = varCmdCtrls(idxCmd, ciiUnits)         'if found, update storage data
                        strUnit = Trim(strUnit)
                        If (Len(strUnit) > 0) Then 'save units, force to uppercase
                            strUnit = UCase(strUnit)
                            strVal = strVal & strUnit
                        End If
                    End If
                    varConfig(idxSetting, 1) = strVal
                Case DP5CmdCtrls.ccsTxt                     'get value (append units), set value
                    strVal = Trim(GetDP5Control(frm, varCmdCtrls, idxCmd, ccsTxt).Text)
                    If (Len(strVal) > 0) Then 'find units
                        strUnit = varCmdCtrls(idxCmd, ciiUnits)         'if found, update storage data
                        strUnit = Trim(strUnit)
                        If (Len(strUnit) > 0) Then 'save units, force to uppercase
                            strUnit = UCase(strUnit)
                            strVal = strVal & strUnit
                        End If
                    End If
                    varConfig(idxSetting, 1) = strVal
                Case DP5CmdCtrls.ccsCboTxt
                    strVal = Trim(GetDP5Control(frm, varCmdCtrls, idxCmd, ccsCbo).Text)
                    If (InStr(strVal, "#") > 0) Then    'Get the textbox value
                        strVal = Trim(GetDP5Control(frm, varCmdCtrls, idxCmd, ccsTxt).Text)
                        If (Len(strVal) > 0) Then 'find units
                            strUnit = varCmdCtrls(idxCmd, ciiUnits)         'if found, update storage data
                            strUnit = Trim(strUnit)
                            If (Len(strUnit) > 0) Then 'save units, force to uppercase
                                strUnit = UCase(strUnit)
                                strVal = strVal & strUnit
                            End If
                        End If
                    End If
                    varConfig(idxSetting, 1) = strVal
            End Select
        End If
    Next
End Sub

Public Function GetTextBoxIndexByTag(varCmdCtrls As Variant, strTag As String) As Long
    Dim idxCmd As Long
    Dim CtrlType As DP5CmdCtrls
    Dim idxCtrlTC As Long

    CtrlType = ccsNone
    idxCtrlTC = -1
    For idxCmd = 0 To UBound(varCmdCtrls, 1)          'loop through settings
        If (varCmdCtrls(idxCmd, ciiTag) = strTag) Then
            CtrlType = varCmdCtrls(idxCmd, ciiCtrlType)
            If (CtrlType = ccsCboTxt) Then
                idxCtrlTC = varCmdCtrls(idxCmd, ciiIndexTC)
                Exit For
            End If
        End If
    Next
    GetTextBoxIndexByTag = idxCtrlTC
End Function

Public Sub SetupStartupCboTxt(frm As Form, varCmdCtrls As Variant)
    Dim idxCmd As Long
    Dim CtrlType As DP5CmdCtrls
    Dim ctrlTC As Control   'TextBox
    Dim ctrlLC As Control   'ComboBox

    For idxCmd = 0 To UBound(varCmdCtrls, 1)          'loop through settings
        CtrlType = varCmdCtrls(idxCmd, ciiCtrlType)
        If (CtrlType = ccsCboTxt) Then
            Set ctrlTC = GetDP5Control(frm, varCmdCtrls, idxCmd, ccsTxt)
            Set ctrlLC = GetDP5Control(frm, varCmdCtrls, idxCmd, ccsCbo)
            AlignTextBoxToComboBox ctrlLC, ctrlTC
        End If
    Next
End Sub

Public Sub CboTxtCtrlVis(frm As Form, strTag As String, isVisible As Boolean)
    Dim ctl As Control
    Dim FoundUnits As Boolean
    Dim FoundLimits As Boolean

    FoundUnits = False
    FoundLimits = False
    For Each ctl In frm.Controls
        If TypeOf ctl Is Label Then     'only labels --> Select Case TypeName(ctl) = "Label"
            If (ctl.Name = "lblValueUnits") Then
                If (ctl.Tag = strTag) Then
                    ctl.Visible = isVisible
                    FoundUnits = True
                End If
            End If
            If (ctl.Name = "lblValueLimits") Then
                If (ctl.Tag = strTag) Then
                    ctl.Visible = isVisible
                    FoundLimits = True
                End If
            End If
        End If
        If (FoundUnits And FoundLimits) Then Exit For
    Next
End Sub

Public Function GetCtrlIdxByNameTag(frm As Form, strName As String, strTag As String) As Long
    Dim ctl As Control
    GetCtrlIdxByNameTag = -1
    For Each ctl In frm.Controls
        If (ctl.Name = strName) Then
            If (ctl.Tag = strTag) Then
                GetCtrlIdxByNameTag = ctl.Index
            End If
        End If
    Next
End Function

'get cmd:val pair value by cmd
Public Function GetValByCmd(strCmdIn As String, varCmdVal As Variant)
    Dim strCmd As String
    Dim idxSetting As Long
    Dim strCfg As String

    GetValByCmd = ""
    If IsEmpty(varCmdVal) Then Exit Function
    If (Not IsArray(varCmdVal)) Then Exit Function
    strCfg = TypeName(varCmdVal)             'test variant data type
    If (strCfg <> "String()") Then Exit Function(
    For idxSetting = 0 To UBound(varCmdVal, 1)          'loop through settings
        strCmd = varCmdVal(idxSetting, 0)
        If (strCmd = strCmdIn) Then
            GetValByCmd = varCmdVal(idxSetting, 1)
            Exit For
        End If
    Next
End Function

Public Function MakeUnitsArray() As Variant
    Dim strUnit(7) As String
    Dim idxUnit As Long

    strUnit(0) = "%"
    strUnit(1) = "CH"
    strUnit(2) = "K"
    strUnit(3) = "MV"
    strUnit(4) = "NS"
    strUnit(5) = "S"
    strUnit(6) = "US"
    strUnit(7) = "V"
    MakeUnitsArray = strUnit
End Function

Public Function DP5UnitsFromData(varUnitsArray As Variant, strData As String, ByRef strRetData As String, ByRef strUnit As String) As Boolean
    Dim lPos As Long
    Dim idxDec As Long
    Dim idxUnit As Long
    Dim bUnitsOK As Boolean

    strRetData = strData
    strUnit = ""
    DP5UnitsFromData = False
    If (Len(strRetData) = 0) Then Exit Function
    For idxDec = 1 To Len(strRetData)   'find pos of units if any
        If (InStr(strDecValueChars, Mid(strRetData, idxDec, 1)) > 0) Then
            lPos = idxDec
        Else
            Exit For
        End If
    Next
    bUnitsOK = False
    If ((lPos > 0) And (lPos < Len(strRetData))) Then
        strUnit = Mid(strRetData, lPos + 1)
        strRetData = Left(strRetData, lPos)
        strUnit = Trim(strUnit)
        If (Len(strUnit) > 0) Then
            For idxUnit = 0 To UBound(varUnitsArray, 1)
                If (strUnit = varUnitsArray(idxUnit)) Then
                    bUnitsOK = True
                    Exit For
                End If
            Next
        End If
    End If
    If (Not bUnitsOK) Then strUnit = ""
    DP5UnitsFromData = bUnitsOK
End Function


modDP5Configuration Source Code

Option Explicit

Public s As New CSCommon

Public Function GetCmdDesc(ByVal strCmd As String) As String
    Dim strCmdName As String
    Select Case strCmd
        Case "RESC"
            strCmdName = "Reset Configuration"
        Case "CLCK"
            strCmdName = "20MHz/80MHz"
        Case "TPEA"
            strCmdName = "Peaking Time"
        Case "GAIF"
            strCmdName = "Fine Gain"
        Case "GAIN"
            strCmdName = "Total Gain (Analog * Fine)"
        Case "RESL"
            strCmdName = "Detector Reset Lockout"
        Case "TFLA"
            strCmdName = "Flat Top"
        Case "TPFA"
            strCmdName = "Fast Channel Peaking Time"
        Case "RTDE"
            strCmdName = "RTD On/Off"
        Case "MCAS"
            strCmdName = "MCA Source"
        Case "RTDD"
            strCmdName = "Custom RTD Oneshot Delay"
        Case "RTDW"
            strCmdName = "Custom RTD Oneshot Width"
        Case "PURE"
            strCmdName = "PUR Interval On/Off"
        Case "SOFF"
            strCmdName = "Set Spectrum Offset"
        Case "INOF"
            strCmdName = "Input Offset"
        Case "ACKE"
            strCmdName = "ACK / Don't ACK Packets With Errors"
        Case "AINP"
            strCmdName = "Analog Input Pos/Neg"
        Case "AUO1"
            strCmdName = "AUX_OUT Selection"
        Case "AUO2"
            strCmdName = "AUX_OUT2 Selection"
        Case "BLRD"
            strCmdName = "BLR Down Correction"
        Case "BLRM"
            strCmdName = "BLR Mode"
        Case "BLRU"
            strCmdName = "BLR Up Correction"
        Case "BOOT"
            strCmdName = "Turn Supplies On/Off At Power Up"
        Case "CUSP"
            strCmdName = "Non-Trapezoidal Shaping"
        Case "DACF"
            strCmdName = "DAC Offset"
        Case "DACO"
            strCmdName = "DAC Output"
        Case "GAIA"
            strCmdName = "Analog Gain Index"
        Case "GATE"
            strCmdName = "Gate Control"
        Case "GPED"
            strCmdName = "G.P. Counter Edge"
        Case "GPGA"
            strCmdName = "G.P. Counter Uses GATE?"
        Case "GPIN"
            strCmdName = "G.P. Counter Input"
        Case "GPMC"
            strCmdName = "G.P. Counter Cleared With MCA Counters?"
        Case "GPME"
            strCmdName = "G.P. Counter Uses MCA_EN?"
        Case "HVSE"
            strCmdName = "HV Set"
        Case "MCAC"
            strCmdName = "MCA/MCS Channels"
        Case "MCAE"
            strCmdName = "MCA/MCS Enable"
        Case "MCSL"
            strCmdName = "MCS Low Threshold"
        Case "MCSH"
            strCmdName = "MCS High Threshold"
        Case "MCST"
            strCmdName = "MCS Timebase"
        Case "PAPS"
            strCmdName = "Preamp 8.5/5 (N/A)"
        Case "PAPZ"
            strCmdName = "Pole-Zero"
        Case "PDMD"
            strCmdName = "Peak Detect Mode (Min/Max)"
        Case "PRCL"
            strCmdName = "Preset Counts Low Threshold"
        Case "PRCH"
            strCmdName = "Preset Counts High Threshold"
        Case "PREC"
            strCmdName = "Preset Counts"
        Case "PRER"
            strCmdName = "Preset Real Time"
        Case "PREL"
            strCmdName = "Preset Live Time"
        Case "PRET"
            strCmdName = "Preset Time"
        Case "RTDS"
            strCmdName = "RTD Sensitivity"
        Case "RTDT"
            strCmdName = "RTD Threshold"
        Case "SCAH"
            strCmdName = "SCAx High Threshold"
        Case "SCAI"
            strCmdName = "SCA Index"
        Case "SCAL"
            strCmdName = "SCAx Low Theshold"
        Case "SCAO"
            strCmdName = "SCAx Output (SCA1-8 Only)"
        Case "SCAW"
            strCmdName = "SCA Pulse Width (Not Indexed - SCA1-8)"
        Case "SCOE"
            strCmdName = "Scope Trigger Edge"
        Case "SCOG"
            strCmdName = "Digital Scope Gain"
        Case "SCOT"
            strCmdName = "Scope Trigger Position"
        Case "TECS"
            strCmdName = "TEC Set"
        Case "THFA"
            strCmdName = "Fast Threshold"
        Case "THSL"
            strCmdName = "Slow Threshold"
        Case "TLLD"
            strCmdName = "LLD Threshold"
        Case "TPMO"
            strCmdName = "Test Pulser On/Off"
        Case "VOLU"
            strCmdName = "Speaker On/Off"
        Case "CON1"
            strCmdName = "Connector 1"
        Case "CON2"
            strCmdName = "Connector 2"
    End Select
    GetCmdDesc = strCmdName
End Function

Public Function CreateFullReadBackCmd() As String
    Dim strCfg As String
    Dim isHVSE As Boolean
    Dim isPAPS As Boolean
    Dim isTECS As Boolean
    Dim isVOLU As Boolean
    Dim isCON1 As Boolean
    Dim isCON2 As Boolean
    Dim isINOF As Boolean
    Dim isBOOT As Boolean
    Dim isGATE As Boolean
    Dim isPAPZ As Boolean
    Dim isSCTC As Boolean
    Dim isDP5_DxK As Boolean
    Dim isDP5_DxL As Boolean

    If (STATUS.DEVICE_ID = dppMCA8000D) Then
        strCfg = CreateFullReadBackCmdMCA8000D()
        CreateFullReadBackCmd = strCfg
        Exit Function
    End If

    ' DP5 Rev Dx K,L needs PAPZ
    If ((STATUS.DEVICE_ID = dppDP5) And STATUS.isDP5_RevDxGains) Then
        If ((STATUS.DPP_ECO And &HF) = &HA) Then
            isDP5_DxK = True
        End If
        If ((STATUS.DPP_ECO And &HF) = &HB) Then
            isDP5_DxL = True
        End If
    End If

    isHVSE = CBool(((STATUS.DEVICE_ID <> dppPX5) And STATUS.PC5_PRESENT) Or (STATUS.DEVICE_ID = dppPX5))
    isPAPS = CBool((STATUS.DEVICE_ID <> dppDP5G) And (STATUS.DEVICE_ID <> dppTB5))
    isTECS = CBool(((STATUS.DEVICE_ID = dppDP5) And STATUS.PC5_PRESENT) Or (STATUS.DEVICE_ID = dppPX5) Or (STATUS.DEVICE_ID = dppDP5X))
    isVOLU = CBool(STATUS.DEVICE_ID = dppPX5)

    isCON1 = CBool((STATUS.DEVICE_ID <> dppDP5) And (STATUS.DEVICE_ID <> dppDP5X))
    isCON2 = CBool((STATUS.DEVICE_ID <> dppDP5) And (STATUS.DEVICE_ID <> dppDP5X))

    isINOF = CBool((STATUS.DEVICE_ID <> dppDP5G) And (STATUS.DEVICE_ID <> dppTB5))
    isSCTC = CBool((STATUS.DEVICE_ID = dppDP5G) Or (STATUS.DEVICE_ID = dppTB5))
    isBOOT = CBool((STATUS.DEVICE_ID = dppDP5) Or (STATUS.DEVICE_ID = dppDP5X))

    isGATE = CBool((STATUS.DEVICE_ID = dppDP5) Or (STATUS.DEVICE_ID = dppDP5X))
    isPAPZ = CBool((STATUS.DEVICE_ID = dppPX5) Or isDP5_DxK Or isDP5_DxL)

    strCfg = ""
    strCfg = strCfg & "RESC=?;"
    strCfg = strCfg & "CLCK=?;"
    strCfg = strCfg & "TPEA=?;"
    strCfg = strCfg & "GAIF=?;"
    strCfg = strCfg & "GAIN=?;"
    strCfg = strCfg & "RESL=?;"
    strCfg = strCfg & "TFLA=?;"
    strCfg = strCfg & "TPFA=?;"
    strCfg = strCfg & "PURE=?;"
    If (isSCTC) Then strCfg = strCfg & "SCTC=?;"
    strCfg = strCfg & "RTDE=?;"
    strCfg = strCfg & "MCAS=?;"
    strCfg = strCfg & "MCAC=?;"
    strCfg = strCfg & "SOFF=?;"
    strCfg = strCfg & "AINP=?;"
    If (isINOF) Then strCfg = strCfg & "INOF=?;"
    strCfg = strCfg & "GAIA=?;"
    strCfg = strCfg & "CUSP=?;"
    strCfg = strCfg & "PDMD=?;"
    strCfg = strCfg & "THSL=?;"
    strCfg = strCfg & "TLLD=?;"
    strCfg = strCfg & "THFA=?;"
    strCfg = strCfg & "DACO=?;"
    strCfg = strCfg & "DACF=?;"
    strCfg = strCfg & "RTDS=?;"
    strCfg = strCfg & "RTDT=?;"
    strCfg = strCfg & "BLRM=?;"
    strCfg = strCfg & "BLRD=?;"
    strCfg = strCfg & "BLRU=?;"
    If (isGATE) Then strCfg = strCfg & "GATE=?;"
    strCfg = strCfg & "AUO1=?;"
    strCfg = strCfg & "PRET=?;"
    strCfg = strCfg & "PRER=?;"
    strCfg = strCfg & "PREC=?;"
    strCfg = strCfg & "PRCL=?;"
    strCfg = strCfg & "PRCH=?;"
    If (isHVSE) Then strCfg = strCfg & "HVSE=?;"
    If (isTECS) Then strCfg = strCfg & "TECS=?;"
    If (isPAPZ) Then strCfg = strCfg & "PAPZ=?;"
    If (isPAPS) Then strCfg = strCfg & "PAPS=?;"
    strCfg = strCfg & "SCOE=?;"
    strCfg = strCfg & "SCOT=?;"
    strCfg = strCfg & "SCOG=?;"
    strCfg = strCfg & "MCSL=?;"
    strCfg = strCfg & "MCSH=?;"
    strCfg = strCfg & "MCST=?;"
    strCfg = strCfg & "AUO2=?;"
    strCfg = strCfg & "TPMO=?;"
    strCfg = strCfg & "GPED=?;"
    strCfg = strCfg & "GPIN=?;"
    strCfg = strCfg & "GPME=?;"
    strCfg = strCfg & "GPGA=?;"
    strCfg = strCfg & "GPMC=?;"
    strCfg = strCfg & "MCAE=?;"
    If (isVOLU) Then strCfg = strCfg & "VOLU=?;"
    If (isCON1) Then strCfg = strCfg & "CON1=?;"
    If (isCON2) Then strCfg = strCfg & "CON2=?;"
    If (isBOOT) Then strCfg = strCfg & "BOOT=?;"
    CreateFullReadBackCmd = strCfg
End Function

Public Function CreateFullReadBackCmdMCA8000D() As String
    Dim strCfg As String
    strCfg = ""
    If (STATUS.DEVICE_ID = dppMCA8000D) Then
        strCfg = strCfg & "RESC=?;"
        strCfg = strCfg & "PURE=?;"
        strCfg = strCfg & "MCAS=?;"
        strCfg = strCfg & "MCAC=?;"
        strCfg = strCfg & "SOFF=?;"
        strCfg = strCfg & "GAIA=?;"
        strCfg = strCfg & "PDMD=?;"
        strCfg = strCfg & "THSL=?;"
        strCfg = strCfg & "TLLD=?;"
        strCfg = strCfg & "GATE=?;"
        strCfg = strCfg & "AUO1=?;"
        strCfg = strCfg & "PRER=?;"
        strCfg = strCfg & "PREL=?;"
        strCfg = strCfg & "PREC=?;"
        strCfg = strCfg & "PRCL=?;"
        strCfg = strCfg & "PRCH=?;"
        strCfg = strCfg & "SCOE=?;"
        strCfg = strCfg & "SCOT=?;"
        strCfg = strCfg & "SCOG=?;"
        strCfg = strCfg & "MCSL=?;"
        strCfg = strCfg & "MCSH=?;"
        strCfg = strCfg & "MCST=?;"
        strCfg = strCfg & "AUO2=?;"
        strCfg = strCfg & "GPED=?;"
        strCfg = strCfg & "GPIN=?;"
        strCfg = strCfg & "GPME=?;"
        strCfg = strCfg & "GPGA=?;"
        strCfg = strCfg & "GPMC=?;"
        strCfg = strCfg & "MCAE=?;"
        strCfg = strCfg & "PDMD=?;"
    End If
    CreateFullReadBackCmdMCA8000D = strCfg
End Function

Public Sub MakeDp5CmdList(ByRef strCfgArr As Collection)
    Dim isHVSE As Boolean
    Dim isPAPS As Boolean
    Dim isTECS As Boolean
    Dim isVOLU As Boolean
    Dim isCON1 As Boolean
    Dim isCON2 As Boolean
    Dim isINOF As Boolean
    Dim isBOOT As Boolean
    Dim isGATE As Boolean
    Dim isPAPZ As Boolean
    Dim isSCTC As Boolean
    Dim isDP5_DxK As Boolean
    Dim isDP5_DxL As Boolean

    If (STATUS.DEVICE_ID = dppMCA8000D) Then
        Call MakeDp5CmdListMCA8000D(strCfgArr)
        Exit Sub
    End If

    ' DP5 Rev Dx K,L needs PAPZ
    If ((STATUS.DEVICE_ID = dppDP5) And STATUS.isDP5_RevDxGains) Then
        If ((STATUS.DPP_ECO And &HF) = &HA) Then
            isDP5_DxK = True
        End If
        If ((STATUS.DPP_ECO And &HF) = &HB) Then
            isDP5_DxL = True
        End If
    End If

    isHVSE = CBool(((STATUS.DEVICE_ID <> dppPX5) And STATUS.PC5_PRESENT) Or (STATUS.DEVICE_ID = dppPX5))
    isPAPS = CBool((STATUS.DEVICE_ID <> dppDP5G) And (STATUS.DEVICE_ID <> dppTB5))
    isTECS = CBool(((STATUS.DEVICE_ID = dppDP5) And STATUS.PC5_PRESENT) Or (STATUS.DEVICE_ID = dppPX5) Or (STATUS.DEVICE_ID = dppDP5X))
    isVOLU = CBool(STATUS.DEVICE_ID = dppPX5)

    isCON1 = CBool((STATUS.DEVICE_ID <> dppDP5) And (STATUS.DEVICE_ID <> dppDP5X))
    isCON2 = CBool((STATUS.DEVICE_ID <> dppDP5) And (STATUS.DEVICE_ID <> dppDP5X))

    isINOF = CBool((STATUS.DEVICE_ID <> dppDP5G) And (STATUS.DEVICE_ID <> dppTB5))
    isSCTC = CBool((STATUS.DEVICE_ID = dppDP5G) Or (STATUS.DEVICE_ID = dppTB5))
    isBOOT = CBool((STATUS.DEVICE_ID = dppDP5) Or (STATUS.DEVICE_ID = dppDP5X))

    isGATE = CBool((STATUS.DEVICE_ID = dppDP5) Or (STATUS.DEVICE_ID = dppDP5X))
    isPAPZ = CBool((STATUS.DEVICE_ID = dppPX5) Or isDP5_DxK Or isDP5_DxL)

    strCfgArr.Add ("RESC")
    strCfgArr.Add ("CLCK")
    strCfgArr.Add ("TPEA")
    strCfgArr.Add ("GAIF")
    strCfgArr.Add ("GAIN")
    strCfgArr.Add ("RESL")
    strCfgArr.Add ("TFLA")
    strCfgArr.Add ("TPFA")
    strCfgArr.Add ("PURE")
    If (isSCTC) Then strCfgArr.Add ("SCTC")
    strCfgArr.Add ("RTDE")
    strCfgArr.Add ("MCAS")
    strCfgArr.Add ("MCAC")
    strCfgArr.Add ("SOFF")
    strCfgArr.Add ("AINP")
    If (isINOF) Then strCfgArr.Add ("INOF")
    strCfgArr.Add ("GAIA")
    strCfgArr.Add ("CUSP")
    strCfgArr.Add ("PDMD")
    strCfgArr.Add ("THSL")
    strCfgArr.Add ("TLLD")
    strCfgArr.Add ("THFA")
    strCfgArr.Add ("DACO")
    strCfgArr.Add ("DACF")
    strCfgArr.Add ("RTDS")
    strCfgArr.Add ("RTDT")
    strCfgArr.Add ("BLRM")
    strCfgArr.Add ("BLRD")
    strCfgArr.Add ("BLRU")
    If (isGATE) Then strCfgArr.Add ("GATE")
    strCfgArr.Add ("AUO1")
    strCfgArr.Add ("PRET")
    strCfgArr.Add ("PRER")
    strCfgArr.Add ("PREC")
    strCfgArr.Add ("PRCL")
    strCfgArr.Add ("PRCH")
    If (isHVSE) Then strCfgArr.Add ("HVSE")
    If (isTECS) Then strCfgArr.Add ("TECS")
    If (isPAPZ) Then strCfgArr.Add ("PAPZ")
    If (isPAPS) Then strCfgArr.Add ("PAPS")
    strCfgArr.Add ("SCOE")
    strCfgArr.Add ("SCOT")
    strCfgArr.Add ("SCOG")
    strCfgArr.Add ("MCSL")
    strCfgArr.Add ("MCSH")
    strCfgArr.Add ("MCST")
    strCfgArr.Add ("AUO2")
    strCfgArr.Add ("TPMO")
    strCfgArr.Add ("GPED")
    strCfgArr.Add ("GPIN")
    strCfgArr.Add ("GPME")
    strCfgArr.Add ("GPGA")
    strCfgArr.Add ("GPMC")
    strCfgArr.Add ("MCAE")
    If (isVOLU) Then strCfgArr.Add ("VOLU")
    If (isCON1) Then strCfgArr.Add ("CON1")
    If (isCON2) Then strCfgArr.Add ("CON2")
    If (isBOOT) Then strCfgArr.Add ("BOOT")
End Sub

Public Sub MakeDp5CmdListMCA8000D(ByRef strCfgArr As Collection)
    If (STATUS.DEVICE_ID = dppMCA8000D) Then
        strCfgArr.Add ("RESC")
        strCfgArr.Add ("PURE")
        strCfgArr.Add ("MCAS")
        strCfgArr.Add ("MCAC")
        strCfgArr.Add ("SOFF")
        strCfgArr.Add ("GAIA")
        strCfgArr.Add ("PDMD")
        strCfgArr.Add ("THSL")
        strCfgArr.Add ("TLLD")
        strCfgArr.Add ("GATE")
        strCfgArr.Add ("AUO1")
        strCfgArr.Add ("PRER")
        strCfgArr.Add ("PREL")
        strCfgArr.Add ("PREC")
        strCfgArr.Add ("PRCL")
        strCfgArr.Add ("PRCH")
        strCfgArr.Add ("SCOE")
        strCfgArr.Add ("SCOT")
        strCfgArr.Add ("SCOG")
        strCfgArr.Add ("MCSL")
        strCfgArr.Add ("MCSH")
        strCfgArr.Add ("MCST")
        strCfgArr.Add ("AUO2")
        strCfgArr.Add ("GPED")
        strCfgArr.Add ("GPIN")
        strCfgArr.Add ("GPME")
        strCfgArr.Add ("GPGA")
        strCfgArr.Add ("GPMC")
        strCfgArr.Add ("MCAE")
        strCfgArr.Add ("PDMD")
    End If
End Sub

Public Function GetCmdData(ByVal cstrCmd As String, ByVal cstrCfgData As String) As String
    Dim iStart As Integer
    Dim iEnd As Integer
    Dim iCmd As Integer
    Dim cstrCmdData As String

    GetCmdData = ""
    cstrCmdData = ""
    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
    iStart = InStr(iCmd, cstrCfgData, "=")
    If (iStart = 0) Then Exit Function ' data start not found
    iEnd = InStr(iCmd, cstrCfgData, ";")
    If (iEnd = 0) Then GetCmdData = cstrCmdData ' data end found
    If (iStart >= iEnd) Then Exit Function ' data error
    cstrCmdData = Mid(cstrCfgData, iStart + 1, iEnd - (iStart + 1))
    GetCmdData = cstrCmdData
End Function

Public Function ReplaceCmdDesc(ByVal cstrCmd As String, ByRef cstrCfgData As String) As String
    Dim iStart As Integer
    Dim iCmd As Integer
    Dim cstrNew As String
    Dim cstrDesc As String

    ReplaceCmdDesc = 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 + "=")
    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, "=")
    If (iStart <> (iCmd + 4)) Then Exit Function ' data start not found
    cstrNew = Left(cstrCfgData, iCmd - 1) & cstrDesc & Mid(cstrCfgData, iStart)
    ReplaceCmdDesc = cstrNew
End Function

Public Function AppendCmdDesc(ByRef cstrCmd As String, ByRef cstrCfgData As String) As String
    Dim iStart As Integer
    Dim iEnd As Integer
    Dim 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 + "=")
    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, "=")
    If (iStart <> (iCmd + 4)) Then Exit Function ' data start not found
    iEnd = InStr(iStart + 1, cstrCfgData, ";")
    If (iEnd > (iStart + 11)) Then Exit Function ' data end not found
    cstrNew = Left(cstrCfgData, iEnd) & "    " & cstrDesc & Mid(cstrCfgData, iEnd + 1)
    AppendCmdDesc = cstrNew
End Function

Public Function RemoveCmd(ByVal cstrCmd As String, ByVal cstrCfgData As String) As String
    Dim iStart As Integer
    Dim iEnd As Integer
    Dim iCmd As Integer
    Dim cstrNew As String
    Dim strLeft As String
    Dim strRight As String

    cstrNew = ""
    RemoveCmd = cstrCfgData
    If (Len(cstrCfgData) < 7) Then Exit Function ' no data
    If (Len(cstrCmd) <> 4) Then Exit Function ' bad command
    iCmd = InStr(1, cstrCfgData, cstrCmd + "=")
    If (iCmd = 0) Then Exit Function ' cmd not found
    iStart = iCmd
    iEnd = InStr(iCmd, cstrCfgData, ";")
    If (iEnd = 0) Then Exit Function
    If (iEnd <= iStart) Then Exit Function ' unknown error
    strLeft = Left(cstrCfgData, iStart - 1)
    strRight = Mid(cstrCfgData, iEnd + 1)
    cstrNew = strLeft & strRight
    RemoveCmd = cstrNew
End Function

'removes selected command by dpp device type
Public Function RemoveCmdByDeviceType(ByVal strCfgDataIn As String, PC5_PRESENT As Boolean, DppType As Byte, isDP5_RevDxGains As Boolean, DPP_ECO As Byte) As String
    Dim strCfgData As String
    Dim isHVSE As Boolean
    Dim isPAPS As Boolean
    Dim isTECS As Boolean
    Dim isVOLU As Boolean
    Dim isCON1 As Boolean
    Dim isCON2 As Boolean
    Dim isINOF As Boolean
    Dim isBOOT As Boolean
    Dim isGATE As Boolean
    Dim isPAPZ As Boolean
    Dim isSCTC As Boolean
    Dim isPREL As Boolean
    Dim isDP5_DxK As Boolean
    Dim isDP5_DxL As Boolean

    strCfgData = strCfgDataIn
    If (DppType = dppMCA8000D) Then
        strCfgData = Remove_MCA8000D_Cmds(strCfgData, DppType)
        RemoveCmdByDeviceType = strCfgData
    End If

    ' DP5 Rev Dx K,L needs PAPZ
    If ((DppType = dppDP5) And isDP5_RevDxGains) Then
        If ((DPP_ECO And &HF) = &HA) Then
                isDP5_DxK = True
        End If
        If ((DPP_ECO And &HF) = &HB) Then
                isDP5_DxL = True
        End If
    End If

    isHVSE = CBool(((DppType <> dppPX5) And PC5_PRESENT) Or (DppType = dppPX5))
    isPAPS = CBool((DppType <> dppDP5G) And (DppType <> dppTB5))
    isTECS = CBool(((DppType = dppDP5) And PC5_PRESENT) Or (DppType = dppPX5) Or (DppType = dppDP5X))
    isVOLU = CBool(DppType = dppPX5)
    isCON1 = CBool((DppType <> dppDP5) And (DppType <> dppDP5X))
    isCON2 = CBool((DppType <> dppDP5) And (DppType <> dppDP5X))
    isINOF = CBool((DppType <> dppDP5G) And (DppType <> dppTB5))
    isSCTC = CBool((DppType = dppDP5G) Or (DppType = dppTB5))
    isBOOT = CBool((DppType = dppDP5) Or (DppType = dppDP5X))
    isGATE = CBool((DppType = dppDP5) Or (DppType = dppDP5X))
    isPAPZ = CBool((DppType = dppPX5) Or isDP5_DxK Or isDP5_DxL)
    isPREL = CBool(DppType = dppMCA8000D)
    If (Not isHVSE) Then strCfgData = RemoveCmd("HVSE", strCfgData)     'High Voltage Bias
    If (Not isPAPS) Then strCfgData = RemoveCmd("PAPS", strCfgData)     'Preamp Voltage
    If (Not isTECS) Then strCfgData = RemoveCmd("TECS", strCfgData)     'Cooler Temperature
    If (Not isVOLU) Then strCfgData = RemoveCmd("VOLU", strCfgData)     'px5 speaker
    If (Not isCON1) Then strCfgData = RemoveCmd("CON1", strCfgData)     'connector 1
    If (Not isCON2) Then strCfgData = RemoveCmd("CON2", strCfgData)     'connector 2
    If (Not isINOF) Then strCfgData = RemoveCmd("INOF", strCfgData)     'input offset
    If (Not isBOOT) Then strCfgData = RemoveCmd("BOOT", strCfgData)     'PC5 On At StartUp
    If (Not isGATE) Then strCfgData = RemoveCmd("GATE", strCfgData)     'Gate input
    If (Not isPAPZ) Then strCfgData = RemoveCmd("PAPZ", strCfgData)     'Pole-Zero
    If (Not isSCTC) Then strCfgData = RemoveCmd("SCTC", strCfgData)     'Scintillator Time Constant
    If (Not isPREL) Then strCfgData = RemoveCmd("PREL", strCfgData)     'Preset Live Time
    RemoveCmdByDeviceType = strCfgData
End Function

''removes MCA8000D commands
Public Function Remove_MCA8000D_Cmds(strCfgDataIn As String, DppType As Byte) As String
    Dim strCfgData As String

    strCfgData = strCfgDataIn
    If (DppType = dppMCA8000D) Then
        strCfgData = RemoveCmd("CLCK", strCfgData)
        strCfgData = RemoveCmd("TPEA", strCfgData)
        strCfgData = RemoveCmd("GAIF", strCfgData)
        strCfgData = RemoveCmd("GAIN", strCfgData)
        strCfgData = RemoveCmd("RESL", strCfgData)
        strCfgData = RemoveCmd("TFLA", strCfgData)
        strCfgData = RemoveCmd("TPFA", strCfgData)
        'strCfgData = RemoveCmd("PURE", strCfgData)
        strCfgData = RemoveCmd("RTDE", strCfgData)
        strCfgData = RemoveCmd("AINP", strCfgData)
        strCfgData = RemoveCmd("INOF", strCfgData)
        strCfgData = RemoveCmd("CUSP", strCfgData)
        strCfgData = RemoveCmd("THFA", strCfgData)
        strCfgData = RemoveCmd("DACO", strCfgData)
        strCfgData = RemoveCmd("DACF", strCfgData)
        strCfgData = RemoveCmd("RTDS", strCfgData)
        strCfgData = RemoveCmd("RTDT", strCfgData)
        strCfgData = RemoveCmd("BLRM", strCfgData)
        strCfgData = RemoveCmd("BLRD", strCfgData)
        strCfgData = RemoveCmd("BLRU", strCfgData)
        strCfgData = RemoveCmd("PRET", strCfgData)
        strCfgData = RemoveCmd("HVSE", strCfgData)
        strCfgData = RemoveCmd("TECS", strCfgData)
        strCfgData = RemoveCmd("PAPZ", strCfgData)
        strCfgData = RemoveCmd("PAPS", strCfgData)
        strCfgData = RemoveCmd("TPMO", strCfgData)
        strCfgData = RemoveCmd("SCAH", strCfgData)
        strCfgData = RemoveCmd("SCAI", strCfgData)
        strCfgData = RemoveCmd("SCAL", strCfgData)
        strCfgData = RemoveCmd("SCAO", strCfgData)
        strCfgData = RemoveCmd("SCAW", strCfgData)
        strCfgData = RemoveCmd("BOOT", strCfgData)

        ' added to list late, recheck at later date 20120817
        strCfgData = RemoveCmd("CON1", strCfgData)
        strCfgData = RemoveCmd("CON2", strCfgData)

        ' not implemented as of 20120817, will be implemented at some time
        strCfgData = RemoveCmd("VOLU", strCfgData)
    End If
    Remove_MCA8000D_Cmds = strCfgData
End Function

Public Function GetCmdChunk(strCmd As String) As Long
    Dim idxCfg As Long
    Dim lChunk As Long
    Dim lEnd As Long
    GetCmdChunk = 0
    lChunk = 0
    lEnd = 0
    For idxCfg = 1 To Len(strCmd)
        lChunk = InStr(lEnd + 1, strCmd, ";")
        If ((lChunk = 0) Or (lChunk > 512)) Then Exit For
        lEnd = lChunk
    Next
    GetCmdChunk = lEnd
End Function

Public Function ReplaceText(ByVal strInTextIn As String, ByVal strFrom As String, ByVal strTo As String) As String
    Dim strInText As String
    Dim strOutText As String
    Dim lFromLen As Long
    Dim lMatchPos As Long

    strInText = strInTextIn
    strOutText = ""
    lFromLen = Len(strFrom)
    Do While Len(strInText) > 0
        lMatchPos = InStr(strInText, strFrom)
        If lMatchPos = 0 Then
            strOutText = strOutText & strInText
            strInText = ""
        Else
            strOutText = strOutText & Left(strInText, lMatchPos - 1) & strTo
            strInText = Mid(strInText, lMatchPos + lFromLen)
        End If
    Loop
    ReplaceText = strOutText
End Function

Public Function CreateResTestReadBackCmd(bSendCoarseFineGain As Boolean) As String
    Dim strCfg As String
    Dim isINOF As Boolean

    isINOF = (STATUS.DEVICE_ID <> dppDP5G) And (STATUS.DEVICE_ID <> dppTB5)
    strCfg = ""
    strCfg = strCfg & "CLCK=?;"
    strCfg = strCfg & "TPEA=?;"
    If (bSendCoarseFineGain) Then strCfg = strCfg & "GAIF=?;"
    If (Not bSendCoarseFineGain) Then strCfg = strCfg & "GAIN=?;"
    strCfg = strCfg & "RESL=?;"
    strCfg = strCfg & "TFLA=?;"
    strCfg = strCfg & "TPFA=?;"
    strCfg = strCfg & "PURE=?;"
    strCfg = strCfg & "RTDE=?;"
    strCfg = strCfg & "MCAS=?;"
    strCfg = strCfg & "MCAC=?;"
    strCfg = strCfg & "SOFF=?;"
    strCfg = strCfg & "AINP=?;"
    If (isINOF) Then strCfg = strCfg & "INOF=?;"
    If (bSendCoarseFineGain) Then strCfg = strCfg & "GAIA=?;"
    CreateResTestReadBackCmd = strCfg
End Function

''''Private Sub SendCfgToHwExample(strCfg As String)
'''''For SCAs'Private Sub SendCfgToHwExample(strCfg As String, sca As scaSetup)
''''    Dim idxCmd As Long
''''    Dim strDisplay As String
''''    Dim strCmd As String
''''    Dim curStart As Currency            'start time from system time in milliseconds
''''    Dim TimeExpired As Boolean          'time expired flag
''''    Dim curElapsed As Currency          'Elapsed time from start time in milliseconds
''''    Dim lCfgLen As Long                 'ASCII Configuration Command String Length
''''    Dim idxSplitCfg As Long             'Configuration split position, only if necessary
''''    Dim bSplitCfg As Boolean            'Configuration split flag
''''    Dim strSplitCfg As String           'Configuration split string second buffer
''''
''''    bSplitCfg = False
''''    strDisplay = ""
''''    If (Len(strCfg) = 0) Then Exit Sub   'not initialized
''''    strCfg = TypeName(varConfig)             'test variant data type
''''    If (strCfg = "String()") Then           'have data
''''        strCfg = ""                         'clear cfg storage
''''    Else
''''        Exit Sub                            'no data
''''    End If
''''    For idxCmd = 0 To UBound(varConfig, 1)
''''        strCmd = varConfig(idxCmd, 0) & "=" & varConfig(idxCmd, 1) & ";"
''''        If (Not (InStr(strCmd, "RESC") > 0)) Then
''''            If (Len(Trim(varConfig(idxCmd, 1))) > 0) Then
''''                strCfg = strCfg & strCmd
''''                strDisplay = strDisplay & strCmd & vbNewLine
''''            Else
''''                strDisplay = strDisplay & ";" & strCmd & vbNewLine
''''            End If
''''        End If
''''    Next
''''    strCfg = "RESC=YES;" & strCfg
''''    strCfg = UCase(strCfg)
''''    strCfg = RemoveCmdByDeviceType(strCfg, STATUS.PC5_PRESENT, STATUS.DEVICE_ID)
''''    Clipboard.SetText strCfg
''''    strDisplay = "RESC=YES;" & vbNewLine & strDisplay
''''    strDisplay = UCase(strDisplay)
''''    'txtSendCfgToHwNoEdit = strDisplay
''''
''''    'Test configuration size
''''    lCfgLen = Len(strCfg)
''''    If (lCfgLen > 512) Then     'configuration is too large, try to reduce
''''        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 = Left(strCfg, idxSplitCfg)
''''        End If
''''    End If
''''
''''    'MsgBox strCfg
''''    'MsgBox strSplitCfg
''''
''''    'lblCfgLenValue = CStr(Len(strCfg))
''''    s.HwCfgReady = False
''''    s.HwCfgExReady = False
''''    s.HwCfgDP5Out = strCfg
''''    If (Len(strCfg) > 0) Then
''''        s.HwCfgReady = True
''''        frmDP5.SendCommand XMTPT_SEND_CONFIG_PACKET_TO_HW
''''        s.HwCfgReady = False
''''    End If
''''
''''    If (bSplitCfg) Then             'send second configuration block
''''        TimeExpired = False
''''        'lblPleaseWait.Visible = True
''''        curStart = msTimeStart()
''''        Do                          'wait for cfg packet to be processed
''''            DoEvents
''''            curElapsed = msTimeDiff(curStart)
''''            TimeExpired = msTimeExpired(curStart, 200)    '200 milliseconds wait
''''        Loop Until (TimeExpired)
''''        'lblPleaseWait.Visible = False
''''        s.HwCfgReady = False
''''        s.HwCfgExReady = False
''''        s.HwCfgDP5Out = strSplitCfg
''''        If (Len(strCfg) > 0) Then
''''            s.HwCfgReady = True
''''            frmDP5.SendCommand XMTPT_SEND_CONFIG_PACKET_TO_HW
''''            s.HwCfgReady = False
''''        End If
''''    End If
''''
'''''For SCAs'    If (s.SCAEnabled And s.isDppConnected) Then
'''''For SCAs'        TimeExpired = False
'''''For SCAs'        'lblPleaseWait.Visible = True
'''''For SCAs'        curStart = msTimeStart()
'''''For SCAs'        Do                          'wait for cfg packet to be processed
'''''For SCAs'            DoEvents
'''''For SCAs'            curElapsed = msTimeDiff(curStart)
'''''For SCAs'            TimeExpired = msTimeExpired(curStart, 200)    '200 milliseconds wait
'''''For SCAs'        Loop Until (TimeExpired)
'''''For SCAs'        'lblPleaseWait.Visible = False
'''''For SCAs'        strCfg = SCAStringALL(sca, True)
'''''For SCAs'        s.HwCfgReady = False
'''''For SCAs'        s.HwCfgExReady = False
'''''For SCAs'        s.HwCfgDP5Out = strCfg
'''''For SCAs'        If (Len(strCfg) > 0) Then
'''''For SCAs'            s.HwCfgReady = True
'''''For SCAs'            frmDP5.SendCommand XMTPT_SEND_CONFIG_PACKET_TO_HW
'''''For SCAs'            s.HwCfgReady = False
'''''For SCAs'        End If
'''''For SCAs'    End If
''''
''''End Sub
''''


modFindPortWin32 Source Code

Option Explicit

Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Private Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" ( _
        ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, _
        lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, _
        ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

Private Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type

Private Const FILE_SHARE_READ = &H1
Private Const FILE_SHARE_WRITE = &H2
Private Const OPEN_EXISTING = &H3
Private Const OPEN_ALWAYS = &H4
Private Const FILE_ATTRIBUTE_NORMAL = &H80
Private Const INVALID_HANDLE_VALUE = -1
Private Const FirstComPort = 1
Private Const LastComPort = 16

Public Function IsPortInList(lstComPortList As Object, ByVal iComPort As Integer) As Boolean
    Dim idxComPort As Integer
    On Error GoTo GetPortFromListError
    IsPortInList = False
    For idxComPort = 0 To lstComPortList.ListCount - 1
        If (lstComPortList.ItemData(idxComPort) = iComPort) Then
            IsPortInList = True
        End If
    Next
    Exit Function
GetPortFromListError:
    'MsgBox Err.Description, vbCritical, "IsPortInList ComPort Resource List Error"
End Function

Public Function GetPortListIndex(lstComPortList As Object, ByVal iComPort As Integer) As Integer
    Dim idxComPort As Integer
    On Error GoTo GetPortFromListError
    GetPortListIndex = -1
    For idxComPort = 0 To lstComPortList.ListCount - 1
        If (lstComPortList.ItemData(idxComPort) = iComPort) Then
            GetPortListIndex = idxComPort
        End If
    Next
    Exit Function
GetPortFromListError:
    'MsgBox Err.Description, vbCritical, "GetPortListIndex ComPort Resource List Error"
End Function

Public Function isComPortAvailable(ByVal iComPort As Integer) As Boolean
    Dim hComPort As Long
    Dim lpSecAttr As SECURITY_ATTRIBUTES
    Dim lRetVal As Long

    On Error GoTo isComPortAvailableError

    hComPort = CreateFile("\\.\COM" & iComPort & "", 0, FILE_SHARE_READ + FILE_SHARE_WRITE, lpSecAttr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0)
    If hComPort = INVALID_HANDLE_VALUE Then
        isComPortAvailable = False
    Else
        isComPortAvailable = True
        lRetVal = CloseHandle(hComPort)
    End If

    Exit Function
isComPortAvailableError:
    MsgBox Err.Description, vbCritical, "is ComPort Available Test Error"
End Function

Public Sub CreateComPortResource(lstComPortList As Object)
    Dim idxComPort As Integer

    On Error GoTo CreateComPortResourceError

    lstComPortList.Clear
    For idxComPort = FirstComPort To LastComPort
        If isComPortAvailable(idxComPort) Then
            lstComPortList.AddItem "COM" & idxComPort
            lstComPortList.ItemData(lstComPortList.NewIndex) = idxComPort
        End If
    Next

    Exit Sub
CreateComPortResourceError:
    MsgBox Err.Description, vbCritical, "CreateComPort Resource List Error"
End Sub

Public Function isAnyComPort() As Boolean
    Dim idxComPort As Integer
    Dim bHavePort As Boolean
    On Error GoTo isAnyComPortError

    bHavePort = False
    isAnyComPort = False
    For idxComPort = FirstComPort To LastComPort
        If isComPortAvailable(idxComPort) Then
            bHavePort = True
        End If
    Next
    isAnyComPort = bHavePort
    Exit Function
isAnyComPortError:
    MsgBox Err.Description, vbCritical, "isAnyComPort Resource Error"
End Function

Public Function GetFirstComPort() As Integer
    Dim idxComPort As Integer
    On Error GoTo GetFirstComPortError

    GetFirstComPort = 0
    For idxComPort = FirstComPort To LastComPort
        If isComPortAvailable(idxComPort) Then
            GetFirstComPort = idxComPort
            Exit Function
        End If
    Next
    Exit Function
GetFirstComPortError:
    MsgBox Err.Description, vbCritical, "GetFirstComPort Resource Error"
End Function

Public Function GetBaudRate(strSettings As String) As String
    Dim lPos As Long

    lPos = InStr(1, strSettings, ","),
    If (lPos > 0) Then
        GetBaudRate = Left(strSettings, lPos - 1)
    Else
        GetBaudRate = ""
    End If
End Function

Public Function ToggleBaudRate(strSettings As String) As String
    Dim lPos As Long
    Dim strNewSettings As String
    Dim strBaudRate As String

    On Error GoTo ToggleBaudRateError

    lPos = InStr(1, strSettings, ","),
    If (lPos > 0) Then
        strBaudRate = Left(strSettings, lPos - 1)
        If (strBaudRate = "115200") Then
            strBaudRate = "57600"
        ElseIf (strBaudRate = "57600") Then
            strBaudRate = "115200"
        Else
            strBaudRate = ""
        End If
        If (Len(strBaudRate) > 0) Then
            ToggleBaudRate = strBaudRate & Mid(strSettings, lPos)
        Else
            ToggleBaudRate = strSettings
        End If
    Else
        ToggleBaudRate = strSettings
    End If

    Exit Function
ToggleBaudRateError:
    MsgBox Err.Description, vbCritical, "Toggle Baud Rate Error"
End Function


modIniFile Source Code

Option Explicit

'Purpose:

'   INI File Utilities for DP5 Configurations.
'
'Example:
'
'Code:'==========================================================================
'Code:'Quick DP5 INI Utility Guide
'Code:'==========================================================================
'Code:'--------------------------------------------------------------------------
'Code:' All INI data arrays are string arrays and have the form:
'Code:'     varData(Records,Fields)
'Code:' Where:
'Code:'     Records is the Number of INI Section Entries
'Code:'     Fields values are 0=INI Key, 1=INI Data
'Code:'--------------------------------------------------------------------------
'Code:' Note: varSectionNames is a string array of section names. (NOT INI DATA)
'Code:'--------------------------------------------------------------------------
'Code:'--------------------------------------------------------------------------
'Code:'
'Code:'----- HOW DO I ? -----
'Code:'
'Code:'--------------------------------------------------------------------------
'Code:'Read a configuration.
'Code:    varConfig = GetDP5ConfigSection(strFilename, strSection, varComments)
'Code:'--------------------------------------------------------------------------
'Code:'Save a configuration.
'Code:    Call SaveDP5ConfigSection(strFilename, strSection, varConfig, varComments)
'Code:'--------------------------------------------------------------------------
'Code:'Save ANY INI data array.
'Code:    Call SaveIniDataArray(strFilename, strSection, varData)
'Code:'--------------------------------------------------------------------------
'Code:'Appends semicolons to configuration data.
'Code:    varConfig = AppendSemicolonsToConfig(varConfig)
'Code:'--------------------------------------------------------------------------
'Code:'Set all keys and config data to upper case.
'Code:    varConfig = ConfigToUCASE(varConfig)
'Code:'--------------------------------------------------------------------------
'Code:'Append comments array to configuration data.
'Code:    varData = AppendDP5Comments(varConfig, varComments)
'Code:'--------------------------------------------------------------------------
'Code:'Search for data in ANY INI array by key.
'Code:    strData = FindIniData(strKey, varData)
'Code:'--------------------------------------------------------------------------
'Code:'Convert ANY INI data array to a formatted text display string.
'Code:    strDisplaySection = DataArrayString(strSection, varData)
'Code:'--------------------------------------------------------------------------
'Code:'Convert ANY INI data file (all sections) to a formatted text display string.
'Code:    strDisplayIniFile = IniFileString(strFilename)
'Code:'--------------------------------------------------------------------------
'Code:'Read all INI file section names.
'Code:    varSectionNames = GetSectionNames(strFilename)
'Code:'--------------------------------------------------------------------------
'Code:'Extract DP5 commands from a INI data array.
'Code:    varData = GetDP5Commands(varData)
'Code:'--------------------------------------------------------------------------
'Code:'Extract DP5 comments from a INI data array.
'Code:    varComments = GetDP5Comments(varData)
'Code:'--------------------------------------------------------------------------
'Code:'Create a copy of an INI array. Copies keys and data.
'Code:    varDataNew = CreateIniArr(varData) (NOTE: bCopyData = True by default)
'Code:'--------------------------------------------------------------------------
'Code:'Create an empty INI array of varData size.
'Code:    varDataNew = CreateIniArr(varData, False)
'Code:'--------------------------------------------------------------------------
'Code:'Display an INI file section to a list control.
'Code:    Call GetIniListEx2(strFilename, strSection, objList, bRemComments)
'Code:'--------------------------------------------------------------------------

Public varConfig As Variant
Public varComments As Variant
Public varValues As Variant
Public varValComments As Variant

Public varCmdCtrls As Variant
Public varUnitsArray As Variant

Public Const IniSectionVal = "DP5 Configuration Values"
Public Const IniSectionCfg = "DP5 Configuration File"
Public Const IniSectionApp = "DP5 Application Settings"

Public strIniFilename As String

Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function GetPrivateProfileSectionNames Lib "kernel32" Alias "GetPrivateProfileSectionNamesA" (ByVal lpReturnBuffer As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long

'Purpose: Read INI configuration data and comments array from file.
'Returns INI configuration data array as return value and comments array as parameter.
'Parameter: strFilename INI Filename.
'Parameter: strSection INI file Section.
'Parameter: varComments INI comment data array.
Public Function GetDP5ConfigSection(strFilename As String, strSection As String, ByRef varComments As Variant) As Variant
    Dim varData As Variant
    Dim varConfig As Variant

    varData = GetAllIniSettings(strFilename, strSection)  'get the configuration
    If IsEmpty(varData) Then
        GetDP5ConfigSection = varData
        Exit Function
    End If
    varConfig = GetDP5Commands(varData)                     'remove the comments
    varComments = GetDP5Comments(varData)                   'save the comments
    GetDP5ConfigSection = varConfig
End Function

'Purpose: Saves INI data array to file with optional append comments to configuration
'Parameter: strFilename INI Filename.
'Parameter: strSection INI file Section.
'Parameter: varConfig INI configuration data array.
'Parameter: varComments INI comment data array.
Public Sub SaveDP5ConfigSection(strFilename As String, strSection As String, varConfig As Variant, Optional varComments As Variant)
    Dim varData As Variant
    Dim bAppendComments As Boolean

    If (IsMissing(varComments)) Then
        bAppendComments = False
    Else
        bAppendComments = True
    End If

    If (bAppendComments) Then
        If (IsArray(varComments)) Then      'create new array with comments
            varData = AppendDP5Comments(varConfig, varComments)
            SaveIniDataArray strFilename, strSection, varData
        Else
            bAppendComments = False         'shut off
        End If
    End If
    If (Not bAppendComments) Then       'the configuration has not been saved
        varData = AppendSemicolonsToConfig(varConfig)
        SaveIniDataArray strFilename, strSection, varData
    End If
End Sub

'Purpose: Saves INI data array to file.
'Parameter: strFilename INI Filename.
'Parameter: strSection INI file Section.
'Parameter: varData INI data array.
Public Sub SaveIniDataArray(strFilename As String, strSection As String, varData As Variant)
    Dim strKey As String
    Dim strData As String
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long

    If (Not IsArray(varData)) Then Exit Sub          'if data array is empty cannot save
    idxLRec = LBound(varData, 1)
    idxURec = UBound(varData, 1)
    For idxRecord = idxLRec To idxURec
        strKey = varData(idxRecord, 0)
        strData = varData(idxRecord, 1)
        SaveToIni strFilename, strSection, strKey, strData
    Next
End Sub

'Purpose: Appends semicolons to configuration data array.
'Returns updated configuration array.
'Parameter: varConfig INI configuration data array.
Public Function AppendSemicolonsToConfig(varConfig As Variant) As Variant
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim varData As Variant

    If (Not IsArray(varConfig)) Then
        AppendSemicolonsToConfig = Empty
        Exit Function     'if data array is empty cannot save
    End If
    varData = CreateIniArr(varConfig)       'create a working copy of config array
    idxLRec = LBound(varConfig, 1)
    idxURec = UBound(varConfig, 1)
    For idxRecord = idxLRec To idxURec
        If (InStr(1, varData(idxRecord, 1), ";") = 0) Then
            varData(idxRecord, 1) = varData(idxRecord, 1) & ";"
        End If
    Next
    AppendSemicolonsToConfig = varData
End Function

'Purpose: Sets configuration data array keys and data to upper case.
'Returns updated configuration array.
'Parameter: varConfig INI configuration data array.
Public Function ConfigToUCASE(varConfig As Variant) As Variant
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim varData As Variant

    If (Not IsArray(varConfig)) Then
        ConfigToUCASE = Empty
        Exit Function     'if data array is empty cannot save
    End If
    varData = CreateIniArr(varConfig)       'create a working copy of config array
    idxLRec = LBound(varConfig, 1)
    idxURec = UBound(varConfig, 1)
    For idxRecord = idxLRec To idxURec
        varData(idxRecord, 0) = UCase(varData(idxRecord, 0))
        varData(idxRecord, 1) = UCase(varData(idxRecord, 1))
    Next
    ConfigToUCASE = varData
End Function

'Purpose: Clears configuration data.
'Returns updated configuration array.
'Parameter: varConfig INI configuration data array.
Public Function ClearConfigData(varConfig As Variant) As Variant
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim varData As Variant

    If (Not IsArray(varConfig)) Then
        ClearConfigData = Empty
        Exit Function     'if data array is empty cannot save
    End If
    varData = CreateIniArr(varConfig)       'create a working copy of config array
    idxLRec = LBound(varConfig, 1)
    idxURec = UBound(varConfig, 1)
    For idxRecord = idxLRec To idxURec
        varData(idxRecord, 1) = ""
    Next
    ClearConfigData = varData
End Function

'Purpose: Appends comments to INI data array.
'Returns the Command Key (Field 0) and the Data (Field 1) with comments and semicolons.
'Parameter: varConfig INI configuration data array.
'Parameter: varComments INI comment data array.
Public Function AppendDP5Comments(varConfig As Variant, varComments As Variant) As Variant
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim strKey As String
    Dim strComment As String
    Dim varData As Variant

    If (Not IsArray(varConfig)) Then        'if config array is empty then cannot append
        AppendDP5Comments = Empty
        Exit Function
    ElseIf (Not IsArray(varComments)) Then  'if comment array is empty no need to append
        AppendDP5Comments = varConfig
        Exit Function
    End If
    varData = CreateIniArr(varConfig)       'create a working copy of config array
    idxLRec = LBound(varConfig, 1)          'the config array size is needed
    idxURec = UBound(varConfig, 1)
    For idxRecord = idxLRec To idxURec
        strKey = varData(idxRecord, 0)                  'get the key to search for comment
        strComment = FindIniData(strKey, varComments)   'search the comments array by key
        varData(idxRecord, 1) = varData(idxRecord, 1) & ";" & strComment    'append comment to config
    Next
    AppendDP5Comments = varData
End Function

'Purpose: Find Data for given Key in INI data array.
'Returns the Data (Field 1).
'Parameter: strKey INI item Key.
'Parameter: varData INI data array.
Public Function FindIniData(strKey As Variant, varData As Variant) As String
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim strData As String

   If (Not IsArray(varData)) Then
        FindIniData = ""
        Exit Function
    End If

    idxLRec = LBound(varData, 1)
    idxURec = UBound(varData, 1)
    strData = ""
    For idxRecord = idxLRec To idxURec
        If (StrComp(strKey, varData(idxRecord, 0), vbTextCompare) = 0) Then
            strData = varData(idxRecord, 1)
            Exit For
        End If
    Next
    FindIniData = strData
End Function

'Purpose: Creates a formatted display string of INI file Section.
'Parameter: strFilename INI Filename.
'Parameter: strSection INI file Section.
Public Function SectionString(strFilename As String, strSection As String) As String
    Dim varData As Variant
    Dim idxKey As Long
    Dim strData As String

    varData = GetAllIniSettings(strFilename, strSection)
    strData = vbNewLine & "[" & strSection & "]" & vbNewLine
    If IsArray(varData) Then
        For idxKey = LBound(varData, 1) To UBound(varData, 1)
            strData = strData & varData(idxKey, 0) & "=" & varData(idxKey, 1) & vbNewLine
        Next
    End If
    SectionString = strData
End Function

'Purpose: Creates a formatted display string of a INI data array.
'Parameter: strSection INI file Section.
'Parameter: varData INI data array.
Public Function DataArrayString(strSection As String, varData As Variant) As String
    Dim idxKey As Long
    Dim strData As String

    strData = vbNewLine & "[" & strSection & "]" & vbNewLine
    If IsArray(varData) Then
        For idxKey = LBound(varData, 1) To UBound(varData, 1)
            strData = strData & varData(idxKey, 0) & "=" & varData(idxKey, 1) & vbNewLine
        Next
    End If
    DataArrayString = strData
End Function

'Purpose: Creates a formatted display string of INI file.
'Parameter: strFilename INI Filename.
Public Function IniFileString(strFilename As String) As String
    Dim varSections As Variant
    Dim idxSection As Long
    Dim strSection As String
    Dim strData As String

    IniFileString = ""
    strData = ""
    varSections = GetSectionNames(strFilename)
    If (IsArray(varSections)) Then
        For idxSection = LBound(varSections) To UBound(varSections)
            strSection = varSections(idxSection)
            strData = strData & SectionString(strFilename, strSection)
        Next
    Else
        strSection = varSections
        If (Len(strSection) > 0) Then
            strData = SectionString(strFilename, strSection)
        End If
    End If
    IniFileString = strData
End Function

'Purpose: Returns the INI file section names.
'Parameter: strFilename INI Filename.
Public Function GetSectionNames(strFilename As String) As Variant
    Dim lngRetVal As Long
    Dim strBuffer As String
    Dim strSections() As String
    Dim strSectionName As String '
    Dim idxSection As Long
    Dim lPos As Long
    Dim lNull As Long
    Dim lBufSize As Long

    idxSection = 0
    lPos = 1
    strBuffer = Space(2048)
    lngRetVal = GetPrivateProfileSectionNames(strBuffer, Len(strBuffer), strFilename)
    lBufSize = Len(strBuffer)
    Do While (lPos < lBufSize)
        lNull = InStr(lPos, strBuffer, vbNullChar)
        If (lNull <> lPos) Then
            ReDim Preserve strSections(0 To idxSection) As String
            strSections(idxSection) = Mid$(strBuffer, lPos, lNull - lPos)
            idxSection = idxSection + 1
            lPos = lNull + 1
        Else
            Exit Do
        End If
    Loop
    GetSectionNames = strSections
End Function

'Purpose: Removes comments from INI section data.
'Returns the Command Key (Field 0) and the Command Setting (Field 1) without semicolons.
'Parameter: varData INI Section array.
'Remarks: The comment whitespace is not trimmed.
Public Function GetDP5Commands(ByRef varData As Variant) As Variant
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim lPos As Long
    Dim varConfig As Variant

    If (Not IsArray(varData)) Then
        GetDP5Commands = Empty
        Exit Function
    End If
    varConfig = CreateIniArr(varData)
    idxLRec = LBound(varConfig, 1)
    idxURec = UBound(varConfig, 1)
    For idxRecord = idxLRec To idxURec
        lPos = InStr(varConfig(idxRecord, 1), ";")
        If lPos = 1 Then    'not data only comments
           varConfig(idxRecord, 1) = ""
        ElseIf (lPos > 1) Then
           varConfig(idxRecord, 1) = Left(varConfig(idxRecord, 1), lPos - 1)
        Else
            'not found
        End If
    Next
    GetDP5Commands = varConfig
End Function

'Purpose: Extracts comments from INI section data.
'Returns the Command Key (Field 0) and the Comments (Field 1) without semicolons.
'Parameter: varData INI Section array.
'Remarks: The comment whitespace is not trimmed.
Public Function GetDP5Comments(ByRef varData As Variant) As Variant
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim lPos As Long
    Dim varComments As Variant

    If (Not IsArray(varData)) Then
        GetDP5Comments = Empty
        Exit Function
    End If
    varComments = CreateIniArr(varData)
    idxLRec = LBound(varComments, 1)
    idxURec = UBound(varComments, 1)
    For idxRecord = idxLRec To idxURec
        lPos = InStr(varComments(idxRecord, 1), ";")
        If (lPos > 0) Then
           varComments(idxRecord, 1) = Mid(varComments(idxRecord, 1), lPos + 1)
        Else    'not found
            varComments(idxRecord, 1) = ""
        End If
    Next
    GetDP5Comments = varComments
End Function

'Purpose: Creates INI data array of existing array size.  Optional copy of existing data.
'Returns a INI data array.
'Parameter: varData INI configuration data array.
'Parameter: bCopyData Copy existing data array.
Public Function CreateIniArr(varData As Variant, Optional bCopyData As Boolean = True) As Variant
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim idxLFld As Long
    Dim idxUFld As Long
    Dim idxField As Long
    Dim lPos As Long
    Dim strData() As String
    Dim strKey As String
    Dim strComment As String

    If (Not IsArray(varData)) Then        'if data array is empty then cannot create new array
        CreateIniArr = Empty
        Exit Function
    End If
    idxLRec = LBound(varData, 1)      'the config array size is needed
    idxURec = UBound(varData, 1)
    idxLFld = LBound(varData, 2)
    idxUFld = UBound(varData, 2)
    ReDim strData(idxURec, idxUFld)     'create new working array to hold combined data and comments
    If (bCopyData) Then
        For idxRecord = idxLRec To idxURec  'copy the config to the working array
            For idxField = idxLFld To idxUFld
                strData(idxRecord, idxField) = varData(idxRecord, idxField)
            Next
        Next
    End If
    CreateIniArr = strData
End Function

'Purpose: Creates INI data array of existing array size.  Optional copy of existing data.
'Returns a INI data array.
'Parameter: varData INI configuration data array.
'Parameter: bCopyData Copy existing data array.
Public Function CopyIniArr(varData As Variant, Optional bCopyEmpty As Boolean = True) As Variant
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim idxLFld As Long
    Dim idxUFld As Long
    Dim idxField As Long
    Dim lPos As Long
    Dim strData() As String
    Dim strKey As String
    Dim strComment As String
    Dim idxNotEmpty As Long
    Dim idxNew As Long

    If (Not IsArray(varData)) Then        'if data array is empty then cannot create new array
        CopyIniArr = Empty
        Exit Function
    End If
    idxLRec = LBound(varData, 1)      'the config array size is needed
    idxURec = UBound(varData, 1)
    idxLFld = LBound(varData, 2)
    idxUFld = UBound(varData, 2)
    If (bCopyEmpty) Then
        ReDim strData(idxURec, idxUFld)     'create new working array to hold combined data and comments
        For idxRecord = idxLRec To idxURec  'copy the config to the working array
            For idxField = idxLFld To idxUFld
                strData(idxRecord, idxField) = varData(idxRecord, idxField)
            Next
        Next
    Else
        idxNotEmpty = -1
        For idxRecord = idxLRec To idxURec  'count the working array valid values
            If (Len(Trim(varData(idxRecord, 1))) > 0) Then idxNotEmpty = idxNotEmpty + 1
        Next
        If (idxNotEmpty >= 0) Then
            idxNew = 0
            ReDim strData(idxNotEmpty, idxUFld)     'create new working array to hold combined data and comments
            For idxRecord = idxLRec To idxURec  'copy the config to the working array
                If (Len(Trim(varData(idxRecord, 1))) > 0) Then
                    If (idxNew <= idxNotEmpty) Then
                        For idxField = idxLFld To idxUFld
                            strData(idxNew, idxField) = varData(idxRecord, idxField)
                        Next
                        idxNew = idxNew + 1
                    End If
                End If
            Next
        End If
    End If
    CopyIniArr = strData
End Function

'Purpose: Reads Ini Section, saves to List control.
'Parameter: strFilename INI Filename.
'Parameter: strSection INI Section requested.
'Parameter: objList INI Section display list.
'Parameter: bRemComments Remove comments from section data.
Public Sub GetIniListEx2(strFilename As String, strSection As String, objList As Object, bRemComments As Boolean)
    Dim varData As Variant
    Dim idxLRec As Long
    Dim idxURec As Long
    Dim idxRecord As Long
    Dim strItem As String
    Dim lPos As Long

    objList.Clear
    varData = GetAllIniSettings(strFilename, strSection)
    If IsEmpty(varData) Then Exit Sub
    idxLRec = LBound(varData, 1)
    idxURec = UBound(varData, 1)
    For idxRecord = idxLRec To idxURec
        strItem = varData(idxRecord, 0) & "=" & varData(idxRecord, 1)
        If (bRemComments) Then
            lPos = InStr(strItem, ";")
            If lPos = 1 Then
               strItem = ""
            ElseIf lPos > 1 Then
               strItem = Left$(strItem, lPos - 1)
            End If
        End If
        objList.AddItem strItem
    Next
    objList.ListIndex = objList.TopIndex
End Sub

Public Sub SaveToIni(strFilename As String, strSection As String, strKey As String, strData As String)
    Dim lngRetVal As Long
    lngRetVal = WritePrivateProfileString(strSection, strKey, strData, strFilename)
End Sub

Public Function GetFromIni(strFilename As String, strSection As String, strKey As String, Optional strDefault As String) As String
    Dim lngRetVal As Long
    Dim lngBuffSz As Long
    Dim strBuff As String

    strBuff = Space(255)
    lngBuffSz = 255
    lngRetVal = GetPrivateProfileString(strSection, strKey, strDefault, strBuff, lngBuffSz, strFilename)
    lngBuffSz = InStr(1, strBuff, Chr(0), vbBinaryCompare)
    If lngBuffSz > 0 Then
        GetFromIni = Trim(Left(strBuff, lngBuffSz - 1))
    Else
        GetFromIni = strBuff
    End If
End Function

Public Function GetAllIniSettings(strFilename As String, Section As String) As Variant
    Dim lRet As Long
    Dim strTemp As String
    Dim Table() As String
    Dim Table2() As String
    Dim iPnt As Integer
    Dim iPnt2 As Integer
    Dim iPosit As Integer

    strTemp = Space(32567)
    lRet = GetPrivateProfileSection(Section, strTemp, Len(strTemp), strFilename)
    iPnt = 0
    'For Redim+Preserve tables only the las index can be changed
    If Left(strTemp, 2) = Chr$(0) & Chr$(0) Then
        Exit Function
    End If

    If (lRet = 0) Then
        Exit Function
    End If

    Do While Left(strTemp, 1) <> Chr$(0)
        ReDim Preserve Table(1, iPnt)
        iPosit = InStr(strTemp, "=")
        Table(0, iPnt) = Left$(strTemp, iPosit - 1)
        strTemp = Mid$(strTemp, iPosit + 1)
        iPosit = InStr(strTemp, Chr$(0))
        Table(1, iPnt) = Left$(strTemp, iPosit - 1)
        strTemp = Mid$(strTemp, iPosit + 1)
        iPnt = iPnt + 1
    Loop
    ReDim Table2(iPnt - 1, 1)

    For iPnt2 = 0 To iPnt - 1
        Table2(iPnt2, 0) = Table(0, iPnt2)
        Table2(iPnt2, 1) = Table(1, iPnt2)
    Next

    GetAllIniSettings = Table2
End Function

Public Function DeleteIniSetting(strFilename As String, Section As String, Optional Key As String)
    Dim lRet As Long
    If Key = "" Then
        lRet = WritePrivateProfileString(Section, vbNullString, vbNullString, strFilename)
    Else
        lRet = WritePrivateProfileString(Section, Key, vbNullString, strFilename)
    End If
End Function

Public Sub GetIniList(strFilename As String, strSection As String, objList As Object)
    Dim varAllIni As Variant
    Dim i As Integer
    Dim j As Integer
    Dim idxLRec As Long
    Dim idxLFld As Long
    Dim idxURec As Long
    Dim idxUFld As Long

    objList.Clear
    varAllIni = GetAllIniSettings(strFilename, strSection)
    If IsEmpty(varAllIni) Then Exit Sub

    idxLRec = LBound(varAllIni, 1)
    idxLFld = LBound(varAllIni, 2)
    idxURec = UBound(varAllIni, 1)
    idxUFld = UBound(varAllIni, 2)

    For i = idxLRec To idxURec
         objList.AddItem varAllIni(i, 1)
    Next
    objList.ListIndex = objList.TopIndex
End Sub

'------------------------------------------------------
' Function:   ValidFilename as string
' arguments:  strFilename         a filename
' Result: ValidFilename returns a valid filename
'-------------------------------------------------------
Function ValidFilename(strFilename As String) As String
    Dim i As Integer
    Dim strFname As String
    Dim legalChar As String
    ValidFilename = strFilename
    strFname = Trim(strFilename)       'remove white space
    ' Remove for illegal characters
    legalChar = " !#$%&'()-0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ^_`{}~.üäöÄÖÜß"
    For i = 1 To Len(strFname)
        If InStr(legalChar, UCase(Mid(strFname, i, 1))) = 0 Then
            Mid(strFname, i, 1) = " "
        End If
    Next i
    ValidFilename = strFname
End Function

Public Sub SaveApplicationSettings(frm As Form, Optional AppSet As Boolean = True, _
                                                Optional CfgSet As Boolean = True, _
                                                Optional ComSet As Boolean = True)
    Dim strFilename As String
    strFilename = App.Path & "\" & App.EXEName & ".ini"

    If (AppSet) Then
        'Application Settings
        SaveToIni strFilename, IniSectionApp, frm.Name & "_Top", frm.Top
        SaveToIni strFilename, IniSectionApp, frm.Name & "_Left", frm.Left
    End If

    If (CfgSet) Then
        'Configuration Settings
        SaveToIni strFilename, IniSectionApp, "SendCoarseFineGain", s.profile.SendCoarseFineGain
        SaveToIni strFilename, IniSectionApp, "SCAEnabled", s.SCAEnabled
    End If

    If (ComSet) Then
        'Communications Interface Settings
        SaveToIni strFilename, IniSectionApp, "CurrentInterface", s.CurrentInterface
        SaveToIni strFilename, IniSectionApp, "ComPort", s.ComPort
        SaveToIni strFilename, IniSectionApp, "SockAddr", s.SockAddr
        SaveToIni strFilename, IniSectionApp, "cstrSockAddr", s.cstrSockAddr
        SaveToIni strFilename, IniSectionApp, "InetPort", s.InetPort
    End If
End Sub

Public Sub LoadApplicationSettings(frm As Form, Optional AppSet As Boolean = True, _
                                                Optional CfgSet As Boolean = True, _
                                                Optional ComSet As Boolean = True)
    Dim strFilename As String
    strFilename = App.Path & "\" & App.EXEName & ".ini"

    If (AppSet) Then
        'Application Settings
        frm.Top = GetFromIni(strFilename, IniSectionApp, frm.Name & "_Top", frm.Top)
        frm.Left = GetFromIni(strFilename, IniSectionApp, frm.Name & "_Left", frm.Left)
    End If

    If (CfgSet) Then
        'Configuration Settings
        s.profile.SendCoarseFineGain = GetFromIni(strFilename, IniSectionApp, "SendCoarseFineGain", False)
        s.SCAEnabled = GetFromIni(strFilename, IniSectionApp, "SCAEnabled", False)
    End If

    If (ComSet) Then
        'Communications Interface Settings
        s.CurrentInterface = GetFromIni(strFilename, IniSectionApp, "CurrentInterface", USB)
        s.ComPort = GetFromIni(strFilename, IniSectionApp, "ComPort", 1)
        s.SockAddr = GetFromIni(strFilename, IniSectionApp, "SockAddr", &HC0A80064)
        s.cstrSockAddr = GetFromIni(strFilename, IniSectionApp, "cstrSockAddr", "192.168.0.100")
        s.InetPort = GetFromIni(strFilename, IniSectionApp, "InetPort", 10001)
    End If
End Sub

'''Private Sub DefaultIpAddress()
'''    Dim lSockAddr As Long
'''    Dim bSockAddr As Variant
'''    Dim strSockAddr As String
'''    Dim strMsg As String
'''
'''    lSockAddr = IpAddrConvert("192.168.0.100")
'''    strMsg = Hex(lSockAddr) & vbNewLine
'''    strSockAddr = IpAddrConvert(lSockAddr)
'''    strMsg = strMsg & strSockAddr & vbNewLine
'''    bSockAddr = IpAddrConvert(lSockAddr, True)
'''    strMsg = strMsg & bSockAddr(0) & "." & bSockAddr(1) & "." & bSockAddr(2) & "." & bSockAddr(3) & vbNewLine
'''    MsgBox strMsg
'''End Sub

'Saves all INI Settings - NOTE:OVERWRITES ENTIRE SECTION - Use with caution!
'Useage - copy all section settings IN ORDER to Settings array, overwrites section settings
'Settings Variant Type of String Array -> Setting(Index,0),Setting(Index,1) -> 0=key,1=data
Public Sub SaveAllIniSettingsEx(strFilename As String, Section As String, Settings As Variant)
    Dim lngRetVal As Long
    Dim strData As String
    Dim strSettings As String
    Dim strNULL As String
    Dim idxSetting As Long
    Dim strSep As String

    strNULL = Chr$(0)
    If (Not IsArray(Settings)) Then Exit Sub
    If (UBound(Settings, 2) <> 1) Then Exit Sub

    For idxSetting = LBound(Settings, 1) To UBound(Settings, 1)
        strData = CStr(Settings(idxSetting, 1))
        If (InStr(strData, ";") > 0) Then
            strSep = ""
        Else
            strSep = ";"
        End If
        strSettings = strSettings & CStr(Settings(idxSetting, 0)) & "=" & strData & strSep & strNULL
    Next
    strSettings = strSettings & strNULL
    lngRetVal = WritePrivateProfileSection(Section, strSettings, strFilename)
End Sub

Public Sub SaveToIniEx(strFilename As String, _
                    strSection As String, _
                    strKey As String, _
                    strData As String)
    Dim lngRetVal As Long
    lngRetVal = WritePrivateProfileString(strSection, _
                                            strKey, _
                                            strData, _
                                            strFilename)
End Sub

Public Function GetFromIniEx(strFilename As String, _
                        strSection As String, _
                        strKey As String, _
                        Optional strDefault As String) As String
    Dim lngRetVal As Long
    Dim lngBuffSz As Long
    Dim strBuff As String

    strBuff = Space(255)
    lngBuffSz = 255
    lngRetVal = GetPrivateProfileString(strSection, _
                                        strKey, _
                                        strDefault, _
                                        strBuff, _
                                        lngBuffSz, _
                                        strFilename)
    lngBuffSz = InStr(1, strBuff, Chr(0), vbBinaryCompare)
    If lngBuffSz > 0 Then
        GetFromIniEx = Trim(Left(strBuff, lngBuffSz - 1))
    Else
        GetFromIniEx = strBuff
    End If
End Function

Public Function DeleteIniSettingEx(strFilename As String, Section As String, Optional Key As String)
    Dim lRet As Long
    If Key = "" Then
        lRet = WritePrivateProfileString(Section, vbNullString, vbNullString, strFilename)
    Else
        lRet = WritePrivateProfileString(Section, Key, vbNullString, strFilename)
    End If
End Function

Public Function GetAllIniSettingsEx(strFilename As String, Section As String) As Variant
    Dim lRet As Long
    Dim strTemp As String
    Dim Table() As String
    Dim Table2() As String
    Dim iPnt As Integer
    Dim iPnt2 As Integer
    Dim iPosit As Integer

    strTemp = Space(32567)
    lRet = GetPrivateProfileSection(Section, strTemp, Len(strTemp), strFilename)
    iPnt = 0
    'For Redim+Preserve tables only the las index can be changed
    If Left(strTemp, 2) = Chr$(0) & Chr$(0) Then
        Exit Function
    End If

    If (lRet = 0) Then
        Exit Function
    End If

    Do While Left(strTemp, 1) <> Chr$(0)
        ReDim Preserve Table(1, iPnt)
        iPosit = InStr(strTemp, "=")
        Table(0, iPnt) = Left$(strTemp, iPosit - 1)
        strTemp = Mid$(strTemp, iPosit + 1)
        iPosit = InStr(strTemp, Chr$(0))
        Table(1, iPnt) = Left$(strTemp, iPosit - 1)
        strTemp = Mid$(strTemp, iPosit + 1)
        iPnt = iPnt + 1
    Loop
    ReDim Table2(iPnt - 1, 1)

    For iPnt2 = 0 To iPnt - 1
        Table2(iPnt2, 0) = Table(0, iPnt2)
        Table2(iPnt2, 1) = Table(1, iPnt2)
    Next

    GetAllIniSettingsEx = Table2
End Function


modNetFinder Source Code

'Purpose:

'    The Netfinder protocol allows a PC application to search for embedded systems on a network.

'    For USB, the NetFinder Packet is used to Identify DPP devices

Option Explicit

Public InetShareDpp As Boolean
Public InetLockDpp As Boolean
Public Const MAX_NETFINDER_ENTRIES = 10
Public Const NO_NETFINDER_ENTRIES = -1
Public Const MAX_NETFINDER_STRING = 80
Public Netfinder_active As Boolean
Public Netfinder_Seq As Integer
Public NewNetfinderRequest As Boolean
Public NetfinderUnit As Integer
Public EthernetConnectionStatus As Integer
Public EthernetConnectionTicker As Integer
Public UnitIP(MAX_NETFINDER_ENTRIES - 1, 3)         ' capture up to 16 IPs per Netfinder?
Public EthernetConnected As Boolean
Public SearchIp As Long
Public isDppFound(RS232 To ETHERNET) As Boolean

Public Type NETDISPLAY_ENTRY
    alert_level As Byte
    event1_days As Long
    event1_hours As Byte
    event1_minutes As Byte
    event1_seconds As Byte
    event2_days As Long
    event2_hours As Byte
    event2_minutes As Byte
    event2_seconds As Byte
    mac(6) As Byte
    ip(4) As Byte
    port As Integer
    subnet(4) As Byte
    gateway(4) As Byte
    str_type As String
    str_description As String
    str_ev1 As String
    str_ev2 As String
    str_display As String
    ccConnectRGB As Long     'COLORREF
    HasData As Boolean
    SockAddr As Long
    SerNum As Long
End Type

Public NfPktEntries(MAX_NETFINDER_ENTRIES - 1) As NETDISPLAY_ENTRY    'RS232,USB,ETHERNET,SPARE
Public DppEntries(MAX_NETFINDER_ENTRIES - 1) As NETDISPLAY_ENTRY

Public Sub AddStr(ByRef strStr As String, str1 As String, Optional str2 As String = "", Optional AddNL As Boolean = True)
    Dim strNL As String
    strNL = ""
    If (AddNL) Then strNL = vbNewLine
    strStr = strStr & str1 & str2 & strNL
End Sub

'Purpose: IpAddrConvert converts multiple IP address formats.
'

'

'Returns:

'   IpAddrConvert convertions with ToByteArray = False

'       long to string

'       byte array to string

'       string to long

'
'   IpAddrConvert convertions with ToByteArray = True

'       long to byte array

'       byte array to string (no change)

'       string to byte array

'

'

'Parameter: IPAddress IP Address to be converted.
'Parameter: ToByteArray IP Address convertion function.
Public Function IpAddrConvert(IPAddress As Variant, Optional ToByteArray As Boolean = False) As Variant
    Dim idxByte As Long     'byte index
    Dim idxPos As Long      'position in hex string
    Dim idxPosOld As Long
    Dim strHex As String
    Dim strSep As String
    Dim ipByte As Byte
    Dim ipByteArr(3) As Byte
    Dim strIpAddr As String

    If IsNumeric(IPAddress) Then                    'convert long
        strIpAddr = ""
        strSep = ""
        strHex = Hex(IPAddress)
        strHex = String(8 - Len(strHex), "0") & strHex
        For idxByte = 0 To 3
            idxPos = 1 + (idxByte * 2)
            ipByte = CByte("&H" & Mid(strHex, idxPos, 2))   'convert hex to byte
            ipByteArr(idxByte) = ipByte
            strIpAddr = strIpAddr & strSep & CStr(ipByte)
            strSep = "."
        Next
        If (ToByteArray) Then
            IpAddrConvert = ipByteArr
        Else
            IpAddrConvert = strIpAddr
        End If
    ElseIf IsArray(IPAddress) Then                  'ByteArray(0-3)
        If ((TypeName(IPAddress) = "Byte()") And (UBound(IPAddress) = 3)) Then
            strIpAddr = ""
            strSep = ""
            For idxByte = 0 To 3
                ipByte = IPAddress(idxByte)
                strIpAddr = strIpAddr & strSep & CStr(ipByte)
                strSep = "."
            Next
            IpAddrConvert = strIpAddr
        End If
    ElseIf (TypeName(IPAddress) = "String") Then    'String 0.0.0.0
        idxPos = 1
        idxPosOld = 0
        strIpAddr = ""
        For idxByte = 0 To 3
            idxPos = InStr(idxPosOld + 1, IPAddress, ".")
            If (idxPos = 0) Then idxPos = Len(IPAddress) + 1    'end of string
            ipByteArr(idxByte) = Val(Mid(IPAddress, idxPosOld + 1, (idxPos - idxPosOld) - 1)) And &HFF
            idxPosOld = idxPos
            strHex = Hex(ipByteArr(idxByte))
            strHex = String(2 - Len(strHex), "0") & strHex
            strIpAddr = strIpAddr & strHex
        Next
        If (ToByteArray) Then
            IpAddrConvert = ipByteArr
        Else
            IpAddrConvert = CLng("&H" & strIpAddr)
        End If
    End If
End Function

'IP Address Convert
'long . string >. string=IpAddrConvert(long)
'long . byte array >. byte array=IpAddrConvert(long,true)
'string . long >. long=IpAddrConvert(string)
'string . byte array >. byte array=IpAddrConvert(string,true)
'byte array . string >. string=IpAddrConvert(byte array)
'(2 steps for byte array to long)
'byte array . long >. string=IpAddrConvert(byte array) >>. long=IpAddrConvert(string)

Public Sub InitEntry(ByRef pEntry As NETDISPLAY_ENTRY)
    Dim idxInit As Long
    pEntry.alert_level = 0
    pEntry.event1_days = 0
    pEntry.event1_hours = 0
    pEntry.event1_minutes = 0
    pEntry.event2_days = 0
    pEntry.event2_hours = 0
    pEntry.event2_minutes = 0
    pEntry.event1_seconds = 0
    pEntry.event2_seconds = 0
    pEntry.port = 0             ' Get port from UDP header
    For idxInit = 0 To MAX_DISPLAY_ENTRIES - 1
        pEntry.mac(idxInit) = 0
        pEntry.ip(idxInit) = 0
        pEntry.subnet(idxInit) = 0
        pEntry.gateway(idxInit) = 0
    Next
    pEntry.mac(4) = 0
    pEntry.mac(5) = 0
    pEntry.str_type = ""
    pEntry.str_description = ""
    pEntry.str_ev1 = ""
    pEntry.str_ev2 = ""
    pEntry.str_display = ""
    pEntry.ccConnectRGB = colorWhite
    pEntry.HasData = False
    pEntry.SockAddr = 0
    pEntry.SerNum = 0
End Sub

Public Sub InitAllEntries(ByRef DppEntries() As NETDISPLAY_ENTRY)
    Dim idxEntry As Long
    Dim lMaxEntry As Long

    lMaxEntry = UBound(DppEntries)
    For idxEntry = 0 To lMaxEntry
        Call InitEntry(DppEntries(idxEntry))
    Next
End Sub

Public Function AlertEntryToCOLORREF(pEntry As NETDISPLAY_ENTRY) As Long   'COLORREF
    AlertEntryToCOLORREF = AlertByteToCOLORREF(pEntry.alert_level)
End Function

Public Function AlertByteToCOLORREF(alert_level As Byte) As Long   'COLORREF
    Select Case alert_level                                     ' Alert Level
        Case &H0:   '0 = Interface is open (unconnected)
            AlertByteToCOLORREF = colorGreen
        Case &H1:   '1 = Interface is connected (sharing is allowed)
            AlertByteToCOLORREF = colorYellow
        Case &H2:   '2 = Interface is connected (sharing is not allowed)
            AlertByteToCOLORREF = colorRed
        Case &H3:   '3 = Interface is locked
            AlertByteToCOLORREF = colorRed
        Case &H4:   '4 = Interface is unavailable because USB is connected
            AlertByteToCOLORREF = colorSilver
        Case Else:  'Interface configuration unknown
            AlertByteToCOLORREF = colorWhite
    End Select
End Function

Public Function FindEntry(SockAddr As Long, DppEntries() As NETDISPLAY_ENTRY) As Long
    Dim idxEntry As Long
    Dim EntryFound As Long
    Dim lMaxEntry As Long

    lMaxEntry = UBound(DppEntries)
    EntryFound = NO_NETFINDER_ENTRIES
    For idxEntry = 0 To lMaxEntry
        If (SockAddr = DppEntries(idxEntry).SockAddr) Then
            EntryFound = idxEntry
            Exit For
        End If
    Next
    FindEntry = EntryFound
End Function

Public Sub AddEntry(ByRef pEntry As NETDISPLAY_ENTRY, Buffer() As Byte, destPort As Long)
    Dim idxBuffer As Long                                   'buffer index
    Dim nfVersion As Byte
    Dim RandSeqNumber As Long

    nfVersion = Buffer(&H0)                                 'byte 0 (for reference)
    pEntry.alert_level = Buffer(&H1)                        'byte 1
    RandSeqNumber = (CLng(Buffer(&H2)) * CLng(256)) + CLng(Buffer(&H3))       'bytes 2 & 3 (for reference)
    pEntry.port = CInt("&H" & Hex(destPort And &HFFFF))     'convert long containing unsigned short
    pEntry.event1_days = EventDays_ByteToULong(Buffer, &H4) 'Event 1 days bytes 4 & 5
    pEntry.event1_hours = Buffer(&H6)                       'Event 1 hours byte 6
    pEntry.event1_minutes = Buffer(&H7)                     'Event 1 minutes byte 7
    pEntry.event2_days = EventDays_ByteToULong(Buffer, &H8) 'Event 2 days bytes 8 & 9
    pEntry.event2_hours = Buffer(&HA)                       'Event 2 hours byte 10
    pEntry.event2_minutes = Buffer(&HB)                     'Event 2 minutes byte 11
    pEntry.event1_seconds = Buffer(&HC)                     'Event 1 seconds byte 12
    pEntry.event2_seconds = Buffer(&HD)                     'Event 1 seconds byte 13
    pEntry.mac(0) = Buffer(&HE)                             'MAC Address byte 14 (6 bytes)
    pEntry.mac(1) = Buffer(&HF)
    pEntry.mac(2) = Buffer(&H10)
    pEntry.mac(3) = Buffer(&H11)
    pEntry.mac(4) = Buffer(&H12)
    pEntry.mac(5) = Buffer(&H13)
    pEntry.ip(0) = Buffer(&H14)                             'IP Address byte 20 (4 bytes)
    pEntry.ip(1) = Buffer(&H15)
    pEntry.ip(2) = Buffer(&H16)
    pEntry.ip(3) = Buffer(&H17)
    pEntry.subnet(0) = Buffer(&H18)                         'Subnet Mask byte 24 (4 bytes)
    pEntry.subnet(1) = Buffer(&H19)
    pEntry.subnet(2) = Buffer(&H1A)
    pEntry.subnet(3) = Buffer(&H1B)
    pEntry.gateway(0) = Buffer(&H1C)                        'Default Gateway byte 28 (4 bytes)
    pEntry.gateway(1) = Buffer(&H1D)
    pEntry.gateway(2) = Buffer(&H1E)
    pEntry.gateway(3) = Buffer(&H1F)
    idxBuffer = &H20    'start of variable Length Null-Terminated strings byte 32
                        'buffer index incremented to start of next string
    pEntry.str_type = GetNetFinderString(Buffer, idxBuffer)         'get embedded system
    pEntry.SerNum = GetSerialNumber(pEntry.str_type)                'get serial number
    pEntry.str_description = GetNetFinderString(Buffer, idxBuffer)  'get description
    pEntry.str_ev1 = GetNetFinderString(Buffer, idxBuffer)          'get event 1 description
    pEntry.str_ev2 = GetNetFinderString(Buffer, idxBuffer)          'get event 2 description
    pEntry.str_ev1 = pEntry.str_ev1 & ": "
    pEntry.str_ev2 = pEntry.str_ev2 & ": "
    pEntry.ccConnectRGB = AlertByteToCOLORREF(pEntry.alert_level)
    pEntry.HasData = True
    pEntry.SockAddr = SockAddr_ByteToULong(Buffer, &H14)        'IP Address (starts at byte 20)
    pEntry.str_display = EntryToStr(pEntry)   ' Convert Entry infor to string
End Sub

Private Function GetNetFinderString(Buffer() As Byte, ByRef Index As Long) As String
    Dim idxCh As Long
    Dim strCh As String
    strCh = ""
    idxCh = Index
    Do
        If (Buffer(idxCh) > 0) And (idxCh < UBound(Buffer)) Then
            strCh = strCh + Chr(Buffer(idxCh))
            idxCh = idxCh + 1
        Else
            idxCh = idxCh + 1   'start of next string
            Exit Do
        End If
    Loop
    Index = idxCh               'update index to next position
    GetNetFinderString = strCh
End Function

Private Function GetSerialNumber(str_type As String) As Long
    Dim lSerNum As Long
    Dim lPos As Long
    Dim strSerNum As String

    lSerNum = 0
    If (Len(str_type) > 0) Then
        lPos = InStr(1, str_type, "S/N", vbTextCompare)
        If (lPos > 0) Then
            If ((lPos + 3) < Len(str_type)) Then
                lSerNum = CLng(Val(Mid(str_type, lPos + 3)))
            End If
        End If
    End If
    GetSerialNumber = lSerNum
End Function

Private Function EventDays_ByteToULong(Buffer() As Byte, Index As Long) As Long
    Dim lngDays As Long
    lngDays = CLng(Buffer(Index)) * 256
    lngDays = lngDays + CLng(Buffer(Index + 1))
    EventDays_ByteToULong = lngDays
End Function

Private Function SockAddr_ByteToULong(Buffer() As Byte, Index As Long) As Long
    Dim idxIp As Long
    Dim byteIp(3) As Byte
    Dim strIp As String
    For idxIp = 0 To 3
        byteIp(idxIp) = Buffer(Index + idxIp)
    Next
    strIp = IpAddrConvert(byteIp)
    SockAddr_ByteToULong = IpAddrConvert(strIp)
End Function

Private Function inc(ByRef varIndex As Variant) As Long
    varIndex = varIndex + 1
    inc = CLng(varIndex)
End Function

Public Function EntryToStr(ByRef pEntry As NETDISPLAY_ENTRY) As String
    Dim cstrAlertLevel As String
    Dim strDeviceType As String
    Dim cstrIpAddress As String
    Dim cstrEvent1, cstrEvent2 As String
    Dim cstrAdditionalDesc As String
    Dim cstrMacAddress As String
    Dim cstrEntry As String
    Dim temp_str, temp_str2 As String
    Dim idxVal As Long
    Dim strSep As String

    cstrAlertLevel = "Connection: "
    Select Case (pEntry.alert_level)            ' Alert Level
        Case &H0:   '0 = Interface is open (unconnected)
            cstrAlertLevel = cstrAlertLevel + "Interface is open (unconnected)"
        Case &H1:   '1 = Interface is connected (sharing is allowed)
            cstrAlertLevel = cstrAlertLevel + "Interface is connected (sharing is allowed)"
        Case &H2:   '2 = Interface is connected (sharing is not allowed)
            cstrAlertLevel = cstrAlertLevel + "Interface is connected (sharing is not allowed)"
        Case &H3:   '3 = Interface is locked
            cstrAlertLevel = cstrAlertLevel + "Interface is locked"
        Case &H4:   '4 = Interface is unavailable because USB is connected
            cstrAlertLevel = cstrAlertLevel + "Interface is unavailable because USB is connected"
        Case Else:
            cstrAlertLevel = cstrAlertLevel + "Interface configuration unknown"
    End Select
    strDeviceType = pEntry.str_type        ' Device Name/Type
    cstrIpAddress = "IP Address: " & IpAddrConvert(pEntry.SockAddr) ' IP Address String
    cstrAdditionalDesc = pEntry.str_description   ' Additional Description
    cstrMacAddress = "MAC Address: "        ' MacAddress
    strSep = ""
    For idxVal = 0 To 5
        cstrMacAddress = cstrMacAddress & strSep & FmtHex(pEntry.mac(idxVal), 2)
        strSep = "-"
    Next
    temp_str = pEntry.str_ev1 + " "                 ' Event1 Time
    temp_str2 = FormatNetFinderTime(pEntry, 1)
    cstrEvent1 = temp_str + temp_str2
    temp_str = pEntry.str_ev2 + " "
    temp_str2 = FormatNetFinderTime(pEntry, 2)      ' Event2 Time
    cstrEvent2 = temp_str + temp_str2
    cstrEntry = strDeviceType & vbNewLine
    cstrEntry = cstrEntry + cstrAlertLevel & vbNewLine
    cstrEntry = cstrEntry + cstrIpAddress & vbNewLine
    cstrEntry = cstrEntry + cstrAdditionalDesc & vbNewLine
    cstrEntry = cstrEntry + cstrMacAddress & vbNewLine
    cstrEntry = cstrEntry + cstrEvent1 & vbNewLine
    cstrEntry = cstrEntry + cstrEvent2 & vbNewLine
    EntryToStr = cstrEntry
End Function

Public Function EntryToStrUSB(ByRef pEntry As NETDISPLAY_ENTRY, strPort As String) As String
    Dim cstrAlertLevel As String
    Dim strDeviceType As String
    Dim cstrIpAddress As String
    Dim cstrEvent1, cstrEvent2 As String
    Dim cstrAdditionalDesc As String
    Dim cstrMacAddress As String
    Dim cstrEntry As String
    Dim temp_str, temp_str2 As String
    Dim idxVal As Long
    Dim strSep As String

    cstrAlertLevel = "Connection: "
    cstrAlertLevel = cstrAlertLevel & strPort
    strDeviceType = pEntry.str_type                                ' Device Name/Type
    cstrIpAddress = "IP Address: " & IpAddrConvert(pEntry.SockAddr) ' IP Address String
    cstrAdditionalDesc = pEntry.str_description                     ' Additional Description
    cstrMacAddress = "MAC Address: "                                ' MacAddress
    strSep = ""
    For idxVal = 0 To 5
        cstrMacAddress = cstrMacAddress & strSep & FmtHex(pEntry.mac(idxVal), 2)
        strSep = "-"
    Next
    temp_str = pEntry.str_ev1 + " "                                 ' Event1 Time
    temp_str2 = FormatNetFinderTime(pEntry, 1)
    cstrEvent1 = temp_str + temp_str2
    temp_str = pEntry.str_ev2 + " "                                 ' Event2 Time
    temp_str2 = FormatNetFinderTime(pEntry, 2)
    cstrEvent2 = temp_str + temp_str2
    cstrEntry = strDeviceType & vbNewLine
    cstrEntry = cstrEntry + cstrAlertLevel & vbNewLine
    cstrEntry = cstrEntry + cstrAdditionalDesc & vbNewLine
    cstrEntry = cstrEntry + cstrEvent1 & vbNewLine
    EntryToStrUSB = cstrEntry
End Function

Public Function FormatNetFinderTime(pEntry As NETDISPLAY_ENTRY, NetFinderEvent As Byte) As String
    Dim event_days As Long
    Dim event_hours As Byte
    Dim event_minutes As Byte
    Dim event_seconds As Byte
    Dim strTime(3) As String
    Dim idxValue As Long
    Dim idxStart As Long
    Dim strEventTime As String

    If (NetFinderEvent = 1) Then
        event_days = pEntry.event1_days
        event_hours = pEntry.event1_hours
        event_minutes = pEntry.event1_minutes
        event_seconds = pEntry.event1_seconds
    ElseIf (NetFinderEvent = 2) Then
        event_days = pEntry.event2_days
        event_hours = pEntry.event2_hours
        event_minutes = pEntry.event2_minutes
        event_seconds = pEntry.event2_seconds
    Else
        FormatNetFinderTime = ""
        Exit Function
    End If

    strTime(0) = CStr(event_days) & " days,"
    strTime(1) = CStr(event_hours) & " hours,"
    strTime(2) = CStr(event_minutes) & " minutes,"
    strTime(3) = CStr(event_seconds) & " seconds"

    idxStart = 0
    If (CBool(event_days)) Then
        idxStart = 0
    ElseIf (CBool(event_hours)) Then
        idxStart = 1
    ElseIf (CBool(event_minutes)) Then
        idxStart = 2
    Else
        idxStart = 3
    End If

    strEventTime = ""
    For idxValue = idxStart To 3
        strEventTime = strEventTime & strTime(idxValue)
    Next
    FormatNetFinderTime = strEventTime
End Function


modParsePacket Source Code

Option Explicit

Public Const USB_DiagDataDelayMS As Long = 2500&

Public ACK_Received As Boolean
Public Timeout_flag As Boolean

Public Type DiagDataType
    ADC_V(12) As Single
    PC5_V(4) As Single
    PC5_PRESENT As Boolean
    PC5_SerialNumber As Long
    Firmware As Byte
    FPGA As Byte
    SRAMTestPass As Boolean
    SRAMTestData As Long
    TempOffset As Integer
    strTempRaw As String
    strTempCal As String
    PC5Initialized As Boolean
    PC5DCAL As Single
    IsPosHV As Boolean
    Is8_5VPreAmp As Boolean
    Sup9VOn As Boolean
    PreAmpON As Boolean
    HVOn As Boolean
    TECOn As Boolean
    DiagData(192) As Byte
End Type

Public Enum DP5_DPP_TYPES
    dppDP5
    dppPX5
    dppDP5G
    dppMCA8000D
    dppTB5
    dppDP5X
End Enum

Public Enum CommType
    commRS232 = 0
    commUSB = 1
    commSockets = 2
    commNone = 3
End Enum

Public Const preqProcessNone = &H0&
Public Const preqProcessStatus = &H1&
Public Const preqProcessSpectrum = &H2&
Public Const preqRequestScopeData = &H4&
Public Const preqProcessScopeData = &H8&
Public Const preqProcessTextData = &H10&
Public Const preqProcessScopeDataOverFlow = &H20&
Public Const preqProcessInetSettings = &H40&
Public Const preqProcessDiagData = &H80&
Public Const preqProcessHwDesc = &H100&
Public Const preqProcessCfgRead = &H200&
Public Const preqProcessNetFindRead = &H400&
'...
Public Const preqProcessSCAData = &H2000&
Public Const preqProcessAck = &H4000&
Public Const preqProcessError = &H8000&

Public Type DppStateType
    Interface As CommType
    strPort As String
    ReqProcess As Long
    HaveScopeData As Boolean
    ScopeAutoRearm As Boolean
End Type

Public DppState As DppStateType

Public Sub ParsePacketStatus(ByRef P() As Byte, ByRef PIN As Packet_In)
    Dim X As Integer

    Dim CSum As Long
    CSum = 0
    If P(0) = SYNC1_ Then
        If P(1) = SYNC2_ Then
            If P(4) < 128 Then  ' LEN MSB < 128, i.e. LEN < 32768
                PIN.LEN = (P(4) * 256) + P(5)
                'PIN.LEN = TwoByteToLong(P(4), P(5))
                PIN.PID1 = P(2)
                PIN.PID2 = P(3)
                For X = 0 To PIN.LEN + 5    ' add up all the bytes except checksum
                    CSum = CSum + P(X)
                Next X
                CSum = CSum + 256 * CLng(P(PIN.LEN + 6)) + CLng(P(PIN.LEN + 7))
                PIN.CheckSum = CSum
                If (CSum And &HFFFF&) = 0 Then
                    PIN.STATUS = 0      ' packet is OK
                    If PIN.LEN > 0 Then
                        For X = 6 To 5 + PIN.LEN
                            PIN.DATA(X - 6) = P(X)
                        Next X
                        ' call processing routines based on PID?
                    End If
                Else
                    PIN.STATUS = PID2_ACK_CHECKSUM_ERROR    ' checksum error
                End If
            Else
                PIN.STATUS = PID2_ACK_LEN_ERROR        ' length error
            End If
        Else
            PIN.STATUS = PID2_ACK_SYNC_ERROR            ' sync error
        End If
    Else
        PIN.STATUS = PID2_ACK_SYNC_ERROR                ' sync error
    End If
    '    Packet_Received = True  ' flag that packet was received, regardless of errors

End Sub

Public Function PID2_TextToString(strPacketSource As String, ByRef PID2 As Byte) As String
    PID2_TextToString = ""
    Select Case PID2
        Case PID2_ACK_OK    ' ACK OK
            'PID2_TextToString = strPacketSource & ": OK" & vbTab
            PID2_TextToString = ""
            ACK_Received = True
        Case PID2_ACK_SYNC_ERROR
            PID2_TextToString = strPacketSource & ": Sync Error" & vbTab
        Case PID2_ACK_PID_ERROR
            PID2_TextToString = strPacketSource & ": PID Error" & vbTab
        Case PID2_ACK_LEN_ERROR
            PID2_TextToString = strPacketSource & ": Length Error" & vbTab
        Case PID2_ACK_CHECKSUM_ERROR
            PID2_TextToString = strPacketSource & ": Checksum Error" & vbTab
        Case PID2_ACK_BAD_PARAM
            PID2_TextToString = strPacketSource & ": Bad Parameter" & vbTab
            '                            TextLog "ACK: BAD PARAM '" + T$ + "'" + vbCrLf
        Case PID2_ACK_BAD_HEX_REC
            PID2_TextToString = strPacketSource & ": Bad HEX Record" & vbTab
        Case PID2_ACK_UNRECOG
            PID2_TextToString = strPacketSource & ": Unrecognized Command" & vbTab
    End Select
End Function

Public Function ParsePacket(ByRef P() As Byte, ByRef PIN As Packet_In) As Long
    ParsePacket = preqProcessNone
    ParsePacketStatus P, PIN
    If (PIN.STATUS = PID2_ACK_OK) Then ' no errors
        If ((PIN.PID1 = PID1_RCV_STATUS) And (PIN.PID2 = PID2_SEND_DP4_STYLE_STATUS)) Then ' DP4-style status
            ParsePacket = preqProcessStatus
        ElseIf ((PIN.PID1 = PID1_RCV_SPECTRUM) And ((PIN.PID2 >= RCVPT_256_CHANNEL_SPECTRUM) And (PIN.PID2 <= RCVPT_8192_CHANNEL_SPECTRUM_STATUS))) Then ' spectrum / spectrum+status
            ParsePacket = preqProcessSpectrum
        'ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = PID2_SEND_SCOPE_DATA)) Then'scope data packet
        '    ParsePacket = preqProcessScopeData
        'ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = PID2_SEND_512_BYTE_MISC_DATA)) Then 'text data packet
        '    ParsePacket = preqProcessTextData
        ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = RCVPT_SCOPE_DATA)) Then 'scope data packet
            'ScopeOverFlow = FALSE
            ParsePacket = preqProcessScopeData
        ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = RCVPT_512_BYTE_MISC_DATA)) Then 'text data packet
            ParsePacket = preqProcessTextData
        ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = RCVPT_SCOPE_DATA_WITH_OVERFLOW)) Then 'scope data with overflow packet
            'ScopeOverFlow = TRUE
            ParsePacket = preqProcessScopeData
            'ParsePacket = preqProcessScopeDataOverFlow
        ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = RCVPT_ETHERNET_SETTINGS)) Then 'ethernet settings packet
            'ParsePacket = preqProcessInetSettings
        ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = RCVPT_DIAGNOSTIC_DATA)) Then 'diagnostic data  packet
            ParsePacket = preqProcessDiagData
        'ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = RCVPT_HARDWARE_DESCRIPTION)) Then 'hardware description packet
            'ParsePacket = preqProcessHwDesc
        ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = RCVPT_CONFIG_READBACK)) Then
            ParsePacket = preqProcessCfgRead
        ElseIf ((PIN.PID1 = PID1_RCV_SCOPE_MISC) And (PIN.PID2 = RCVPT_NETFINDER_READBACK)) Then
            ParsePacket = preqProcessNetFindRead
            'MsgBox "NetFinder!"
        ElseIf (PIN.PID1 = PID1_ACK) Then
            ParsePacket = preqProcessAck
        Else
            PIN.STATUS = PID2_ACK_PID_ERROR  ' unknown PID
            ParsePacket = preqProcessError
        End If
    Else
        ParsePacket = preqProcessError
    End If

    'PIN.PID1 = 0    ' overwrite the PIDs so packet can't be erroneously processed again
    'PIN.PID2 = 0

End Function

'convert a 4 byte long word to a double
'lwStart - starting index of longword
'buffer - byte buffer
Private Function LongWordToDouble(lwStart As Long, Buffer() As Byte) As Double
    Dim dblVal As Double
    Dim idxByte As Long
    Dim ByteMask As Double
    dblVal = 0
    For idxByte = 0 To 3      ' build 4 bytes (lwStart-lwStart+3) into double
        ByteMask = 2 ^ (8 * idxByte)
        dblVal = dblVal + (Buffer((lwStart + idxByte)) * ByteMask)
    Next
    LongWordToDouble = dblVal
End Function

Public Sub Process_Status(STATUS As Stat)
    Dim bDMCA_LiveTime As Boolean
    Dim uiFwBuild As Long
    uiFwBuild = 0
    bDMCA_LiveTime = False
    STATUS.DEVICE_ID = STATUS.RAW(39)       '0=dp5,1=px5,2=dp5g,3=mca8000d,4=tb5
    Select Case STATUS.DEVICE_ID
        Case 0
            STATUS.strDeviceID = "DP5"
        Case 1
            STATUS.strDeviceID = "PX5"
        Case 2
            STATUS.strDeviceID = "DP5G"
        Case 3
            STATUS.strDeviceID = "MCA8000D"
        Case 4
            STATUS.strDeviceID = "TB5"
        Case 5
            STATUS.strDeviceID = "DP5X"
        Case Else
            STATUS.strDeviceID = "DP5" 'default
    End Select

    STATUS.FastCount = LongWordToDouble(0, STATUS.RAW)
    STATUS.SlowCount = LongWordToDouble(4, STATUS.RAW)
    STATUS.GP_COUNTER = LongWordToDouble(8, STATUS.RAW)
    STATUS.AccumulationTime = STATUS.RAW(12) * 0.001 + (STATUS.RAW(13) + STATUS.RAW(14) * 256# + STATUS.RAW(15) * 65536#) * 0.1
    STATUS.RealTime = LongWordToDouble(20, STATUS.RAW) * 0.001

    STATUS.Firmware = STATUS.RAW(24)
    STATUS.FPGA = STATUS.RAW(25)

    If (STATUS.Firmware > &H65) Then
        STATUS.Build = STATUS.RAW(37) And &HF   ' Build # added in FW6.06
    Else
        STATUS.Build = 0
    End If

    'Firmware Version:  6.07  Build:  0 has LiveTime and PREL
    'DEVICE_ID 0=DP5,1=PX5,2=DP5G,3=MCA8000D,4=TB5
    If (STATUS.DEVICE_ID = dppMCA8000D) Then
        If (STATUS.Firmware >= &H67) Then
            bDMCA_LiveTime = True
        End If
    End If

    If (bDMCA_LiveTime) Then
        STATUS.LiveTime = LongWordToDouble(16, STATUS.RAW) * 0.001
    Else
        STATUS.LiveTime = 0
    End If

    If (STATUS.RAW(29) < 128) Then
        STATUS.SerialNumber = CLng(LongWordToDouble(26, STATUS.RAW))
    Else
        STATUS.SerialNumber = -1
    End If

    If (STATUS.RAW(30) < 128) Then    ' not negative
        STATUS.HV = CDbl(STATUS.RAW(31) + (STATUS.RAW(30) * 256#)) * 0.5  ' 0.5V/count
    Else
        STATUS.HV = CDbl((STATUS.RAW(31) + (STATUS.RAW(30) * 256#)) - 65536#) * 0.5   ' 0.5V/count
    End If

    STATUS.DET_TEMP = CSng(STATUS.RAW(33) + (STATUS.RAW(32) And 15) * 256) * 0.1 - 273.16 ' 0.1K/count
    STATUS.DP5_TEMP = STATUS.RAW(34) - ((STATUS.RAW(34) And 128) * 2)

    STATUS.PresetRtDone = ((STATUS.RAW(35) And 128) = 128)

    'BYTE:35 BIT:D6
    ' = Preset LiveTime Done for MCA8000D
    ' = FAST Thresh locked for other dpp devices
    STATUS.PresetLtDone = False
    STATUS.AFAST_LOCKED = False
    If (bDMCA_LiveTime) Then       ' test for MCA8000D
        STATUS.PresetLtDone = ((STATUS.RAW(35) And 64) = 64)
    Else
        STATUS.AFAST_LOCKED = ((STATUS.RAW(35) And 64) = 64)
    End If
    STATUS.MCA_EN = ((STATUS.RAW(35) And 32) = 32)
    STATUS.PresetCountDone = ((STATUS.RAW(35) And 16) = 16)
    STATUS.SCOPE_DR = ((STATUS.RAW(35) And 4) = 4)
    STATUS.DP5_CONFIGURED = ((STATUS.RAW(35) And 2) = 2)

    STATUS.AOFFSET_LOCKED = ((STATUS.RAW(36) And 128) = 0)  ' 0=locked, 1=searching
    STATUS.MCS_DONE = ((STATUS.RAW(36) And 64) = 64)

    STATUS.b80MHzMode = ((STATUS.RAW(36) And 2) = 2)
    STATUS.bFPGAAutoClock = ((STATUS.RAW(36) And 1) = 1)

    STATUS.PC5_PRESENT = ((STATUS.RAW(38) And 128) = 128)
    If (STATUS.PC5_PRESENT) Then
        STATUS.PC5_HV_POL = ((STATUS.RAW(38) And 64) = 64)
        STATUS.PC5_8_5V = ((STATUS.RAW(38) And 32) = 32)
    Else
        STATUS.PC5_HV_POL = False
        STATUS.PC5_8_5V = False
    End If

    If (STATUS.Firmware >= &H65) Then   ' reboot flag added FW6.05
        If ((STATUS.RAW(36) And 32) = 32) Then
            STATUS.ReBootFlag = True
        Else
            STATUS.ReBootFlag = False
        End If
    Else
        STATUS.ReBootFlag = False
    End If

    STATUS.TEC_Voltage = ((CDbl(STATUS.RAW(40) And 15) * 256#) + CDbl(STATUS.RAW(41))) / 758.5
    STATUS.DPP_ECO = STATUS.RAW(49)
    STATUS.bScintHas80MHzOption = False
    STATUS.DPP_options = (STATUS.RAW(42) And 15)
    STATUS.HPGe_HV_INH = False
    STATUS.HPGe_HV_INH_POL = False
    STATUS.AU34_2 = False
    STATUS.isAscInstalled = False
    STATUS.isDP5_RevDxGains = False
    If (STATUS.DEVICE_ID = dppPX5) Then
        If (STATUS.DPP_options = PX5_OPTION_HPGe_HVPS) Then
            STATUS.HPGe_HV_INH = ((STATUS.RAW(42) And 32) = 32)
            STATUS.HPGe_HV_INH_POL = ((STATUS.RAW(42) And 16) = 16)
            If (STATUS.DPP_ECO = 1) Then
                STATUS.isAscInstalled = True
                STATUS.AU34_2 = ((STATUS.RAW(42) And 64) = 64)
            End If
        End If
     ElseIf ((STATUS.DEVICE_ID = dppDP5G) Or (STATUS.DEVICE_ID = dppTB5)) Then
        If ((STATUS.DPP_ECO = 1) Or (STATUS.DPP_ECO = 2)) Then
            STATUS.bScintHas80MHzOption = True
        End If

    ElseIf (STATUS.DEVICE_ID = dppDP5) Then
        uiFwBuild = STATUS.Firmware
        uiFwBuild = uiFwBuild * CLng(256)   '  << 8
        uiFwBuild = uiFwBuild + STATUS.Build
        ' uiFwBuild - firmware with build for comparison
        uiFwBuild = uiFwBuild And &HFFFF
        If (uiFwBuild >= &H686) Then
            ' 0xFF Value indicates old Analog Gain Count of 16
            ' Values < 0xFF indicate new gain count of 24 and new board rev
            ' "DP5 G3 Configuration P" will not be used (==&HFF)
            If (STATUS.DPP_ECO < &HFF) Then
                STATUS.isDP5_RevDxGains = True
            End If
        End If
    End If

'    MsgBox DP5_Dx_OptionFlags(STATUS.DPP_ECO)

End Sub

'DP5 Revision and Configuration from ECO Byte
'   D7-D6: 0-4, = DP5 Rev D-G
'   D5-D4: minor rev, 0-3 (i.e. Rev D0, D1 etc.)
'   D3-D0: Configuration 0 = A, 1=B, 2=C... 15=P.
Public Function DP5_Dx_OptionFlags(DP5_Dx_Options As Byte) As String
    Dim strRev As String
    strRev = "Reported Rev/Config: "
    strRev = strRev & Chr(((DP5_Dx_Options \ 64) And &H3) + Asc("D"))       'D7D6
    strRev = strRev & Chr((DP5_Dx_Options And &H30) \ 16 + Asc("0")) + "-"  'D5D4
    strRev = strRev & Chr((DP5_Dx_Options And 15) + Asc("A"))               'D3D0
    DP5_Dx_OptionFlags = strRev
End Function

Public Sub Process_Diagnostics(PIN As Packet_In, ByRef dd As DiagDataType)
    Dim idxVal As Long
    Dim strVal As String
    Dim DP5_ADC_Gain(10) As Single  ' convert each ADC count to engineering units - values calculated in FORM.LOAD
    Dim PC5_ADC_Gain(3) As Single
    Dim PX5_ADC_Gain(11) As Single

    DP5_ADC_Gain(0) = 1# / 0.00286              ' 2.86mV/C
    DP5_ADC_Gain(1) = 1#                        ' Vdd mon (out-of-scale)
    DP5_ADC_Gain(2) = (30.1 + 20#) / 20#        ' PWR
    DP5_ADC_Gain(3) = (13# + 20#) / 20#         ' 3.3V
    DP5_ADC_Gain(4) = (4.99 + 20#) / 20#        ' 2.5V
    DP5_ADC_Gain(5) = 1#                        ' 1.2V
    DP5_ADC_Gain(6) = (35.7 + 20#) / 20#        ' 5.5V
    DP5_ADC_Gain(7) = (35.7 + 75#) / 35.7       ' -5.5V (this one is tricky)
    DP5_ADC_Gain(8) = 1#                        ' AN_IN
    DP5_ADC_Gain(9) = 1#                        ' VREF_IN

    PC5_ADC_Gain(0) = 500#                      ' HV: 1500V/3V
    PC5_ADC_Gain(1) = 100#                      ' TEC: 300K/3V
    PC5_ADC_Gain(2) = (20# + 10#) / 10#         ' +8.5/5V

    'PX5_ADC_Gain(0) = (30.1 + 20#) / 20#       ' PWR
    PX5_ADC_Gain(0) = (69.8 + 20#) / 20#        ' 9V (was originally PWR)
    PX5_ADC_Gain(1) = (13# + 20#) / 20#         ' 3.3V
    PX5_ADC_Gain(2) = (4.99 + 20#) / 20#        ' 2.5V
    PX5_ADC_Gain(3) = 1#                        ' 1.2V
    PX5_ADC_Gain(4) = (30.1 + 20#) / 20#        ' 5V
    PX5_ADC_Gain(5) = (10.7 + 75#) / 10.7       ' -5V (this one is tricky)
    PX5_ADC_Gain(6) = (64.9 + 20#) / 20#        ' +PA
    PX5_ADC_Gain(7) = (10.7 + 75#) / 10.7       ' -PA
    PX5_ADC_Gain(8) = (16# + 20#) / 20#         ' +TEC
    PX5_ADC_Gain(9) = 500#                      ' HV: 1500V/3V
    PX5_ADC_Gain(10) = 100#                     ' TEC: 300K/3V
    PX5_ADC_Gain(11) = 1# / 0.00286             ' 2.86mV/C

    dd.Firmware = PIN.DATA(0)
    dd.FPGA = PIN.DATA(1)
    strVal = FmtHex(PIN.DATA(2), 2) & FmtHex(PIN.DATA(3), 2) & FmtHex(PIN.DATA(4), 2)
    dd.SRAMTestData = CLng("&H" & strVal)
    dd.SRAMTestPass = CBool(dd.SRAMTestData = &HFFFFFF)
    dd.TempOffset = PIN.DATA(180) + 256 * (PIN.DATA(180) > 127)  ' 8-bit signed value
    If (STATUS.DEVICE_ID = dppDP5) Then
        For idxVal = 0 To 9
            dd.ADC_V(idxVal) = (((PIN.DATA(5 + idxVal * 2) And 3) * 256) + PIN.DATA(6 + idxVal * 2)) * 2.44 / 1024 * DP5_ADC_Gain(idxVal) ' convert counts to engineering units (C or V)
        Next
        dd.ADC_V(7) = dd.ADC_V(7) + dd.ADC_V(6) * (1 - DP5_ADC_Gain(7)) ' -5.5V is a function of +5.5V
        dd.strTempRaw = Format(dd.ADC_V(0) - 271.3, "###.0C")
        dd.strTempCal = Format(dd.ADC_V(0) - 280 + dd.TempOffset, "###.0C")
    ElseIf (STATUS.DEVICE_ID = dppPX5) Then
        For idxVal = 0 To 10
            dd.ADC_V(idxVal) = (((PIN.DATA(5 + idxVal * 2) And 15) * 256) + PIN.DATA(6 + idxVal * 2)) * 3 / 4096 * PX5_ADC_Gain(idxVal)   ' convert counts to engineering units (C or V)
        Next
        dd.ADC_V(11) = (((PIN.DATA(5 + 11 * 2) And 3) * 256) + PIN.DATA(6 + 11 * 2)) * 3 / 1024 * PX5_ADC_Gain(11)  ' convert counts to engineering units (C or V)
        dd.ADC_V(5) = dd.ADC_V(5) - (3 * PX5_ADC_Gain(5)) + 3 ' -5V uses +3VR
        dd.ADC_V(7) = dd.ADC_V(7) - (3 * PX5_ADC_Gain(7)) + 3 ' -PA uses +3VR
        dd.strTempRaw = Format(dd.ADC_V(11) - 271.3, "###.0C")
        dd.strTempCal = Format(dd.ADC_V(11) - 280 + dd.TempOffset, "###.0C")
    End If

    dd.PC5_PRESENT = False  ' assume no PC5, then check to see if there are any non-zero bytes
    For idxVal = 25 To 38
        If PIN.DATA(idxVal) > 0 Then
            dd.PC5_PRESENT = True
            Exit For
        End If
    Next

    If dd.PC5_PRESENT Then
        For idxVal = 0 To 2
            dd.PC5_V(idxVal) = (((PIN.DATA(25 + idxVal * 2) And 15) * 256) + PIN.DATA(26 + idxVal * 2)) * 3 / 4096 * PC5_ADC_Gain(idxVal) ' convert counts to engineering units (C or V)
        Next
        If PIN.DATA(34) < 128 Then
            dd.PC5_SerialNumber = CLng(PIN.DATA(31)) + CLng(PIN.DATA(32)) * 256 + CLng(PIN.DATA(33)) * (256 ^ 2) + CLng(PIN.DATA(34)) * (256 ^ 3)
        Else
            dd.PC5_SerialNumber = -1 ' no PC5 S/N
        End If
        If (PIN.DATA(35) = 255) And (PIN.DATA(36) = 255) Then
            dd.PC5Initialized = False
            dd.PC5DCAL = 0
        Else
            dd.PC5Initialized = True
            dd.PC5DCAL = CSng((CSng(PIN.DATA(35)) * 256 + CSng(PIN.DATA(36))) * 3 / 4096)
        End If
        dd.IsPosHV = CBool(PIN.DATA(37) And 128)
        dd.Is8_5VPreAmp = CBool(PIN.DATA(37) And 64)
        dd.Sup9VOn = CBool(PIN.DATA(38) And 8)
        dd.PreAmpON = CBool(PIN.DATA(38) And 4)
        dd.HVOn = CBool(PIN.DATA(38) And 2)
        dd.TECOn = CBool(PIN.DATA(38) And 1)
    Else
        For idxVal = 0 To 2
            dd.PC5_V(idxVal) = 0
        Next
        dd.PC5_SerialNumber = -1 ' no PC5 S/N
        dd.PC5Initialized = False
        dd.PC5DCAL = 0
        dd.IsPosHV = False
        dd.Is8_5VPreAmp = False
        dd.Sup9VOn = False
        dd.PreAmpON = False
        dd.HVOn = False
        dd.TECOn = False
    End If
    For idxVal = 0 To 191
        dd.DiagData(idxVal) = PIN.DATA(idxVal + 39)
    Next idxVal
End Sub

Public Function DiagnosticsToString(dd As DiagDataType) As String
    Dim idxVal As Long
    Dim strDiag As String

    strDiag = "Firmware: " & VersionToStr(dd.Firmware) & vbNewLine
    strDiag = strDiag & "FPGA: " & VersionToStr(dd.FPGA) & vbNewLine
    strDiag = strDiag & "SRAM Test: "
    If dd.SRAMTestPass Then
        strDiag = strDiag & "PASS" & vbNewLine
    Else
        strDiag = strDiag & "ERROR @ 0x" & FmtHex(dd.SRAMTestData, 6) & vbNewLine
    End If

    If (STATUS.DEVICE_ID = dppDP5) Then
        strDiag = strDiag & "DP5 Temp (raw): " & dd.strTempRaw & vbNewLine
        strDiag = strDiag & "DP5 Temp (cal'd): " & dd.strTempCal & vbNewLine
        strDiag = strDiag & "PWR: " & Format(dd.ADC_V(2), "#.##0V") & vbNewLine
        strDiag = strDiag & "3.3V: " & Format(dd.ADC_V(3), "#.##0V") & vbNewLine
        strDiag = strDiag & "2.5V: " & Format(dd.ADC_V(4), "#.##0V") & vbNewLine
        strDiag = strDiag & "1.2V: " & Format(dd.ADC_V(5), "#.##0V") & vbNewLine
        strDiag = strDiag & "+5.5V: " & Format(dd.ADC_V(6), "#.##0V") & vbNewLine
        strDiag = strDiag & "-5.5V: " & Format(dd.ADC_V(7), "#.##0V") & vbNewLine
        strDiag = strDiag & "AN_IN: " & Format(dd.ADC_V(8), "#.##0V") & vbNewLine
        strDiag = strDiag & "VREF_IN: " & Format(dd.ADC_V(9), "#.##0V") & vbNewLine

        strDiag = strDiag & vbNewLine
        If dd.PC5_PRESENT Then
            strDiag = strDiag & "PC5: Present" & vbNewLine
            strDiag = strDiag & "HV: " & Format(dd.PC5_V(0), "####V") & vbNewLine
            strDiag = strDiag & "Detector Temp: " & Format(dd.PC5_V(1), "###.#K") & vbNewLine
            strDiag = strDiag & "+8.5/5V: " & Format(dd.PC5_V(2), "#.##0V") & vbNewLine
            If (dd.PC5_SerialNumber > -1) Then
                strDiag = strDiag & "PC5 S/N:" + str(dd.PC5_SerialNumber) & vbNewLine
            Else
                strDiag = strDiag & "PC5 S/N: none" & vbNewLine
            End If
            If (dd.PC5Initialized) Then
                strDiag = strDiag & "PC5 DCAL: " & Format(dd.PC5DCAL, "#.##0V") & vbNewLine
            Else
                strDiag = strDiag & "PC5 DCAL: Uninitialized" & vbNewLine
            End If
            strDiag = strDiag & "PC5 Flavor: "
            strDiag = strDiag & IsAorB(dd.IsPosHV, "+HV, ", "-HV, "),
            strDiag = strDiag & IsAorB(dd.Is8_5VPreAmp, "8.5V preamp", "5V preamp") & vbNewLine
            strDiag = strDiag & "9V: " & OnOffStr(dd.Sup9VOn) & vbNewLine
            strDiag = strDiag & "Preamp: " & OnOffStr(dd.PreAmpON) & vbNewLine
            strDiag = strDiag & "HV: " & OnOffStr(dd.HVOn) & vbNewLine
            strDiag = strDiag & "TEC: " & OnOffStr(dd.TECOn) & vbNewLine
        Else
            strDiag = strDiag & "PC5: Not Present" & vbNewLine
        End If

    ElseIf (STATUS.DEVICE_ID = dppPX5) Then
        strDiag = strDiag & "PX5 Temp (raw): " & dd.strTempRaw & vbNewLine
        strDiag = strDiag & "PX5 Temp (cal'd): " & dd.strTempCal & vbNewLine
        'strDiag = strDiag & "PWR: " & Format(dd.ADC_V(0), "#.##0V") & vbNewLine
        strDiag = strDiag & "9V: " & Format(dd.ADC_V(0), "#.##0V") & vbNewLine
        strDiag = strDiag & "3.3V: " & Format(dd.ADC_V(1), "#.##0V") & vbNewLine
        strDiag = strDiag & "2.5V: " & Format(dd.ADC_V(2), "#.##0V") & vbNewLine
        strDiag = strDiag & "1.2V: " & Format(dd.ADC_V(3), "#.##0V") & vbNewLine
        strDiag = strDiag & "+5V: " & Format(dd.ADC_V(4), "#.##0V") & vbNewLine
        strDiag = strDiag & "-5V: " & Format(dd.ADC_V(5), "#.##0V") & vbNewLine
        strDiag = strDiag & "+PA: " & Format(dd.ADC_V(6), "#.##0V") & vbNewLine
        strDiag = strDiag & "-PA: " & Format(dd.ADC_V(7), "#.##0V") & vbNewLine
        strDiag = strDiag & "TEC: " & Format(dd.ADC_V(8), "#.##0V") & vbNewLine
        strDiag = strDiag & "ABS(HV): " & Format(dd.ADC_V(9), "###0.0V") & vbNewLine
        strDiag = strDiag & "DET_TEMP: " & Format(dd.ADC_V(10), "##0.0K") & vbNewLine
    End If

    strDiag = strDiag & vbNewLine & "Diagnostic Data" & vbNewLine
    strDiag = strDiag & "---------------" & vbNewLine
    For idxVal = 0 To 191
        If idxVal Mod 8 = 0 Then strDiag = strDiag & FmtHex(idxVal, 2) & ":"
        strDiag = strDiag & FmtHex(dd.DiagData(idxVal), 2) + " "
        If idxVal Mod 8 = 7 Then strDiag = strDiag & vbNewLine
    Next
    DiagnosticsToString = strDiag
End Function

Public Function FmtHex(ByVal DecNum As Long, ByVal HexDig As Long) As String
    Dim strHex As String
    Dim lHex As Long

    strHex = Hex(DecNum)
    lHex = Len(strHex)
    If (lHex < HexDig) Then
        FmtHex = String(HexDig - lHex, "0") + strHex
    Else
        FmtHex = strHex
    End If
End Function

Public Function VersionToStr(bVersion As Byte) As String
    VersionToStr = Trim(str((bVersion And &HF0) / 16)) + "." + Format((bVersion And &HF), "00")
End Function

Public Function OnOffStr(bOnOff As Boolean) As String
    If (bOnOff) Then
        OnOffStr = "ON"
    Else
        OnOffStr = "OFF"
    End If
End Function

Public Function IsAorB(bIsA As Boolean, strA As String, strB As String) As String
    If (bIsA) Then
        IsAorB = strA
    Else
        IsAorB = strB
    End If
End Function


modPlot Source Code

Option Explicit

'converts vb type 24bit rgb (BlueGreenRed) to QBColor
Public Function RgbToQbColor(PlotColor As Long)
    Dim PlotColorIndex As Integer   'QBColors 0-15
    Select Case PlotColor
        Case &H0&: PlotColorIndex = 0   'Black
        Case &H800000: PlotColorIndex = 1    'Blue
        Case &H8000&: PlotColorIndex = 2    'Green
        Case &H808000: PlotColorIndex = 3    'Cyan
        Case &H80&: PlotColorIndex = 4    'Red
        Case &H800080: PlotColorIndex = 5    'Magenta
        Case &H8080&: PlotColorIndex = 6    'Brown
        Case &HC0C0C0: PlotColorIndex = 7    'White
        Case &H808080: PlotColorIndex = 8    'Grey
        Case &HFF0000: PlotColorIndex = 9    'Light Blue
        Case &HFF00&: PlotColorIndex = 10    'Light Green
        Case &HFFFF00: PlotColorIndex = 11    'Light Cyan
        Case &HFF&: PlotColorIndex = 12    'Light Red
        Case &HFF00FF: PlotColorIndex = 13    'Light Magenta
        Case &HFFFF&: PlotColorIndex = 14    'Yellow
        Case &HFFFFFF: PlotColorIndex = 15    'Bright White
        Case Else
            PlotColorIndex = &H0   'unknown color
    End Select
    PlotColorIndex = PlotColorIndex + 1
    If (PlotColorIndex >= 16) Then PlotColorIndex = 0
    RgbToQbColor = QBColor(PlotColorIndex)
End Function

Public Sub Plot_Spectrum(picMCAPlot As VB.PictureBox, SPECTRUM As Spec, isLinear As Boolean, isLines As Boolean)
    Dim X As Integer
    Dim Y As Integer

    Dim MCAMax As Long
    Dim MCAPeak As Long
    Dim TString As String
    Dim Buffer(64)
    Dim MCSScale As Long
    Dim MCAScale As Long

    Dim PlotXMin As Long
    Dim PlotXMax As Long

    Dim LogScaleValue As Long

    MCAMax = 0
    MCAPeak = 0
    For X = 0 To SPECTRUM.Channels - 1
        If SPECTRUM.DATA(X) > MCAMax Then
            MCAMax = SPECTRUM.DATA(X)
            MCAPeak = X
        End If
    Next X
    If isLinear Then
        MCAScale = Fix(MCAMax + 10 + (10# * Log(MCAMax + 1)))
    Else
        LogScaleValue = Fix(Log(MCAMax + 1) / Log(10) + 1)
        MCAScale = 10 ^ LogScaleValue
    End If

    PlotXMin = 0
    PlotXMax = SPECTRUM.Channels - 1

    If isLinear Then
        picMCAPlot.Scale (PlotXMin, MCAScale)-(PlotXMax + 1, 0)
        picMCAPlot.Line (PlotXMin, 0)-(PlotXMax + 1, MCAScale), picMCAPlot.BackColor, BF
    Else
        picMCAPlot.Scale (PlotXMin, Log(MCAScale))-(PlotXMax + 1, 0)
        picMCAPlot.Line (PlotXMin, 0)-(PlotXMax + 1, Log(MCAScale)), picMCAPlot.BackColor, BF
    End If

    If isLinear Then
        picMCAPlot.Line (PlotXMin, 0)-(PlotXMax + 1, MCAScale), picMCAPlot.BackColor, BF
        For X = 1 To 9
            picMCAPlot.Line (PlotXMin, MCAScale * X / 10)-(PlotXMax + 1, MCAScale * X / 10), vbWhite
        Next X
    Else
        picMCAPlot.Line (PlotXMin, 0)-(PlotXMax + 1, Log(MCAScale)), picMCAPlot.BackColor, BF
        For Y = 1 To LogScaleValue
            For X = 1 To 9
                picMCAPlot.Line (PlotXMin, Log(MCAScale * X / (10 ^ Y)))-(PlotXMax + 1, Log(MCAScale * X / (10 ^ Y))), colorLightGray
            Next X
        Next Y
    End If

    If isLines Then
        For X = PlotXMin To PlotXMax - 1
            If isLinear Then
                picMCAPlot.Line (X, SPECTRUM.DATA(X))-(X + 1, SPECTRUM.DATA(X + 1)), PlotColor
            Else
                picMCAPlot.Line (X, Log(1# + SPECTRUM.DATA(X)))-(X + 1, Log(1# + SPECTRUM.DATA(X + 1))), PlotColor
            End If
        Next X
    Else
        For X = PlotXMin To PlotXMax
            If isLinear Then
                picMCAPlot.Line (X, 0)-(X + 0.5, SPECTRUM.DATA(X)), PlotColor, BF
            Else
                picMCAPlot.Line (X, 0)-(X + 0.5, Log(1# + SPECTRUM.DATA(X))), PlotColor, BF
            End If
        Next X
    End If
End Sub

Public Sub Plot_Scope(picScope As VB.PictureBox, Scope() As Byte, PlotColor As Long)
    Dim X As Integer
    picScope.Scale (0, 255)-(2047, 0)
    picScope.Line (0, 0)-(2047, 255), picScope.BackColor, BF
    For X = 0 To 2046
        picScope.Line (X, Scope(X))-(X + 1, Scope(X + 1)), PlotColor
    Next X
End Sub

Public Sub WriteTextFile(strFilename As String, strData As String, Optional OverWrite As Boolean = False)
    Dim intFile As Integer

    intFile = FreeFile
    If (OverWrite) Then
        Open strFilename For Output As #intFile
    Else
        Open strFilename For Append As #intFile
    End If
    Print #intFile, strData
    Close #intFile
End Sub


modProject Source Code

'Project: Amptek Visual Basic Demonstration Application for DPP Devices
'This example demonstrates communications to Amptek devices
' using the WinUSB, Sockets and Serial Ports.
'

'

Copyright 2012-2017 Amptek Inc.

'

' ***********************************************************************

' Software License Agreement

'

' Licensor grants any person obtaining a copy of this software ("You")
' a worldwide, royalty-free, non-exclusive license, for the duration of
' the copyright, free of charge, to store and execute the Software in a
' computer system and to incorporate the Software or any portion of it
' in computer programs You write.

'

' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
' THE SOFTWARE.

' ***********************************************************************

'

'

'

'Project:
'Purpose: Amptek Visual Basic DP5 Demonstration Project
Option Explicit


modSCA Source Code

Option Explicit

Public Const SCA_SECTION = "DP5 SCA Configuration"
Public Const CFG_SECTION = "DP5 Configuration File"

Public Type scaRegister
    Index As Variant
    Low As Variant
    High As Variant
    OutPut As Variant
End Type

Public Type scaSetup
    strIniFilename As String
    Channels As Variant
    HaveChannels As Boolean
    Index As Variant
    HaveIndex As Boolean
    PulseWidth As Variant
    sca(15) As scaRegister
End Type

Public sca As scaSetup

Public Function SplitData(strData As String, ByRef varValue As Variant, strDefault As Variant) As Boolean
    Dim lSep As Long
    Dim strChan As String
    lSep = InStr(strData, ";")
    If (lSep > 0) Then      'file has setting, separate comments from data, if any
        varValue = Trim(Left(strData, lSep - 1))
        SplitData = True
    Else
        varValue = strDefault
        SplitData = False
    End If
End Function

Public Function varValueToIndex(varData As Variant) As Long
    Dim strCase As String
    strCase = UCase(CStr(varData))
    Select Case strCase
        Case "OFF"
            varValueToIndex = 0
        Case "HI"
            varValueToIndex = 1
        Case "LOW"
            varValueToIndex = 2
        Case "256"
            varValueToIndex = 0
        Case "512"
            varValueToIndex = 1
        Case "1024"
            varValueToIndex = 2
        Case "2048"
            varValueToIndex = 3
        Case "4096"
            varValueToIndex = 4
        Case "8192"
            varValueToIndex = 5
        Case "100"
            varValueToIndex = 0
        Case "1000"
            varValueToIndex = 1
        Case "1"
            varValueToIndex = 0
        Case "2"
            varValueToIndex = 1
        Case "3"
            varValueToIndex = 2
        Case "4"
            varValueToIndex = 3
        Case "5"
            varValueToIndex = 4
        Case "6"
            varValueToIndex = 5
        Case "7"
            varValueToIndex = 6
        Case "8"
            varValueToIndex = 7
        Case "HIGH"
            varValueToIndex = 1
        Case "HIG"
            varValueToIndex = 1
        Case "LO"
            varValueToIndex = 2
        Case Else
            varValueToIndex = 0
    End Select
End Function

'these must be in the correct order, old sca settings will be deleted and new appended to end
Public Sub SaveSCASetupINI(sca As scaSetup)
    Dim strData As String
    Dim Index As Long

    If (Not sca.HaveChannels) Then
        strData = CStr(sca.Channels) & ";"
        SaveToIniEx sca.strIniFilename, CFG_SECTION, "MCAC", strData
    End If

    Index = Val(sca.Index)

    Call DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAI")
    Call DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAO")
    Call DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAL")
    Call DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAH")
    Call DeleteIniSettingEx(sca.strIniFilename, CFG_SECTION, "SCAW")

    strData = CStr(sca.PulseWidth) & ";"
    SaveToIniEx sca.strIniFilename, CFG_SECTION, "SCAW", strData
End Sub

Public Sub SaveSCASettingsINI(sca As scaSetup, Index As Long)
    Dim strIdx As String
    Dim strData As String
    strIdx = CStr(Index)

    strData = CStr(sca.sca(Index - 1).OutPut) & ";"
    SaveToIniEx sca.strIniFilename, SCA_SECTION, "SCAO" & strIdx, strData

    strData = CStr(sca.sca(Index - 1).Low) & ";"
    SaveToIniEx sca.strIniFilename, SCA_SECTION, "SCAL" & strIdx, strData

    strData = CStr(sca.sca(Index - 1).High) & ";"
    SaveToIniEx sca.strIniFilename, SCA_SECTION, "SCAH" & strIdx, strData
End Sub

Public Sub GetSCASetupINI(sca As scaSetup)
    Dim lSep As Long
    Dim strValue As String
    Dim strComment As String
    Dim strData As String
    Dim Index As Long

    strData = GetFromIniEx(sca.strIniFilename, CFG_SECTION, "MCAC", "1024")
    sca.HaveChannels = SplitData(strData, sca.Channels, "1024")

    strData = GetFromIniEx(sca.strIniFilename, CFG_SECTION, "SCAW", "100")
    Call SplitData(strData, sca.PulseWidth, "100")

    strData = GetFromIniEx(sca.strIniFilename, CFG_SECTION, "SCAI", "1")
    sca.HaveIndex = SplitData(strData, sca.Index, "1")

    If (sca.HaveIndex) Then     'update sca from latest config data
        Index = Val(sca.Index)

        strData = GetFromIniEx(sca.strIniFilename, CFG_SECTION, "SCAO", strData)
        Call SplitData(strData, sca.sca(Index - 1).OutPut, "OFF")

        strData = GetFromIniEx(sca.strIniFilename, CFG_SECTION, "SCAL", strData)
        Call SplitData(strData, sca.sca(Index - 1).Low, "1")

        strData = GetFromIniEx(sca.strIniFilename, CFG_SECTION, "SCAH", strData)
        Call SplitData(strData, sca.sca(Index - 1).High, "1024")
    End If
End Sub

Public Sub GetSCASettingsINI(sca As scaSetup, Index As Long)
    Dim lSep As Long
    Dim strValue As String
    Dim strComment As String
    Dim strIdx As String
    Dim strData As String

    strIdx = CStr(Index)

    sca.sca(Index - 1).Index = strIdx       'for future use

    'skip updating data that was updated from the configuration settings
    If (sca.HaveIndex And (Val(sca.Index) = Index)) Then Exit Sub

    strData = GetFromIniEx(sca.strIniFilename, SCA_SECTION, "SCAO" & strIdx, strData)
    Call SplitData(strData, sca.sca(Index - 1).OutPut, "OFF")

    strData = GetFromIniEx(sca.strIniFilename, SCA_SECTION, "SCAL" & strIdx, strData)
    Call SplitData(strData, sca.sca(Index - 1).Low, "1")

    strData = GetFromIniEx(sca.strIniFilename, SCA_SECTION, "SCAH" & strIdx, strData)
    Call SplitData(strData, sca.sca(Index - 1).High, "1024")
End Sub

'                                       1234567
'expecting data format strCMD=strData; (CMD1=?;)
Public Sub ReadSCASetting(ByRef sca As scaSetup, strSCAInfo As String)
    Dim strCmd As String
    Dim strData As String
    Dim lSep As Long
    Dim lTerm As Long

    lSep = InStr(strSCAInfo, "=")
    lTerm = InStr(strSCAInfo, ";")
    If (lSep <> 5) Then Exit Sub
    If (lTerm < 7) Then Exit Sub
    strCmd = UCase(Left(strSCAInfo, 4))
    strData = UCase(Mid(strSCAInfo, 6, lTerm - 6))
    Select Case strCmd
        Case "MCAC"
            sca.Channels = strData
        Case "SCAW"
            sca.PulseWidth = strData
        Case "SCAI"
            sca.Index = strData
            sca.HaveIndex = True
            sca.sca(Val(sca.Index) - 1).Index = strData
        Case "SCAL"
            If (Val(sca.Index) > 0) Then sca.sca(Val(sca.Index) - 1).Low = strData
        Case "SCAH"
            If (Val(sca.Index) > 0) Then sca.sca(Val(sca.Index) - 1).High = strData
        Case "SCAO"
            If (Val(sca.Index) > 0) Then sca.sca(Val(sca.Index) - 1).OutPut = strData
        Case Else
            'unknown data error
    End Select
End Sub

'reads dpp command string removes and returns byref next dpp config command
'functions returns true if command found, false otherwise
Public Function GetNextCMD(ByRef strCMDList As String, ByRef strCmd As String) As Boolean
    Dim strCMDs As String
    Dim strCMDOut As String
    Dim lNextCMD As Long

    GetNextCMD = False
    If (Len(strCMDList) < 7) Then Exit Function     '1234=6;8
    lNextCMD = InStr(strCMDList, ";")
    If (lNextCMD < 7) Then Exit Function            '1234=6;8
    strCmd = UCase(Left(strCMDList, lNextCMD))
    strCMDList = Mid(strCMDList, lNextCMD + 1)
    GetNextCMD = True
End Function

Public Sub SCACfgParser(ByRef sca As scaSetup, strSCASettings As String)
    Dim strCMDList As String
    Dim strCmd As String
    Dim idxCMDs As Long
    Dim CMDMax As Long
    Dim bHaveCMD As Boolean

    If (Len(strSCASettings) < 7) Then Exit Sub
    strCMDList = strSCASettings
    strCmd = ""
    CMDMax = CLng(Len(strSCASettings) \ 7) + 1     'loop the max number of times
    For idxCMDs = 0 To CMDMax
        bHaveCMD = GetNextCMD(strCMDList, strCmd)
        If (bHaveCMD) Then
            ReadSCASetting sca, strCmd
        Else
            Exit For
        End If
    Next
End Sub

Public Function SCAString(strCmd As String, strData As String, Optional bDppMsg As Boolean)
    Dim str As String
    str = UCase(strCmd)
    str = str & "="
    str = str & UCase(strData) & ";"
    If (Not bDppMsg) Then
        str = str & vbNewLine
    End If
    SCAString = str
End Function

'these must be in the correct order, old sca settings will be delected and new appended to end
Public Function SCASetupString(sca As scaSetup, Optional bDppMsg As Boolean = True)
    Dim strData As String
    Dim Index As Long
    Dim strSCAsus As String
    Dim str As String

    strSCAsus = ""
    If (Not sca.HaveChannels) Then
        str = SCAString("MCAC", CStr(sca.Channels), bDppMsg)
        strSCAsus = strSCAsus & str
    End If

    strData = CStr(sca.PulseWidth)
    str = SCAString("SCAW", strData, bDppMsg)
    strSCAsus = strSCAsus & str

    SCASetupString = strSCAsus
End Function

Public Function SCASettingsString(sca As scaSetup, Index As Long, Optional bDppMsg As Boolean = True)
    Dim strIdx As String
    Dim strData As String
    Dim strSCAsets As String
    Dim str As String

    strIdx = CStr(Index)

    strData = CStr(sca.sca(Index - 1).Index)
    str = SCAString("SCAI", strData, bDppMsg)
    strSCAsets = strSCAsets & str

    strData = CStr(sca.sca(Index - 1).OutPut)
    str = SCAString("SCAO", strData, bDppMsg)
    strSCAsets = strSCAsets & str

    strData = CStr(sca.sca(Index - 1).Low)
    str = SCAString("SCAL", strData, bDppMsg)
    strSCAsets = strSCAsets & str

    strData = CStr(sca.sca(Index - 1).High)
    str = SCAString("SCAH", strData, bDppMsg)
    strSCAsets = strSCAsets & str

    SCASettingsString = strSCAsets
End Function

Public Function SCAStringALL(sca As scaSetup, Optional bDppMsg As Boolean = True)
    Dim idxSCA As Long
    Dim strSCA As String

    strSCA = SCASetupString(sca, bDppMsg)
    For idxSCA = 1 To 8
        strSCA = strSCA & SCASettingsString(sca, idxSCA, bDppMsg)
    Next
    SCAStringALL = strSCA
End Function

Public Function SCAStringALLDisplay(sca As scaSetup)
    Dim idxSCA As Long
    Dim strSCA As String
    Dim bDppMsg As Boolean

    bDppMsg = True
    strSCA = SCASetupString(sca, bDppMsg)
    For idxSCA = 1 To 8
        strSCA = strSCA & vbNewLine
        strSCA = strSCA & SCASettingsString(sca, idxSCA, bDppMsg)
    Next
    SCAStringALLDisplay = strSCA
End Function

Public Sub InitSCA()
    Dim idxSCA As Long
    sca.strIniFilename = ""
    sca.HaveChannels = False
    sca.Channels = "1024"
    sca.Index = 1
    sca.PulseWidth = "100"
    For idxSCA = 0 To 15
        sca.sca(idxSCA).Low = 1
        sca.sca(idxSCA).High = sca.Channels
        If (idxSCA < 8) Then
            sca.sca(idxSCA).OutPut = "OFF"
        End If
    Next
End Sub


modSendCommand Source Code

Option Explicit

Public Const DP4_PX4_OLD_CFG_SIZE = 64
Public Whitespace As String

Public Function DP5_CMD(ByRef Buffer() As Byte, XmtCmd As TRANSMIT_PACKET_TYPE) As Boolean
    Dim bCmdFound As Boolean
    Dim iFileNum As Integer
    Dim D As String
    Dim bt As Byte
    Dim idxData As Integer
    Dim idxMiscData As Integer
    Dim POUT As Packet_Out
    Dim lLen As Long
    Dim cstrCfg As String
    Dim strTemp As String

    bCmdFound = True
    POUT.LEN = 0

    Select Case XmtCmd
        ''REQUEST_PACKETS_TO_DP5
        Case XMTPT_SEND_STATUS
            POUT.PID1 = PID1_REQ_STATUS
            POUT.PID2 = PID2_SEND_DP4_STYLE_STATUS
        'Case XMTPT_SEND_SPECTRUM
        'Case XMTPT_SEND_CLEAR_SPECTRUM
        Case XMTPT_SEND_SPECTRUM_STATUS
            POUT.PID1 = PID1_REQ_SPECTRUM
            POUT.PID2 = PID2_SEND_SPECTRUM_STATUS   ' send spectrum & status
        Case XMTPT_SEND_CLEAR_SPECTRUM_STATUS
            POUT.PID1 = PID1_REQ_SPECTRUM
            POUT.PID2 = PID2_SEND_CLEAR_SPECTRUM_STATUS   ' send & clear spectrum & status
        'Case XMTPT_BUFFER_SPECTRUM
        'Case XMTPT_BUFFER_CLEAR_SPECTRUM
        'Case XMTPT_SEND_BUFFER
        'Case XMTPT_SEND_DP4_STYLE_STATUS
        'Case XMTPT_SEND_CONFIG
        Case XMTPT_SEND_SCOPE_DATA
            POUT.PID1 = PID1_REQ_SCOPE_MISC
            POUT.PID2 = PID2_SEND_SCOPE_DATA
        Case XMTPT_SEND_512_BYTE_MISC_DATA
            POUT.PID1 = PID1_REQ_SCOPE_MISC
            POUT.PID2 = PID2_SEND_512_BYTE_MISC_DATA ' request misc data
        'Case XMTPT_SEND_SCOPE_DATA_REARM
        'Case XMTPT_SEND_ETHERNET_SETTINGS
        Case XMTPT_SEND_DIAGNOSTIC_DATA
            POUT.PID1 = PID1_REQ_SCOPE_MISC
            POUT.PID2 = PID2_SEND_DIAGNOSTIC_DATA   ' Request Diagnostic Packet
            POUT.LEN = 0
        Case XMTPT_SEND_NETFINDER_PACKET
            POUT.PID1 = PID1_REQ_SCOPE_MISC
            POUT.PID2 = PID2_SEND_NETFINDER_READBACK   ' Request NetFinder Packet
            POUT.LEN = 0
        'Case XMTPT_SEND_HARDWARE_DESCRIPTION
        'Case XMTPT_SEND_SCA
        'Case XMTPT_LATCH_SEND_SCA
        'Case XMTPT_LATCH_CLEAR_SEND_SCA
        'Case XMTPT_SEND_ROI_OR_FIXED_BLOCK
        Case XMTPT_PX4_STYLE_CONFIG_PACKET
            iFileNum = FreeFile
            Open App.Path & "\RAW.CFG" For Input As #iFileNum
            For bt = 0 To 63
                Input #iFileNum, D$
                POUT.DATA(bt) = Val("&H" + D$)
            Next
            Close #iFileNum
            POUT.PID1 = PID1_REQ_CONFIG
            POUT.PID2 = PID2_PX4_STYLE_CONFIG_PACKET   ' PX4-style config packet
            POUT.LEN = DP4_PX4_OLD_CFG_SIZE

'''''        Case XMTPT_SEND_CONFIG_PACKET_TO_HW
'''''                Do
'''''                    Line Input #iFileNum, S$
'''''                    S$ = StrConv(S$, vbUpperCase)   ' convert line to upper case
'''''                    If (Left(S$, 1) >= "A") And (Left(S$, 1) <= "Z") And (InStr(S$, ";") > 0) Then ' for command, first character on line has to be uppercase alpha and ends with ';'
'''''                        S$ = Left(S$, InStr(S$, ";"))
'''''                        For X = 1 To Len(S$)
'''''                            If InStr(1, Whitespace$, Mid$(S$, X, 1)) = 0 Then
'''''                                D$ = D$ + Mid$(S$, X, 1)    ' add character to command string if not whitespace
'''''                            End If
'''''                        Next X
'''''                    End If
'''''                Loop While Not EOF(1)
'''''                For idxData = 1 To Len(D$)
'''''                    POUT.DATA(idxData - 1) = Asc(Mid(D$, idxData, 1))
'''''                Next idxData
'''''                Close #iFileNum
'''''                POUT.PID1 = PID1_REQ_CONFIG
'''''                POUT.PID2 = PID2_TEXT_CONFIG_PACKET   ' text config packet
'''''                POUT.LEN = Len(D$)
''''''            End If
        Case XMTPT_SEND_CONFIG_PACKET_TO_HW
            cstrCfg = ""
            cstrCfg = s.HwCfgDP5Out

            If (s.profile.SendCoarseFineGain) Then
                cstrCfg = RemoveCmd("GAIN", cstrCfg)
            Else
                cstrCfg = RemoveCmd("GAIA", cstrCfg)
                cstrCfg = RemoveCmd("GAIF", cstrCfg)
            End If

            cstrCfg = RemoveCmdByDeviceType(cstrCfg, STATUS.PC5_PRESENT, STATUS.DEVICE_ID, STATUS.isDP5_RevDxGains, STATUS.DPP_ECO)

            '''''==== remove whitespace ====================================================
            ''''lLen = Len(cstrCfg)
            ''''strTemp = cstrCfg
            ''''cstrCfg = ""
            ''''If (lLen > 0) Then
            ''''    For idxData = 1 To lLen
            ''''        If InStr(1, Whitespace, Mid(strTemp, idxData, 1)) = 0 Then
            ''''            cstrCfg = cstrCfg & Mid(strTemp, idxData, 1)  'append non-whitespace chars
            ''''        End If
            ''''    Next
            ''''End If
            '''''==== remove whitespace ====================================================

            lLen = Len(cstrCfg)
            If (lLen > 0) Then
                For idxData = 1 To lLen
                    POUT.DATA(idxData - 1) = Asc(Mid(cstrCfg, idxData, 1))
                Next
            End If
            POUT.PID1 = PID1_REQ_CONFIG
            POUT.PID2 = PID2_TEXT_CONFIG_PACKET  ' text config packet
            POUT.LEN = lLen
        Case XMTPT_SEND_CONFIG_PACKET_EX           ' bypass any filters
            cstrCfg = ""
            cstrCfg = s.HwCfgDP5Out
            lLen = Len(cstrCfg)
            If (lLen > 0) Then
                For idxData = 1 To lLen
                    POUT.DATA(idxData - 1) = Asc(Mid(cstrCfg, idxData, 1))
                Next
            End If
            POUT.PID1 = PID1_REQ_CONFIG
            POUT.PID2 = PID2_TEXT_CONFIG_PACKET  ' text config packet
            POUT.LEN = lLen
         Case XMTPT_READ_CONFIG_PACKET
            cstrCfg = ""
            cstrCfg = s.HwRdBkDP5Out
            lLen = Len(cstrCfg)
            If (lLen > 0) Then
                For idxData = 1 To lLen
                    POUT.DATA(idxData - 1) = Asc(Mid(cstrCfg, idxData, 1))
                Next
            End If
            POUT.PID1 = PID1_REQ_CONFIG
            POUT.PID2 = PID2_CONFIG_READBACK_PACKET   ' read config packet
            POUT.LEN = lLen
         Case XMTPT_FULL_READ_CONFIG_PACKET
            cstrCfg = ""
            cstrCfg = CreateFullReadBackCmd()

            lLen = Len(cstrCfg)
            If (lLen > 0) Then
                For idxData = 1 To lLen
                    POUT.DATA(idxData - 1) = Asc(Mid(cstrCfg, idxData, 1))
                Next
            End If
            POUT.PID1 = PID1_REQ_CONFIG
            POUT.PID2 = PID2_CONFIG_READBACK_PACKET   ' read config packet
            POUT.LEN = lLen
        Case XMTPT_ERASE_FPGA_IMAGE
            POUT.PID1 = PID1_REQ_FPGA_UC
            POUT.PID2 = PID2_ERASE_FPGA_IMAGE
            POUT.LEN = 2
            POUT.DATA(0) = &H12
            POUT.DATA(1) = &H34
        'Case XMTPT_UPLOAD_PACKET_FPGA
        'Case XMTPT_REINITIALIZE_FPGA
        'Case XMTPT_ERASE_UC_IMAGE_0
        Case XMTPT_ERASE_UC_IMAGE_1
            POUT.PID1 = PID1_REQ_FPGA_UC
            POUT.PID2 = PID2_ERASE_UC_IMAGE_1   ' erase image #1 (sector 5)
            POUT.LEN = 2
            POUT.DATA(0) = &H12
            POUT.DATA(1) = &H34

        'Case XMTPT_ERASE_UC_IMAGE_2
        'Case XMTPT_UPLOAD_PACKET_UC
        'Case XMTPT_SWITCH_TO_UC_IMAGE_0
        Case XMTPT_SWITCH_TO_UC_IMAGE_1
            POUT.PID1 = PID1_REQ_FPGA_UC
            POUT.PID2 = PID2_SWITCH_TO_UC_IMAGE_1   ' switch to uC image #1
            POUT.LEN = 2
            POUT.DATA(0) = &HA5 ' uC FLASH unlock keys
            POUT.DATA(1) = &HF1
        'Case XMTPT_SWITCH_TO_UC_IMAGE_2
        'Case XMTPT_UC_FPGA_CHECKSUMS

        ''VENDOR_REQUESTS_TO_DP5
        'Case XMTPT_CLEAR_SPECTRUM_BUFFER
        Case XMTPT_ENABLE_MCA_MCS
            POUT.PID1 = PID1_VENDOR_REQ
            POUT.PID2 = PID2_ENABLE_MCA_MCS
            POUT.LEN = 0
        Case XMTPT_DISABLE_MCA_MCS
            POUT.PID1 = PID1_VENDOR_REQ
            POUT.PID2 = PID2_DISABLE_MCA_MCS
            POUT.LEN = 0
        Case XMTPT_ARM_DIGITAL_OSCILLOSCOPE
            POUT.PID1 = PID1_VENDOR_REQ
            POUT.PID2 = PID2_ARM_DIGITAL_OSCILLOSCOPE   ' arm trigger
        'Case XMTPT_AUTOSET_INPUT_OFFSET
        'Case XMTPT_AUTOSET_FAST_THRESHOLD
        'Case XMTPT_READ_IO3_0
        'Case XMTPT_WRITE_IO3_0
        'Case XMTPT_SET_DCAL
        'Case XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL
        'Case XMTPT_SET_PZ_CORRECTION_UC_TEMP_CAL
        'Case XMTPT_SET_BOOT_FLAGS
        'Case XMTPT_SET_HV_DP4_EMULATION
        'Case XMTPT_SET_TEC_DP4_EMULATION
        'Case XMTPT_SET_INPUT_OFFSET_DP4_EMULATION
        'Case XMTPT_SET_ADC_CAL_GAIN_OFFSET
        'Case XMTPT_SET_SPECTRUM_OFFSET
        'Case XMTPT_REQ_SCOPE_DATA_MISC_DATA_SCA_PACKETS
        'Case XMTPT_SET_SERIAL_NUMBER
        'Case XMTPT_CLEAR_GP_COUNTER
        'Case XMTPT_SWITCH_SUPPLIES
        'Case XMTPT_SEND_TEST_PACKET

        Case Else
            bCmdFound = False
    End Select

    If bCmdFound Then
        If (Not POUT_Buffer(POUT, Buffer())) Then
            bCmdFound = False
        End If
    End If
    DP5_CMD = bCmdFound
End Function

Public Function DP5_CMD_Data(ByRef Buffer() As Byte, XmtCmd As TRANSMIT_PACKET_TYPE, DataOut As Variant) As Boolean
    Dim bCmdFound As Boolean
    Dim idxData As Integer
    Dim idxMiscData As Integer
    Dim POUT As Packet_Out
    Dim PktLen As Integer

    bCmdFound = False
    POUT.LEN = 0
    Select Case XmtCmd
        Case XMTPT_WRITE_512_BYTE_MISC_DATA
            POUT.PID1 = PID1_VENDOR_REQ
            POUT.PID2 = PID2_WRITE_512_BYTE_MISC_DATA ' write misc data
            POUT.LEN = 512
            For idxMiscData = 0 To 511
                POUT.DATA(idxMiscData) = Asc(Mid(DataOut + String(512, 0), idxMiscData + 1, 1))
            Next idxMiscData
            bCmdFound = True
            If (Not POUT_Buffer(POUT, Buffer())) Then
                bCmdFound = False
            End If
        Case XMTPT_SEND_TEST_PACKET
            If (Not IsMissing(DataOut)) Then
                PktLen = Len(DataOut)
                If (PktLen >= 8) Then
                    For idxData = 0 To PktLen - 1
                        Buffer(idxData) = CLng(DataOut(idxData))
                    Next
                    bCmdFound = True
                End If
            End If
        Case Else
            bCmdFound = False
    End Select
    DP5_CMD_Data = bCmdFound
End Function

Public Function POUT_Buffer(POUT As Packet_Out, ByRef Buffer() As Byte) As Boolean
    Dim idxBuffer As Integer
    Dim CS As Long
    On Error GoTo POUT_BufferErr

    If (UBound(Buffer) < POUT.LEN + 7) Then ReDim Buffer(POUT.LEN + 7)
    Buffer(0) = SYNC1_
    Buffer(1) = SYNC2_
    Buffer(2) = POUT.PID1
    Buffer(3) = POUT.PID2
    Buffer(4) = (POUT.LEN And &HFF00) \ 256
    Buffer(5) = POUT.LEN And &HFF

    CS = SYNC1_ + SYNC2_ + POUT.PID1 + POUT.PID2 + (POUT.LEN And &HFF00) \ 256 + (POUT.LEN And &HFF)

    If POUT.LEN > 0 Then
        For idxBuffer = 0 To POUT.LEN - 1
            Buffer(idxBuffer + 6) = POUT.DATA(idxBuffer)
            CS = CS + POUT.DATA(idxBuffer)
        Next idxBuffer
    End If
    CS = (CS Xor &HFFFF&) + 1
    Buffer(POUT.LEN + 6) = (CS And &HFF00) \ 256
    Buffer(POUT.LEN + 7) = CS And &HFF
    POUT_Buffer = True
    Exit Function
POUT_BufferErr:
    POUT_Buffer = False
End Function


modShaping Source Code

Option Explicit
'=========================================================
'==== Shaping ============================================
'=========================================================

Public Const MAXPEAKINGTIMES = 26
Public Const MAXPEAKINGTIMES_20MHZ = MAXPEAKINGTIMES - 2
Public Const MAXPEAKINGTIMES_80MHZ = MAXPEAKINGTIMES
Public b80MHzModeCfg As Boolean
Public b80MHzModeCfg_old As Boolean

' 0. read config values (from file or hw)
' 1. default is 20MHz FPGA Clock (CLCK=fpga clock),(fpga clock MODE=b80MHzModeCfg)
' 2. FPGA Clock is read BEFORE peaking time is set (TPEA=peaking time)
' 3. if no CLCK found or is AUTO then default fpga clock MODE is 20MHz (b80MHzModeCfg=false)
' 4. if the CLCK is set to 80 then fpga clock MODE is 80MHz (b80MHzModeCfg=true)
' 5. b80MHzModeCfg MUST be determined BEFORE peaking/flattop combobox values are generated
' 6. for CLCK=AUTO and TPEA>=5Us then b80MHzModeCfg=false(20mhz)
' 7. for CLCK=AUTO and TPEA<5Us then b80MHzModeCfg=true(80mhz)
' 8. if CLCK=20 or CLCK=80 then b80MHzModeCfg=false(20mhz) or b80MHzModeCfg=true(80mhz)
' 9. set peaking time combo using b80MHzModeCfg
'10. search for closest peaking value index, update (hidden text value)
'11. calculate flattop combo values using
'12. search for closet flattop, update (hidden text value)

'the fpga clock speed determines the multiplier for calulating the combobox peaking times
'the fpga clock speed can (and should) be read from the hardware if connected
'GetFPGAClockMode is needed when no dpp device is attached and a configuration is being generated
Public Function GetFPGAClockMode(strCLCK As String, strTPEA As String) As Boolean
    Dim is80MHz As Boolean
    Dim dblPeaking As Double
    Dim dblCLCK As Double
    Dim isAuto As Boolean
    Dim inRange As Boolean

    isAuto = CBool("AUTO" = strCLCK)            'true=the clock is not known
    dblPeaking = CDbl(Val(strTPEA))
    dblCLCK = CDbl(Val(strCLCK))
    is80MHz = False                             'default=20MHz FPGA Clock mode
    If (isAuto) Then                            'use TPEA to determine fpga clock
        If (dblPeaking < 5#) Then               'dblPeaking is uS, TPEA<5Us=fpga 80MHz mode
            is80MHz = True    'fpga clock MODE=80MHz
        End If
    Else
        If (dblCLCK = 80) Then                  'clock setting
            is80MHz = True    'fpga clock MODE=
        End If
    End If
''''    'the clock should be set, test the clock to verify it matches TPEA
''''    inRange = False
''''    If (isAuto) Then                        'if auto, the clock was already set by TPEA
''''        inRange = True
''''    Else
''''        If (is80MHz) Then                       'TPEA 80MHz Range (0.050-25.600)
''''            If (dblPeaking >= 0.05) And (dblPeaking <= 25.6) Then
''''                inRange = True
''''            End If
''''        Else                                    'TPEA 20MHz Range (0.800-102.400)
''''            If (dblPeaking >= 0.8) And (dblPeaking <= 102.4) Then
''''                inRange = True
''''            End If
''''        End If
''''    End If
    GetFPGAClockMode = is80MHz
End Function

' 9. set peaking time combo using b80MHzModeCfg
'10. search for closest peaking value index, update (hidden text value)
'11. calculate flattop combo values using
'12. search for closet flattop, update (hidden text value)

'Private Sub cmdFlattopSearch_Click()
'    txtFlattopFound = "0.000"
'    SetShapingIndex cboFlatTop, txtFlattopSearch
'    If (cboFlatTop.ListIndex <> LB_ERR) Then
'        txtFlattopFound = cboFlatTop.List(cboFlatTop.ListIndex)
'    End If
'End Sub
'
'Private Sub cmdPeakingSearch_Click()
'    txtPeakingFound = "0.000"
'    SetShapingIndex cboRise, txtPeakingSearch
'    If (cboRise.ListIndex <> LB_ERR) Then
'        txtPeakingFound = cboRise.List(cboRise.ListIndex)
'    End If
'End Sub

Public Sub cboRiseUpdate(cboRise As ComboBox, cboFlatTop As ComboBox, is80MHz As Boolean)
    Dim Decimation As Integer
    Dim idxFlattop As Integer
    Dim idx As Integer
    Dim strVal As String

    If (cboRise.ListCount > 0) Then
        Decimation = SetRiseAndAvg(cboRise.ListIndex, is80MHz)
    End If
    'idxFlattop = cboFlatTop.ListIndex
    If (idxFlattop < 0) Then idxFlattop = 0
    GetFlattopValues cboFlatTop, Decimation, idxFlattop, is80MHz
    strVal = ""
    If (cboFlatTop.ListCount > 0) Then
        For idx = 0 To (cboFlatTop.ListCount - 1)
            strVal = strVal & cboFlatTop.List(idx) & vbNewLine
        Next
        'txtFlattop = strVal
    End If
End Sub

Public Sub LoadPeakingValues(cboRise As ComboBox, cboFlatTop As ComboBox, is80MHz As Boolean)
    Dim Decimation As Integer
    Dim idx As Integer
    Dim strVal As String

    SetComboRiseValues cboRise, is80MHz
    strVal = ""
    If (cboRise.ListCount > 0) Then
        For idx = 0 To (cboRise.ListCount - 1)
            strVal = strVal & cboRise.List(idx) & vbNewLine
        Next
        'txtRise = strVal
        cboRise.ListIndex = 0
    End If
    Decimation = SetRiseAndAvg(cboRise.ListIndex, is80MHz)
    GetFlattopValues cboFlatTop, Decimation, 0, is80MHz
    strVal = ""
    If (cboFlatTop.ListCount > 0) Then
        For idx = 0 To (cboFlatTop.ListCount - 1)
            strVal = strVal & cboFlatTop.List(idx) & vbNewLine
        Next
        'txtFlattop = strVal
        cboRise.ListIndex = 0
    End If
End Sub

Public Sub SetShapingIndex(cboShaping As ComboBox, strShapingIn As String)
    Dim ListIndex As Long
    Dim strShaping As String
    Dim idxShaping As Long
    Dim dblShapingIn As Double
    Dim dblShapingMin As Double
    Dim dblShapingMax As Double

    If (cboShaping.ListCount < 2) Then Exit Sub             'Shaping value error
    ListIndex = LB_ERR
    dblShapingIn = CDbl(Val(strShapingIn))                      'test min
    strShaping = Format(dblShapingIn, "0.000")                 'format like cbo values
    ListIndex = FindCboIdxExact(cboShaping, strShaping)     'search for exact value
    If (ListIndex = LB_ERR) Then
        ListIndex = FindCboIdx(cboShaping, strShaping)      'search for similar value
    End If
    If (ListIndex = LB_ERR) Then        'find closet value by comparison
        dblShapingMin = CDbl(Val(cboShaping.List(0)))                           'Shaping min
        dblShapingMax = CDbl(Val(cboShaping.List(cboShaping.ListCount - 1)))    'Shaping max
        If (dblShapingIn <= dblShapingMin) Then        'test min
            ListIndex = 0
        ElseIf (dblShapingIn >= dblShapingMax) Then    'test max
            ListIndex = cboShaping.ListCount - 1
        Else                                    'test in range
            For idxShaping = 0 To cboShaping.ListCount - 2
                dblShapingMin = CDbl(Val(cboShaping.List(idxShaping)))         'Shaping range min
                dblShapingMax = CDbl(Val(cboShaping.List(idxShaping + 1)))     'Shaping range max
                If ((dblShapingIn >= dblShapingMin) And (dblShapingIn <= dblShapingMax)) Then
                    ListIndex = idxShaping
                    Exit For
                End If
            Next
        End If
    End If
    If ((ListIndex > LB_ERR) And (ListIndex < cboShaping.ListCount)) Then
        cboShaping.ListIndex = ListIndex
    End If
End Sub

Public Sub GetFlattopValues(cboFlatTop As ComboBox, DecimationIn As Integer, FlatTop As Integer, is80MHz As Boolean)
    Dim idxFlattop As Integer
    Dim dblPeakingMult As Double
    Dim Decimation As Integer

    If (is80MHz) Then
        dblPeakingMult = 0.25
    Else
        dblPeakingMult = 1#
    End If

    Decimation = DecimationIn - 1 ' adjust to use px4 algorithm
    cboFlatTop.Clear
    For idxFlattop = 1 To 8
        cboFlatTop.AddItem Trim(Format(CDbl(idxFlattop) * 0.05 * (2# ^ Decimation) * dblPeakingMult, "0.000") + "uS")
    Next
    For idxFlattop = 9 To 62
        If ((idxFlattop Mod 4) = 0) Then
            cboFlatTop.AddItem Trim(Format(CDbl(idxFlattop) * 0.05 * (2# ^ Decimation) * dblPeakingMult, "0.000") + "uS")
        End If
    Next
    cboFlatTop.AddItem Trim(Format(CDbl(63#) * 0.05 * (2# ^ Decimation) * dblPeakingMult, "0.000") + "uS")
    cboFlatTop.ListIndex = FlatTop
End Sub

Public Sub SetComboRiseValues(cboRise As ComboBox, is80MHz As Boolean)
    Dim idxRise As Integer
    Dim Decimation As Integer
    Dim dblPeakingMult As Double

    cboRise.Clear
    If (is80MHz) Then
        dblPeakingMult = 0.25
        cboRise.AddItem Format((CDbl(1) * 0.2 * dblPeakingMult), "0.000") + "uS"
        cboRise.AddItem Format((CDbl(2) * 0.2 * dblPeakingMult), "0.000") + "uS"
    Else
        dblPeakingMult = 1#
    End If

    For idxRise = 1 To 8
        cboRise.AddItem Format((CDbl(idxRise) * 0.8 * dblPeakingMult), "0.000") + "uS"
    Next
    For Decimation = 1 To 4
        For idxRise = 5 To 8
            cboRise.AddItem Format((CDbl(idxRise) * 0.8 * (2# ^ Decimation) * dblPeakingMult), "0.000") + "uS"
        Next
    Next
End Sub

Public Function CheckRangeCDbl(TestVal As Single, MinVal As Single, MaxVal As Single)
    CheckRangeCDbl = CBool((TestVal >= MinVal) And (TestVal <= MaxVal))
End Function

Private Function GetRiseTextValue(RiseIndex As Long, is80MHz As Boolean, isRiseAveCalc As Boolean) As String
    Dim idxRiseText As Long
    Dim idxAve As Long
    Dim idxX As Long
    Dim RiseTextArray(MAXPEAKINGTIMES - 1) As String
    Dim strMsg As String
    Dim dblPeakingMult As Double

    If (isRiseAveCalc) Then
        dblPeakingMult = 1#     'always use 20mhz values for riseave calcs
    ElseIf (is80MHz) Then
        dblPeakingMult = 0.25
    Else
        dblPeakingMult = 1#
    End If

    strMsg = ""
    If ((RiseIndex < 0) Or (RiseIndex >= MAXPEAKINGTIMES)) Then Exit Function
    idxRiseText = -1
    If (is80MHz) Then
        For idxX = 1 To 2
            idxRiseText = idxRiseText + 1
            If (isRiseAveCalc) Then     'create valid 20mhz values for 80mhz rise ave
                RiseTextArray(idxRiseText) = CStr(CDbl(1) * 0.8 * dblPeakingMult) + "uS"
            Else                        'create real 80mhz values
                RiseTextArray(idxRiseText) = CStr(CDbl(idxX) * 0.2 * dblPeakingMult) + "uS"
            End If
            strMsg = strMsg & RiseTextArray(idxRiseText) & vbNewLine
        Next idxX
    End If
    For idxX = 1 To 8
        idxRiseText = idxRiseText + 1
        RiseTextArray(idxRiseText) = CStr(CDbl(idxX) * 0.8 * dblPeakingMult) + "uS"
        strMsg = strMsg & RiseTextArray(idxRiseText) & vbNewLine
    Next idxX
    For idxAve = 1 To 4
        strMsg = ""
        For idxX = 5 To 8
            idxRiseText = idxRiseText + 1
            RiseTextArray(idxRiseText) = CStr(CDbl(idxX) * 0.8 * (2# ^ idxAve) * dblPeakingMult) + "uS"
            strMsg = strMsg & RiseTextArray(idxRiseText) & vbNewLine
        Next idxX
    Next idxAve
    If (Not is80MHz) Then       'fill array with valid values
        For idxX = 1 To 2
            idxRiseText = idxRiseText + 1
            RiseTextArray(idxRiseText) = CStr(CDbl(8) * 0.8 * (2# ^ 4) * dblPeakingMult) + "uS"
            strMsg = strMsg & RiseTextArray(idxRiseText) & vbNewLine
        Next
    End If
    GetRiseTextValue = RiseTextArray(RiseIndex)
End Function

'Sets Rise and Avg global values from stored combobox index
'FlatTop = FlatTop combobox control index value
Public Function SetRiseAndAvg(RiseIndex As Long, is80MHz As Boolean) As Integer
    Dim strRiseText As String
    Dim SngRiseVal As Single
    Dim Rise As Integer
    Dim Avg As Integer

    If ((RiseIndex < 0) Or (RiseIndex >= MAXPEAKINGTIMES)) Then Exit Function
    strRiseText = GetRiseTextValue(RiseIndex, is80MHz, True)    'uses value 20mhz only
    SngRiseVal = CDbl(Val(strRiseText))
    If CheckRangeCDbl(SngRiseVal, 0, 6.4) Then
        Rise = SngRiseVal / 0.8
        Avg = 1
    ElseIf CheckRangeCDbl(SngRiseVal, 8, 12.8) Then
        Rise = SngRiseVal / 1.6
        Avg = 2
    ElseIf CheckRangeCDbl(SngRiseVal, 16, 25.6) Then
        Rise = SngRiseVal / 3.2
        Avg = 3
    ElseIf CheckRangeCDbl(SngRiseVal, 32, 51.2) Then
        Rise = SngRiseVal / 6.4
        Avg = 4
    ElseIf CheckRangeCDbl(SngRiseVal, 64, 102.4) Then
        Rise = SngRiseVal / 12.8
        Avg = 5
    End If
    SetRiseAndAvg = Avg
End Function

'=========================================================
'==== Shaping ============================================
'=========================================================


modSpectrumFile Source Code

Option Explicit

Public Function ShowStatusValueStrings(m_DP5_Status As Stat) As String
    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: " & CStr(m_DP5_Status.SerialNumber) & 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: " & CStr(CDbl(m_DP5_Status.FastCount)) & vbNewLine     'FastCount
    strConfig = strConfig & strTemp
    strTemp = "Slow Count: " & CStr(CDbl(m_DP5_Status.SlowCount)) & vbNewLine      'FastCount
    strConfig = strConfig & strTemp
    strTemp = "Accumulation Time: " & CStr(m_DP5_Status.AccumulationTime) '& vbNewLine       'AccumulationTime
    strConfig = strConfig & strTemp
    ShowStatusValueStrings = strConfig
End Function

Public Function ProcessSpectrumCfgForFile(strCfgIn As String, Dp5CmdList As Collection) As String
    Dim cstrRawCfgIn As String
    Dim cstrCmdD As String
    Dim cstrDisplayCfgOut As String
    Dim idxCfg As Long
    Dim varCmd As Variant
    Dim strSpectrumCfg As String
    ProcessSpectrumCfgForFile = ""
    cstrRawCfgIn = ""
    For idxCfg = 1 To Len(strCfgIn)
        cstrRawCfgIn = cstrRawCfgIn + Mid(strCfgIn, idxCfg, 1)
        If (Mid(strCfgIn, idxCfg, 1) = ";") Then
            cstrRawCfgIn = cstrRawCfgIn + vbNewLine
        End If
    Next
    cstrDisplayCfgOut = cstrRawCfgIn
    For Each varCmd In Dp5CmdList
        cstrCmdD = CStr(varCmd)
        If (Len(cstrCmdD) > 0) Then
            cstrDisplayCfgOut = AppendCmdDesc(cstrCmdD, cstrDisplayCfgOut)
        End If
    Next
    strSpectrumCfg = cstrDisplayCfgOut
    'remove a vbnewline to display correctly
    If (Right(strSpectrumCfg, 2) = vbNewLine) Then
        strSpectrumCfg = Left(strSpectrumCfg, Len(strSpectrumCfg) - 2)
    End If
    ProcessSpectrumCfgForFile = strSpectrumCfg
End Function

Public Function GetSpectrumFilename(ByRef strFilename As String, cmnDlg As CommonDialog) As Boolean
    GetSpectrumFilename = False
    If (dlgSave(cmnDlg, dlgMCA_Filter)) Then
        strFilename = cmnDlg.filename
        GetSpectrumFilename = True
    End If
End Function

Public Sub SaveSpectrum(strFilename As String, SPECTRUM As Spec, strCfg As String, STATUS As Stat, strTag As String, strDescription As String, dateStart As Date)
    Dim idxData As Long
    Dim iFile As Integer
    Dim strDate As String
    Dim strStatus As String

    iFile = FreeFile
    Open strFilename For Output As #iFile
    If (Len(strTag) = 0) Then strTag = "live_data"
    Print #iFile, "<<PMCA SPECTRUM>>"
    Print #iFile, "TAG - " & strTag
    Print #iFile, "DESCRIPTION - " & strDescription
    Print #iFile, "<gen>"
    Print #iFile, "<sys>"
    Print #iFile, "<not>"

    Select Case SPECTRUM.Channels
        Case 256
            Print #iFile, "GAIN - 0"
        Case 512
            Print #iFile, "GAIN - 1"
        Case 1024
            Print #iFile, "GAIN - 2"
        Case 2048
            Print #iFile, "GAIN - 3"
        Case 4096
            Print #iFile, "GAIN - 4"
        Case 8192
            Print #iFile, "GAIN - 5"
        Case Else
            Print #iFile, "GAIN - 2"
    End Select

    'Print #iFile, "THRESHOLD - 0"
    Print #iFile, "LIVE_MODE - 0"
    Print #iFile, "PRESET_TIME - 0"
    Print #iFile, "LIVE_TIME - 0"

    Print #iFile, "REAL_TIME -"; STATUS.AccumulationTime
    'Print #iFile, "START_TIME - "; Date & " " & Time       'MM/DD/YYYY HH:MM:SS
    strDate = Format(dateStart, "MM/DD/YYYY HH:MM:SS")
    Print #iFile, "START_TIME - "; Date & " " & Time        'MM/DD/YYYY HH:MM:SS
    Print #iFile, "SERIAL_NUMBER -"; STATUS.SerialNumber

    Print #iFile, "<<DATA>>"
    For idxData = 0 To SPECTRUM.Channels - 1
        Print #iFile, SPECTRUM.DATA(idxData)
    Next idxData
    Print #iFile, "<<END>>"

    Print #iFile, "<<DP5 CONFIGURATION>>"
    Print #iFile, strCfg
    Print #iFile, "<<DP5 CONFIGURATION END>>"
    Print #iFile, "<<DPP STATUS>>"
    strStatus = ShowStatusValueStrings(STATUS)
    If (strStatus = "") Then
        Print #iFile, "Device Type: DP5"
        Print #iFile, "Serial Number: 0"
    Else
        Print #iFile, strStatus
    End If
    Print #iFile, "<<DPP STATUS END>>"
    Close #iFile
End Sub

Public Sub LogEvent(strEvent As String, Optional bOverWrite As Boolean = False)
    Dim FileNumber As Integer
    Dim strMsg As String
    strMsg = Now & "," & strEvent,
    FileNumber = FreeFile
    If (bOverWrite) Then
        Open "EventLog.txt" For Output As #FileNumber
    Else
        Open "EventLog.txt" For Append As #FileNumber
    End If
    Print #FileNumber, strMsg
    Close #FileNumber
End Sub


modWinUSB Source Code

'Purpose:

'   Windows DDK WinUSB API and Setup API Converted to Visual Basic 5/6

'       Note:   WinUSB Index represents CurrentControlSet device index

'               MultiUSB Index represents Index of stored WinUsbDevice for multiple DPP devices

Option Explicit

'#Const bEnableDeviceNotification = 0
#Const bEnableDeviceNotification = 1

'Purpose: MultiUSB Index to DPP Serial Number storage type.
Public Type MUSB_SN_TO_INDEX
    Index As Long   'WinUSB Device Information Array Index for Device
    SerNum As Long  'DPP Device Serial Number
End Type

Public MUSB_MAX_INDEX As Long           'max index is 4 for five devices 0-4
Public MUSB_LAST_INDEX As Long          'last index is read fron vbDP5_MultiUSB.ini file
Public MUSB_SN(4) As Long               'multiusb serial numbers read from file
Public MUSB_Idx(4) As MUSB_SN_TO_INDEX  'multiusb serial numbers read from file

Public CurrentUSBDevice As Long         'WinUSB
Public NumUSBDevices As Long

'Purpose: Enumerates the error levels returned by ProcessError.
Public Type Message
    hwnd As Long    'Handle of window.
    Msg As Long     'Message.
    wParam As Long  'First message parameter.
    lParam As Long  'Second message parameter.
End Type

Public Enum ERRORLEVEL
    elevCodeReturn          'Return error code.
    elevDescReturn          'Return error description string.
    elevSrcDescReturn       'Return error description string and error source string.
    elevMsgBox              'Return/Display error description string and error source string.
End Enum

'Purpose: CopyMemory (RtlMoveMemory) moves memory either forward or backward, _
'         aligned or unaligned, in 4-byte blocks, followed by any remaining bytes.
'

'

'Remarks: The (Source + Length) can overlap the Destination range passed in to CopyMemory (RtlMoveMemory).
'

'

'Parameter: Destination Points to the destination of the move.
'Parameter: Source      Points to the memory to be copied.
'Parameter: Length      Specifies the number of bytes to be copied.
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Public Const GWL_WNDPROC = (-4)
Public glngPrevWndProc As Long
Public Declare Function RtlMoveMemory Lib "kernel32" (Dest As Any, src As Any, ByVal Count As Long) As Long
Public Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, ByRef lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageZId As Long, ByVal lpBuffer As String, ByVal nSize As Long, ByVal Arguments As Long) As Long

Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000

Public Const DBT_DEVICEARRIVAL As Long = 32768
Public Const DBT_DEVICEREMOVECOMPLETE As Long = 32772
Public Const DBT_DEVTYP_DEVICEINTERFACE     As Long = 5
Public Const DEVICE_NOTIFY_WINDOW_HANDLE As Long = 0
Public Const WM_DEVICECHANGE As Long = &H219
Public Const DIGCF_PRESENT As Integer = &H2
Public Const DIGCF_DEVICEINTERFACE As Integer = &H10

Public Type Guid
    D1 As Long
    D2 As Integer
    D3 As Integer
    D4(7) As Byte
End Type

Public Type DEV_BROADCAST_DEVICEINTERFACE
    dbcc_size As Long
    dbcc_devicetype As Long
    dbcc_reserved As Long
    dbcc_classguid As Guid
    dbcc_name As Long
End Type

Public Type DEV_BROADCAST_DEVICEINTERFACE2
  dbcc_size As Long
  dbcc_devicetype As Long
  dbcc_reserved As Long
  dbcc_classguid As Guid
  dbcc_name As String * 1024
End Type

Public Type DEV_BROADCAST_HDR
    dbch_size As Long
    dbch_devicetype As Long
    dbch_reserved As Long
End Type

Public Type SP_DEVICE_INTERFACE_DATA
    cbSize As Long
    InterfaceClassGuid As Guid
    Flags As Long
    Reserved As Long
End Type

Public Type SP_DEVICE_INTERFACE_DETAIL_DATA
    cbSize As Long
    DevicePath As Byte
    'DataPath(256) As Byte
End Type

Public Declare Function SetupDiDestroyDeviceInfoList Lib "setupapi.dll" (ByVal DeviceInfoSet As Long) As Long
Public Declare Function SetupDiEnumDeviceInterfaces Lib "setupapi.dll" (ByVal DeviceInfoSet As Long, ByVal DeviceInfoData As Long, ByRef InterfaceClassGuid As Guid, ByVal MemberIndex As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA) As Boolean
Public Declare Function SetupDiGetClassDevs Lib "setupapi.dll" Alias "SetupDiGetClassDevsA" (ByRef ClassGuid As Guid, ByVal Enumerator As String, ByVal hwndParent As Long, ByVal Flags As Long) As Long
Public Declare Function SetupDiGetDeviceInterfaceDetail Lib "setupapi.dll" Alias "SetupDiGetDeviceInterfaceDetailA" (ByVal DeviceInfoSet As Long, ByRef DeviceInterfaceData As SP_DEVICE_INTERFACE_DATA, ByVal DeviceInterfaceDetailData As Long, ByVal DeviceInterfaceDetailDataSize As Long, ByRef RequiredSize As Long, ByVal DeviceInfoData As Long) As Boolean
Public Declare Function RegisterDeviceNotification Lib "user32.dll" Alias "RegisterDeviceNotificationA" (ByVal hRecipient As Long, NotificationFilter As Any, ByVal Flags As Long) As Long
Public Declare Function UnregisterDeviceNotification Lib "user32.dll" (ByVal Handle As Long) As Boolean

Public Const FILE_ATTRIBUTE_NORMAL As Integer = &H80
Public Const FILE_FLAG_OVERLAPPED As Long = &H40000000
Public Const FILE_SHARE_READ As Integer = &H1
Public Const FILE_SHARE_WRITE As Integer = &H2
Public Const GENERIC_READ As Long = &H80000000
Public Const GENERIC_WRITE As Long = &H40000000
Public Const OPEN_EXISTING As Integer = 3

Public Type SECURITY_ATTRIBUTES
    nLength As Long
    lpSecurityDescriptor As Long
    bInheritHandle As Long
End Type

Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Boolean
Public Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long

Public Enum PIPE_POLICY_TYPE
    SHORT_PACKET_TERMINATE = &H1
    AUTO_CLEAR_STALL
    PIPE_TRANSFER_TIMEOUT
    IGNORE_SHORT_PACKETS
    ALLOW_PARTIAL_READS
    AUTO_FLUSH
    RAW_IO
    MAXIMUM_TRANSFER_SIZE
End Enum

Public Type WINUSB_PIPE_INFORMATION
    PipeType As USBD_PIPE_TYPE
    PipeId As Byte
    MaximumPacketSize As Integer
    Interval As Byte
End Type

Public Enum USBD_PIPE_TYPE
    UsbdPipeTypeControl
    UsbdPipeTypeIsochronous
    UsbdPipeTypeBulk
    UsbdPipeTypeInterrupt
End Enum

Public Type USB_INTERFACE_DESCRIPTOR
    bLength As Byte
    bDescriptorType As Byte
    bInterfaceNumber As Byte
    bAlternateSetting As Byte
    bNumEndpoints As Byte
    bInterfaceClass As Byte
    bInterfaceSubClass As Byte
    bInterfaceProtocol As Byte
    iInterface As Byte
End Type

Public Declare Function WinUsb_Initialize Lib "winusb.dll" (ByVal DeviceHandle As Long, ByRef InterfaceHandle As Long) As Boolean
Public Declare Function WinUsb_Free Lib "winusb.dll" (ByVal InterfaceHandle As Long) As Boolean
Public Declare Function WinUsb_QueryInterfaceSettings Lib "winusb.dll" (ByVal InterfaceHandle As Long, ByVal AlternateInterfaceNumber As Byte, ByRef UsbAltInterfaceDescriptor As USB_INTERFACE_DESCRIPTOR) As Boolean
Public Declare Function WinUsb_QueryPipe Lib "winusb.dll" (ByVal InterfaceHandle As Long, ByVal AlternateInterfaceNumber As Byte, ByVal PipeIndex As Byte, ByRef PipeInformation As WINUSB_PIPE_INFORMATION) As Boolean
Public Declare Function WinUsb_SetPipePolicy Lib "winusb.dll" (ByVal InterfaceHandle As Long, ByVal PipeId As Byte, ByVal PolicyType As Long, ByVal ValueLength As Long, ByRef Value As Byte) As Boolean
Public Declare Function WinUsb_SetPipePolicy1 Lib "winusb.dll" Alias "WinUsb_SetPipePolicy" (ByVal InterfaceHandle As Long, ByVal PipeId As Byte, ByVal PolicyType As Long, ByVal ValueLength As Long, ByRef Value As Long) As Boolean
Public Declare Function WinUsb_ReadPipe Lib "winusb.dll" (ByVal InterfaceHandle As Long, ByVal PipeId As Byte, ByRef Buffer As Byte, ByVal BufferLength As Long, ByRef LengthTransferred As Long, ByVal Overlapped As Long) As Boolean
Public Declare Function WinUsb_WritePipe Lib "winusb.dll" (ByVal InterfaceHandle As Long, ByVal PipeId As Byte, ByRef Buffer As Byte, ByVal BufferLength As Long, ByRef LengthTransferred As Long, ByVal Overlapped As Long) As Boolean
Public Declare Function WinUsb_ResetPipe Lib "winusb.dll" (ByVal InterfaceHandle As Long, ByVal PipeId As Byte) As Boolean
Public Declare Function WinUsb_AbortPipe Lib "winusb.dll" (ByVal InterfaceHandle As Long, ByVal PipeId As Byte) As Boolean
Public Declare Function WinUsb_FlushPipe Lib "winusb.dll" (ByVal InterfaceHandle As Long, ByVal PipeId As Byte) As Boolean

'Purpose: DPP WinUSB device information data type.
Public Type WinUsbDevice
    DeviceHandle As Long        'Communications device resource handle.
    winUsbHandle As Long        'WinUSB interface handle.
    bulkInPipe As Long          'Bulk IN pipe id.
    bulkOutPipe As Long         'Bulk OUT pipe id.
    interruptInPipe As Long     'Interrupt IN pipe id.
    interruptOutPipe As Long    'Interrupt OUT pipe id.
    devicespeed As Long         'Device speed indicator.
    SerNum As Long              'dpp serial number
    idxUSB As Long              'WinUSB device index (1-NumDevices)
    idxMUSB As Long             'MUSB array index
End Type

Public DppWinUSB As WinUsbDevice     'DppWinUSB device information
Public EmptyWinUSB As WinUsbDevice     'DppWinUSB device information
Public MultiWinUSB(4) As WinUsbDevice     'Multiple WinUSB device information, 0-4
Public NumMultiDpp As Long                  'number of multiusb devices

Public USBDeviceNotificationHandle As Long
Public USBDeviceConnected As Boolean
Public USBDevicePathName As String

'Registry functions for counting WinUSB devices
Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Public Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_QUERY_VALUE = &H1
Public Const ERROR_SUCCESS = 0&
Public Const MAX_PATH = 260
Public Const MAXREGBUFFER = 128
Public Const MAXERRBUFFER = 256
Public Const MAX_DEVPATH_LENGTH = 256
Public Const NUM_ASYNCH_IO = 100
Public Const BUFFER_SIZE = 1024

Public Const MAXDP5S = 128              ' max number of devices
Public Const WinUSBService = "SYSTEM\CurrentControlSet\Services\WinUSB\Enum"
Public Const WinUsbDP5 = "USB\Vid_10c4&Pid_842a"
Public Const WinUsbDP5Size = 21
Public Const ERROR_NO_MORE_ITEMS = 259&

Public Const REG_NONE = 0                       ' No value type
Public Const REG_DWORD = 4                      ' 32-bit number

Public Function OpenDevice(hwnd As Long, ByRef DppWinUSB As WinUsbDevice, ByRef DeviceConnected As Boolean, DevicePathName As String, MemberIndex As Long) As Boolean
    Dim deviceFound As Boolean
    Dim NewDevicePathName As String
    Dim success As Boolean
    Dim winUsbDemoGuid As Guid
    OpenDevice = False
    NewDevicePathName = ""
    On Error GoTo OpenDeviceErr
    If Not DeviceConnected Then
        winUsbDemoGuid.D1 = &H5A8ED6A1
        winUsbDemoGuid.D2 = &H7FC3
        winUsbDemoGuid.D3 = &H4B6A
        winUsbDemoGuid.D4(0) = &HA5
        winUsbDemoGuid.D4(1) = &H36
        winUsbDemoGuid.D4(2) = &H95
        winUsbDemoGuid.D4(3) = &HDF
        winUsbDemoGuid.D4(4) = &H35
        winUsbDemoGuid.D4(5) = &HD0
        winUsbDemoGuid.D4(6) = &H34
        winUsbDemoGuid.D4(7) = &H48
        'Fill an array with the device path names of all attached devices with matching GUIDs.
        deviceFound = FindDeviceFromGuid(winUsbDemoGuid, NewDevicePathName, MemberIndex)
        If deviceFound = True Then
            success = GetDeviceHandle(DppWinUSB, NewDevicePathName)
            success = VbBool(success)
            If (success) Then
                DeviceConnected = True
                DevicePathName = NewDevicePathName   'Save NewDevicePathName so OnDeviceChange() knows which name is Test device.
            Else    'There was a problem in retrieving the information.
                DeviceConnected = False
                CloseDeviceHandle DppWinUSB
            End If
        End If
        If DeviceConnected Then    'The device was detected.
            #If (bEnableDeviceNotification) Then
            '(Re)Register to receive notifications if the device is removed or attached.
            If USBDeviceNotificationHandle <> 0 Then   'Unregister old notification before creating new
                Call UnregisterDeviceNotification(USBDeviceNotificationHandle) 'Stop receiving notification messages.
            End If
            SetWindowLong hwnd, GWL_WNDPROC, glngPrevWndProc 'pass control back to previous windows
            success = RegisterForDeviceNotifications(DevicePathName, hwnd, winUsbDemoGuid, USBDeviceNotificationHandle)
            success = VbBool(success)
            If success Then
                glngPrevWndProc = GetWindowLong(hwnd, GWL_WNDPROC)
                SetWindowLong hwnd, GWL_WNDPROC, AddressOf WndProc
                InitializeDevice DppWinUSB
            End If
            #Else
                InitializeDevice DppWinUSB
            #End If
        End If
    End If
    OpenDevice = DeviceConnected
    Exit Function
OpenDeviceErr:
    Call ProcessError(Err)
End Function

'Purpose: Copies WinUsbDevice storage.
'Parameter: Source WinUsbDevice storage to be saved
'Parameter: Destination WinUsbDevice storage copy
Public Sub CopyWinUsbDevice(Source As WinUsbDevice, Destination As WinUsbDevice)
    Destination.DeviceHandle = Source.DeviceHandle             'Communications device resource handle.
    Destination.winUsbHandle = Source.winUsbHandle             'WinUSB interface handle.
    Destination.bulkInPipe = Source.bulkInPipe                 'Bulk IN pipe id.
    Destination.bulkOutPipe = Source.bulkOutPipe               'Bulk OUT pipe id.
    Destination.interruptInPipe = Source.interruptInPipe       'Interrupt IN pipe id.
    Destination.interruptOutPipe = Source.interruptOutPipe     'Interrupt OUT pipe id.
    Destination.devicespeed = Source.devicespeed               'Device speed indicator.

    Destination.SerNum = Source.SerNum                          'dpp serial number
    Destination.idxUSB = Source.idxUSB                          'WinUSB device index (1-NumDevices)
    Destination.idxMUSB = Source.idxMUSB                        'MUSB array index
End Sub

Public Sub DeviceConnectedDisplay(rtbStatus As RichTextLib.RichTextBox, isDetected As Boolean)
    If (isDetected) Then
        UpdateStatusList rtbStatus, "Device connected.", RGB(0, 128, 0)
    Else
        UpdateStatusList rtbStatus, "Could not connect to device.", vbRed
    End If
End Sub

Public Sub UpdateStatusList(rtbStatus As RichTextLib.RichTextBox, strStatus As String, Optional clrColor As Long = vbBlack)
    On Error GoTo UpdateStatusListErr
    StatusList rtbStatus, strStatus, clrColor
    Exit Sub
UpdateStatusListErr:
    Call ProcessError(Err)
End Sub

Public Sub StatusList(rtbStatus As RichTextLib.RichTextBox, strStatus As String, clrColor As Long, Optional bNL As Boolean = True)
    Dim prvlen As Long
    Dim strNL As String
On Error GoTo 0
    prvlen = Len(rtbStatus.Text)
    rtbStatus.SelStart = Len(rtbStatus.Text) + 1
    strNL = ""
    If (bNL) Then strNL = vbNewLine
    rtbStatus.SelText = strStatus & strNL
    rtbStatus.SelStart = prvlen
    rtbStatus.SelLength = Len(strStatus & strNL)
    rtbStatus.SelColor = clrColor
    rtbStatus.SelStart = Len(rtbStatus.Text) + 1
End Sub

'Purpose: Closes the device handle obtained with CreateFile and frees resources.
Public Sub CloseDeviceHandle(DppWinUSB As WinUsbDevice)
    Dim success As Boolean
    On Error GoTo CloseDeviceHandleErr
        success = WinUsb_Free(DppWinUSB.winUsbHandle)
        success = VbBool(success)
        If Not (DppWinUSB.DeviceHandle = 0) Then
            If Not (DppWinUSB.DeviceHandle) Then
                CloseHandle (DppWinUSB.DeviceHandle)
            End If
        End If
    Exit Sub
CloseDeviceHandleErr:
    Call ProcessError(Err)
End Sub

'Purpose: Requests a handle with CreateFile.
'

' Returns The handle.
'

'

'Parameter: devicePathName Returned by SetupDiGetDeviceInterfaceDetail
' in an SP_DEVICE_INTERFACE_DETAIL_DATA structure.
Public Function GetDeviceHandle(ByRef DppWinUSB As WinUsbDevice, ByVal DevicePathName As String) As Boolean
    Dim security As SECURITY_ATTRIBUTES
    security.lpSecurityDescriptor = 0
    security.bInheritHandle = 1
    security.nLength = Len(security)
    DppWinUSB.DeviceHandle = CreateFile(DevicePathName, _
                                GENERIC_WRITE Or GENERIC_READ, FILE_SHARE_READ Or FILE_SHARE_WRITE, _
                                security, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL Or FILE_FLAG_OVERLAPPED, 0)
    If Not (DppWinUSB.DeviceHandle) Then
        GetDeviceHandle = True
    Else
        MsgBox GetErrorString(Err.LastDllError)
        GetDeviceHandle = False
    End If
End Function

'Purpose: Initializes a device interface and obtains information about it.  Calls these
' winusb API functions: WinUsb_Initialize,WinUsb_QueryInterfaceSettings, WinUsb_QueryPipe
'

' Returns True on success, False on failure.
'

'

'Parameter: DppWinUSB DPP WinUSB device information
Public Function InitializeDevice(ByRef DppWinUSB As WinUsbDevice) As Boolean
    Dim ifaceDescriptor As USB_INTERFACE_DESCRIPTOR
    Dim pipeInfo As WINUSB_PIPE_INFORMATION
    Dim pipeTimeout As Long
    Dim success As Boolean
    Dim success1 As Boolean
    Dim i As Long

    pipeTimeout = 500   ' 2/4/10 - seems like 500mS should be plenty?
    'Erase FPGA' takes 4s, worst case! Change timeout just for that command
    On Error GoTo InitializeDeviceErr
    success = WinUsb_Initialize(DppWinUSB.DeviceHandle, DppWinUSB.winUsbHandle)
    success = VbBool(success)
    If success Then
        success = WinUsb_QueryInterfaceSettings(DppWinUSB.winUsbHandle, 0, ifaceDescriptor)
        success = VbBool(success)
        If success Then
            ' Get the transfer type, endpoint number, and direction for the interface's
            ' bulk and interrupt endpoints. Set pipe policies.
            For i = 0 To ifaceDescriptor.bNumEndpoints - 1
                success1 = WinUsb_QueryPipe(DppWinUSB.winUsbHandle, 0, CByte(i), pipeInfo)
                success1 = VbBool(success1)
                If ((pipeInfo.PipeType = USBD_PIPE_TYPE.UsbdPipeTypeBulk) And _
                    UsbEndpointDirectionIn(pipeInfo.PipeId)) Then
                    DppWinUSB.bulkInPipe = pipeInfo.PipeId
                    Call SetPipePolicy(DppWinUSB, CByte(DppWinUSB.bulkInPipe), CInt(PIPE_POLICY_TYPE.IGNORE_SHORT_PACKETS), False)   ' this is the default, but set it anyway
                    Call SetPipePolicy(DppWinUSB, CByte(DppWinUSB.bulkInPipe), CInt(PIPE_POLICY_TYPE.AUTO_CLEAR_STALL), True)    ' new - 2/5/2010
                    Call SetPipePolicy(DppWinUSB, CByte(DppWinUSB.bulkInPipe), CInt(PIPE_POLICY_TYPE.ALLOW_PARTIAL_READS), False)    ' new - 5/25/2010
                    Call SetPipePolicy1(DppWinUSB, CByte(DppWinUSB.bulkInPipe), CInt(PIPE_POLICY_TYPE.PIPE_TRANSFER_TIMEOUT), pipeTimeout)
                ElseIf ((pipeInfo.PipeType = USBD_PIPE_TYPE.UsbdPipeTypeBulk) And _
                    UsbEndpointDirectionOut(pipeInfo.PipeId)) Then
                    DppWinUSB.bulkOutPipe = pipeInfo.PipeId
                    'Call SetPipePolicy(CByte(DppWinUSB.bulkOutPipe), CInt(PIPE_POLICY_TYPE.IGNORE_SHORT_PACKETS), False)
                    Call SetPipePolicy(DppWinUSB, CByte(DppWinUSB.bulkOutPipe), CInt(PIPE_POLICY_TYPE.SHORT_PACKET_TERMINATE), True)
                    Call SetPipePolicy(DppWinUSB, CByte(DppWinUSB.bulkOutPipe), CInt(PIPE_POLICY_TYPE.AUTO_CLEAR_STALL), True)
                    Call SetPipePolicy1(DppWinUSB, CByte(DppWinUSB.bulkOutPipe), CInt(PIPE_POLICY_TYPE.PIPE_TRANSFER_TIMEOUT), pipeTimeout)
                End If
            Next i
        Else
            success = False
        End If
    End If
    success = VbBool(success)
    InitializeDevice = success
    Exit Function
InitializeDeviceErr:
    Call ProcessError(Err)
End Function

'Purpose: Sets pipe policy.
' Used when the value parameter is a byte (all except PIPE_TRANSFER_TIMEOUT).
'

' Returns True on success, False on failure.
'

'

'Parameter: PipeId Pipe to set a policy for.
'Parameter: PolicyType PIPE_POLICY_TYPE member.
'Parameter: Value Policy value.
Private Function SetPipePolicy(ByRef DppWinUSB As WinUsbDevice, ByVal PipeId As Byte, ByVal PolicyType As Long, ByVal Value As Boolean) As Boolean
    Dim success As Boolean
    On Error GoTo SetPipePolicyErr
    success = WinUsb_SetPipePolicy(DppWinUSB.winUsbHandle, PipeId, PolicyType, 1, CByte(Value))
    success = VbBool(success)
    SetPipePolicy = success
    Exit Function
SetPipePolicyErr:
    Call ProcessError(Err)
End Function

'Purpose: Sets pipe policy.
' Used when the value parameter is a long (PIPE_TRANSFER_TIMEOUT only).
'

' Returns True on success, False on failure.
'

'

'Parameter: PipeId     Pipe to set a policy for.
'Parameter: PolicyType PIPE_POLICY_TYPE member.
'Parameter: Value      Policy value.
Public Function SetPipePolicy1(ByRef DppWinUSB As WinUsbDevice, ByVal PipeId As Byte, ByVal PolicyType As Long, ByVal Value As Long) As Boolean
    Dim success As Boolean
    SetPipePolicy1 = False
    On Error GoTo SetPipePolicy1Err
    success = WinUsb_SetPipePolicy1(DppWinUSB.winUsbHandle, PipeId, PolicyType, 4, Value)
    success = VbBool(success)
    SetPipePolicy1 = success
    Exit Function
SetPipePolicy1Err:
    Call ProcessError(Err)
End Function

'Purpose: Is the endpoint's direction IN (device to host)
'

' Returns True if IN (device to host), False if OUT (host to device)
'

'

'Parameter: addr The endpoint address.
Private Function UsbEndpointDirectionIn(ByVal addr As Long) As Boolean
    On Error GoTo UsbEndpointDirectionInErr
        If ((addr And &H80) = &H80) Then
            UsbEndpointDirectionIn = True
        Else
            UsbEndpointDirectionIn = False
        End If
    Exit Function
UsbEndpointDirectionInErr:
    Call ProcessError(Err)
End Function

'Purpose: Is the endpoint's direction OUT (host to device)
'

' Returns True if OUT (host to device, False if IN (device to host)
'

'

'Parameter: addr The endpoint address.
Private Function UsbEndpointDirectionOut(ByVal addr As Long) As Boolean
    On Error GoTo UsbEndpointDirectionOutErr
        If ((addr And &H80) = 0) Then
            UsbEndpointDirectionOut = True
        Else
            UsbEndpointDirectionOut = False
        End If
    Exit Function
UsbEndpointDirectionOutErr:
    Call ProcessError(Err)
End Function

'Purpose: Compares two device path names. Used to find out if the device name
'       of a recently attached or removed device matches the name of a
'       device the application is communicating with.
'

'

' Returns True if the names match, False if not.
'

'

'Parameter: m              A WM_DEVICECHANGE message. A call to RegisterDeviceNotification
'                          causes WM_DEVICECHANGE messages to be passed to an OnDeviceChange routine..
'Parameter: DevicePathName A device pathname returned by SetupDiGetDeviceInterfaceDetail
'                          in an SP_DEVICE_INTERFACE_DETAIL_DATA structure.
Public Function DeviceNameMatch(m As Message, ByVal DevicePathName As String) As Boolean
    Dim deviceNameString As String
    Dim stringSize As Long
    deviceNameString = ""
    On Error GoTo DeviceNameMatchErr
    Dim devBroadcastDeviceInterface As DEV_BROADCAST_DEVICEINTERFACE2
    Dim devBroadcastHeader As DEV_BROADCAST_HDR
    CopyMemory devBroadcastHeader, ByVal (m.lParam), Len(devBroadcastHeader)
    If (devBroadcastHeader.dbch_devicetype = DBT_DEVTYP_DEVICEINTERFACE) Then
        CopyMemory devBroadcastDeviceInterface, ByVal (m.lParam), ByVal (devBroadcastHeader.dbch_size)
        stringSize = CInt((devBroadcastHeader.dbch_size - 32) / 2) + 1
        deviceNameString = CStr(Left(devBroadcastDeviceInterface.dbcc_name, stringSize)) 'Store the device name in a String.
        If (StrComp(deviceNameString, DevicePathName, vbTextCompare) = 0) Then    'Set ignorecase True.
            DeviceNameMatch = True
        Else
            DeviceNameMatch = False
        End If
    End If
    Exit Function
DeviceNameMatchErr:
    Call ProcessError(Err)
End Function

'Purpose: Use SetupDi (Setup Device Installation) API functions to retrieve the device path name of an
'           attached device that belongs to a device interface class.
'

'

' Returns True if a device is found, False if not.
'

'

'Parameter: TestGuid         Interface class GUID.
'Parameter: devicePathName A pointer to the device path name of an attached device.
Public Function FindDeviceFromGuid(ByRef TestGuid As Guid, ByRef DevicePathName As String, MemberIndex As Long) As Boolean
    Dim bufferSize As Long
    Dim bufferSizeReq As Long
    Dim detailDataBuffer() As Byte
    Dim DevDetailData As SP_DEVICE_INTERFACE_DETAIL_DATA
    Dim deviceFound As Boolean
    Dim DeviceInfoSet As Long
    Dim lastDevice As Boolean
    Dim TestDeviceInterfaceData As SP_DEVICE_INTERFACE_DATA
    'Dim pDevicePathName As Long
    Dim success As Boolean
    Dim pDevicePathName As String

    On Error GoTo FindDeviceFromGuidErr
    DeviceInfoSet = SetupDiGetClassDevs(TestGuid, vbNullString, 0, DIGCF_PRESENT Or DIGCF_DEVICEINTERFACE)
    deviceFound = False
    'MemberIndex = 0
    'Do
        TestDeviceInterfaceData.cbSize = Len(TestDeviceInterfaceData)   'The size is 28 bytes.
        success = SetupDiEnumDeviceInterfaces(DeviceInfoSet, 0, TestGuid, MemberIndex, TestDeviceInterfaceData)
        success = VbBool(success)
        If (Not CBool(success)) Then    'Find out if a device information set was retrieved.
            lastDevice = True
        Else    'A device is present.
            success = SetupDiGetDeviceInterfaceDetail(DeviceInfoSet, TestDeviceInterfaceData, 0, 0, bufferSize, 0)
            success = VbBool(success)
            DevDetailData.cbSize = Len(DevDetailData)
            ReDim detailDataBuffer(bufferSize)  '
            Call RtlMoveMemory(detailDataBuffer(0), DevDetailData, 4)
            success = SetupDiGetDeviceInterfaceDetail _
                        (DeviceInfoSet, _
                        TestDeviceInterfaceData, _
                        VarPtr(detailDataBuffer(0)), _
                        bufferSize, _
                        bufferSizeReq, _
                        0)
            success = VbBool(success)
            pDevicePathName = CStr(detailDataBuffer())                          'Convert the byte array to a string.
            pDevicePathName = StrConv(pDevicePathName, vbUnicode)               'Convert to Unicode.
            pDevicePathName = Right$(pDevicePathName, Len(pDevicePathName) - 4) 'Strip cbSize (4 bytes) from the beginning.
            DevicePathName = pDevicePathName    'Get the String containing the devicePathName.
            deviceFound = True
        End If
        'MemberIndex = MemberIndex + 1
    'Loop Until (lastDevice = True)
    SetupDiDestroyDeviceInfoList (DeviceInfoSet)
    FindDeviceFromGuid = deviceFound
    Exit Function
FindDeviceFromGuidErr:
    Call ProcessError(Err)
End Function

'Purpose: Requests to receive a notification when a device is attached or removed.
'

'

' Returns True on success, False otherwise.
'

'

'Parameter: devicePathName           Handle to a device.
'Parameter: formHandle               Handle to the window that will receive device events.
'Parameter: classGuid                Device interface GUID.
'Parameter: deviceNotificationHandle Returned device notification handle.
Public Function RegisterForDeviceNotifications(ByVal DevicePathName As String, ByVal formHandle As Long, ByRef ClassGuid As Guid, ByRef deviceNotificationHandle As Long) As Boolean
    Dim devBroadcastDeviceInterface As DEV_BROADCAST_DEVICEINTERFACE
    Dim devBroadcastDeviceInterfaceBuffer As Long
    Dim size As Long
    On Error GoTo RegisterForDeviceNotificationsErr
    size = Len(devBroadcastDeviceInterface)         'Set the size.
    devBroadcastDeviceInterface.dbcc_size = size
    devBroadcastDeviceInterface.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE
    devBroadcastDeviceInterface.dbcc_reserved = 0
    devBroadcastDeviceInterface.dbcc_classguid = ClassGuid  'Specify the interface class to receive notifications about.
    #If (bEnableDeviceNotification) Then
    deviceNotificationHandle = RegisterDeviceNotification(formHandle, devBroadcastDeviceInterface, DEVICE_NOTIFY_WINDOW_HANDLE)
    If (deviceNotificationHandle = 0#) Then
        RegisterForDeviceNotifications = False
    Else
        RegisterForDeviceNotifications = True
    End If
    #Else
        RegisterForDeviceNotifications = False
    #End If
    Exit Function
RegisterForDeviceNotificationsErr:
    Call ProcessError(Err)
End Function

'Purpose: Returns and/or displays process error messages
Public Function ProcessError(errError As ErrObject, Optional errSource As String = "", Optional errControl As ERRORLEVEL = elevSrcDescReturn) As Variant
    Select Case errControl
        Case elevCodeReturn
            ProcessError = errError.Number
        Case elevDescReturn
            ProcessError = errError.Description
        Case elevSrcDescReturn
            ProcessError = errSource & " : " & errError.Description
        Case elevMsgBox
            ProcessError = errSource & " : " & errError.Description
            MsgBox errError.Description, vbCritical, errSource
        Case Else
            ProcessError = errSource & " : " & errError.Description
    End Select
    MsgBox errError.Description & " " & errError.LastDllError
End Function

'Purpose: Converts any C boolean type to a VB boolean type
Public Function VbBool(bBool As Variant) As Boolean
    On Error GoTo VbBoolErr
    VbBool = False
    If (bBool = 0) Then
        VbBool = False
    Else
        VbBool = True
    End If
    Exit Function
VbBoolErr:
End Function

'Purpose: Returns the error message for the last error.
'Adapted from Dan Appleman's "Win32 API Puzzle Book"
Public Function GetErrorString(ByVal LastError As Long) As String
    Dim Bytes As Long
    Dim ErrorString As String
    ErrorString = String$(129, 0)
    Bytes = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, 0&, LastError, 0, ErrorString$, 128, 0)
    'Subtract two characters from the message to strip the CR and LF.
    If Bytes > 2 Then
        GetErrorString = Left$(ErrorString, Bytes - 2)
    End If
End Function

#If (bEnableDeviceNotification) Then
'Purpose: Overrides WndProc to enable checking for and handling WM_DEVICECHANGE messages.
'Parameter: Windows message info
Public Function WndProc(ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    On Error GoTo WndProcErr
    If Msg = WM_DEVICECHANGE Then   'The OnDeviceChange routine processes WM_DEVICECHANGE messages.
        'frmDP5.OnDeviceChange hWnd, Msg, wParam, lParam
        frmDP5.OnDeviceChange hwnd, Msg, wParam, lParam
    End If
    Debug.Print Msg
    'Pass the messages onto VB's own Window Procedure to let the base form process the message.
    WndProc = CallWindowProc(glngPrevWndProc, hwnd, Msg, wParam, lParam)
    Exit Function
WndProcErr:
    Call ProcessError(Err)
End Function
#End If

'Purpose: Counts the number of WinUSB DPP device connected
Public Function CountDP5WinusbDevices()
    Dim hKey As Long
    Dim retCode As Long
    Dim lRet As Long
    Dim idxDP5 As Long
    Dim DevicePath(MAXREGBUFFER - 1) As Byte
    Dim cbDevicePath As Long
    Dim KeyName As String
    Dim cbKeyName As Long
    Dim ErrMsg As String
    Dim cbErrMsg As Long
    Dim strDevicePath As String

    NumUSBDevices = 0
    retCode = RegOpenKeyEx(HKEY_LOCAL_MACHINE, WinUSBService, 0&, KEY_QUERY_VALUE, hKey)
    If (retCode <> ERROR_SUCCESS) Then
        CountDP5WinusbDevices = 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, ByVal KeyName, cbKeyName, 0&, REG_NONE, DevicePath(0), cbDevicePath)
        If (retCode = ERROR_SUCCESS) Then
            strDevicePath = ByteArrayToString(DevicePath)
            If (StrComp(Left(KeyName, 5), "Count", vbTextCompare) = 0) Then
                'do nothing
            ElseIf (StrComp(Left(strDevicePath, WinUsbDP5Size), WinUsbDP5, vbTextCompare) = 0) Then ' DP5 device path found
                '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
            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 = Left(ErrMsg, lRet) Else ErrMsg = ""
            'MsgBox ErrMsg
            Exit For
        End If
    Next
    Call RegCloseKey(hKey)
    CountDP5WinusbDevices = NumUSBDevices      '/* return number of devices */
End Function

Public Function ByteArrayToString(byteArray() As Byte) As String
    Dim str As String
    Dim PosTerminator As String
    str = StrConv(byteArray, vbUnicode)
    PosTerminator = InStr(str, Chr(0))
    If PosTerminator > 0 Then str = Left(str, PosTerminator - 1)
    ByteArrayToString = str
End Function