Exemple #1
0
        public static void Example_FixCRC()
        {
            Device MyReader = new Device("COM3", 0x52, SpdSize.DDR4);

            // Read first 126 bytes
            byte[] spdHeader = Eeprom.ReadByte(MyReader, 0, 126);

            // Calculate CRC
            ushort crc = Spd.Crc16(spdHeader);

            // Get LSB (byte 127) and MSB (byte 128)
            byte CrcLsb = (byte)(crc & 0xff);   // CRC LSB at 0x7e for 0-125 range or @ 0xfe for 128-253 range
            byte CrcMsb = (byte)(crc >> 8);     // CRC MSB at 0x7f for 0-125 range or @ 0xff for 128-253 range

            // Compare calculated CRC against SPD data
            if (Eeprom.ReadByte(MyReader, 0x7e, 1)[0] == CrcLsb && Eeprom.ReadByte(MyReader, 0x7f, 1)[0] == CrcMsb)
            {
                // The checksum is correct, do nothing
                return;
            }
            else
            {
                // Write correct values to SPD
                Eeprom.UpdateByte(MyReader, 0x7e, CrcLsb);
                Eeprom.UpdateByte(MyReader, 0x7f, CrcMsb);
            }
            // Note: you'll have to do the same for 128-253 range, checksum bytes are 0xfe and 0xff
        }
Exemple #2
0
        private void enableWriteProtectionMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult _protectConfirmation = MessageBox.Show(
                "You won't be able to write to EEPROM again until the protection is cleared.\n\nAre you sure you want to enable write protection?\n\n",
                "Write protection",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Exclamation,
                MessageBoxDefaultButton.Button2);

            if (_protectConfirmation == DialogResult.No)
            {
                return;
            }

            for (int i = 0; i <= 3; i++)
            {
                if (Eeprom.SetWriteProtection(MySpdReader, i))
                {
                    Logger($"Write protection is set on block {i}");
                }
                else
                {
                    Logger($"Could not set write protection on block {i}");
                }
            }
        }
Exemple #3
0
        public static async Task <Eeprom> ReadEepromAsync(this ISerial serial)
        {
            uint[] values = await serial.GetEpromValuesAsync(SerialExtension.DefaultEpromTimeout);

            if (values != null)
            {
                var ee = new EepromV1 {
                    Values = values
                };

                if (ee.IsValid)
                {
                    File.WriteAllLines(Environment.ExpandEnvironmentVariables(@"%TEMP%\EepromRead.nc"), ee.ToGCode());
                    byte numAxis = ee[EepromV1.EValueOffsets8.NumAxis];

                    var eeprom = Eeprom.Create(ee[EepromV1.EValueOffsets32.Signature], numAxis);
                    eeprom.Values = values;
                    eeprom.ReadFrom(ee);

                    return(eeprom);
                }
            }

            return(null);
        }
Exemple #4
0
        public void Pre()
        {
            this.mRnd = new Random(DateTime.Now.Millisecond);

            this.mMemory = new Eeprom();
            Eeprom.Result result = this.mMemory.Initialize(WordsOnPage, PagesCount);
            Assert.That(result, Is.EqualTo(Eeprom.Result.Success));
        }
Exemple #5
0
        /// <summary>
        /// Erase SPD contents (fill with 0xff's)
        /// </summary>
        public static void Example_EraseSPD()
        {
            Device MyReader = new Device(readerSettings, portName, 0x50, SpdSize.DDR4);

            for (ushort i = 0; i <= (int)MyReader.SpdSize; i++)
            {
                Eeprom.UpdateByte(MyReader, i, 0xff);
                Console.WriteLine(i.ToString());
            }
        }
Exemple #6
0
        public ActionResult <UInt32[]> GetEepromInfo([FromBody] Eeprom eeprom)
        {
            var eePromV1 = new EepromV1()
            {
                Values = eeprom.Values
            };

            eeprom.WriteTo(eePromV1);
            return(Ok(eeprom.Values));
        }
Exemple #7
0
 private void clearWriteProtection(object sender, EventArgs e)
 {
     if (Eeprom.ClearWriteProtection(MySpdReader))
     {
         Logger($"Write protection is cleared on {MySpdReader.PortName}:{MySpdReader.EepromAddress}");
     }
     else
     {
         Logger($"Could not clear write protection on {MySpdReader.PortName}:{MySpdReader.EepromAddress}");
     }
 }
