コード例 #1
0
        protected override void _backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            byte[] data;

            RTD266x.Result result = Read(_address, _length, out data, _updateConsole);

            e.Result = new object[] { result, data };
        }
コード例 #2
0
        private void btnClearLock_Click(object sender, EventArgs e)
        {
            AppendConsoleText("Clearing lock bits... ");

            RTD266x.Result result = _rtd.WriteStatus(0x00, 0x00);

            if (result == RTD266x.Result.Ok)
            {
                AppendConsoleText("done\r\n");
            }
            else
            {
                AppendConsoleText(RTD266x.ResultToString(result) + "\r\n");
            }
        }
コード例 #3
0
        private void ReadWorkerFinished(RTD266x.Result result, byte[] data)
        {
            UpdateBackgroundWorkerActive(false);

            if (result != RTD266x.Result.Ok)
            {
                AppendConsoleText(RTD266x.ResultToString(result) + "\r\n");
                return;
            }

            AppendConsoleText("done\r\n");

            if (chkReadConsole.Checked)
            {
                StringBuilder dataLog = new StringBuilder();
                int           column  = 0;

                foreach (byte dataByte in data)
                {
                    dataLog.Append($"{dataByte:X2} ");

                    column++;

                    if (column == 16)
                    {
                        dataLog.Append("\r\n");
                        column = 0;
                    }
                }

                AppendConsoleText(dataLog.ToString());
            }

            if (chkReadFile.Checked)
            {
                try
                {
                    File.WriteAllBytes(txtReadFileName.Text, data);
                    AppendConsoleText($"Data successfully written to \"{txtReadFileName.Text}\"\r\n");
                }
                catch (Exception ex)
                {
                    AppendConsoleText($"Cannot write file \"{txtReadFileName.Text}\"! {ex.Message}\r\n");
                }
            }
        }
コード例 #4
0
        private RTD266x.Result WritePatchedSector(byte[] firmware, int address)
        {
            int sectorAddress = (address / 4096) * 4096;

            byte[] sector = new byte[4096];

            Array.Copy(firmware, sectorAddress, sector, 0, sector.Length);

            ReportStatus("Writing patched sector...\r\n");

            RTD266x.Result result = Write(sectorAddress, sector, true);

            if (result != RTD266x.Result.Ok)
            {
                ReportStatus(RTD266x.ResultToString(result) + "\r\n");
            }

            return(result);
        }
コード例 #5
0
        private void btnEraseChip_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you really want to erase the whole chip?", "Erase chip", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
            {
                return;
            }

            AppendConsoleText("Erasing chip (all data)... ");

            RTD266x.Result result = _rtd.EraseChip();

            if (result == RTD266x.Result.Ok)
            {
                AppendConsoleText("done\r\n");
            }
            else
            {
                AppendConsoleText(RTD266x.ResultToString(result) + "\r\n");
            }
        }
コード例 #6
0
        private void btnReadStatus_Click(object sender, EventArgs e)
        {
            AppendConsoleText("Reading status info... ");

            RTD266x.StatusInfo statusInfo;

            RTD266x.Result result = _rtd.ReadStatus(out statusInfo);

            if (result != RTD266x.Result.Ok)
            {
                AppendConsoleText("error\r\n");
                return;
            }

            AppendConsoleText("done\r\n");

            AppendConsoleText($"Manufacturer ID: 0x{statusInfo.ManufacturerId:X2} ({statusInfo.Manufacturer})\r\n");
            AppendConsoleText($"Device ID: 0x{statusInfo.DeviceId:X2} ({statusInfo.Type})\r\n");
            AppendConsoleText($"JEDEC Manufacturer ID: 0x{statusInfo.JedecManufacturerId:X2} ({statusInfo.Manufacturer})\r\n");
            AppendConsoleText($"JEDEC Memory Type: 0x{statusInfo.JedecMemoryType:X2}\r\n");
            AppendConsoleText($"JEDEC Capacity: 0x{statusInfo.JedecCapacity:X2} ({statusInfo.Capacity})\r\n");
            AppendConsoleText($"Status: 0x{statusInfo.Status:X4}\r\n");
        }
コード例 #7
0
 private void ModifyFirmwareWorkerFinished(RTD266x.Result result)
 {
     UpdateBackgroundWorkerActive(false);
 }
コード例 #8
0
 private void WriteWorkerFinished(RTD266x.Result result)
 {
     UpdateBackgroundWorkerActive(false);
 }
コード例 #9
0
ファイル: FormArduino.cs プロジェクト: xzw168/RTD266xFlash
        private void btnConnect_Click(object sender, EventArgs e)
        {
            if (_comPort != null && _comPort.IsOpen)
            {
                _comPort.Close();
            }

            _comPort           = new SerialPort(comboBoxPorts.Text, (int)numericBaudRate.Value);
            _comPort.Parity    = Parity.None;
            _comPort.StopBits  = StopBits.One;
            _comPort.DataBits  = 8;
            _comPort.Handshake = Handshake.None;

            AppendConsoleText("Connecting...\r\n");

            try
            {
                _comPort.Open();
            }
            catch (Exception ex)
            {
                AppendConsoleText($"Error! Cannot open {comboBoxPorts.Text}: {ex.Message}");
                UpdateConnected(false);
                return;
            }

            _rtd = new RTD266x(_comPort);

            UpdateConnected(true);

            RTD266x.ErrorCode errorCode = RTD266x.ErrorCode.NoError;
            uint errorInfo = 0;

            RTD266x.Result result  = RTD266x.Result.NotOk;
            int            retries = 5;

            // try to connect a few times
            for (int i = 0; i < retries; i++)
            {
                result = _rtd.ReadErrorCode(out errorCode, out errorInfo);

                if (result == RTD266x.Result.Ok)
                {
                    break;
                }

                _rtd.ClearReadBuffer();

                AppendConsoleText($"Connection error: {RTD266x.ResultToString(result)}, retrying... ({i + 1}/{retries})\r\n");
            }

            if (result != RTD266x.Result.Ok)
            {
                AppendConsoleText($"Connection error: {RTD266x.ResultToString(result)}\r\n");
                AppendConsoleText("Did you download the sketch RTD266xArduino to your Arduino?\r\n");
                AppendConsoleText("Is the Arduino connected properly to the display?\r\n");
                AppendConsoleText("Did you select the correct COM port?\r\n");
                AppendConsoleText("Is the display powered?\r\n");
                AppendConsoleText("If the Arduino's user LED is on, the I2C connection to the display does not work.\r\n");
                AppendConsoleText("Press the Arduino's reset button and try again.\r\n\r\n");

                btnDisconnect_Click(null, null);
                return;
            }

            if (errorCode == RTD266x.ErrorCode.NoError)
            {
                AppendConsoleText("Connection successful!\r\n");
            }
            else
            {
                AppendConsoleText("Initialization error: ");
                AppendConsoleText(RTD266x.ErrorCodeToString(errorCode, errorInfo) + "\r\n");

                btnDisconnect_Click(null, null);
            }
        }
コード例 #10
0
ファイル: WriteWorker.cs プロジェクト: xzw168/RTD266xFlash
        protected override void _backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            RTD266x.Result status = Write(_address, _data, _updateConsole);

            e.Result = status;
        }