private void SuccessCallback(byte[] b) { Invoke((MethodInvoker) delegate { ByteArrayDecoderClass decoder = new ByteArrayDecoderClass(b); decoder.Get2BytesAsInt(); // Ignore first 2 values (message length) // Get raw value and convert to human readable values, with and without gain var rawValue = decoder.Get2BytesAsInt16(); float fValue = SupercapHelperClass.ConvertToFloatInMiliVolts(rawValue); float givenValue; if (!float.TryParse(textBoxFixedVoltage.Text, out givenValue)) { FormCustomConsole.WriteLineWithConsole("Wrong float value for calibration!"); return; } // Add to list var calPt = new CalibratePoint(rawValue, fValue, givenValue); calibValues.Add(calPt); numberOfSamples++; // Append to display AppendToDisplay(calPt); // Calculate average CalculateAverage(); } ); }
private void AppendToDisplay(CalibratePoint cp) { string newLine = "Raw: " + cp.rawValue + " sampled: " + cp.sampledValue + " given: " + cp.givenValue + " gain: " + cp.CalculateGain(); textBoxDisplay.Text += "\r\n" + newLine; }