Exemple #8
0
        public static void Example_EraseSPD()
        {
            // Erase SPD contents (fill with 0xff's)
            Device MyReader = new Device("COM3", 0x50, SpdSize.DDR4);

            for (ushort i = 0; i <= (int)MyReader.SpdSize; i++)
            {
                Eeprom.UpdateByte(MyReader, i, 0xff);
                Console.WriteLine(i.ToString());
            }
        }
Exemple #9
0
        private void mnuArduinoPromRead_Click(object sender, EventArgs e)
        {
            string port = ((ToolStripMenuItem)sender).Text;

            ArduinoPromTest(port);

            _eeprom = new Eeprom(ArduinoPromRead(port));

            UpdateFormFromEeprom();

            MessageBox.Show("EEPROM contents read successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemple #10
0
        private void mnuOpen_Click(object sender, EventArgs e)
        {
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Filter = "Xbox EEPROM (*.bin) |*.bin";

                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    _eeprom = new Eeprom(ofd.FileName);
                    UpdateFormFromEeprom();
                }
            }
        }
Exemple #11
0
        private void connectToDevice(object sender, EventArgs e)
        {
            ToolStripMenuItem _sender = (ToolStripMenuItem)sender;

            string _port    = _sender.Text.Split(':')[0];
            int    _address = Int32.Parse(_sender.Text.Split(':')[1]);

            // Disconnect
            if (MySpdReader != null && MySpdReader.IsConnected)
            {
                if (MySpdReader.Disconnect())
                {
                    Logger($"{MySpdReader.PortName}:{MySpdReader.EepromAddress} disconnected");
                }

                if (!MySpdReader.IsConnected)
                {
                    // Uncheck all devices
                    ToolStripItem[] _existingDeviceItem = toolStripDeviceButton.DropDownItems.Find("FoundDevicePortAddress", false);

                    if (_existingDeviceItem.Length > 0)
                    {
                        foreach (ToolStripMenuItem toolStripItem in _existingDeviceItem)
                        {
                            toolStripItem.Checked = false;
                        }
                    }
                    //_sender.Checked = false;
                }

                // Do not reconnect if checked item was clicked
                if (MySpdReader.PortName == _port && MySpdReader.EepromAddress == _address)
                {
                    return;
                }
            }

            // Connect
            if (MySpdReader == null || !MySpdReader.IsConnected)
            {
                MySpdReader         = new Device(_port, _address);
                MySpdReader.SpdSize = Eeprom.GetSpdSize(MySpdReader);
                if (MySpdReader.Connect())
                {
                    _sender.Checked = true;
                    rt = Eeprom.GetRamType(MySpdReader);
                    Logger($"{_port}:{_address} connected ({rt})");
                }
            }
        }
Exemple #12
0
        public async Task <bool> WriteEepromAsync(Eeprom EepromValue)
        {
            var ee = new EepromV1 {
                Values = EepromValue.Values
            };

            if (ee.IsValid)
            {
                EepromValue.WriteTo(ee);

                File.WriteAllLines(Environment.ExpandEnvironmentVariables(@"%TEMP%\EepromWrite.nc"), ee.ToGCode());

                await new MachineGCodeHelper().WriteEepromValuesAsync(ee);
                return(true);
            }
            return(false);
        }
Exemple #13
0
        public static async Task <bool> WriteEepromAsync(this ISerial serial, Eeprom eepromValue)
        {
            var ee = new EepromV1 {
                Values = eepromValue.Values
            };

            if (ee.IsValid)
            {
                eepromValue.WriteTo(ee);

                File.WriteAllLines(Environment.ExpandEnvironmentVariables(@"%TEMP%\EepromWrite.nc"), ee.ToGCode());

                await serial.WriteEepromValuesAsync(ee);

                return(true);
            }

            return(false);
        }
