To choose step or number of reading

Nov 19 2015 10:52 PM
This is the code I have so i did what is I have to select either step or number of readings.So error i get at number of readings saying input string not in a correct format i have commented the line and other one is I need five readings which then will be taken as average. I just want a correction in my code so requesting to please assist me in this.
 
private void CalibrateVoltage_Click(object sender, EventArgs e)
{
//double[] Reading;
//Reading = new double[5];
double startvalue;
double endvalue;
double step;
double sum = 0;
double noofreading;
string op_csv = "Equipment:Calibrator Burster 4462, " + "ID No:565510164849," + "Temp: ," + "Humidity: ," + DateTime.Now.ToString() + "\n";
op_csv = op_csv + "Parameter:DC VOLT O/P" + "\n";
op_csv = op_csv + "SrNo.,Standard Measured Value,Deviation Observed\n";
double diff;
startvalue = Convert.ToDouble(textBox3.Text);
endvalue = Convert.ToDouble(textBox4.Text);
//step = Convert.ToDouble(textBox5.Text);
noofreading = Convert.ToDouble(textBox6.Text);//input string not in a correct format when this textbox is disabled
if (comboBox8.Text == "NumberofReadings")
{
step = (endvalue - startvalue) / noofreading;
}
else
{
step = Convert.ToDouble(textBox5.Text);//gives error
}
Burster_init(serialPort1);
agi_init();
for (double i = startvalue; i <= endvalue; i = i + step)
{
for (double a = 0; a <= 5; a++)
{
if (com_type == 0)
{
burster_send_signal(serialPort1, BursterConstant.burs_Volt, "V", Convert.ToString(i));
}
else
{
burster_send_signal(null, BursterConstant.burs_Volt, "V", Convert.ToString(i));
}
Byte[] burread;
Thread.Sleep(3000);
//burread = Burster_receive_signal(serialPort1);
if (com_type == 0)
{
burread = Burster_receive_signal(serialPort1);
}
else
{
burread = Burster_receive_signal(null);
}
if (burread[0] != 0x06)
{
MessageBox.Show("Burster Error");
return;
}
sum = 0;
agi_send_signal(BursterConstant.burs_Volt);
Byte[] readagilent;
//Thread.Sleep(1000)
Thread.Sleep(3000);
readagilent = Agilent_receive_signal();
double agilent_read_val = agilent_read_value(readagilent);
//double agilent_read_val = agilent_read_value(readagilent);
//agi_send_signal(serialPort2, BursterConstant.burs_Volt);
//Thread.Sleep(1000);
//readagilent = Agilent_receive_signal(serialPort2);
//double agilent_read_val2 = agilent_read_value(readagilent);
sum += agilent_read_val;
sum /= 5;
diff = i - sum;
op_csv = op_csv + "," + i.ToString() + "," + sum.ToString() + "\n";
op_to_csv(op_csv);
}
}
}
 

Answers (1)