Amptek MultiUSB for DPP Devices Project

Amptek MultiUSB for DPP Devices

This API provides access to Amptek devices that use the Microsoft WinUSB Driver.

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 |


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


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.


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.


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_MultiUSB Module


mod_vbDP5_MultiUSB Consts

Consts

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


LoadDeviceSettings Method

Public Method LoadDeviceSettings

Type Return

None

Syntax

Object.LoadDeviceSettings

The LoadDeviceSettings Methods syntax has these parts:

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


isNetFinderReady Property

Public Property isNetFinderReady

Type

A Boolean Value. The property is Read-Write

Syntax

Object.isNetFinderReady [ = Boolean ]

The isNetFinderReady Property syntax has these parts:

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


isWinUsbDppFound Property

Public Property isWinUsbDppFound

Type

A Boolean Value. The property is Read-Write

Syntax

Object.isWinUsbDppFound [ = Boolean ]

The isWinUsbDppFound Property syntax has these parts:

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


strNetFinder Property

Public Property strNetFinder

Type

A String Value. The property is Read-Write

Syntax

Object.strNetFinder [ = String ]

The strNetFinder Property syntax has these parts:

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


frmDP5 Module

frmDP5 Form


InitCommonControls Method

Private Declaration InitCommonControls

Demonstrates Amptek DPP WinUSB communications to multiple DPP devices.

Library

comctl32.dll

Type Return

A None Object

Syntax

InitCommonControls

The InitCommonControls Declaration syntax has these parts:

Part Description


Load Method

Private Declaration Load

Demonstrates Amptek DPP WinUSB communications to multiple DPP devices.

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.


btnOK_Click Method

Public 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.


CloseDevice Method

Public Method CloseDevice

Type Return

None

Syntax

Object.CloseDevice

The CloseDevice 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.


cmdConnectDevice_Click Method

Private Method cmdConnectDevice_Click

Type Return

None

Syntax

Object.cmdConnectDevice_Click Index

The cmdConnectDevice_Click Methods syntax has these parts:

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


cmdCopyDevice_Click Method

Private Method cmdCopyDevice_Click

Type Return

None

Syntax

Object.cmdCopyDevice_Click Index

The cmdCopyDevice_Click Methods syntax has these parts:

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


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.


cmdEnumerateDevices_Click Method

Public Method cmdEnumerateDevices_Click

Type Return

None

Syntax

Object.cmdEnumerateDevices_Click

The cmdEnumerateDevices_Click Methods syntax has these parts:

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


cmdMultiUsbTest_Click Method

Private Method cmdMultiUsbTest_Click

Type Return

None

Syntax

Object.cmdMultiUsbTest_Click

The cmdMultiUsbTest_Click Methods syntax has these parts:

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


cmdNextDevice_Click Method

Private Method cmdNextDevice_Click

Type Return

None

Syntax

Object.cmdNextDevice_Click

The cmdNextDevice_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.


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.


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.


Connect_Form_Load Method

Private Method Connect_Form_Load

Type Return

None

Syntax

Object.Connect_Form_Load

The Connect_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 Connect_Form_Paint

Type Return

None

Syntax

Object.Connect_Form_Paint

The Connect_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 Connect_Form_Unload

Type Return

None

Syntax

Object.Connect_Form_Unload Cancel

The Connect_Form_Unload Methods syntax has these parts:

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


CountDevices Method

Private Method CountDevices

Type Return

None

Syntax

Object.CountDevices

The CountDevices 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.


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.


FindDevice Method

Public Method FindDevice

Type Return

None

Syntax

Object.FindDevice

The FindDevice Methods syntax has these parts:

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


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.


GetDeviceByIndex Method

Public Method GetDeviceByIndex

Type Return

None

Syntax

Object.GetDeviceByIndex idxDevice, idxMUSB

The GetDeviceByIndex Methods syntax has these parts:

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


GetDeviceBySN Method

Public Method GetDeviceBySN

Type Return

None

Syntax

Object.GetDeviceBySN DppSerNum

The GetDeviceBySN Methods syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
DppSerNum | Required. A Long 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.


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.


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.


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.


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.


SelectDevice Method

Private Method SelectDevice

Type Return

None

Syntax

Object.SelectDevice NextDevice

The SelectDevice Methods syntax has these parts:

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


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.


SendConfigToDpp Method

Public Method SendConfigToDpp

Type Return

None

Syntax

Object.SendConfigToDpp strCfg

The SendConfigToDpp Methods syntax has these parts:

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