Exemple #14
0
        public static void Example_DuplicateRam()
        {
            // Copy SPD contents from one DIMM to another
            Device source      = new Device("COM3", 80, SpdSize.DDR4);
            Device destination = new Device("COM4", 82, source.SpdSize);

            for (ushort i = 0; i < (int)source.SpdSize; i++)
            {
                Eeprom.WriteByte(destination, i, Eeprom.ReadByte(source, i));
            }

            // Verify contents
            for (ushort i = 0; i < (int)source.SpdSize; i++)
            {
                if (Eeprom.ReadByte(source, i) != Eeprom.ReadByte(destination, i))
                {
                    // Mismatched contents detected
                }
            }
        }
Exemple #15
0
        private void saveToFile(object sender, EventArgs e)
        {
            if (SpdContents.Length == 0)
            {
                Logger("No SPD loaded");
                return;
            }

            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.Filter           = "Binary files (*.bin)|*.bin|SPD Dumps (*.spd)|*.spd|All files (*.*)|*.*";
            saveFileDialog.FilterIndex      = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.FileName         = Eeprom.GetModuleModelName(SpdContents);

            if (saveFileDialog.ShowDialog() == DialogResult.OK && saveFileDialog.FileName != "")
            {
                currentFileName = saveFileDialog.FileName;
                File.WriteAllBytes(currentFileName, SpdContents);
                Logger($"Saved {SpdContents.Length} byte(s) to '{currentFileName}'");
            }
        }
Exemple #16
0
        public static void Example_BasicUse()
        {
            // Initialize the device
            Device myDevice = new Device("COM3");

            //myDevice.Connect();

            // Test if the device responds (optional)
            myDevice.Test();

            // Set EEPROM address to 80 (0x50)
            myDevice.EepromAddress = 80;

            // Make sure the address is valid (optional)
            myDevice.ProbeAddress(myDevice.EepromAddress);
            myDevice.ProbeAddress(); // You can omit the address if myDevice already has "EepromAddress" set

            // Set SPD size to DDR4's EEPROM size (512 bytes)
            myDevice.SpdSize = SpdSize.DDR4;

            // The device can also be initialized in one line, like so:
            Device myOtherDevice = new Device("COM3", 80, SpdSize.DDR4);

            // Read first byte at offset 0
            byte firstByte = Eeprom.ReadByte(myDevice, 0);

            // Read last byte (located at offset 511, not 512!)
            byte lastByte = Eeprom.ReadByte(myDevice, (ushort)(myDevice.SpdSize - 1));

            // Read the entire EEPROM (this will take a bit longer, about 1-5 seconds)
            byte[] spdDump = Eeprom.ReadByte(myDevice, 0, (int)myDevice.SpdSize);

            // When you're done, disconnect
            myDevice.Disconnect();

            // Attempt to read  once we're disconnected (this will fail)
            Eeprom.ReadByte(myDevice, 0, (int)SpdSize.DDR4);
        }
Exemple #17
0
        public async Task <Eeprom> ReadEepromAsync()
        {
            UInt32[] values = await new MachineGCodeHelper().GetEpromValuesAsync(MachineGCodeHelper.DefaultEpromTimeout);
            if (values != null)
            {
                var ee = new EepromV1 {
                    Values = values
                };

                if (ee.IsValid)
                {
                    File.WriteAllLines(Environment.ExpandEnvironmentVariables(@"%TEMP%\EepromRead.nc"), ee.ToGCode());
                    byte numaxis = ee[EepromV1.EValueOffsets8.NumAxis];

                    var eeprom = Eeprom.Create(ee[EepromV1.EValueOffsets32.Signatrue], numaxis);
                    eeprom.Values = values;
                    eeprom.ReadFrom(ee);

                    return(eeprom);
                }
            }
            return(null);
        }
