/// <summary>
        /// Event called by the "Write Updated File" option of the ToolStripMenu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void WriteChangesToolStripMenuItem_Click(object sender, System.EventArgs e)
        {
            if (SrecFileWasAdded)
            {
                string filepath  = OpenSRECFile.FileName;
                string extension = Path.GetExtension(filepath);

                if (extension == ".srec")
                {
                    filepath = filepath.Replace(".srec", "_Updated.srec");
                }
                if (extension == ".s19")
                {
                    filepath = filepath.Replace(".s19", "_Updated.s19");
                }
                if (extension == ".sx")
                {
                    filepath = filepath.Replace(".sx", "_Updated.sx");
                }

                HwCalStruct.UpdateHwCalValuesFromDvg(dgvHWCAL);
                SrecFile = HwCalStruct.ConvertHwCalToSrec();

                SrecFile.WriteSrecToFile(filepath);
                string message = String.Format("The output file was saved in the same folder as the input file!\n{0}", filepath);
                MessageBox.Show(message, "Write Updated File - Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("First step: Load a SREC file.", "Write Updated File - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create the HwCalibration structure from one SREC line
        /// </summary>
        /// <param name="srecFile"></param>
        public HwCal(SrecFile srecFile)
        {
            HwCal_SrecFile = srecFile;
            int    hwCal_WordIndex = 0;
            UInt32 currentWord;

            /* create the channels array */
            hwcal_chans = new hwcal_chan[(int)HWCAL_CHANS_ENUM.HWCAL_CHAN_MAX_NO];

            /* Read head of the HwCal structure */
            hwcal_head.start      = (UInt16)((UInt16)(srecFile.GetDataWord(hwCal_WordIndex)[0] << 8) | (UInt16)(srecFile.GetDataWord(hwCal_WordIndex)[1]));
            hwcal_head.struct_ver = srecFile.GetDataWord(hwCal_WordIndex)[2];
            hwcal_head.data_ver   = srecFile.GetDataWord(hwCal_WordIndex)[3];
            hwCal_WordIndex++;

            /* Read calibration for all channels */
            for (int i = 0; i < hwcal_chans.Length; i++)
            {
                hwcal_chans[i].ChannelName = (HWCAL_CHANS_ENUM)(i);
                currentWord         = ConvertWordBytesToUint32(srecFile.GetDataWord(hwCal_WordIndex++));
                hwcal_chans[i].gain = currentWord;
                currentWord         = ConvertWordBytesToUint32(srecFile.GetDataWord(hwCal_WordIndex++));
                hwcal_chans[i].offs = currentWord;
            }

            /* Read tail of the Hw structure */
            hwcal_tail.stop = (UInt16)((UInt16)(srecFile.GetDataWord(hwCal_WordIndex)[0] << 8) | (UInt16)(srecFile.GetDataWord(hwCal_WordIndex)[1]));
            hwcal_tail.crc  = (UInt16)((UInt16)(srecFile.GetDataWord(hwCal_WordIndex)[2] << 8) | (UInt16)(srecFile.GetDataWord(hwCal_WordIndex)[3]));
        }
 /// <summary>
 /// Read the SREC input file and create the HwCal structure in RAM
 /// </summary>
 /// <param name="FileName"></param>
 private void ReadInputData(string FileName)
 {
     SrecFile         = new SrecFile(FileName);
     HwCalStruct      = new HwCal(SrecFile);
     SrecFileWasAdded = true;
 }