예제 #1
0
        private void buttonByteApply_Click(object sender, EventArgs e)
        {
            byte byAddr;

            try
            {
                if (textBoxByteAddress.Text.Length <= 0 || textBoxByteAddress.Text.Length > 2)
                {
                    throw new FormatException();
                }

                byAddr = Convert.ToByte(textBoxByteAddress.Text, 16);
            }
            catch
            {
                MessageBox.Show("Address format incorrect. Hex?", "Warning");
                return;
            }

            if (radioButtonReadByte.Checked == true)
            {
                byte byData;
                LastErrCode = EEPROM_API.ReadByte(byAddr, out byData);
                if (LastErrCode != IMCAPIErrCode.IMC_ERR_NO_ERROR)
                {
                    MessageBox.Show("Fails to ReadByte EERPOM " + LastErrCode.ToString("X4"));
                    return;
                }
                textBoxByteData.Text = byData.ToString("X2");
            }
            else
            {
                byte byData;

                try
                {
                    if (textBoxByteData.Text.Length <= 0 || textBoxByteData.Text.Length > 2)
                    {
                        throw new FormatException();
                    }
                    byData = Convert.ToByte(textBoxByteData.Text, 16);
                }
                catch
                {
                    MessageBox.Show("Format incorrect. Hex?", "Warning");
                    return;
                }

                LastErrCode = EEPROM_API.WriteByte(byAddr, byData);
                if (LastErrCode != IMCAPIErrCode.IMC_ERR_NO_ERROR)
                {
                    MessageBox.Show("Fails to WriteByte EERPOM " + LastErrCode.ToString("X4"));
                    return;
                }
            }
        }