Exemple #18
0
        private void readSpdFromEeprom(object sender, EventArgs e)
        {
            int start = Environment.TickCount;

            // Clear viewer
            //displayContents(new byte[0]);

            SpdContents = new byte[(int)MySpdReader.SpdSize];

            statusProgressBar.Value   = 0;
            statusProgressBar.Maximum = SpdContents.Length;

            // Read each byte to display status in the progress bar
            for (int i = 0; i < SpdContents.Length; i++)
            {
                SpdContents[i]          = Eeprom.ReadByte(MySpdReader, i);
                statusProgressBar.Value = i + 1;
                Application.DoEvents();
            }

            int stop = Environment.TickCount;

            if (SpdContents.Length > 0)
            {
                // Reset file name
                currentFileName = "";
                displayContents(SpdContents);
                crcValidChecksum = validateCrc(SpdContents);
                tabPageMain.Text = $"{MySpdReader.PortName}:{MySpdReader.EepromAddress}";
                if (tabControlMain.SelectedTab != tabPageMain)
                {
                    tabPageMain.Text = $"* {tabPageMain.Text}";
                }
            }

            Logger($"Read SPD ({SpdContents.Length} bytes) from {MySpdReader.PortName}:{MySpdReader.EepromAddress} in {stop - start} ms");
        }
