Example #1
0
        }// Constructor()

        //---------------------------------------------------------------------
        // Constructor()
        //---------------------------------------------------------------------
        public clsParseSettings(int piBootloaderSizeR, clsDevice pobjDevice, bool pbIgnoreOverwrit, bool pbNoGoto)
        {
            bootloaderSizeR  = piBootloaderSizeR;
            device           = pobjDevice;
            allowBlOverwrite = pbIgnoreOverwrit;
            noGoto           = pbNoGoto;
        }// Constructor()
        }// Constructor()


 		//---------------------------------------------------------------------
		// Constructor()
		//---------------------------------------------------------------------
		public clsParseSettings( int piBootloaderSizeR, clsDevice pobjDevice, bool pbIgnoreOverwrit, bool pbNoGoto )
		{
            bootloaderSizeR = piBootloaderSizeR;
            device = pobjDevice;
            allowBlOverwrite = pbIgnoreOverwrit;
            noGoto = pbNoGoto;
        }// Constructor()
Example #3
0
        }        // Constructor()

        //---------------------------------------------------------------------
        // BytesToWrite()
        //---------------------------------------------------------------------
        override public int BytesToWrite(clsDevice pobjDevice, bool pbWriteProgram, bool pbWriteEEPROM, bool pbWriteConfigs)
        {
            return
                (Convert.ToInt32(pbWriteProgram) * (iProgPagesUsed * pobjDevice.pageSizeR * pobjDevice.rowsizeW * 3) +
                 Convert.ToInt32(pbWriteConfigs) * iConfigWordsUsed * 2
                );
        }        // BytesToWrite()
        }// Constructor()


        //---------------------------------------------------------------------
        // BytesToWrite()
        //---------------------------------------------------------------------
        override public int BytesToWrite( clsDevice pobjDevice, bool pbWriteProgram, bool pbWriteEEPROM, bool pbWriteConfigs ) 
        {
            return 
                    Convert.ToInt32( pbWriteProgram ) * ( iProgRowsUsed * pobjDevice.rowsizeW * 3 ) + 
                    Convert.ToInt32( pbWriteEEPROM  ) * iEEWordsUsed * 2 + 
                    Convert.ToInt32( pbWriteConfigs ) * iConfigWordsUsed * 2
            ;
        }// BytesToWrite()
Example #5
0
        }//Property: rowSizeW


        //---------------------------------------------------------------------
        // DeviceAdd()
        // Description: adds a device to this devicefamily
        //---------------------------------------------------------------------
        public void DeviceAdd(clsDevice pobjDevice, ref bool pbResult)
        {
            // Check for existence
            if (DeviceExists(pobjDevice.id) == true)
            {
                pbResult = false;
                return;
            }

            //
            htDevices.Add(pobjDevice.id, pobjDevice);
            pbResult = true;
        }// DeviceAdd()
        //---------------------------------------------------------------------
        // DeviceAdd()
        // Description: adds a device to this devicefamily
        //---------------------------------------------------------------------
        public void DeviceAdd( clsDevice pobjDevice, ref bool pbResult )
        {
            // Check for existence
            if ( DeviceExists( pobjDevice.id ) == true ) {
                pbResult = false;
                return;
            }

            //
            htDevices.Add( pobjDevice.id, pobjDevice );
            pbResult = true;
        }
