private void tmrSampling_Tick(object sender, EventArgs e) { double voltage = 0.0; if (bWithHardware) { voltage = USBInterface.AnalogIn[cAnalogIn1, cRange]; } else // without hardware { // Max 2,49 V Min =0,415V // Zufallszahl im Bereich 0,415V bis 2,49V //voltage = (2.49 - 0.415) * RandomVoltage.NextDouble() + 0.415; // 2.49 - 0.42 = 2.07 /2 = 1.035 // Verschieben in Y-Richtung 1.035 + 0.415 = 1.45 voltage = 1.035 * Math.Sin(SinCount) + 1.45; SinCount = (SinCount + Math.PI * 3 / 180.0); } voltage = Math.Max(0.415, Math.Min(2.49, voltage)); lblVoltage.Text = voltage.ToString("#0.000 V"); // Umrechungsformel mit Excel berechnet //double distance = 29.044 * Math.Pow(voltage, -1.162); double distance = 35 * Math.Sin(SinCount) + 45; lblDistance.Text = distance.ToString("#0.0 cm"); double diff = 0; if (MVList.Count > 0) { diff = distance - MVList[MVList.Count - 1]; } MVListDiff.Add(diff); lboDiffValues.Items.Add(diff); MVList.Add(distance); while (MVList.Count > cMaxNumOfMV) { MVList.RemoveAt(0); MVListDiff.RemoveAt(0); } // PictureBox ungültig setzen und daher wird die Paint-Methode zum Neuzeichen aufgerufen picChart.Invalidate(); }
private void tmrSampling_Tick(object sender, EventArgs e) { double voltage = 0.0; double mv2 = 0; if (bWithHardware) { voltage = (double)(USBInterface.AnalogIn[cAnalogIn1, cRange]); } else // No hardware -> simulation { // Randomnumber from 0.42 to 2.5 V voltage = RandomVoltage.NextDouble() * (2.5 - 0.42) + 0.42; //mv2 = 100 * Math.Sin(((double)DateTime.Now.Millisecond) / 1000.0 *2 * Math.PI); } // Calculated with Excel double distance = 29.071 * Math.Pow(voltage, -1.159); lblVoltage.Text = voltage.ToString("#0.000 V"); lblDistance.Text = distance.ToString("#0.0 cm"); MVList.Add(voltage); cMinMV = MVList.Min() - 0.2; cMaxMV = MVList.Max() + 0.2; //Differential der Funktion // Aktueller Wert minus Vorgänger = Änderung des Abstandes[m] /ms if (MVList.Count >= 2) { mv2 = 10 * (MVList[MVList.Count - 1] - MVList[MVList.Count - 2]) / tmrSampling.Interval; } else { mv2 = 10 * (MVList[MVList.Count - 1] - 0) / tmrSampling.Interval; } MVList2.Add(mv2); // Adapt Minimum and Maximum //double delta = (cMaxMV2 - cMinMV2) / NumOfScaleLines; while (mv2 < cMinMV2) { cMinMV2 -= 2; } while (mv2 > cMaxMV2) { cMaxMV2 += 2; } while (MVList.Count > cMaxNumOfMV) { MVList.RemoveAt(0); } while (MVList2.Count > cMaxNumOfMV) { MVList2.RemoveAt(0); } pboChart.Invalidate(); }