예제 #1
0
        private void buttonI2Cread_Click(object sender, EventArgs e)
        {
            listBoxProgramMessages.Items.Clear();

            USB_I2C_Flash i2cflash = null;

            switch (comboBoxI2CFlashType.Text)
            {
            case "Microchip 24FC256":
                i2cflash = new USB_24FC256();
                break;
            }
            if (i2cflash == null)
            {
                postMessage("No flash type selected");
                return;
            }

            List <string> msgs      = new List <string>();
            bool          connected = i2cflash.connect(msgs);

            postMessages(msgs);

            if (!connected)
            {
                postMessage("Programmer: connection failed");
                return;
            }
            postMessage("Programmer: connected");

            int flashsiz = i2cflash.FlashSize();

            postMessage("FlashInfo: " + flashsiz.ToString() + " bytes flash");

            postMessage("Reading device at address 0 number of bytes " + flashsiz.ToString());
            long tick2 = System.DateTime.Now.Ticks;

            byte[] flashprogrammemory = i2cflash.SequentialRead(0, flashsiz);
            double tock2 = (System.DateTime.Now.Ticks - tick2) / 10000000.0;

            postMessage("Reading took " + tock2.ToString() + "s");

            SaveFileDialog fd = new SaveFileDialog();

            fd.AddExtension = true;
            fd.Filter       = "Raw Binary File (*.bin)|*.bin";
            DialogResult res = fd.ShowDialog();

            if (res == DialogResult.OK)
            {
                RawBinaryfile rbf = new RawBinaryfile(flashprogrammemory);
                rbf.SaveFile(fd.FileName);
            }
        }
예제 #2
0
        public static void Main()
        {
            List <string> msgs = new List <string>();

            USB_24FC256 usb = new USB_24FC256();

            if (!usb.connect(msgs))
            {
                return;
            }

            usb.Address = 0;

            //usb.PageWrite(0, new byte[]{161,162,163,164,165});

            byte ss = usb.RandomRead(0);

            ss = usb.RandomRead(1);
            ss = usb.CurrentAddressRead();

            byte[] b = usb.SequentialRead(0, 512);
        }
예제 #3
0
        private void buttonI2Cprogram_Click(object sender, EventArgs e)
        {
            listBoxProgramMessages.Items.Clear();

            USB_I2C_Flash i2cflash = null;

            switch (comboBoxI2CFlashType.Text)
            {
            case "Microchip 24FC256":
                i2cflash = new USB_24FC256();
                break;
            }
            if (i2cflash == null)
            {
                postMessage("No flash type selected");
                return;
            }

            List <string> msgs      = new List <string>();
            bool          connected = i2cflash.connect(msgs);

            postMessages(msgs);

            if (!connected)
            {
                postMessage("Programmer: connection failed");
                return;
            }
            postMessage("Programmer: connected");

            int flashsiz = i2cflash.FlashSize();

            postMessage("Flash chip info: " + flashsiz.ToString() + " bytes flash memory");

            postMessage("Reading binary file");
            RawBinaryfile rbf = new RawBinaryfile(textBoxI2CFlashHEXFile.Text);

            byte[] hexdata = rbf.GetData();
            postMessage("File info: " + hexdata.Length + " bytes data");

            bool fastWrite = checkBoxI2CfastFlash.Checked;

            int  address = 0;
            long tick2   = System.DateTime.Now.Ticks;

            while ((address < flashsiz) && (address < hexdata.Length))
            {
                int    pagesiz = i2cflash.PageSize(address);
                byte[] buff    = new byte[pagesiz];
                int    copysiz = Math.Min(pagesiz, hexdata.Length - address);
                Array.Copy(hexdata, address, buff, 0, copysiz);

                //postMessage("Writing data at " + address.ToString());
                i2cflash.PageWrite(address, buff, fastWrite);

                address += pagesiz;
            }
            double tock2 = (System.DateTime.Now.Ticks - tick2) / 10000000.0;

            postMessage("Writing took " + tock2.ToString() + "s");

            i2cflash.condition_STOP();
        }