Example #7
0
        }//Property: progWordsUsed


        //---------------------------------------------------------------------
        // BytesToWrite()
        //---------------------------------------------------------------------
        virtual public int BytesToWrite(clsDevice pobjDevice, bool pbWriteProgram, bool pbWriteEEPROM, bool pbWriteConfigs)
        {
            return(0);
        }        // BytesToWrite()
 //---------------------------------------------------------------------
 // BytesToWrite()
 //---------------------------------------------------------------------
 public override int BytesToWrite( clsDevice pobjDevice, bool pbWriteProgram, bool pbWriteEEPROM, bool pbWriteConfigs )
 {
     return
         Convert.ToInt32(pbWriteProgram) * (iProgPagesUsed * pobjDevice.pageSizeR * pobjDevice.rowsizeW * 3) +
         Convert.ToInt32(pbWriteConfigs ) * iConfigWordsUsed * 2
     ;
 }
 //---------------------------------------------------------------------
 // BytesToWrite()
 //---------------------------------------------------------------------
 public virtual int BytesToWrite( clsDevice pobjDevice, bool pbWriteProgram, bool pbWriteEEPROM, bool pbWriteConfigs )
 {
     return 0;
 }
        }// PrintHelp()


        //-------------------------------------------------------------------------
        // ValidateParseArgs()
        //-------------------------------------------------------------------------
        private void ValidateParseArgs( string[] pstrArgs, clsParseSettings pobjParseSettings, clsDownloadSettings pobjDownloadSettings, ref bool pbResult ) 
        {
            pbResult = false;

            //
            string [] strSplitArgs;
            string strOption;
            string strOptionValue;
            string strArgument;

            //
            bool bFileSpecified = false;
            bool bPortSpecified = false;
            bool bBaudrateSpecified = false;
            bool bDeviceSpecified = false;


            foreach ( string strArg in pstrArgs ) {
                //
                strArgument = strArg;
                if ( strArg.EndsWith("=") ) {
                    strArgument += "0";
                }
                strSplitArgs = strArgument.Split('=');
                
                // Argument                
                strOption = strSplitArgs[0].ToLower();
                
                // Argument value
                if ( strSplitArgs.Length == 2 ) {
                    strOptionValue = strSplitArgs[1];
                } else if (strSplitArgs.Length == 1 ) {
                    strOptionValue = "";
                } else {
                    Console.WriteLine( "Invalid argument: " + strArg );
                    return;
                }

                switch ( strOption ) {
                    //---------------------------------------------------------
                    // Misc
                    //---------------------------------------------------------

                    // Help
                    case "-h":
                    case "--help":
                        PrintHelp();
                        return;

                    // Debugmode
                    case "-l":
                    case "--debugmode":
                        clsds30Loader.debugMode = true;
                        return;

                    // Non-interactive
                    case "-o":
                    case "--non-interactive":
                        bNonInteractive = true;
                        return;

                    
                    //---------------------------------------------------------
                    // Basic
                    //---------------------------------------------------------

                    // Devicename
                    case "-d":
                    case "--device":
                        objDevice = clsDevices.DeviceGet( strOptionValue );
                        if ( objDevice == null ) {
                            Console.WriteLine( "Unknown device specified." );
                            return;
                        }
                        bDeviceSpecified = true;
                        break;

                    // Hex-file
                    case "-f":
                    case "--file":
                        strFile = strOptionValue;    
                        if ( File.Exists(strFile) == false ) {
                            Console.WriteLine( "Non-existing file specified." );
                            return;
                        }
                        bFileSpecified = true;
                        
                        break;                        

                    // Portname
                    case "-k":
                    case "--port":
                        strPort = strOptionValue;
                        bPortSpecified = true;
                        break; 
                    
                    // Baudrate
                    case "-r":
                    case "--baudrate":
                        try {
                            iBaudrate = int.Parse( strOptionValue );
                        } catch {
                            Console.WriteLine( "Invalid baudrate specified." );
                            return;
                        }
                        if ( iBaudrate <= 0 ) {
                            Console.WriteLine( "Invalid baudrate specified." );
                            return;
                        }
                        bBaudrateSpecified = true;
                        break;
                    
                    // Write program
                    case "-p":
                    case "--write-program":
                        pobjDownloadSettings.writeProgram = true;
                        break;
                    
                    // Write eeprom
                    case "-e":
                    case "--write-eeprom":
                        pobjDownloadSettings.writeEEPROM = true;
                        break;                    
                    

                    //---------------------------------------------------------
                    // Advanced
                    //---------------------------------------------------------

                    // Write configs
                    case "-c":
                    case "--write-configs":
                        pobjDownloadSettings.writeConfigs = true;
                        break;
                    
                    // Don't write goto
                    case "-g":
                    case "--no-goto":
                        pobjParseSettings.noGoto = true;
                        pobjDownloadSettings.noGoto = true;
                        break;
                     
                    // Allow overwrite of bootloader
                    case "-s":
                    case "--allow-bl-overwrite":
                        pobjParseSettings.allowBlOverwrite = true;
                        pobjDownloadSettings.allowBlOverwrite = true;
                        break;
                   

                    //---------------------------------------------------------
                    // Timing
                    //---------------------------------------------------------

                    // Polltime
                    case "-a":
                    case "--polltime":
                        int iPolltime;
                        try {
                            iPolltime = int.Parse( strOptionValue );
                        } catch {
                            Console.WriteLine( "Invalid polltime specified." );
                            return;
                        }
                        if ( iPolltime <= 0 ) {
                            Console.WriteLine( "Invalid polltime specified." );
                            return;
                        }
                        pobjDownloadSettings.polltime = iPolltime;
                        break;
                    
                    // Timeout
                    case "-t":
                    case "--timeout":
                        int iTimeout;
                        try {
                            iTimeout = int.Parse( strOptionValue );
                        } catch {
                            Console.WriteLine( "Invalid timeout specified." );
                            return;
                        }
                        if ( iTimeout <= 0 ) {
                            Console.WriteLine( "Invalid timeout specified." );
                            return;
                        }
                        pobjDownloadSettings.timeout = iTimeout;
                        break;


                    //---------------------------------------------------------
                    // Reset
                    //---------------------------------------------------------

                    // Reset by command
                    case "-q":
                    case "--reset-command":
                        pobjDownloadSettings.resetCommand = true;
                        pobjDownloadSettings.resetCommandSequence = strOptionValue;
                        break;

                     // Reset baudrate
                    case "-u":
                    case "--reset-baudrate":
                        int iResetBaudrate;
                        try {
                            iResetBaudrate = int.Parse( strOptionValue );
                        } catch {
                            Console.WriteLine( "Invalid reset baudrate specified." );
                            return;
                        }
                        if ( iResetBaudrate <= 0 ) {
                            Console.WriteLine( "Invalid reset baudrate specified." );
                            return;
                        }
                        pobjDownloadSettings.resetBaudrate = iResetBaudrate;
                        break;
                   
                    // Reset by dtr
                    case "-m":
                    case "--reset-dtr":
                        pobjDownloadSettings.resetDtr = true;
                        break;

                    // Reset by rts
                    case "-n":
                    case "--reset-rts":
                        pobjDownloadSettings.resetRts = true;
                        break;
                    
                    // Resettime
                    case "-b":
                    case "--resettime":
                        int iResettime;
                        try {
                            iResettime = int.Parse( strOptionValue );
                        } catch {
                            Console.WriteLine( "Invalid resettime specified." );
                            return;
                        }
                        if ( iResettime <= 0 ) {
                            Console.WriteLine( "Invalid resettime specified." );
                            return;
                        }
                        pobjDownloadSettings.resetTime = iResettime;
                        break;


                    //---------------------------------------------------------
                    // Activation
                    //---------------------------------------------------------

                    // Activate by dtr
                    case "-i":
                    case "--activate-dtr":
                        pobjDownloadSettings.activateDTR = true;
                        break;

                    // Activate by rts
                    case "-j":
                    case "--activate-rts":
                        pobjDownloadSettings.activateRTS = true;
                        break;


                    //---------------------------------------------------------
                    // Unknown option
                    //---------------------------------------------------------
                    default:
                        Console.WriteLine( "Unknown option \"" + strArg + "\"" );
                        Console.WriteLine( "" );
                        return;

                }
            }

            if ( bFileSpecified == false ) {
                Console.WriteLine( "File not specified" );
                return;
            }
            if ( bPortSpecified == false ) {
                Console.WriteLine( "Port not specified" );
                return;
            }
            if ( bBaudrateSpecified == false ) {
                Console.WriteLine( "Baudrate not specified" );
                return;
            }
            if ( bDeviceSpecified == false ) {
                Console.WriteLine( "Device not specified" );
                return;
            }

            pbResult = true;
        }// ValidateParseArgs()
		}// Constructor()
				

        //---------------------------------------------------------------------
		// BytesToWrite()
		//---------------------------------------------------------------------
		override public int BytesToWrite( clsDevice pobjDevice, bool pbWriteProgram, bool pbWriteEEPROM, bool pbWriteConfigs )
		{
			return Convert.ToInt32(pbWriteProgram) * (iProgPagesUsed * pobjDevice.pageSizeR * pobjDevice.rowsizeW * 2);  
		}// BytesToWrite()
        //---------------------------------------------------------------------
        // Download()
        //---------------------------------------------------------------------
        public static void Download( clsDevice pobjDevice, clsSerialPort pobjPort, clsHex pobjHex, clsDownloadSettings pobjSettings, int iTabLevel, ref bool pbResult )
        {
            //
            bool bWriteSuccess = false;
            bool bParseResult = false;

            pbResult = false;
            bAbort = false;
            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.started, "Initiating download...", iTabLevel++) );

            // Test-mode
            if ( bTestMode == true ) {
                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.warning, "Test-mode is active", iTabLevel) );
            }

            //--------------------------------------------------------------------------
            // Reset device
            //--------------------------------------------------------------------------
            bool bResetResult = false;
            ResetDevice( pobjPort, pobjSettings, iTabLevel, ref bResetResult );
            if ( bResetResult == false ) {
                return;
            }

            //--------------------------------------------------------------------------
            // Open port
            //--------------------------------------------------------------------------
            bool bOpenPortResult = false;
            PortOpen( pobjPort, pobjSettings, ref bOpenPortResult );

            //--------------------------------------------------------------------------
            // Find loader
            //--------------------------------------------------------------------------
            bool bFindLoaderResult = false;
            FindLoader( pobjDevice, pobjPort, pobjSettings, iTabLevel, ref bFindLoaderResult );
            if ( bFindLoaderResult == false ) {
                PortClose( pobjPort );
                return;
            }

            //--------------------------------------------------------------------------
            // Init progressbar
            //--------------------------------------------------------------------------
            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.progressStarted, "", 0) );

            //--------------------------------------------------------------------------
            // Determine size of the bootloader found
            //--------------------------------------------------------------------------
            bool bGetBLSizeResult = false;
            iBootloaderSizeR = GetBLSize( pobjDevice, ref bGetBLSizeResult );
            if ( bGetBLSizeResult == false ) {
                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Unknown firmware version", iTabLevel) );
                PortClose( pobjPort );
                return;
            }

            //--------------------------------------------------------------------------
            //
            //--------------------------------------------------------------------------
            bool WaitBLReadyResponseResult = false;
            WaitBLReadyResponse( pobjPort, iTabLevel, ref WaitBLReadyResponseResult );
            if ( WaitBLReadyResponseResult == false ) {
                PortClose( pobjPort );
                return;
            }

            //--------------------------------------------------------------------------
            // Setup parse settings
            //--------------------------------------------------------------------------
            clsParseSettings objParseSettings = new clsParseSettings( iBootloaderSizeR, pobjDevice, false, pobjSettings.noGoto );

            //--------------------------------------------------------------------------
            // PIC18F
            //--------------------------------------------------------------------------
            if ( pobjDevice.family.name == "PIC18F" ) {
                clsHex18F objHex18F = (clsHex18F)pobjHex;

                // Parse
                objHex18F.ParseHexFile( objParseSettings, iTabLevel, ref bParseResult );
                if ( bParseResult == false ) {
                    PortClose( pobjPort );
                    return;
                }

                // Write versions 0.9.0 - 1.0.0
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 2 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 1 )
                ) {
                    bWriteSuccess = WriteFlash18F_0_9_0( pobjPort, pobjDevice, objHex18F, pobjSettings.writeProgram, pobjSettings.writeEEPROM, pobjSettings.writeConfigs, iTabLevel );

                    // Write versions 1.5
                } else if (
                    ( iFWVerMaj == 1 && iFWVerMin == 5 )
                ) {
                    bWriteSuccess = WriteFlash18F_0_9_0( pobjPort, pobjDevice, objHex18F, pobjSettings.writeProgram, false, false, iTabLevel );

                // Unkown version
                } else {
                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Unknown firmware version", iTabLevel) );
                    PortClose( pobjPort );
                    return;
                }

            //--------------------------------------------------------------------------
            // PIC18FJ
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "PIC18FJ" ) {
                clsHex18FJ objHex18FJ = (clsHex18FJ)pobjHex;

                // Parse
                objHex18FJ.ParseHexFile( objParseSettings, iTabLevel, ref bParseResult );
                if ( bParseResult == false ) {
                    PortClose( pobjPort );
                    return;
                }

                // Write versions 0.9.0 - 0.9.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 )
                ) {
                    bWriteSuccess = WriteFlash18FJ_0_9_0( pobjPort, pobjDevice, objHex18FJ, pobjSettings.writeProgram, iTabLevel );

                // Unkown version
                } else {
                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Unknown firmware version", iTabLevel) );
                    PortClose( pobjPort );
                    return;
                }

            //--------------------------------------------------------------------------
            // PIC24F
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "PIC24F" ) {
                clsHex24F objHex24F = (clsHex24F)pobjHex;

                // Parse
                objHex24F.ParseHexFile( objParseSettings, iTabLevel, ref bParseResult );
                if ( bParseResult == false ) {
                    PortClose( pobjPort );
                    return;
                }

                // Write versions 0.9.0 - 0.9.0
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 )
                ) {
                    bWriteSuccess = WriteFlash24F_0_9_0( pobjPort, pobjDevice, objHex24F, pobjSettings.writeProgram, pobjSettings.writeEEPROM, pobjSettings.writeConfigs, iTabLevel );

                // Unkown version
                } else {
                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Unknown firmware version", iTabLevel) );
                    PortClose( pobjPort );
                    return;
                }

            //--------------------------------------------------------------------------
            // PIC24FJ
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "PIC24FJ" ) {
                clsHex24FJ objHex24FJ = (clsHex24FJ)pobjHex;

                // Parse
                objHex24FJ.ParseHexFile( objParseSettings, iTabLevel, ref bParseResult );
                if ( bParseResult == false ) {
                    PortClose( pobjPort );
                    return;
                }

                // Write versions 0.9.0 - 1.0.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 2 )
                ) {
                    bWriteSuccess = WriteFlash24FJ_1_0_0( pobjPort, pobjDevice, objHex24FJ, pobjSettings.writeProgram, pobjSettings.writeEEPROM, pobjSettings.writeConfigs, iTabLevel );

                // Unkown version
                } else {
                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Unknown firmware version", iTabLevel) );
                    PortClose( pobjPort );
                    return;
                }

            //--------------------------------------------------------------------------
            // PIC24H
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "PIC24H" ) {
                clsHex24H objHex24H = (clsHex24H)pobjHex;

                // Parse
                objHex24H.ParseHexFile( objParseSettings, iTabLevel, ref bParseResult );
                if ( bParseResult == false ) {
                    PortClose( pobjPort );
                    return;
                }

                // Write versions 0.9.0 - 0.9.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 )
                ) {
                    bWriteSuccess = WriteFlash24H_0_9_0( pobjPort, pobjDevice, objHex24H, pobjSettings.writeProgram, pobjSettings.writeConfigs, iTabLevel );

                // Unkown version
                } else {
                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Unknown firmware version", iTabLevel) );
                    PortClose( pobjPort );
                    return;
                }

            //--------------------------------------------------------------------------
            // dsPIC30F
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "dsPIC30F" ) {
                clsHex30F objHex30F = (clsHex30F)pobjHex;

                // Parse
                objHex30F.ParseHexFile( objParseSettings, iTabLevel, ref bParseResult );
                if ( bParseResult == false ) {
                    PortClose( pobjPort );
                    return;
                }

                // Write versions 0.9.4 - 1.0.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 4 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 1 )
                ) {
                    bWriteSuccess = WriteFlash30_1_0_1( pobjPort, pobjDevice, objHex30F, pobjSettings.writeProgram, pobjSettings.writeEEPROM, pobjSettings.writeConfigs, iTabLevel );

                // Versions 2.0.0 - 2.0.2
                } else if (
                    ( iFWVerMaj == 2 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 2 && iFWVerMin == 0 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 2 && iFWVerMin == 0 && iFWVerRev == 2 )
                ) {
                    bWriteSuccess = WriteFlash30_2_0_0( pobjPort, pobjDevice, objHex30F, pobjSettings.writeProgram, pobjSettings.writeEEPROM, pobjSettings.writeConfigs, iTabLevel );

                // Unkown version
                } else {
                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Unknown firmware version", iTabLevel) );
                    PortClose( pobjPort );
                    return;
                }

            //--------------------------------------------------------------------------
            // dsPIC33F
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "dsPIC33FJ" ) {
                clsHex33FJ objHex33F = (clsHex33FJ)pobjHex;

                // Parse
                objHex33F.ParseHexFile( objParseSettings, iTabLevel, ref bParseResult );
                if ( bParseResult == false ) {
                    PortClose( pobjPort );
                    return;
                }

                // Write vrsions 0.9.0 - 1.0.0
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 2 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 3 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 4 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 2 )
                ) {
                    bWriteSuccess = WriteFlash33_1_0_0( pobjPort, pobjDevice, objHex33F, pobjSettings.writeProgram, pobjSettings.writeConfigs, iTabLevel );

                // Unkown version
                } else {
                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Unknown firmware version", iTabLevel) );
                    PortClose( pobjPort );
                    return;
                }
            }

            //--------------------------------------------------------------------------
            // Download completed
            //--------------------------------------------------------------------------
            pobjPort.Close();

            if ( bWriteSuccess == true ) {
                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.completed, "Download finished", iTabLevel) );
            }

            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.progressEnded, "", 0) );
            pbResult = bWriteSuccess;
        }
        }// DeviceGet()

               
 		//---------------------------------------------------------------------
		// Init()
		// Description:
		//---------------------------------------------------------------------
		static public void Init()
		{   
            bool bDeviceAddResult = false;
            bool bDeviceFamilyAddResult = false;
			//
			htDeviceFamilys = new Hashtable( 7 );			
			
			// Add devices and devicefamilies, this should be read from xml some day
			clsDeviceFamily objDeviceFamily;
			clsDevice objDevice;


            //-----------------------------------------------------------------
            // PIC18F
            //-----------------------------------------------------------------
            objDeviceFamily = new clsDeviceFamily( "PIC18F", 2, 16); DeviceFamilyAdd(objDeviceFamily, ref bDeviceFamilyAddResult );

            objDevice = new clsDevice( objDeviceFamily, 301, "1220", 0x1000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 302, "1230", 0x1000, 128, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 303, "2220", 0x1000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 304, "2221", 0x1000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 305, "4220", 0x1000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 306, "4221", 0x1000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 307, "1320", 0x2000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 308, "1330", 0x2000, 128, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 309, "13K22",0x2000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 310, "13K50",0x2000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 311, "2320", 0x2000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 312, "2321", 0x2000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 313, "2331", 0x2000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 314, "23K20",0x2000, 256, 16, 4, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 315, "4320", 0x2000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 316, "4321", 0x2000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 317, "4331", 0x2000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 318, "43K20",0x2000, 256, 16, 4, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 319, "14K22",0x4000, 256, 16, 4,  8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 320, "14K50",0x4000, 256, 16, 4,  8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 321, "2420", 0x4000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 322, "2423", 0x4000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 323, "2431", 0x4000, 256, 16, 8,  4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 324, "2450", 0x4000,   0, 16, 4,  8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 325, "2480", 0x4000, 256, 16, 8,  4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 326, "24K20",0x4000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 327, "4420", 0x4000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 328, "4423", 0x4000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 329, "4431", 0x4000, 256, 16, 8,  4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 330, "4450", 0x4000,   0, 16, 4,  8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 331, "4480", 0x4000, 256, 16, 8,  4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 332, "44K20",0x4000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 333, "2455", 0x6000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 334, "2458", 0x6000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 335, "4455", 0x6000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 336, "4458", 0x6000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 337, "2520", 0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 338, "2523", 0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 339, "2550", 0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 340, "2553", 0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 341, "2580", 0x8000, 256, 16, 8,  4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 342, "25K20",0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 343, "4520", 0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 344, "4523", 0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 345, "4550", 0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 346, "4553", 0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 347, "4580", 0x8000, 256, 16, 8,  4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 348, "45K20",0x8000, 256, 16, 2, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 349, "6520", 0x8000,1024, 16, 8,  4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 350, "8520", 0x8000,1024, 16, 8,  4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 351, "2525", 0xC000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 352, "2585", 0xC000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 353, "4525", 0xC000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 354, "4585", 0xC000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 355, "6527", 0xC000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 356, "8527", 0xC000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 357, "2620", 0x10000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 358, "2680", 0x10000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 359, "26K20",0x10000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 360, "4620", 0x10000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 361, "4680", 0x10000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 362, "46K20",0x10000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 363, "6622", 0x10000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 364, "8622", 0x10000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 365, "2682", 0x14000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 366, "4682", 0x14000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 367, "2685", 0x18000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 368, "4685", 0x18000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 369, "6627", 0x18000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 370, "6628", 0x18000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 371, "8627", 0x18000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 372, "8628", 0x18000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 373, "6722", 0x20000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 374, "6723", 0x20000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 375, "8722", 0x20000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 376, "8723", 0x20000, 1024, 16, 1, 32 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 377, "452", 0x8000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 378, "458", 0x8000, 256, 16, 8, 4 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );


            //-----------------------------------------------------------------
            // PIC18FJ
            //-----------------------------------------------------------------
            objDeviceFamily = new clsDeviceFamily( "PIC18FJ", 16, 32); DeviceFamilyAdd(objDeviceFamily, ref bDeviceFamilyAddResult);

            objDevice = new clsDevice( objDeviceFamily, 400, "63J11", 0x2000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 401, "63J90", 0x2000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 402, "83J11", 0x2000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 403, "83J90", 0x2000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 404, "24J10", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 405, "24J11", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 406, "24J50", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 407, "44J10", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 408, "44J11", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 409, "44J50", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 410, "64J11", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 411, "64J90", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 412, "84J11", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 413, "84J90", 0x4000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 414, "25J10", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 415, "25J11", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 416, "25J50", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 417, "45J10", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 418, "45J11", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 419, "45J50", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 420, "65J10", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 421, "65J11", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 422, "65J50", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 423, "65J90", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 424, "85J10", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 425, "85J11", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 426, "85J50", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 427, "85J90", 0x8000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 428, "65J15", 0xC000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 429, "85J15", 0xC000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 430, "26J11", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 431, "26J50", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 432, "46J11", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 433, "46J50", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 434, "66J10", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 435, "66J11", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 436, "66J50", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 437, "66J60", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 438, "66J90", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 439, "66J93", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 440, "86J10", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 441, "86J11", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 442, "86J50", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 443, "86J60", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 444, "86J90", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 445, "86J93", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 446, "96J60", 0x10000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 447, "66J15", 0x18000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 448, "66J16", 0x18000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 449, "66J55", 0x18000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 450, "66J65", 0x18000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 451, "86J15", 0x18000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 452, "86J16", 0x18000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 453, "86J55", 0x18000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 454, "86J65", 0x18000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 455, "96J65", 0x18000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 456, "67J10", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 457, "67J11", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 458, "67J50", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 459, "67J60", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 460, "67J90", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 461, "67J93", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 462, "87J10", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 463, "87J11", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 464, "87J50", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 465, "87J60", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 466, "87J90", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 467, "87J93", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 468, "97J60", 0x20000, 0, 16 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );


            //-----------------------------------------------------------------
            // PIC24F
            //-----------------------------------------------------------------
            objDeviceFamily = new clsDeviceFamily( "PIC24F", 1, 32); DeviceFamilyAdd(objDeviceFamily, ref bDeviceFamilyAddResult);

            objDevice = new clsDevice( objDeviceFamily, 200, "04KA200", 0xB00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 201, "04KA201", 0xB00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 202, "08KA101", 0x1600, 512, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 203, "08KA102", 0x1600, 512, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 204, "16KA101", 0x2C00, 512, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 205, "16KA102", 0x2C00, 512, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            
            //-----------------------------------------------------------------
            // PIC24FJ
            //-----------------------------------------------------------------
            objDeviceFamily = new clsDeviceFamily( "PIC24FJ", 8, 64); DeviceFamilyAdd(objDeviceFamily, ref bDeviceFamilyAddResult);

            objDevice = new clsDevice( objDeviceFamily, 206, "16GA002", 0x2C00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 207, "16GA004", 0x2C00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            
            objDevice = new clsDevice( objDeviceFamily, 208, "32GA002", 0x5800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 209, "32GA004", 0x5800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 210, "48GA002", 0x8400, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 211, "48GA004", 0x8400, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 212, "64GA002", 0xAC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 213, "64GA004", 0xAC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 214, "64GA006", 0xAC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 215, "64GA008", 0xAC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 216, "64GA010", 0xAC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 217, "64GB106", 0xAC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 218, "64GB108", 0xAC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 219, "64GB110", 0xAC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 220, "96GA006", 0x10000, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 221, "96GA008", 0x10000, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 222, "96GA010", 0x10000, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 223, "128GA006", 0x15800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 224, "128GA008", 0x15800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 225, "128GA010", 0x15800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 226, "128GA106", 0x15800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 227, "128GA108", 0x15800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 228, "128GA110", 0x15800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 229, "128GB106", 0x15800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 230, "128GB108", 0x15800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 231, "128GB110", 0x15800, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 232, "192GA106", 0x20C00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 233, "192GA108", 0x20C00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 234, "192GA110", 0x20C00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 235, "192GB106", 0x20C00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 236, "192GB108", 0x20C00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 237, "192GB110", 0x20C00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 238, "256GA106", 0x2AC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 239, "256GA108", 0x2AC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 240, "256GA110", 0x2AC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 241, "256GB106", 0x2AC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 242, "256GB108", 0x2AC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 243, "256GB110", 0x2AC00, 0, 0 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            //-----------------------------------------------------------------
            // PIC24H
            //-----------------------------------------------------------------
            objDeviceFamily = new clsDeviceFamily( "PIC24H", 8, 64); DeviceFamilyAdd(objDeviceFamily, ref bDeviceFamilyAddResult );

            objDevice = new clsDevice( objDeviceFamily, 40, "J12GP201", 0x2000, 0, 7 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 41, "J12GP202", 0x2000, 0, 7 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 42, "J16GP304", 0x2C00, 0, 7 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 43, "J32GP202", 0x5800, 0, 7 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 44, "J32GP204", 0x5800, 0, 7 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 45, "J32GP302", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 46, "J32GP304", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            
            objDevice = new clsDevice( objDeviceFamily, 47, "J64GP202", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 48, "J64GP204", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 49, "J64GP206", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 50, "J64GP210", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 51, "J64GP210A", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 52, "J64GP502", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 53, "J64GP504", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 54, "J64GP506", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 55, "J64GP506A", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 56, "J64GP510", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 57, "J64GP510A", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 58, "J128GP202", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 59, "J128GP204", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 60, "J128GP206", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 61, "J128GP210", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 62, "J128GP210A", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 63, "J128GP306", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 64, "J128GP310", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 65, "J128GP310A", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 66, "J128GP502", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 67, "J128GP504", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 68, "J128GP506", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 69, "J128GP506A", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 70, "J128GP510", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 71, "J128GP510A", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

            objDevice = new clsDevice( objDeviceFamily, 72, "J256GP206", 0x2AC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 73, "J256GP210", 0x2AC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
            objDevice = new clsDevice( objDeviceFamily, 74, "J256GP610", 0x2AC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );


            //-----------------------------------------------------------------
			// dsPIC30F
            //-----------------------------------------------------------------
			objDeviceFamily = new clsDeviceFamily( "dsPIC30F", 1, 32 ); DeviceFamilyAdd( objDeviceFamily, ref bDeviceFamilyAddResult );		
			
			objDevice = new clsDevice( objDeviceFamily, 30, "1010", 0x1000, 0, 7 );		objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			
			objDevice = new clsDevice( objDeviceFamily, 10, "2010", 8192, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 20, "2011", 8192, 0, 5 );		objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 22, "2012", 8192, 0, 5 );		objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );			
			objDevice = new clsDevice( objDeviceFamily, 31, "2020", 8192, 0, 7);		objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );			
			objDevice = new clsDevice( objDeviceFamily, 32, "2023", 8192, 0, 7 );		objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );						
			
			objDevice = new clsDevice( objDeviceFamily, 11, "3010", 16384, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 13, "3011", 16384, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );			
			objDevice = new clsDevice( objDeviceFamily, 21, "3012", 16384, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 23, "3013", 16384, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily,  1, "3014", 16384, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			
			objDevice = new clsDevice( objDeviceFamily, 14, "4011", 32768, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );			
			objDevice = new clsDevice( objDeviceFamily, 12, "4012", 32768, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily,  2, "4013", 32768, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			
			objDevice = new clsDevice( objDeviceFamily,  3, "5011", 45056, 1024, 7 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily,  6, "5013", 45056, 1024, 7 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 15, "5015", 45056, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 33, "5016", 45056, 1024, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			
			objDevice = new clsDevice( objDeviceFamily, 16, "6010", 98304, 4096, 7 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily,  4, "6011", 90112, 2048, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily,  4, "6011A", 90112, 2048, 7 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily,  5, "6012", 98304, 4096, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );			
			objDevice = new clsDevice( objDeviceFamily,  5, "6012A", 98304, 4096, 7 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );			
			objDevice = new clsDevice( objDeviceFamily,  7, "6013", 90112, 2048, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );			
			objDevice = new clsDevice( objDeviceFamily,  7, "6013A", 90112, 2048, 7 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );			
			objDevice = new clsDevice( objDeviceFamily,  8, "6014", 98304, 4096, 5 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );		
			objDevice = new clsDevice( objDeviceFamily,  8, "6014A", 98304, 4096, 7 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );		
			objDevice = new clsDevice( objDeviceFamily, 34, "6015", 98304, 4096, 7 );	objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );


            //-----------------------------------------------------------------
			// dsPIC33FJ
            //-----------------------------------------------------------------
			objDeviceFamily = new clsDeviceFamily( "dsPIC33FJ", 8, 64 ); DeviceFamilyAdd( objDeviceFamily, ref bDeviceFamilyAddResult );
						
			objDevice = new clsDevice( objDeviceFamily, 100, "06GS101", 0x1000, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 101, "06GS102", 0x1000, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 102, "06GS202", 0x1000, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

			objDevice = new clsDevice( objDeviceFamily, 110, "12GP201", 0x2000, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 111, "12GP202", 0x2000, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 112, "12MC201", 0x2000, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 113, "12MC202", 0x2000, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

			objDevice = new clsDevice( objDeviceFamily, 120, "16GP304", 0x2C00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 121, "16GS402", 0x2C00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 122, "16GS404", 0x2C00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 123, "16GS502", 0x2C00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 124, "16GS504", 0x2C00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 125, "16MC304", 0x2C00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

			objDevice = new clsDevice( objDeviceFamily, 130, "32GP202", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 131, "32GP204", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 132, "32GP302", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 133, "32GP304", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 134, "32MC202", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 135, "32MC204", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 136, "32MC302", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 137, "32MC304", 0x5800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

			objDevice = new clsDevice( objDeviceFamily, 140, "64GP202", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 141, "64GP204", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 142, "64GP206", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 143, "64GP306", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 144, "64GP310", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 145, "64GP706", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 146, "64GP706A", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 147, "64GP708", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 148, "64GP710", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 149, "64GP802", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 150, "64GP804", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 151, "64MC202", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 152, "64MC204", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 153, "64MC506", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 154, "64MC508", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 155, "64MC510", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 156, "64MC510A", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 157, "64MC706", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 158, "64MC710", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 159, "64MC802", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 160, "64MC804", 0xAC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

			objDevice = new clsDevice( objDeviceFamily, 170, "128GP202", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 171, "128GP204", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 172, "128GP206", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 173, "128GP206A", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 174, "128GP306", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 175, "128GP306A", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 176, "128GP310", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 177, "128GP706", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 178, "128GP708", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 179, "128GP710", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 180, "128GP802", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 181, "128GP804", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 182, "128MC202", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 183, "128MC204", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 184, "128MC506", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 185, "128MC510", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 186, "128MC706", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 187, "128MC708", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 188, "128MC710", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 189, "128MC802", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 190, "128MC804", 0x15800, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

			objDevice = new clsDevice( objDeviceFamily, 195, "256GP506", 0x2AC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 196, "256GP510", 0x2AC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 197, "256GP710", 0x2AC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 198, "256MC510", 0x2AC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );
			objDevice = new clsDevice( objDeviceFamily, 199, "256MC710", 0x2AC00, 0, 8 ); objDeviceFamily.DeviceAdd( objDevice, ref bDeviceAddResult );

        }// DeviceFamilyGet()	  		
        //---------------------------------------------------------------------
        // GetBLSize()
        //---------------------------------------------------------------------
        private static int GetBLSize( clsDevice pobjDevice, ref bool pbResult )
        {
            int iBootloaderSizeR = 0;

            //--------------------------------------------------------------------------
            // PIC18F
            //--------------------------------------------------------------------------
            if ( pobjDevice.family.name == "PIC18F" ) {
                // Firmware version 0.9.0 - 0.9.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 )
                ){
                    iBootloaderSizeR = pobjDevice.pageSizeR * 4;    //bl size is 4 pages, rowsize varies among devices

                // Firmware version 0.9.2 - 1.0.0
                } else if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 2 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 2 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 1 )
                ){
                    iBootloaderSizeR = pobjDevice.pageSizeR * 5;    //bl size is 5 pages, rowsize varies among devices

                // Firmware version 1.5 - 1.5
                } else if (
                    ( iFWVerMaj == 1 && iFWVerMin == 5 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 5 )
                ){
                    iBootloaderSizeR = pobjDevice.pageSizeR * 3;    //bl size is 3 pages, rowsize varies among devices

                // Unknown firmware version
                } else {
                    pbResult = false;
                    return 0;
                }

            //--------------------------------------------------------------------------
            // PIC18FJ
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "PIC18FJ" ) {
                // Firmware version 0.9.0 - 0.9.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 )
                ){
                    iBootloaderSizeR = 16;

                // Unknown firmware version
                } else {
                    pbResult = false;
                    return 0;
                }

            //--------------------------------------------------------------------------
            // PIC24F
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "PIC24F" ) {
                // Firmware version 0.9.0 - 0.9.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1  )
                ){
                    iBootloaderSizeR = 4;

                // Unknown firmware version
                } else {
                    pbResult = false;
                    return 0;
                }

            //--------------------------------------------------------------------------
            // PIC24FJ
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "PIC24FJ" ) {
                // Firmware version 0.9.0 - 1.0.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 2 )
                ){
                    iBootloaderSizeR = 8;

                // Unknown firmware version
                } else {
                    pbResult = false;
                    return 0;
                }

            //--------------------------------------------------------------------------
            // PIC24H
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "PIC24H" ) {
                // Firmware version 0.9.0 - 0.9.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 )
                ){
                    iBootloaderSizeR = 8;

                // Unknown firmware version
                } else {
                    pbResult = false;
                    return 0;
                }

            //--------------------------------------------------------------------------
            // dsPIC30F
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "dsPIC30F" ) {
                // Firmware version 0.9.4 - 1.0.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 4 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 1 )
                ) {
                    iBootloaderSizeR = 3;

                // Firmware version 2.0.0 - 2.0.2
                } else if (
                    ( iFWVerMaj == 2 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 2 && iFWVerMin == 0 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 2 && iFWVerMin == 0 && iFWVerRev == 2 )
                ) {
                    iBootloaderSizeR = 4;

                // Unknown firmware version
                } else {
                    pbResult = false;
                    return 0;
                }

            //--------------------------------------------------------------------------
            // dsPIC33F
            //--------------------------------------------------------------------------
            } else if ( pobjDevice.family.name == "dsPIC33FJ" ) {
                // Firmware version 0.9.0 - 1.0.1
                if (
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 2 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 3 ) ||
                    ( iFWVerMaj == 0 && iFWVerMin == 9 && iFWVerRev == 4 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 0 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 1 ) ||
                    ( iFWVerMaj == 1 && iFWVerMin == 0 && iFWVerRev == 2 )
                ) {
                    iBootloaderSizeR = 8;

                // Unknown firmware version
                } else {
                    pbResult = false;
                    return 0;
                }
            }

            pbResult = true;
            return iBootloaderSizeR;
        }
        //---------------------------------------------------------------------
        // FindLoader()
        //---------------------------------------------------------------------
        public static void FindLoader( clsDevice pobjDevice, clsSerialPort pobjPort , clsDownloadSettings pobjSettings, int iTabLevel, ref bool pbResult )
        {
            int iDeviceIdFound = -1;
            bool bGetResponseResult = false;
            bool bPortWasOpened = false;

            pbResult = false;

            //-----------------------------------------------------------------
            // Test-mode
            //-----------------------------------------------------------------
            if ( bTestMode == true ) {
                iFWVerMaj = iTestVerMaj;
                iFWVerMin = iTestVerMin;
                iFWVerRev = iTestVerRev;
                iDeviceIdFound = iTestDeviceID;
                //return true;

            //-----------------------------------------------------------------
            // Real-mode
            //-----------------------------------------------------------------
            } else {

                int iVerMaj = 0, iVerMinRev = 0;
                int iTimeIdReceived = 0;

                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Searching for bl ", iTabLevel) );

                //--------------------------------------------------------------------------
                // Open port if not open
                //--------------------------------------------------------------------------
                if ( pobjPort.isOpen == false ) {
                    pobjPort.Open();
                    if ( pobjPort.isOpen == false ) {
                        OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Failed to open port", iTabLevel) );
                        return;
                    }
                    bPortWasOpened = true;
                }

                // Empty buffers prior to hello command incase there's some crap
                pobjPort.EmptyBuffers( true, false );

                //--------------------------------------------------------------------------
                // Send hello to bootloader
                //--------------------------------------------------------------------------
                bool bDeviceIDReceived = false;
                {
                    int iLastSend = Environment.TickCount - pobjSettings.polltime;
                    int iLastPoll = Environment.TickCount - pobjSettings.polltime;
                    int iStartTime = Environment.TickCount;

                    bool bByteReceived = false;

                    bool bTimedOut = false;

                    do {
                        // Check first byte, discard if null
                        if ( Environment.TickCount - iLastPoll >= pobjSettings.polltime/10) {
                            iLastPoll = Environment.TickCount;

                            if ( bByteReceived == false && pobjPort.inBufferCount > 0 ) {
                                bByteReceived = true;
                                iDeviceIdFound = GetResponse( pobjPort, ref bGetResponseResult );
                                if ( bGetResponseResult == false ) {
                                    if ( bPortWasOpened == true ) pobjPort.Close();
                                    return;
                                }
                                if ( iDeviceIdFound == 0 ) {
                                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "(discarded null byte)", -1) );
                                } else {
                                    bDeviceIDReceived = true;
                                    iTimeIdReceived = Environment.TickCount;
                                    break;
                                }

                            }
                        }

                        // Send hello
                       if ( Environment.TickCount - iLastSend >= pobjSettings.polltime ) {
                            iLastSend = Environment.TickCount;
                            pobjPort.SendByte( cHello );
                            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, ". ", -1) );
                        }

                        // Check for timeout
                        bTimedOut = ( Environment.TickCount - iStartTime >= pobjSettings.timeout );

                        // Handle message queue
                        Application.DoEvents();
                    } while (
                        bAbort == false &&
                        bTimedOut == false &&
                        (bByteReceived == false || pobjPort.inBufferCount == 0)
                    );

                    if ( bAbort == true  ) {
                        OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "aborted", -1) );
                        bAbort = false;
                        if ( bPortWasOpened == true ) pobjPort.Close();
                        return;
                    } else if ( bTimedOut == true ) {
                        OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "timed out", -1) );
                        if ( bPortWasOpened == true ) pobjPort.Close();
                        return;
                    }
                }

                //--------------------------------------------------------------------------
                // Read device id
                //--------------------------------------------------------------------------
                if ( bDeviceIDReceived == false ) {
                    iDeviceIdFound = GetResponse( pobjPort, ref bGetResponseResult );
                    if ( bGetResponseResult == false ) {
                        iTimeIdReceived = Environment.TickCount;
                        if ( bPortWasOpened == true ) pobjPort.Close();
                        return;
                    }
                }

                //--------------------------------------------------------------------------
                // Delay to receive firmware version if any
                //--------------------------------------------------------------------------
                int iTime = 1 + 30000 / pobjPort.baudrate;
                while ( Environment.TickCount - iTimeIdReceived < iTime && pobjPort.inBufferCount < 3 ) {
                }

                //--------------------------------------------------------------------------
                // Firmware doesn´t send version, assume 0.9.4
                //--------------------------------------------------------------------------
                if ( pobjPort.inBufferCount == 1 ) {
                        iFWVerMaj = 0;
                        iFWVerMin = 9;
                        iFWVerRev = 4;

                //--------------------------------------------------------------------------
                // Firmware that sends major and minor
                //--------------------------------------------------------------------------
                } else if ( pobjPort.inBufferCount == 2 ) {
                    iVerMaj = GetResponse( pobjPort, ref bGetResponseResult );
                    if ( bGetResponseResult == false ) {
                        if ( bPortWasOpened == true ) pobjPort.Close();
                        return;
                    }
                    iFWVerMaj = ( (iVerMaj & 0x70) >> 4 );
                    iFWVerMin = ( iVerMaj & 0xF );
                    iFWVerRev = 0;

                //--------------------------------------------------------------------------
                // Firmware that sends major, minor and revision
                //--------------------------------------------------------------------------
                } else if ( pobjPort.inBufferCount == 3 ) {
                    iVerMaj = GetResponse( pobjPort, ref bGetResponseResult );
                    if ( bGetResponseResult == false ) {
                        if ( bPortWasOpened == true ) pobjPort.Close();
                        return;
                    }
                    iVerMinRev = GetResponse( pobjPort, ref bGetResponseResult );
                    if ( bGetResponseResult == false ) {
                        if ( bPortWasOpened == true ) pobjPort.Close();
                        return;
                    }

                    iFWVerMaj = ( iVerMaj & 0x7F );
                    iFWVerMin = ( (iVerMinRev & 0xF0) >> 4 );
                    iFWVerRev = ( iVerMinRev & 0xF );
                }

                //--------------------------------------------------------------------------
                // PIC18 indicated by msb in fw ver major
                //--------------------------------------------------------------------------
                if ( (iVerMaj & 0x80) > 0 ) {
                    iDeviceIdFound += 300;
                }
            }//Test-/real-mode

            //--------------------------------------------------------------------------
            // Find device from device id
            //--------------------------------------------------------------------------
            clsDevice objFoundDevice = clsDevices.DeviceGet( iDeviceIdFound );

            //--------------------------------------------------------------------------
            // Invalid ID returned
            //--------------------------------------------------------------------------
            if ( objFoundDevice == null ) {
                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Found unknown device id(" + iDeviceIdFound.ToString() + ") fw ver. " + iFWVerMaj.ToString() + "." + iFWVerMin.ToString() + "." + iFWVerRev.ToString(), iTabLevel) );
                if ( bPortWasOpened == true ) pobjPort.Close();
                return;
            }

            //--------------------------------------------------------------------------
            // Bootloader found
            //--------------------------------------------------------------------------
            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.success, "Found " + objFoundDevice.name + " fw ver. " + iFWVerMaj.ToString() + "." + iFWVerMin.ToString() + "." + iFWVerRev.ToString(), iTabLevel) );

            //--------------------------------------------------------------------------
            // Different device found from choosen
            //--------------------------------------------------------------------------
            if ( objFoundDevice.id != pobjDevice.id ) {
                OnDownloading(new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "Wrong pic detected(" + objFoundDevice.id.ToString() + ")/selected(" + pobjDevice.id.ToString() + "), aborting", iTabLevel));
                if ( bPortWasOpened == true ) pobjPort.Close();
                return;
            }

            pbResult = true;

            // Close port if it was openeed
            if ( bPortWasOpened == true ) {
                pobjPort.Close();
            }
        }
        //---------------------------------------------------------------------
        // WriteFlash33_1_0_0()
        //---------------------------------------------------------------------
        private static bool WriteFlash33_1_0_0(clsSerialPort pobjPort, clsDevice pobjDevice, clsHex33FJ pobjHex, bool pbWriteProgram, bool pbWriteConfigs, int iTabLevel)
        {
            //--------------------------------------------------------------------------
            // Variables
            //--------------------------------------------------------------------------
            int iChecksum;
            int iSum;
            int iAddrP;
            int iRetries;
            byte[] bBuffer = new byte[256];
            int iBufferIndx;
            byte bAddrU, bAddrH, bAddrL, bSize, bProg;
            bool bRetry = false;
            int iByteToWrite = pobjHex.BytesToWrite( pobjDevice, pbWriteProgram, false, pbWriteConfigs );
            int iBytesWritten = 0;
            bool bProcessWriteResponseResult = false;

            //--------------------------------------------------------------------------
            // Write flash
            //--------------------------------------------------------------------------
            int iRow;

            if ( pbWriteProgram == true ) {
                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing flash...", iTabLevel) );

                //-------------------------------------------------------------
                // Iterate pages
                //-------------------------------------------------------------
                for ( int iPage = 0; iPage < clsHex33FJ.iProgPageUsedBufferSize; iPage++ ) {
                    if ( pobjHex.bProgPageUsed[iPage] == true ) {
                        iRetries = 0;
                        do {
                            if ( clsds30Loader.debugMode ) {
                                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Erasing page " + iPage.ToString(), iTabLevel) );
                            }

                            //---------------------------------------------------------
                            // Erase page
                            //---------------------------------------------------------
                            iSum = 0;
                            iBufferIndx = 0;

                            // Calculate
                            iAddrP = iPage * pobjDevice.pageSizeR * pobjDevice.rowsizeW * 2;	//24-bit address in memory to write to
                            bAddrU = Convert.ToByte((iAddrP & 0xff0000) >> 16);				//address upper byte
                            bAddrH = Convert.ToByte((iAddrP & 0x00ff00) >> 8);				//address high byte
                            bAddrL = Convert.ToByte((iAddrP & 0x0000ff) >> 0);				//address low byte
                            bSize = Convert.ToByte(1/*checksum*/ );

                            //
                            bBuffer[iBufferIndx++] = bAddrU; iSum += bAddrU;
                            bBuffer[iBufferIndx++] = bAddrH; iSum += bAddrH;
                            bBuffer[iBufferIndx++] = bAddrL; iSum += bAddrL;
                            bBuffer[iBufferIndx++] = cCmdErasePage; iSum += cCmdErasePage;
                            bBuffer[iBufferIndx++] = bSize; iSum += bSize;

                            // Calculate checksum and add to buffer
                            iSum %= 256;
                            iChecksum = Convert.ToInt16((256 - iSum) % 256);
                            bBuffer[iBufferIndx++] = Convert.ToByte(iChecksum);

                            // Send address, command, packetsize & checksum
                            pobjPort.SendBytes(ref bBuffer, iBufferIndx);

                            // Get response, checksum ok
                            ProcessWriteResponse( pobjPort, ref iRetries, iTabLevel, "flash", ref bRetry, ref bProcessWriteResponseResult );
                            if ( bProcessWriteResponseResult == false ) {
                                return false;
                            }

                            //
                            Application.DoEvents();
                        } while (bRetry == true && bAbort == false);

                        //---------------------------------------------------------
                        // Iterate rows, write all rows in page even if not in hex-file
                        //---------------------------------------------------------
                        for ( iRow = iPage * pobjDevice.pageSizeR; iRow < iPage * pobjDevice.pageSizeR + pobjDevice.pageSizeR; iRow++ ) {
                            iRetries = 0;
                            do {
                                if ( clsds30Loader.debugMode ) {
                                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing row " + iRow.ToString(), iTabLevel) );
                                }

                                iBufferIndx = 0;
                                iSum = 0;

                                // Calculate
                                iAddrP = iRow * (pobjDevice.rowsizeW * 2);				//24-bit address in memory to write to
                                bAddrU = Convert.ToByte((iAddrP & 0xff0000) >> 16);	    //address upper byte
                                bAddrH = Convert.ToByte((iAddrP & 0x00ff00) >> 8);	    //address high byte
                                bAddrL = Convert.ToByte((iAddrP & 0x0000ff));			//address low byte
                                bSize = Convert.ToByte(pobjDevice.rowsizeW * 3 + 1/*checksum*/ );

                                //
                                bBuffer[iBufferIndx++] = bAddrU; iSum += bAddrU;
                                bBuffer[iBufferIndx++] = bAddrH; iSum += bAddrH;
                                bBuffer[iBufferIndx++] = bAddrL; iSum += bAddrL;
                                bBuffer[iBufferIndx++] = cCmdWriteRow; iSum += cCmdWriteRow;
                                bBuffer[iBufferIndx++] = bSize; iSum += bSize;

                                // Calculate startindex in hex-buffer
                                iAddrP = iRow * pobjDevice.rowsizeW * 3;

                                // Buffer row, upper-low-high, ordered in ParseHex()
                                for ( int iByte = 0; iByte < pobjDevice.rowsizeW * 3; iByte++ ) {
                                    bProg = Convert.ToByte( pobjHex.iProgMem[iAddrP + iByte] );
                                    bBuffer[ iBufferIndx++ ] = bProg; iSum = (iSum + bProg) % 256;
                                }

                                // Calculate checksum and add to buffer
                                iSum %= 256;
                                iChecksum = Convert.ToInt16((256 - iSum) % 256);
                                bBuffer[iBufferIndx++] = Convert.ToByte(iChecksum);

                                // Send address, command, packetsize, row & checksum
                                pobjPort.SendBytes(ref bBuffer, iBufferIndx);

                                // Get response, checksum ok
                                ProcessWriteResponse( pobjPort, ref iRetries, iTabLevel, "flash", ref bRetry, ref bProcessWriteResponseResult );
                                if ( bProcessWriteResponseResult == false ) {
                                    return false;
                                }

                                //
                                Application.DoEvents();
                            } while ( bRetry == true && bAbort == false );

                            //
                            if (bAbort == true) {
                                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "aborted by user", -1) );
                                return false;
                            }

                            //
                            iBytesWritten += pobjDevice.rowsizeW * 3;
                            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.progress, "", (100 * iBytesWritten) / iByteToWrite ) );

                        }//for ( iRow = 0; iRow < iRowUsedBufferSize; iRow++ ) {

                    } //if ( bPageUsed[iIter] == true ) {

                }//for ( iPage = 0; iPage < iPageUsedBufferSize; iPage++ ) {

                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.success, "ok", -1) );
            }//if ( pbWriteProgram == true ) {

            //--------------------------------------------------------------------------
            // Write Config Bits
            //--------------------------------------------------------------------------
            if ( pbWriteConfigs == true ) {
                int iConfig;
                int iByte;
                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing configs...", iTabLevel) );
                iRetries = 0;

                for ( iConfig = 0; iConfig < clsHex33FJ.iConfigWordsUsedBufferSize; iConfig++ ) {
                    if ( pobjHex.bConfigWordUsed[iConfig] == true ) {
                        iRetries = 0;
                        do {
                            for ( iByte = 0; iByte < 2; iByte++ ) {
                                if ( clsds30Loader.debugMode ) {
                                    OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing config byte " + (iConfig*2 + iByte).ToString(), iTabLevel) );
                                }

                                iBufferIndx = 0;
                                iSum = 0;

                                // Calculate
                                iAddrP = 0xF80000 + iConfig * 2 + iByte;				//24-bit address in memory to write to
                                bAddrU = Convert.ToByte( (iAddrP & 0xff0000) >> 16 );	//address upper byte
                                bAddrH = Convert.ToByte( (iAddrP & 0x00ff00) >> 8 );	//address high byte
                                bAddrL = Convert.ToByte( (iAddrP & 0x0000ff) );			//address low byte
                                bSize = Convert.ToByte( 1 + 1/*checksum*/ );

                                //
                                bBuffer[ iBufferIndx++ ] = bAddrU;	iSum += bAddrU;
                                bBuffer[ iBufferIndx++ ] = bAddrH;	iSum += bAddrH;
                                bBuffer[ iBufferIndx++ ] = bAddrL;	iSum += bAddrL;
                                bBuffer[ iBufferIndx++ ] = cCmdWriteConfig;iSum += cCmdWriteConfig;
                                bBuffer[ iBufferIndx++ ] = bSize;	iSum += bSize;

                                // Buffer config word
                                bProg = Convert.ToByte( pobjHex.iConfigMem[ iConfig * 2 + iByte ] );
                                bBuffer[ iBufferIndx++ ] = bProg; iSum = (iSum + bProg) % 256;

                                // Calculate checksum and add to buffer
                                iSum %= 256;
                                iChecksum = Convert.ToInt16( (256 - iSum) % 256 );
                                bBuffer[ iBufferIndx++ ] = Convert.ToByte(iChecksum);

                                // Send row+checksum
                                pobjPort.SendBytes( ref bBuffer, iBufferIndx );

                                // Get response, checksum ok
                                ProcessWriteResponse( pobjPort, ref iRetries, iTabLevel, "flash", ref bRetry, ref bProcessWriteResponseResult );
                                if ( bProcessWriteResponseResult == false ) {
                                    return false;
                                }
                            }
                            Application.DoEvents();
                        } while ( bRetry == true && bAbort == false );

                        //
                        if ( bAbort == true ) {
                            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "aborted by user", -1) );
                            return false;
                        }

                        //
                        iBytesWritten += 2;
                        OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.progress, "", (100 * iBytesWritten) / iByteToWrite ) );
                    }//if ( bConfigUsed[iIter] == true ) {

                }//for ( iIter = 0;  iIter < iConfigUsedBufferSize; iIter++ ) {

                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.success, "ok", -1) );
            }//if ( bWriteConfigs == true )

            //--------------------------------------------------------------------------
            // Write completed
            //--------------------------------------------------------------------------
            return true;
        }
        //---------------------------------------------------------------------
        // WriteFlash30_1_0_1()
        //---------------------------------------------------------------------
        private static bool WriteFlash30_1_0_1( clsSerialPort pobjPort, clsDevice pobjDevice, clsHex30F pobjHex, bool pbWriteProgram, bool pbWriteEEPROM, bool pbWriteConfigs, int iTabLevel )
        {
            //--------------------------------------------------------------------------
            // Variables
            //--------------------------------------------------------------------------
            int iIter2;
            int iChecksum;
            int iSum;
            int iAddrP;
            int iRetries;
            byte [] bBuffer = new byte [256];
            int iBufferIndx;
            byte bAddrU, bAddrH, bAddrL, bSize, bProg;
            bool bRetry = false;
            int iByteToWrite = pobjHex.BytesToWrite( pobjDevice, pbWriteProgram, pbWriteEEPROM, pbWriteConfigs );
            int iBytesWritten = 0;
            bool bProcessWriteResponseResult = false;

            //--------------------------------------------------------------------------
            // Write flash
            //--------------------------------------------------------------------------
            if ( pbWriteProgram == true ) {
                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing flash...", iTabLevel) );

                //-------------------------------------------------------------
                // Iterate rows
                //-------------------------------------------------------------
                for ( int iRow = 0; iRow < clsHex30F.iProgRowsUsedBufferSize; iRow++ ) {
                    if ( pobjHex.bProgRowUsed[iRow] == true ) {
                        iRetries = 0;
                        do {
                            if ( clsds30Loader.debugMode ) {
                                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing row " + iRow.ToString(), iTabLevel) );
                            }

                            iBufferIndx = 0;
                            iSum = 0;

                            // Calculate
                            iAddrP = iRow * (pobjDevice.rowsizeW * 2);				//24-bit address in memory to write to
                            bAddrU = Convert.ToByte( (iAddrP & 0xff0000) >> 16 );	//address upper byte
                            bAddrH = Convert.ToByte( (iAddrP & 0x00ff00) >> 8 );	//address high byte
                            bAddrL = Convert.ToByte( (iAddrP & 0x0000ff) );			//address low byte
                            bSize = Convert.ToByte( pobjDevice.rowsizeW * 3 + 1/*checksum*/ );

                            //
                            bBuffer[ iBufferIndx++ ] = bAddrU;	iSum += bAddrU;
                            bBuffer[ iBufferIndx++ ] = bAddrH;	iSum += bAddrH;
                            bBuffer[ iBufferIndx++ ] = bAddrL;	iSum += bAddrL;
                            bBuffer[ iBufferIndx++ ] = bSize;	iSum += bSize;

                            // Calculate startindex in hex-buffer
                            iAddrP = iRow * pobjDevice.rowsizeW * 3;

                            // Buffer row, upper-low-high, ordered in ParseHex()
                            for ( int iByte = 0; iByte < pobjDevice.rowsizeW*3; iByte++ ) {
                                bProg = Convert.ToByte( pobjHex.iProgMem[iAddrP + iByte] );
                                bBuffer[ iBufferIndx++ ] = bProg; iSum = (iSum + bProg) % 256;
                            }

                            // Calculate checksum and add to buffer
                            iSum %= 256;
                            iChecksum = Convert.ToInt16( (256 - iSum) % 256 );
                            bBuffer[ iBufferIndx++ ] = Convert.ToByte(iChecksum);

                            // Send address, command, packetsize, row & checksum
                            pobjPort.SendBytes( ref bBuffer, iBufferIndx );

                            // Get response, checksum ok
                            ProcessWriteResponse( pobjPort, ref iRetries, iTabLevel, "flash", ref bRetry, ref bProcessWriteResponseResult );
                            if ( bProcessWriteResponseResult == false ) {
                                return false;
                            }

                            //
                            Application.DoEvents();
                        } while ( bRetry == true && bAbort == false );

                        //
                        if ( bAbort == true ) {
                            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "aborted by user", -1) );
                            return false;
                        }

                        //
                        iBytesWritten += pobjDevice.rowsizeW * 3;
                        OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.progress, "", (100 * iBytesWritten) / iByteToWrite ) );

                    } //if ( bProgRowUsed[iIter] == true ) {
                }//for ( iRow = 0; iRow < iProgRowUsedBufferSize; iRow++ ) {

                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.success, "ok", -1) );
            }//if ( pbWriteProgram == true ) {

            //--------------------------------------------------------------------------
            // Write EEPROM
            //--------------------------------------------------------------------------
            if ( pbWriteEEPROM == true ) {
                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing eeprom...", iTabLevel) );

                for ( int iEEPROMWord = 0; iEEPROMWord < pobjDevice.eepromSizeB/2; iEEPROMWord++ ) {
                    if (  pobjHex.bEEWordUsed[iEEPROMWord] == true ) {
                        iRetries = 0;

                        do {
                            if ( clsds30Loader.debugMode ) {
                                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing eeprom word " + iEEPROMWord.ToString(), iTabLevel) );
                            }

                            iBufferIndx = 0;
                            iSum = 0;

                            // Calculate
                            iAddrP = pobjDevice.eepromStartAddress + iEEPROMWord * 2;		//24-bit address in memory to write to
                            bAddrU = Convert.ToByte( (iAddrP & 0xff0000) >> 16 );	//address upper byte
                            bAddrH = Convert.ToByte( (iAddrP & 0x00ff00) >> 8 );	//address high byte
                            bAddrL = Convert.ToByte( (iAddrP & 0x0000ff) );			//address low byte
                            bSize = Convert.ToByte( 2 + 1/*checksum*/ );

                            //
                            bBuffer[ iBufferIndx++ ] = bAddrU;	iSum += bAddrU;
                            bBuffer[ iBufferIndx++ ] = bAddrH;	iSum += bAddrH;
                            bBuffer[ iBufferIndx++ ] = bAddrL;	iSum += bAddrL;
                            bBuffer[ iBufferIndx++ ] = bSize;	iSum += bSize;

                            // Low byte
                            bProg = Convert.ToByte( pobjHex.iEEMem[iEEPROMWord*2 + 0] );
                            bBuffer[ iBufferIndx++ ] = bProg; iSum = (iSum + bProg) % 256;

                            // High byte
                            bProg = Convert.ToByte( pobjHex.iEEMem[iEEPROMWord*2 + 1] );
                            bBuffer[ iBufferIndx++ ] = bProg; iSum = (iSum + bProg) % 256;

                            // Calculate checksum and add to buffer
                            iSum %= 256;
                            iChecksum = Convert.ToInt16( (256 - iSum) % 256 );
                            bBuffer[ iBufferIndx++ ] = Convert.ToByte(iChecksum);

                            // Send row+checksum
                            pobjPort.SendBytes( ref bBuffer, iBufferIndx );

                            // Get response, checksum ok
                            ProcessWriteResponse( pobjPort, ref iRetries, iTabLevel, "flash", ref bRetry, ref bProcessWriteResponseResult );
                            if ( bProcessWriteResponseResult == false ) {
                                return false;
                            }

                            //
                            Application.DoEvents();
                        } while ( bRetry == true && bAbort == false );

                        //
                        if ( bAbort == true ) {
                            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "aborted by user", -1) );
                            return false;
                        }

                        //
                        iBytesWritten += 2;
                        OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.progress, "", (100 * iBytesWritten) / iByteToWrite ) );
                     }//if (  bEEWordUsed[iEEPROMWord] == true ) {

                }//for ( iIter = 0; iIter < pobjDevice.eepromSizeB/2; iIter++ ) {

                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.success, "ok", -1) );
            }//if ( pbWriteEEPROM == true ) {

            //--------------------------------------------------------------------------
            // Write Config Bits
            //--------------------------------------------------------------------------
            if ( pbWriteConfigs == true ) {
                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing configs...", iTabLevel) );

                for ( int iConfig = 0;  iConfig < clsHex30F.iConfigWordsUsedBufferSize; iConfig++ ) {
                    if ( pobjHex.bConfigWordUsed[iConfig] == true ) {
                        iRetries = 0;

                        do {
                            if ( clsds30Loader.debugMode ) {
                                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.info, "Writing config word " + iConfig.ToString(), iTabLevel) );
                            }

                            iBufferIndx = 0;
                            iSum = 0;

                            // Calculate
                            iAddrP = 0xF80000 + iConfig * 2;						//24-bit address in memory to write to
                            bAddrU = Convert.ToByte( (iAddrP & 0xff0000) >> 16 );	//address upper byte
                            bAddrH = Convert.ToByte( (iAddrP & 0x00ff00) >> 8 );	//address high byte
                            bAddrL = Convert.ToByte( (iAddrP & 0x0000ff) );			//address low byte
                            bSize = Convert.ToByte( 2 + 1/*checksum*/ );

                            //
                            bBuffer[ iBufferIndx++ ] = bAddrU;	iSum += bAddrU;
                            bBuffer[ iBufferIndx++ ] = bAddrH;	iSum += bAddrH;
                            bBuffer[ iBufferIndx++ ] = bAddrL;	iSum += bAddrL;
                            bBuffer[ iBufferIndx++ ] = bSize;	iSum += bSize;

                            // Buffer config word
                            for ( iIter2 = 0; iIter2 < 2; iIter2++ ) {
                                bProg = Convert.ToByte( pobjHex.iConfigMem[ iConfig * 2 + iIter2 ] );
                                bBuffer[ iBufferIndx++ ] = bProg; iSum = (iSum + bProg) % 256;
                            }

                            // Calculate checksum and add to buffer
                            iSum %= 256;
                            iChecksum = Convert.ToInt16( (256 - iSum) % 256 );
                            bBuffer[ iBufferIndx++ ] = Convert.ToByte(iChecksum);

                            // Send row+checksum
                            pobjPort.SendBytes( ref bBuffer, iBufferIndx );

                            // Get response, checksum ok
                            ProcessWriteResponse( pobjPort, ref iRetries, iTabLevel, "flash", ref bRetry, ref bProcessWriteResponseResult );
                            if ( bProcessWriteResponseResult == false ) {
                                return false;
                            }

                            //
                            Application.DoEvents();
                        } while ( bRetry == true && bAbort == false );

                        //
                        if ( bAbort == true ) {
                            OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.error, "aborted by user", -1) );
                            return false;
                        }

                        //
                        iBytesWritten += 2;
                        OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.progress, "", (100 * iBytesWritten) / iByteToWrite ) );
                    }//if ( bConfigWordUsed[iIter] == true ) {

                }//for ( iIter = 0;  iIter < iConfigUsedBufferSize; iIter++ ) {

                OnDownloading( new clsDownloadingEventArgs(clsDownloadingEventArgs.EventType.success, "ok", -1) );
            }//if ( bWriteConfigs == true )

            //--------------------------------------------------------------------------
            // Write completed
            //--------------------------------------------------------------------------
            return true;
        }