private void buttonTestVPP_Click(object sender, EventArgs e) { float vdd = 0; float vpp = 0; labelVPPLow.Visible = false; labelVPPMCLR.Visible = false; labelVPPMCLROff.Visible = false; labelVPPPass.Visible = false; labelVPPShort.Visible = false; labelVPPVDDShort.Visible = false; labelReadVPP.Text = ""; Thread.Sleep(250); // sleep a bit to let VDD bleed down. // check for a powered target first if (Pk2.CheckTargetPower(ref vdd, ref vpp) == KONST.PICkit2PWR.selfpowered) { Pk2.VddOff(); } else { Pk2.SetVDDVoltage((float)numericUpDown1.Value, 0.85F); Pk2.VddOn(); } // Set VPP voltage float expectedVPP; if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].Vpp > 1) { expectedVPP = Pk2.DevFile.Families[Pk2.GetActiveFamily()].Vpp; } else { expectedVPP = (float)numericUpDown1.Value; } Pk2.SetVppVoltage(expectedVPP, 0.50F); byte[] vppscript = new byte[8]; vppscript[0] = KONST._VPP_OFF; vppscript[1] = KONST._VPP_PWM_ON; vppscript[2] = KONST._DELAY_LONG; vppscript[3] = 30; vppscript[4] = KONST._MCLR_GND_OFF; vppscript[5] = KONST._VPP_ON; vppscript[6] = KONST._DELAY_LONG; vppscript[7] = 20; Pk2.SendScript(vppscript); // check status first for shorts KONST.PICkit2PWR status = Pk2.PowerStatus(); if ((status == KONST.PICkit2PWR.vdderror) || (status == Constants.PICkit2PWR.vddvpperrors)) { //VDD short! labelVPPVDDShort.Visible = true; } else if (status == KONST.PICkit2PWR.vpperror) {//VPP short labelVPPShort.Visible = true; labelReadVPP.Text = "Short!"; } else if (status != Constants.PICkit2PWR.no_response) { // status OK, read VPP voltage if (Pk2.ReadPICkitVoltages(ref vdd, ref vpp)) { labelReadVPP.Text = string.Format("{0:0.0} V", vpp); if ((expectedVPP - vpp) > 0.3F) { labelVPPLow.Visible = true; } else { labelVPPPass.Visible = true; } } } }