public DialogUnitSelect() { InitializeComponent(); this.Size = new Size(this.Size.Width, (int)(FormPICkit2.ScalefactH * this.Size.Height)); // Find up to 8 PICkit 2 Units. for (ushort i = 0; i < 8; i++) { KONST.PICkit2USB detRes = Pk2.DetectPICkit2Device(i, false); if (detRes != KONST.PICkit2USB.notFound) { // found something /*if (detRes == KONST.PICkit2USB.bootloader) * { * listBoxUnits.Items.Add(" " + i.ToString() + " <Bootloader>"); * } * else if (detRes == Constants.PICkit2USB.firmwareInvalid) * { // min FW for UnitID is 2.10 * if ((Pk2.FirmwareVersion[0] == '2') && (ushort.Parse(Pk2.FirmwareVersion.Substring(2,2)) >= 10)) * { * string unitID = Pk2.UnitIDRead(); * if (unitID == "") * unitID = "-"; * listBoxUnits.Items.Add(" " + i.ToString() + " " + unitID); * } * else * { * listBoxUnits.Items.Add(" " + i.ToString() + " <FW v" + Pk2.FirmwareVersion + ">"); * } * * } * else * { * string unitID = Pk2.UnitIDRead(); * if (unitID == "") * unitID = "-"; * listBoxUnits.Items.Add(" " + i.ToString() + " " + unitID); * }*/ string unitID = Pk2.GetSerialUnitID(); if (unitID == "PIC18F2550") { unitID = "<bootloader>"; } listBoxUnits.Items.Add(" " + i.ToString() + " " + unitID); } else { break; } } }
static public KONST.PICkit2USB WriteProgrammerOs(string ApHexFile, uint Command) { //TODO There is a "Magic Key" in APs and RS that we should check. uint StartAddr = 0; int NumBytes = 0; byte[] Ap; NumBytes = ImportHexFileAsBytes(out Ap, ApHexFile, out StartAddr); NumBytes = AdjustHexFileDataForSend(ref Ap); // Adjust the start address for the programmer StartAddr = StartAddr / 2; // dsPIC has 2 bytes per program word byte[] memObj = new byte[8]; // MemObj start address memObj[0] = Convert.ToByte(StartAddr & 0xFF); memObj[1] = Convert.ToByte((StartAddr >> 8) & 0xFF); memObj[2] = Convert.ToByte((StartAddr >> 16) & 0xFF); memObj[3] = Convert.ToByte((StartAddr >> 24) & 0xFF); // MemObj length in bytes uint RangeInBytes = (uint)Ap.Length; memObj[4] = Convert.ToByte(RangeInBytes & 0xFF); memObj[5] = Convert.ToByte((RangeInBytes >> 8) & 0xFF); memObj[6] = Convert.ToByte((RangeInBytes >> 16) & 0xFF); memObj[7] = Convert.ToByte((RangeInBytes >> 24) & 0xFF); SendCommandWithData(Command, memObj); SendBulkData(Ap); // The programmer will restart now, so we need to reinit comms Thread.Sleep(2000); KONST.PICkit2USB res = KONST.PICkit2USB.notFound; while (res == KONST.PICkit2USB.notFound) { res = Pk3.DetectPICkit2Device(FormPICkit2.pk2number, true); Thread.Sleep(500); // Delay a bit so we don't hammer the programmer } //Initialize(); return(res); }