public SingleTactData Clone() { SingleTactData clone = new SingleTactData(); clone.mostRecentTime_ = this.mostRecentTime_; clone.data = this.data; return(clone); }
public new bool Initialise(string portName) { try { _dataBuffer = new SingleTactData(); _frameList = new List <SingleTactFrame>(); _singleTact = new SingleTact(); _arduino = new ArduinoSingleTactDriver(); _arduino.Initialise(portName); //Start Arduino driver _singleTact.Initialise(_arduino); _singleTact.I2cAddressForCommunications = ((byte)(4)); isCalibrated = _singleTact.isCalibrated; return(true); } catch { return(false); } }
//Save data to CSV private void buttonSave_Click(object sender, EventArgs e) { bool backgroundWasRunning = AcquisitionWorker.IsBusy; if (backgroundWasRunning) { StopAcquisitionThread(); } // Initialize the Dialog to save the file SaveFileDialog saveDataDialog = new SaveFileDialog(); saveDataDialog.Filter = "*.csv|*.csv"; saveDataDialog.RestoreDirectory = true; saveDataDialog.FileName = "SingleTactSampleData"; Invoke((Action)(() => { if (saveDataDialog.ShowDialog() == DialogResult.OK) { // To fix Issue 3, separate exported values by semi-colon instead // of comma if current locale's decimal separator is comma. string separator = safeSeparator(); string saveFileName = saveDataDialog.FileName; StreamWriter dataWriter = new StreamWriter(saveFileName, false, Encoding.Default); // write column headers string columnNames = "Time(s)" + separator; // populate columns with serial port names foreach (string portName in comPortList) { int index = comPortList.IndexOf(portName); string name = portName.ToString().Split('-')[1] + " " + (index + 1).ToString(); if (USBdevices[index].singleTact.firmwareVersion > 0) { if (USBdevices[index].isCalibrated) { name = name + "(calibrated)"; } } if (NBtoForceFactor != 0) { columnNames += portName + " (N)" + separator; } else { columnNames += portName + " (NB)" + separator; } } if (NBtoForceFactor == 0) { columnNames += "NB (0 = 0 PSI; 511 = Full Scale Range)"; } else { columnNames += "(Selected Full Scale Range: " + NBtoForceFactor + "N)"; } dataWriter.WriteLine(columnNames); // write data string row = ""; int data_length = USBdevices[0].dataBuffer.data[0].Count; for (int i = 0; i < data_length; i++) // for each sensor reading { bool first = true; foreach (USBdevice_GUI USB in USBdevices) { try { SingleTactData data = USB.dataBuffer; PointPair dataPoint = data.data[0][i]; if (first) // only save the time the first sensor's reading was taken { // round the time value to mitigate any uncertainty around sampling time row += Math.Round(dataPoint.X, 3) + separator + dataPoint.Y + separator; first = false; } else { row += dataPoint.Y + separator; } } catch // index out of range, unequal number of sensor readings { row += "null" + separator; } } dataWriter.WriteLine(row); row = ""; } dataWriter.Close(); } })); if (backgroundWasRunning) { StartAcquisitionThread(); } }
private void updateGraph(USBdevice_GUI USB) { int index = USBdevices.IndexOf(USB); // get current sensor number SingleTactData data_pt = USB.dataBuffer; Color[] colours = { Color.Blue, Color.Orange, Color.DarkViolet, Color.Red, Color.DeepPink, Color.DarkSlateGray }; if (data_pt.data.Count > 0 && index < colours.Length) { // start graphing GraphPane graphPane = graph_.GraphPane; if (graphPane.CurveList.Count <= index) // initialise curves { string name = comPortList[index].ToString().Split('-')[1] + " " + (index + 1).ToString(); if (USBdevices[index].singleTact.firmwareVersion > 0) { if (USBdevices[index].isCalibrated) { name = name + "(calibrated)"; } if (USB.singleTact.Settings.SerialNumber != 0) { name += " SN" + USB.singleTact.Settings.SerialNumber.ToString("D5"); } } LineItem myCurve = new LineItem( name, new PointPairList(), colours[index], SymbolType.None, 3.0f); graphPane.CurveList.Add(myCurve); } else { // update curve data with new readings if (data_pt.data[0].Count > 1) { graphPane.CurveList[index].AddPoint(data_pt.data[0].Peek()); //grab the latest value from the buffer. if (graphPane.CurveList[index].NPts > 100 * 60) //only keep 6000 points on the screen { graphPane.CurveList[index].RemovePoint(0); } } } // This is to update the max and min value if (isFirstFrame_) { graphPane.XAxis.Scale.Min = data_pt.MostRecentTime; graphPane.XAxis.Scale.Max = graphPane.XAxis.Scale.Min + graphXRange_; isFirstFrame_ = false; } if (data_pt.MostRecentTime >= graphPane.XAxis.Scale.Max) { graphPane.XAxis.Scale.Max = data_pt.MostRecentTime; graphPane.XAxis.Scale.Min = graphPane.XAxis.Scale.Max - graphXRange_; //Update green valid region box BoxObj b = (BoxObj)graphPane.GraphObjList[0]; b.Location.X = graphPane.XAxis.Scale.Max - graphXRange_; if (NBtoForceFactor != 0) { b.Location.Y = Math.Min(graphPane.YAxis.Scale.Max, NBtoForceFactor); b.Location.Height = Math.Min(graphPane.YAxis.Scale.Max - graphPane.YAxis.Scale.Min, NBtoForceFactor); } else { b.Location.Y = Math.Min(graphPane.YAxis.Scale.Max, 512); b.Location.Height = Math.Min(graphPane.YAxis.Scale.Max - graphPane.YAxis.Scale.Min, 512); } try { graph_.AxisChange(); } catch { } } graph_.Refresh(); } }