Ejemplo n.º 1
0
        private void buttonMultiApply_Click(object sender, EventArgs e)
        {
            byte byAddr, bySize;

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

                byAddr = Convert.ToByte(textBoxMultiAddress.Text, 16);
                bySize = Convert.ToByte(textBoxMultiSize.Text, 16);
            }
            catch
            {
                MessageBox.Show("Format incorrect. Hex?", "Warning");
                return;
            }

            if (bySize < 1 || bySize > EEPROM_API.PAGE_SIZE)
            {
                MessageBox.Show("Incorrect Input. The range of the input should be 1 to "
                                + EEPROM_API.PAGE_SIZE.ToString(), "Warning");
                return;
            }

            byte isReadWrite = 0;

            byte[] byDataArray = new byte[bySize];
            if (radioButtonReadMulti.Checked == true)
            {
                LastErrCode = EEPROM_API.ReadMultiByte(byAddr, bySize, byDataArray, out isReadWrite);
                if (LastErrCode != IMCAPIErrCode.IMC_ERR_NO_ERROR)
                {
                    MessageBox.Show("Fails to ReadMultiByte EERPOM " + LastErrCode.ToString("X4"));
                    return;
                }

                textBoxMultiData.Text = ConvertByte2HexString(byDataArray, isReadWrite);
            }
            else
            {
                if (textBoxMultiData.Text.Length != bySize * 2)
                {
                    MessageBox.Show("Incorrect Input. The data not match the size", "Warning");
                    return;
                }

                byDataArray = String2ByteArray(textBoxMultiData.Text);
                LastErrCode = EEPROM_API.WriteMultiByte(byAddr, bySize, byDataArray, out isReadWrite);
                if (LastErrCode != IMCAPIErrCode.IMC_ERR_NO_ERROR)
                {
                    MessageBox.Show("Fails to WriteMultiByte EERPOM " + LastErrCode.ToString("X4"));
                    return;
                }
            }
            textBoxMultiNumReadWrite.Text = isReadWrite.ToString("X2");
        }