Exemple #19
0
        static void ParseCommand(string[] args)
        {
            string mode = args[0];

            if (mode == "/help")
            {
                ShowHelp();
                return;
            }

            try {
                // Setup
                SerialPortSettings readerSettings = new SerialPortSettings(
                    115200,
                    true,
                    true,
                    8,
                    Handshake.None,
                    "\n",
                    Parity.None,
                    StopBits.One,
                    true,
                    10);

                // Find
                if (mode == "/find")
                {
                    // Find
                    string[] devices = new Device(readerSettings).Find();
                    if (devices.Length > 0)
                    {
                        foreach (string portName in devices)
                        {
                            Console.WriteLine($"Found Device on Serial Port: {portName}\n");
                        }
                    }
                    else
                    {
                        throw new Exception("Nothing found");
                    }
                    return;
                }

                // Other functions that require additional parameters
                if (mode != "/find" && args.Length >= 2)
                {
                    // Init
                    string portName = args[1];

                    if (!portName.StartsWith("COM"))
                    {
                        throw new Exception("Port name should start with \"COM\" followed by a number.");
                    }

                    Device reader = new Device(readerSettings, portName);

                    if (!reader.Connect())
                    {
                        throw new Exception($"Could not connect to the device on port {portName}.");
                    }

                    if (reader.GetFirmwareVersion() < SpdReaderWriterDll.Settings.MINVERSION)
                    {
                        throw new Exception($"The device on port {portName} requires its firmware to be updated.");
                    }

                    //if (!reader.Test()) {
                    //	throw new Exception($"The device on port {portName} does not respond.");
                    //}

                    // Scan
                    if (mode == "/scan")
                    {
                        byte[] addresses = reader.Scan();

                        if (addresses.Length == 0)
                        {
                            throw new Exception("No EEPROM devices found.");
                        }

                        foreach (int location in addresses)
                        {
                            Console.WriteLine($"Found EEPROM at address: {location}");
                        }

                        reader.Disconnect();
                        return;
                    }

                    // Test reversible write protection capabilities
                    if (mode == "/enablewriteprotection" || mode == "/disablewriteprotection")
                    {
                        if (!reader.TestAdvancedFeatures())
                        {
                            throw new Exception("Your device does not support write protection features.");
                        }

                        // Turn on write protection
                        if (mode == "/enablewriteprotection")
                        {
                            int[] block;

                            if (args.Length == 3)   // Block # was specified
                            {
                                try {
                                    block = new[] { (Int32.Parse(args[2])) };
                                }
                                catch {
                                    throw new Exception("Block number should be specified in decimal notation.");
                                }
                            }
                            else   // No block number specified, protect all available
                            {
                                if (Spd.GetRamType(reader) == RamType.DDR4)
                                {
                                    block = new[] { 0, 1, 2, 3 };
                                }
                                else   // DDR3 + DDR2
                                {
                                    block = new[] { 0 };
                                }
                            }

                            reader.ResetAddressPins();

                            for (int i = 0; i < block.Length; i++)
                            {
                                if (Eeprom.SetWriteProtection(reader, i))
                                {
                                    Console.WriteLine($"Block {i} is now read-only");
                                }
                                else
                                {
                                    throw new Exception($"Unable to set write protection for block {i}. Either SA0 is not connected to HV, or the block is already read-only.");
                                }
                            }

                            return;
                        }

                        // Disable write protection
                        if (mode == "/disablewriteprotection")
                        {
                            reader.SetAddressPin(Pin.SA1, PinState.HIGH);

                            if (Eeprom.ClearWriteProtection(reader))
                            {
                                Console.WriteLine("Write protection successfully disabled.");
                            }
                            else
                            {
                                throw new Exception("Unable to clear write protection");
                            }

                            reader.ResetAddressPins();

                            return;
                        }
                    }

                    byte address;

                    try {
                        address = (byte)Int32.Parse(args[2]);
                    }
                    catch {
                        throw new Exception("EEPROM address should be specified in decimal notation.");
                    }

                    reader.I2CAddress = address;
                    reader.SpdSize    = Spd.GetSpdSize(reader);

                    if (!reader.ProbeAddress())
                    {
                        throw new Exception($"EEPROM is not present at address {reader.I2CAddress}.");
                    }

                    string filePath = (args.Length >= 4) ? args[3] : "";
                    bool   silent   = (args.Length >= 5 && args[4] == "/silent") ? true : false;

                    // Read SPD contents
                    if (mode == "/read")
                    {
                        Console.Write($"Reading EEPROM at address {reader.I2CAddress} ({Spd.GetRamType(reader)})");

                        if (filePath != "")
                        {
                            Console.WriteLine($" to {filePath}");
                        }
                        Console.WriteLine("\n");

                        int startTick = Environment.TickCount;

                        byte[] spdDump = Eeprom.ReadByte(reader, 0, (int)reader.SpdSize);

                        for (int i = 0; i < spdDump.Length; i++)
                        {
                            if (!silent)
                            {
                                ConsoleDisplayByte(i, spdDump[i]);
                            }
                        }

                        Console.Write("\n\nRead {0} {1} from EEPROM at address {2} on port {3} in {4} ms",
                                      spdDump.Length,
                                      (spdDump.Length > 1) ? "bytes" : "byte",
                                      reader.I2CAddress,
                                      reader.PortName,
                                      Environment.TickCount - startTick
                                      );

                        if (filePath != "")
                        {
                            try {
                                File.WriteAllBytes(filePath, spdDump);
                            }
                            catch {
                                throw new Exception($"Unable to write to {filePath}");
                            }
                            Console.Write($" to file \"{filePath}\"");
                        }

                        reader.Disconnect();
                        return;
                    }

                    // Write contents to EEPROM
                    if (mode.StartsWith("/write"))
                    {
                        if (filePath.Length < 1)
                        {
                            throw new Exception("File path is mandatory for write mode.");
                        }

                        if (!File.Exists(filePath))
                        {
                            throw new Exception($"File \"{filePath}\" not found.");
                        }

                        byte[] inputFile;
                        try {
                            inputFile = File.ReadAllBytes(filePath);
                        }
                        catch {
                            throw new Exception($"Unable to read {filePath}");
                        }

                        Console.WriteLine(
                            "Writing \"{0}\" ({1} {2}) to EEPROM at address {3}\n",
                            filePath,
                            inputFile.Length,
                            (inputFile.Length > 1) ? "bytes" : "byte",
                            reader.I2CAddress);

                        if (inputFile.Length > (int)reader.SpdSize)
                        {
                            throw new Exception($"File \"{filePath}\" is larger than {reader.SpdSize} bytes.");
                        }

                        int  bytesWritten = 0;
                        int  startTick    = Environment.TickCount;
                        byte b;

                        for (int i = 0; i != inputFile.Length; i++)
                        {
                            b = inputFile[i];
                            bool writeResult = (mode == "/writeforce")
                                ? Eeprom.WriteByte(reader, (ushort)i, inputFile[i])
                                : Eeprom.UpdateByte(reader, (ushort)i, inputFile[i]);

                            if (!writeResult)
                            {
                                throw new Exception($"Could not write byte {i} to EEPROM at address {reader.I2CAddress} on port {reader.PortName}.");
                            }

                            bytesWritten++;

                            if (!silent)
                            {
                                ConsoleDisplayByte(i, b);
                            }
                        }
                        reader.Disconnect();

                        Console.WriteLine(
                            "\n\nWritten {0} {1} to EEPROM at address {2} on port {3} in {4} ms",
                            bytesWritten,
                            (bytesWritten > 1) ? "bytes" : "byte",
                            reader.I2CAddress,
                            reader.PortName,
                            Environment.TickCount - startTick);
                        return;
                    }

                    if (mode == "/enablepermanentwriteprotection")
                    {
                        if (Eeprom.SetPermanentWriteProtection(reader))
                        {
                            Console.WriteLine($"Permanent write protection enabled on {reader.PortName}:{reader.I2CAddress}");
                        }
                        else
                        {
                            throw new Exception($"Unable to set permanent write protection on {reader.PortName}:{reader.I2CAddress}");
                        }
                    }
                }
            }
            catch (Exception e) {
                //Console.ForegroundColor = ConsoleColor.Red;
#if DEBUG
                Console.WriteLine($"{e}\n");
#else
                Console.WriteLine($"{e.Message}\n");
#endif

                //Console.ForegroundColor = ConsoleColor.Gray;
                return;
            }

            Console.WriteLine("Unknown command line parameters.\n");
            ShowHelp();
        }