SetOptMultiTest Method

Private Method SetOptMultiTest

Type Return

None

Syntax

Object.SetOptMultiTest Index

The SetOptMultiTest Methods syntax has these parts:

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


tmrAcquisition_Timer Method

Private Method tmrAcquisition_Timer

Type Return

None

Syntax

Object.tmrAcquisition_Timer

The tmrAcquisition_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.


DppSerNum Property

Private Property DppSerNum

Type

A Long Value. The property is Read-Write

Syntax

Object.DppSerNum [ = Long ]

The DppSerNum Property syntax has these parts:

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


DppSnLst Property

Private Property DppSnLst

Type

A Long Value. The property is Read-Write

Syntax

Object.DppSnLst [ = Long ]

The DppSnLst Property syntax has these parts:

Part | Description
object | An expression evaluating to an Object of type frmDP5.
Long | A Long 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.


MultiUSBOpType Enumeration

Private MultiUSBOpType enumeration

Members

Name | Value | Description
musbt_0_SetPresets | 0 |
musbt_1_StartAcquisition | 1 |
musbt_2_MonitoringAcquisition | 2 |
musbt_3_SaveSpectra | 3 |
musbt_4_MultiUSBTestDone | 4 |


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.


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


frmDP5 Source Code

Option Explicit
'Purpose:

'   Demonstrates Amptek DPP WinUSB communications to multiple DPP devices.
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)
Private DppSerNum As Long
Private DppSnLst(10) As Long

Private Enum MultiUSBOpType
    musbt_0_SetPresets
    musbt_1_StartAcquisition
    musbt_2_MonitoringAcquisition
    musbt_3_SaveSpectra
    musbt_4_MultiUSBTestDone
End Enum

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 Function GetMcaFileCfg() As String
    Dim bDelay As Boolean
    s.HwCfgDP5 = ""
    s.DppConfig.bSpectrumCfg = True
    SendCommand XMTPT_FULL_READ_CONFIG_PACKET
    bDelay = msDelay(50)
    GetMcaFileCfg = s.HwCfgDP5
End Function

Private Sub SetOptMultiTest(Index As MultiUSBOpType)
    Dim idxTest As MultiUSBOpType
    For idxTest = musbt_0_SetPresets To musbt_4_MultiUSBTestDone
        optMultiTest(idxTest).Enabled = False
        optMultiTest(idxTest).Value = False
    Next
    optMultiTest(Index).Enabled = True
    optMultiTest(Index).Value = True
End Sub

Private Sub cmdMultiUsbTest_Click()
    Dim idxDevice As Long
    Dim NextDevice As Long
    Dim bAcqDone As Boolean
    Dim dtsStart As Date
    Dim dtsEnd As Date
    Dim dtsNow As Date
    Dim bDelay As Boolean
    Dim lAcqDone As Long
    Dim strFilename As String
    Dim strCfg As String
    Dim strTag As String
    Dim strDescription As String

    cmdMultiUsbTest.Enabled = False
    LogEvent "Starting MultiUSB Test", True
    LogEvent "MultiUSB Test Devices " & NumUSBDevices
    For idxDevice = 1 To NumUSBDevices
        LogEvent "Device " & idxDevice & " SerNum:" & DppSnLst(idxDevice)
    Next
    SetOptMultiTest musbt_0_SetPresets
    dtsStart = Now
    lblMultiUSBTestDTS.Caption = Format(dtsStart, "YYYYMMDD_HHMMSS")
    dtsEnd = DateAdd("s", (Val(txtPresetTime.Text) + 30#), dtsStart)
    If (NumUSBDevices = 0) Then Exit Sub
    If (CurrentUSBDevice = 0) Then Exit Sub

    fraSpectrumFunctions.Enabled = False        'disable controls
    tmrAcquisition.Enabled = False              'stop acquistion timer x1
    chkDeltaMode.Value = vbUnchecked
    For idxDevice = 1 To NumUSBDevices
        If (idxDevice > NumUSBDevices) Then Exit Sub
        If (cmdConnectDevice(idxDevice).Enabled And Len(lblUnit(idxDevice).Caption) > 0) Then
            cmdConnectDevice_Click (idxDevice - 1)  'control index is one less than device index
        End If
        If (Not (DppSnLst(idxDevice) = DppSerNum)) Then
            cmdConnectDevice_Click (idxDevice - 1)  'control index is one less than device index
        End If
        If (Not (DppSnLst(idxDevice) = DppSerNum)) Then
            LogEvent "Device Error: " & DppSnLst(idxDevice) & " != " & DppSerNum
        End If
        LogEvent DppSnLst(idxDevice) & " Preset Setup"
        SendCommand XMTPT_DISABLE_MCA_MCS       'pause mca
        SendConfigToDpp "PRET=" & Trim(txtPresetTime.Text) & ";"    'send presets
        SendCommand XMTPT_SEND_CLEAR_SPECTRUM_STATUS                'clear data
    Next
    SetOptMultiTest musbt_1_StartAcquisition
    bDelay = msDelay(1000)
    For idxDevice = 1 To NumUSBDevices
        If (idxDevice > NumUSBDevices) Then Exit Sub
        If (cmdConnectDevice(idxDevice).Enabled And Len(lblUnit(idxDevice).Caption) > 0) Then
            cmdConnectDevice_Click (idxDevice - 1)
        End If
        If (Not (DppSnLst(idxDevice) = DppSerNum)) Then
            cmdConnectDevice_Click (idxDevice - 1)  'control index is one less than device index
        End If
        If (Not (DppSnLst(idxDevice) = DppSerNum)) Then
            LogEvent "Device Error: " & DppSnLst(idxDevice) & " != " & DppSerNum
        End If
        LogEvent DppSnLst(idxDevice) & " Verify Spectrum Data Cleared"
        cmdSingleUpdate_Click
    Next
    bDelay = msDelay(2000)
    tmrAcquisition.Enabled = True               'start acquistion timer x1
    For idxDevice = 1 To NumUSBDevices
        If (idxDevice > NumUSBDevices) Then Exit Sub
        If (cmdConnectDevice(idxDevice).Enabled And Len(lblUnit(idxDevice).Caption) > 0) Then
            cmdConnectDevice_Click (idxDevice - 1)
        End If
        If (Not (DppSnLst(idxDevice) = DppSerNum)) Then
            cmdConnectDevice_Click (idxDevice - 1)  'control index is one less than device index
        End If
        If (Not (DppSnLst(idxDevice) = DppSerNum)) Then
            LogEvent "Device Error: " & DppSnLst(idxDevice) & " != " & DppSerNum
        End If
        LogEvent DppSnLst(idxDevice) & " Start Acquisition"
        SendCommand XMTPT_ENABLE_MCA_MCS        'start acquisitions
    Next
    SetOptMultiTest musbt_2_MonitoringAcquisition
    lAcqDone = NumUSBDevices

    LogEvent "Monitoring Devices"
    Do                                          'monitor data until all units done or timeout
        cmdNextDevice_Click
        bDelay = msDelay(2000)
        If (STATUS.MCA_EN) Then
            lAcqDone = NumUSBDevices
            LogEvent DppSerNum & " Acquiring Data"
        Else
            lAcqDone = lAcqDone - 1
            LogEvent DppSerNum & " Preset Done"
        End If
        dtsNow = Now
    Loop While ((dtsNow < dtsEnd) And (lAcqDone > 0))
    If (dtsNow > dtsEnd) Then
        LogEvent "Test timed out"
    Else
        LogEvent "Data Acquisition Done"
    End If
    SetOptMultiTest musbt_3_SaveSpectra
    If (lAcqDone = 0) Then                      'save the spectrum data
    For idxDevice = 1 To NumUSBDevices
        If (idxDevice > NumUSBDevices) Then Exit Sub
        If (cmdConnectDevice(idxDevice).Enabled And Len(lblUnit(idxDevice).Caption) > 0) Then
            cmdConnectDevice_Click (idxDevice - 1)
        End If
        If (Not (DppSnLst(idxDevice) = DppSerNum)) Then
            bDelay = msDelay(20)
            cmdConnectDevice_Click (idxDevice - 1)  'control index is one less than device index
        End If
        If (Not (DppSnLst(idxDevice) = DppSerNum)) Then
            LogEvent "Device Error: " & DppSnLst(idxDevice) & " != " & DppSerNum
        End If
        LogEvent DppSnLst(idxDevice) & " Saving Spectrum Data"
        bDelay = msDelay(2000)
        cmdSingleUpdate_Click                   'get final acquisition
        strFilename = CStr(STATUS.SerialNumber) & "_" & lblMultiUSBTestDTS.Caption & ".mca"
        strCfg = GetMcaFileCfg()
        Set s.Dp5CmdList = New Collection
        MakeDp5CmdList s.Dp5CmdList
        strCfg = ProcessSpectrumCfgForFile(strCfg, s.Dp5CmdList)
        strTag = Trim(txtSpectrumTag.Text)
        strDescription = Trim(txtSpectrumDescription.Text)
        Call SaveSpectrum(strFilename, SPECTRUM, strCfg, STATUS, strTag, strDescription, dtsStart)
    Next
    End If
    SetOptMultiTest musbt_4_MultiUSBTestDone
    LogEvent "MultiUSB Test Done"
    cmdMultiUsbTest.Enabled = True
End Sub

Private Sub cmdNextDevice_Click()
    Dim idxDevice As Long
    Dim NextDevice As Long
    If (NumUSBDevices = 0) Then Exit Sub
    If (CurrentUSBDevice = 0) Then Exit Sub
    NextDevice = CurrentUSBDevice
    NextDevice = NextDevice + 1
    If (NextDevice > NumUSBDevices) Then NextDevice = 1
    idxDevice = NextDevice - 1
    If (cmdConnectDevice(idxDevice).Enabled And Len(lblUnit(idxDevice).Caption) > 0) Then
        cmdConnectDevice_Click (idxDevice)
    End If
End Sub

'''device numbers can be 1 through 5, control indexes are 0-4
Private Sub SelectDevice(NextDevice As Long)
    Dim idxDevice As Long
    If (NumUSBDevices = 0) Then Exit Sub
    If (CurrentUSBDevice = 0) Then Exit Sub
    If (NextDevice > NumUSBDevices) Then Exit Sub
    idxDevice = NextDevice - 1
    If (cmdConnectDevice(idxDevice).Enabled And Len(lblUnit(idxDevice).Caption) > 0) Then
        cmdConnectDevice_Click (idxDevice)
    End If
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

Private Sub cmdStartAcquisition_Click()
    SendCommand XMTPT_ENABLE_MCA_MCS
    tmrAcquisition.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 Sub cmdSingleUpdate_Click()
    tmrAcquisition.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 cmdUSBDeviceTest()
    SendCommand XMTPT_SEND_NETFINDER_PACKET
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()
    LoadApplicationSettings Me
    LoadDeviceSettings

    DppSerNum = 0

    'InitAllEntries NfPktEntries

    CurrentUSBDevice = 1
    NumUSBDevices = 0

    s.DppConfig.CfgReadBack = False
    s.DppConfig.DisplayCfg = False
    s.DppConfig.bSpectrumCfg = False

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

    EnableDppCmdControls 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)
    PlotColor = &HFF&
    USBDevicePathName = ""
    USBDeviceConnected = False
    pnlStatus = "DP5 test application ready..."
    lblVersion.Caption = "DP5 SDK vbDP5_MultiUSB v" + Right(str(App.Major), 1) + "." + Right(str(App.Minor), 2)
    cmdEnumerateDevices_Click   'Search for devices
End Sub

Private Sub Form_Unload(Cancel As Integer)
    Dim bStatusDone As Boolean
    If (tmrAcquisition.Enabled) Then
        tmrAcquisition.Enabled = False
        bStatusDone = msDelay(500)
    End If
    SaveApplicationSettings Me
    CloseDeviceHandle DppWinUSB
    CloseProgram
End Sub

Public Sub CloseProgram()
    Dim frm As Form
    For Each frm In Forms
        Unload frm
    Next frm
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

    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

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

Private Sub picScope_DblClick()
    picScope.Cls
End Sub

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

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

Private Sub ParsePacketEx(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
    If (CurrentUSBDevice < 1) Then Exit Sub
    InitEntry NfPktEntries(CurrentUSBDevice - 1)
    AddEntry NfPktEntries(CurrentUSBDevice - 1), Buffer, 0
    If (USBDeviceTest) Then
        USBDeviceTest = False
        strDisplay = EntryToStrUSB(NfPktEntries(CurrentUSBDevice - 1), "USB Device " & CurrentUSBDevice & " of " & NumUSBDevices)
        DppSerNum = NfPktEntries(CurrentUSBDevice - 1).SerNum
        rtbStatus = ""
        rtbStatus = strDisplay
        strNetFinder = strDisplay
        isNetFinderReady = True
        isWinUsbDppFound = 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.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

    End If

    s.DppConfig.DisplayCfg = False
    s.DppConfig.CfgReadBack = False
    s.DppConfig.bSpectrumCfg = False
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
    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)
    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 ProcessDiagDataEx(PIN As Packet_In, DppState As DppStateType)
    Dim dd As DiagDataType
    Dim strDiag As String
    Call Process_Diagnostics(PIN, dd)
    strDiag = DiagnosticsToString(dd)
    txtMiscData = strDiag
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
        SentPkt = SendPacketUSB(DppWinUSB, BufferOUT, PacketIn())
        If (SentPkt) Then
            RemCallParsePacket PacketIn()
        Else
            tmrAcquisition.Enabled = False
        End If
    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
        SentPkt = SendPacketUSB(DppWinUSB, BufferOUT, PacketIn())
        If (SentPkt) Then
            RemCallParsePacket PacketIn()
        Else
            tmrAcquisition.Enabled = False
        End If
    End If
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

    '---- 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

'========================================================
Public Sub btnOK_Click()
    Dim strSelectedComm As String
    strSelectedComm = "Select Communications"
    If (isWinUsbDppFound) Then
        strSelectedComm = "USB - " & "WinUSB"
        s.isDppConnected = True
    Else
        s.isDppConnected = False
    End If
    SaveApplicationSettings Me, True, False, True
    Unload Me
End Sub

Public Sub CloseDevice()
    If (USBDeviceConnected) Then
        CloseDeviceHandle DppWinUSB
        USBDeviceConnected = False
    End If
End Sub

Private Sub cmdConnectDevice_Click(Index As Integer)
    If (Index < NumUSBDevices) Then
        CurrentUSBDevice = Index + 1
        lblCurrentDevice = CurrentUSBDevice
        FindDevice
    End If
End Sub

Private Sub cmdCopyDevice_Click(Index As Integer)
    Clipboard.Clear ' Clear Clipboard.
    Clipboard.SetText lblUnit(Index).Caption
End Sub

Private Sub CountDevices()
    NumUSBDevices = CountDP5WinusbDevices()
    lblNumUSBDevices = NumUSBDevices
    If (NumUSBDevices > 1) Then
        If (CurrentUSBDevice > NumUSBDevices) Then
            CurrentUSBDevice = NumUSBDevices
        End If
    Else    'disable spin and device selection
        CurrentUSBDevice = 1
    End If
End Sub

Public Sub cmdEnumerateDevices_Click()
    Dim idxDevice As Long
    Dim SerNum As Long

    Erase DppSnLst

    For idxDevice = 0 To (lblUnit.Count - 1)
        lblUnit(idxDevice).Caption = ""
    Next
    rtbStatus.Text = ""

    For idxDevice = 1 To cmdConnectDevice.Count
        cmdConnectDevice(idxDevice - 1).Visible = False
    Next

    CountDevices
    For idxDevice = 1 To NumUSBDevices
        CloseDevice
        isNetFinderReady = False
        strNetFinder = ""
        CurrentUSBDevice = idxDevice
        lblCurrentDevice = CurrentUSBDevice
        FindDevice
        If ((idxDevice > 0) And (idxDevice < 6)) Then
            lblUnit(idxDevice - 1) = strNetFinder   ' & vbNewLine   ' & isNetFinderReady
            SerNum = NfPktEntries(idxDevice - 1).SerNum
            MUSB_Idx(idxDevice - 1).Index = idxDevice
            MUSB_Idx(idxDevice - 1).SerNum = SerNum
            cmdConnectDevice(idxDevice - 1).Visible = True
            DppSnLst(idxDevice) = SerNum
            ''''DppSerNum = DppWinUSB.SerNum
        End If
    Next
End Sub

Public Sub GetDeviceBySN(DppSerNum As Long)
    Dim idxDevice As Long
    Dim SerNum As Long
    CountDevices
    For idxDevice = 1 To NumUSBDevices
        CloseDevice
        isNetFinderReady = False
        strNetFinder = ""
        CurrentUSBDevice = idxDevice
        lblCurrentDevice = CurrentUSBDevice
        FindDevice
        If ((idxDevice > 0) And (idxDevice < 4)) Then
            SerNum = NfPktEntries(idxDevice - 1).SerNum
            If (DppSerNum = SerNum) Then Exit Sub
            'lblUnit(idxDevice - 1) = strNetFinder   ' & vbNewLine   ' & isNetFinderReady
        End If
    Next
End Sub

' open a specific device by index.
Public Sub GetDeviceByIndex(idxDevice As Long, idxMUSB As Long)
    Dim SerNum As Long
    Dim isDetected As Boolean

    isNetFinderReady = False
    strNetFinder = ""
    CurrentUSBDevice = idxDevice
    lblCurrentDevice = CurrentUSBDevice
    CopyWinUsbDevice EmptyWinUSB, DppWinUSB
    USBDeviceConnected = False
    USBDevicePathName = ""

    isDetected = OpenDevice(frmDP5.hwnd, DppWinUSB, USBDeviceConnected, USBDevicePathName, idxDevice - 1)
    DeviceConnectedDisplay rtbStatus, USBDeviceConnected
    DeviceConnectedDisplay frmDP5.rtbStatus, USBDeviceConnected
    If (USBDeviceConnected) Then
        isWinUsbDppFound = True
        USBDeviceTest = True
        frmDP5.cmdUSBDeviceTest
        SerNum = NfPktEntries(idxDevice - 1).SerNum
        lblUnit(idxDevice - 1) = strNetFinder   ' & vbNewLine   ' & isNetFinderReady
        DppWinUSB.idxMUSB = idxMUSB
        DppWinUSB.idxUSB = idxDevice
        DppWinUSB.SerNum = SerNum
        CopyWinUsbDevice DppWinUSB, MultiWinUSB(idxMUSB)
    Else
        isWinUsbDppFound = False
    End If
End Sub

Private Sub Connect_Form_Load()
    Dim idxCommType As Long
    Dim byteSockAddr As Variant
    Dim idxIp As Long

    LoadApplicationSettings Me, True, False, False

    strCommStatus = ""
    isWinUsbDppFound = False
    CountDevices
    USBDeviceTest = False
    strCommStatus = "USB"
    Call FindDevice
    DppState.Interface = commUSB

End Sub

Private Sub Connect_Form_Paint()
    DoEvents
End Sub

Private Sub Connect_Form_Unload(Cancel As Integer)
    btnOK_Click
End Sub

Public Sub FindDevice()
' Search for a specific device.
    Dim isDetected As Boolean
    Dim bStatusDone As Boolean
    'On Error GoTo FindDeviceErr
    CloseDevice

    isDetected = OpenDevice(frmDP5.hwnd, DppWinUSB, USBDeviceConnected, USBDevicePathName, CurrentUSBDevice - 1)
    DeviceConnectedDisplay rtbStatus, USBDeviceConnected
    If (USBDeviceConnected) Then
        isWinUsbDppFound = True
        USBDeviceTest = True
        cmdUSBDeviceTest
        SendCommand XMTPT_SEND_STATUS
        EnableDppCmdControls True
    Else
        DppSerNum = 0
        isWinUsbDppFound = False
        EnableDppCmdControls False
    End If
    Exit Sub
FindDeviceErr:
    Call ProcessError(Err)
End Sub

'sends a specified configuration to dpp
Public Sub SendConfigToDpp(strCfg As String)
    Dim bResult As Boolean
    s.DppConfig.CfgReadBack = True
    s.HwCfgDP5Out = strCfg
    If (Len(strCfg) > 0) Then
        Call SendCommand(XMTPT_SEND_CONFIG_PACKET_EX)
    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


mod_vbDP5_MultiUSB Source Code

Option Explicit

Public isWinUsbDppFound As Boolean
Public isNetFinderReady As Boolean
Public strNetFinder As String
Public Const MAX_DISPLAY_ENTRIES = 5

Public Sub LoadDeviceSettings()
    Dim idxMUSB As Long
    Dim lNumberUnits As Long
    Dim strFilename As String
    strFilename = App.Path & "\" & App.EXEName & ".ini"

    'max index is 4 for five devices 0-4
    MUSB_MAX_INDEX = 4
    'last index is read fron vbDP5_MultiUSB.ini file
    lNumberUnits = GetFromIni(strFilename, IniSectionApp, "Number_MUSB_Units", 0)
    MUSB_LAST_INDEX = lNumberUnits - 1
    If (MUSB_LAST_INDEX > MUSB_MAX_INDEX) Then
        MUSB_LAST_INDEX = MUSB_MAX_INDEX
        lNumberUnits = MUSB_MAX_INDEX + 1
    End If

    If (lNumberUnits > 0) Then
        'multiusb serial numbers read from file (1 to five units connected)
        For idxMUSB = 0 To MUSB_LAST_INDEX
            MUSB_SN(idxMUSB) = CLng(Val(GetFromIni(strFilename, IniSectionApp, "MUSB_SN" & CStr(idxMUSB), 0)))
        Next
    End If
End Sub


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
''''


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 MultiUSB for DPP Devices
'This API provides access to Amptek devices that use the Microsoft WinUSB Driver.
'

'

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 DP5 FW6 MultiUSB Demonstration Project
Option Explicit


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


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