Exemple #20
0
        private void timerInterfaceUpdater_Tick(object sender, EventArgs e)
        {
            // Enable or disable EEPROM toolbar buttons and menus depending on device state
            bool _deviceConnectionEstablished = MySpdReader != null && MySpdReader.IsConnected;
            bool _eepromWriteable             = _deviceConnectionEstablished && SpdContents.Length != 0;
            bool _progressBarActive           = statusProgressBar.Value == statusProgressBar.Minimum || statusProgressBar.Value == statusProgressBar.Maximum;

            readEeprom_button.Enabled           = _deviceConnectionEstablished && _progressBarActive;
            readToolStripMenuItem.Enabled       = _deviceConnectionEstablished && _progressBarActive;
            disconnectToolStripMenuItem.Enabled = _deviceConnectionEstablished;
            testToolStripMenuItem.Enabled       = _deviceConnectionEstablished;
            clearToolStripMenuItem.Enabled      = _deviceConnectionEstablished && _progressBarActive && rt == RamType.DDR4;
            enableToolStripMenuItem.Enabled     = _deviceConnectionEstablished && _progressBarActive && rt == RamType.DDR4;
            enableRswpButton.Enabled            = _deviceConnectionEstablished && _progressBarActive && rt == RamType.DDR4;
            clearRswpButton.Enabled             = _deviceConnectionEstablished && _progressBarActive && rt == RamType.DDR4;
            writeEeprom_button.Enabled          = _eepromWriteable && _progressBarActive;
            writeToolStripMenuItem.Enabled      = _eepromWriteable && _progressBarActive;
            refreshToolStripMenuItem.Enabled    = !_deviceConnectionEstablished;

            // Enable or disable file operations
            bool _spdLoaded = SpdContents.Length != 0;

            toolSaveFile_button.Enabled = _spdLoaded;
            //crcDropdownMenu.Enabled        = toolSaveFile_button.Enabled;
            saveToolStripMenuItem.Enabled    = _spdLoaded;
            saveasToolStripMenuItem.Enabled  = _spdLoaded;
            copyHexToolStripMenuItem.Enabled = _spdLoaded;

            // CRC status
            if (_spdLoaded && (Eeprom.GetRamType(SpdContents) != RamType.UNKNOWN))
            {
                statusBarCrcStatus.Visible      = statusProgressBar.Value == statusProgressBar.Maximum;
                statusBarCrcStatus.Text         = (crcValidChecksum) ? "CRC OK" : "CRC Error";
                statusBarCrcStatus.ForeColor    = (crcValidChecksum) ? Color.FromArgb(128, 255, 128) : Color.White;
                statusBarCrcStatus.BackColor    = (crcValidChecksum) ? Color.FromArgb(255, 0, 64, 0) : Color.FromArgb(192, 255, 0, 0);
                fixCrcToolStripMenuItem.Enabled = !crcValidChecksum && _spdLoaded;
            }
            else
            {
                // Hide CRC status for non DDR4 RAM
                statusBarCrcStatus.Visible = false;
            }

            // RAM type
            if (_spdLoaded)
            {
                toolStripStatusRamType.Text    = $"{Eeprom.GetRamType(SpdContents)}";              //, {Eeprom.GetModuleModelName(SpdContents)}
                toolStripStatusRamType.Visible = true;
            }

            // Status progress bar (hide when value is 0 or maximum)
            //statusProgressBar.Visible = (statusProgressBar.Value > 0 && statusProgressBar.Value < statusProgressBar.Maximum);
            statusProgressBar.Visible = !_progressBarActive;

            // Connection Status
            statusBarConnectionStatus.Enabled   = _deviceConnectionEstablished;
            statusBarConnectionStatus.ForeColor = (_deviceConnectionEstablished) ? Color.Navy : SystemColors.Control;
            statusBarConnectionStatus.Text      = (_deviceConnectionEstablished) ? $"Connected to {MySpdReader.PortName}:{MySpdReader.EepromAddress}" : "Not connected";
            toolStripDeviceButton.Text          = (_deviceConnectionEstablished) ? $"{MySpdReader.PortName}:{MySpdReader.EepromAddress}" : "Device";

            // Toolbar device button
            toolStripDeviceButton.Text        = (_deviceConnectionEstablished) ? $"{MySpdReader.PortName}:{MySpdReader.EepromAddress}" : "Device";
            toolStripDeviceButton.ToolTipText = (_deviceConnectionEstablished) ? $"Connected to {MySpdReader.PortName}:{MySpdReader.EepromAddress}" : "Select device port and address";

            // Split container looks
            splitContainerViewer.Panel1.MinimumSize = labelTopOffsetHex.GetPreferredSize(new Size());
            if (splitContainerViewer.SplitterDistance < splitContainerViewer.Panel1.MinimumSize.Width)
            {
                splitContainerViewer.SplitterDistance = splitContainerViewer.Panel1.MinimumSize.Width;
            }
            splitContainerViewer.Panel2.MinimumSize = labelTopOffsetAscii.GetPreferredSize(new Size());
            if (splitContainerViewer.SplitterDistance > splitContainerViewer.Panel1.MinimumSize.Width + splitContainerViewer.Panel2.MinimumSize.Width)
            {
                splitContainerViewer.SplitterDistance = splitContainerViewer.Panel1.MinimumSize.Width + splitContainerViewer.Panel2.MinimumSize.Width;
            }

            // Main tab label
            if (currentFileName != "" && tabPageMain.Text != Path.GetFileName(currentFileName))
            {
                //tabPageMain.Text = Path.GetFileName(currentFileName);
            }

            // Main tab color
            //if (tabControlMain.SelectedTab == tabPageMain) {
            //	tabPageMain.ForeColor = SystemColors.ControlText;
            //}

            // Disable Save log button if log is empty
            buttonSaveLog.Enabled = loggerBox.Items.Count > 0;

            // ASCII textbox size to match ascii offset box width
            //Size asciiBoxSize = textBoxAscii.Size;
            //asciiBoxSize.Width = labelTopOffsetAscii.Size.Width;
        }
Exemple #21
0
        private byte[] fixCrc(byte[] input)
        {
            byte[] _spd = new byte[input.Length];

            for (int i = 0; i < _spd.Length; i++)
            {
                _spd[i] = input[i];
            }

            int[] headerStart  = new int[0];
            int   headerLength = 0;
            int   crcPosition  = 126;

            // Get DDR4 CRC data
            if (Eeprom.GetRamType(input) == RamType.DDR4)
            {
                // Read 126 bytes from headersStart positions
                headerStart  = new [] { 0, 128 };
                headerLength = 126;
            }

            // Get DDR3 CRC data
            if (Eeprom.GetRamType(input) == RamType.DDR3)
            {
                headerStart = new [] { 0 };
                // Exclude SN from CRC?
                headerLength = ((input[0] >> 7) == 1) ? 117 : 126;
            }

            // Calculate DDR3 and DDR4 CRC
            if (Eeprom.GetRamType(input) == RamType.DDR4 || Eeprom.GetRamType(input) == RamType.DDR3)
            {
                foreach (int _headerStart in headerStart)
                {
                    byte[] header = new byte[headerLength];
                    for (int i = 0; i < headerLength; i++)
                    {
                        header[i] = _spd[i + _headerStart];
                    }

                    ushort crc = Eeprom.Crc16(header);

                    byte CrcLsb = (byte)(crc & 0xff);
                    byte CrcMsb = (byte)(crc >> 8);

                    if (_spd[_headerStart + crcPosition + 0] != CrcLsb ||                     // MSB
                        _spd[_headerStart + crcPosition + 1] != CrcMsb)                       //LSB

                    {
                        _spd[_headerStart + crcPosition + 0] = CrcLsb;
                        _spd[_headerStart + crcPosition + 1] = CrcMsb;
                    }
                }
            }

            // Calculate SDR - DDR2 CRC
            else if (Eeprom.GetRamType(input) != RamType.UNKNOWN)
            {
                //headerStart = new [] { 0 };
                headerLength = 63;
                crcPosition  = 64;
                byte[] header = new byte[headerLength];

                for (int i = 0; i < headerLength; i++)
                {
                    header[i] += _spd[i];
                }

                byte crc = (byte)Eeprom.Crc(header);

                if (_spd[crcPosition - 1] != crc)
                {
                    _spd[crcPosition - 1] = crc;
                }
            }

            return(_spd);
        }
Exemple #22
0
 private void mnuReset_Click(object sender, EventArgs e)
 {
     _eeprom = new Eeprom();
     UpdateFormFromEeprom();
 }
Exemple #23
0
        private void writeSpdToEeprom(object sender, EventArgs e)
        {
            DialogResult _writeConfirmation = MessageBox.Show(
                "Are you sure you want to write SPD to EEPROM?\n\nThis process is irreversible and you will not be able to restore old SPD, unless you have a backup copy.",
                "Write",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Exclamation,
                MessageBoxDefaultButton.Button2);

            if (_writeConfirmation == DialogResult.No)
            {
                return;
            }

            Logger("Write started");

            // Warn if CRC is invalid
            if (!crcValidChecksum)
            {
                DialogResult _crcConfirmation = MessageBox.Show(
                    "The loaded SPD CRC is not valid!\n\nAre you sure you want to write this SPD?",
                    "Warning",
                    MessageBoxButtons.YesNo,
                    MessageBoxIcon.Warning);
                if (_crcConfirmation == DialogResult.No)
                {
                    Logger("Invalid CRC - write aborted by user");
                    return;
                }
            }

            int start = Environment.TickCount;

            statusProgressBar.Value = 0;

            if (SpdContents.Length > 0)
            {
                statusProgressBar.Maximum = SpdContents.Length;

                for (int i = 0; i < SpdContents.Length; i++)
                {
                    if (!Eeprom.UpdateByte(MySpdReader, i, SpdContents[i]))
                    {
                        string message = $"Could not write to offset 0x{i:X3} at {MySpdReader.PortName}:{MySpdReader.EepromAddress}";
                        Logger(message);

                        string       _question = "Do you want to clear write protection?\n\nClick 'Retry' to attempt to disable write protection and try again or 'Ignore' to continue.";
                        DialogResult _result   = MessageBox.Show($"{message}\n\n{_question}", "Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Warning);
                        // Yes button pressed
                        if (_result == DialogResult.Retry)
                        {
                            Logger("Attempting to clear write protection");
                            clearWriteProtection(this, null);
                            Thread.Sleep(100);
                            i--;                             // Decrement the value of i to retry writing the same byte after WP clear is attempted
                            continue;
                        }

                        // Abort button pressed
                        if (_result == DialogResult.Abort)
                        {
                            Logger("Could not write to EEPROM - write aborted by user");
                            statusProgressBar.Value = statusProgressBar.Maximum;
                            return;
                        }
                    }

                    // Redraw interface every N bytes written
                    if (i % 16 == 0)
                    {
                        statusProgressBar.Value = i;
                        Application.DoEvents();
                    }
                }
                statusProgressBar.Value = statusProgressBar.Maximum;

                if (currentFileName != "")
                {
                    // Log filename if file was written to EEPROM
                    Logger($"Written {currentFileName} ({SpdContents.Length} bytes) to {MySpdReader.PortName}:{MySpdReader.EepromAddress} in {Environment.TickCount - start} ms");
                }
                else
                {
                    Logger($"Written {SpdContents.Length} byte(s) to {MySpdReader.PortName}:{MySpdReader.EepromAddress} in {Environment.TickCount - start} ms");
                }
            }
        }