public virtual void SetDataBlock(DataBlock db) { if (nextConsumer != null) { nextConsumer.SetDataBlock(db); } }
public DataBlock(DataBlock db) { if (db == null) { return; } Copy(db); }
public static void InitLoopThoughWave(DataBlock db) { find_max = true; delta_time = 0; fine = 0; extreme = 0; extreme_time = 0; m_db = db; adc_ptr = 0; zero = m_db.GetAverage(0); }
public override bool GetDataBlock(ref DataBlock db) { bool result; Config(); time = DateTime.Now; Read(res, 1); if (res[0] == 85) { db.m_sample = SampleID++; db.m_start = DateTime.Now; db.m_channels = 6; db.m_triggerVoltage = 0; db.m_triggerPos = 0; db.m_sampleRate = GetSampleRate(); db.m_samplesPerChannel = GetNumberOfSamplesPerChannel(); db.m_channelsBitField = GetChannelBitField(); db.m_dataType = DataBlock.DATA_TYPE.DIGITAL; db.Alloc(); if (m_arduinoBuffer.Length != db.m_samplesPerChannel) { // if (db.m_samplesPerChannel * db.m_channels > 94000) db.m_samplesPerChannel = 94000 / db.m_channels; m_arduinoBuffer = new byte[db.m_samplesPerChannel]; } result = Read(m_arduinoBuffer, m_arduinoBuffer.Length); for (int i = 0; i < m_arduinoBuffer.Length; i++) { db.SetVoltage(0, i, m_arduinoBuffer[i]); } db.m_stop = DateTime.Now; return result; } return false; }
public void Copy(DataBlock db) { this.m_channelsBitField = db.m_channelsBitField; this.m_channels = db.m_channels; this.m_sample = db.m_sample; this.m_start = db.m_start; this.m_stop = db.m_stop; this.m_min = db.m_min; this.m_max = db.m_max; this.m_sampleRate = db.m_sampleRate; this.m_samplesPerChannel = db.m_samplesPerChannel; this.m_triggerVoltage = db.m_triggerVoltage; this.m_triggerPos = db.m_triggerPos; this.m_result = db.m_result; this.m_dataType = db.m_dataType; this.m_Annotations = db.m_Annotations; this.m_index = db.m_index; Alloc(); System.Array.Copy(db.m_Buffer, 0, m_Buffer, 0, db.m_Buffer.Length); }
override public void SetDataBlock(DataBlock db) { dataBlock.Copy(db); if (enabled) { filter.SetSampleRate(db.m_sampleRate); //filter a few times the first value to initialize filter for (int i = 0; i < 4; i++) { double volt = db.GetVoltage(0, 0); filter.DoFilter(volt); } for (int i = 0; i < db.GetChannelLength(); i++) { double volt = db.GetVoltage(0, i); dataBlock.SetVoltage(0, i, (int)filter.DoFilter(volt)); } } base.SetDataBlock(dataBlock); }
public bool Open(DataBlock db) { return true; }
public override bool GetDataBlock(ref DataBlock db) { db.Copy(m_db); return true; }
override public bool GetDataBlock(ref DataBlock db) { bool result; //assume it timed out db.m_result = DataBlock.RESULT.TIMEOUT; if (GetNumberOfEnabledChannels() == 0) { return false; } //-------------Get settings this needs a crytical section) // int numberOfSamples; int numberOfEnabledChannels; uint channelsBitField; int sampleRate; lock (thisLock) { numberOfSamples = GetNumberOfSamplesPerChannel(); numberOfEnabledChannels = GetNumberOfEnabledChannels(); channelsBitField = GetChannelBitField(); sampleRate = GetSampleRate(); } //-------------Request data byte[] configBuffer = new byte[10]; configBuffer[0] = (byte)COMMANDS.READ_ADC_TRACE; configBuffer[1] = m_triggerValue; configBuffer[2] = (byte)(numberOfSamples >> 8); configBuffer[3] = (byte)(numberOfSamples & 0xff); configBuffer[4] = (byte)numberOfEnabledChannels; int index = 0; for (byte i = 0; i < 4; i++) { if (((channelsBitField>>i)&1)!=0) { configBuffer[5 + index] = i; index++; } } configBuffer[9] = (byte)127; //pwm Write(configBuffer, configBuffer.Length); //-------------Get data Read(res, 1); if (res[0] == 85) { db.m_min = 0; db.m_max = 5; db.m_channels = numberOfEnabledChannels; db.m_channelsBitField = channelsBitField; db.m_triggerVoltage = 0; db.m_triggerPos = 0; db.m_sampleRate = (db.m_channels > 0) ? (sampleRate / db.m_channels) : 0; db.m_samplesPerChannel = numberOfSamples; db.m_dataType = DataBlock.DATA_TYPE.ANALOG; db.Alloc(); //read actual data if (m_arduinoBuffer.Length != db.m_samplesPerChannel * db.m_channels) { m_arduinoBuffer = new byte[db.m_samplesPerChannel * db.m_channels]; } result = Read(m_arduinoBuffer, m_arduinoBuffer.Length); index = 0; for(int ch=0;ch<2;ch++) { if ( ((db.m_channelsBitField>>ch)&1) == 1) { for (int i = 0; i < db.GetChannelLength(); i++) { db.SetVoltage(index, i, m_arduinoBuffer[i * db.m_channels + index]); } index++; } } db.m_result = DataBlock.RESULT.OK; return result; } return false; }
virtual public void Draw(Graphics g, DataBlock db) { }
override public bool GetDataBlock(ref DataBlock db) { bool result = true; lock (thisLock) { //assume it timed out db.m_min = 0; db.m_max = 5; db.m_channels = GetNumberOfEnabledChannels(); db.m_channelsBitField = GetChannelBitField(); db.m_triggerVoltage = 0; db.m_triggerPos = 0; db.m_sampleRate = GetSampleRate(); db.m_samplesPerChannel = GetNumberOfSamplesPerChannel(); db.m_dataType = DataBlock.DATA_TYPE.ANALOG; db.Alloc(); } for (int i = 0; i < db.GetChannelLength(); i++) { /* * byte header = GetStream().ReadByte(); * if (header < 128) * { * byte b1 = GetStream().ReadByte(); * byte b2 = GetStream().ReadByte(); * * for (int c = 0; c < db.m_channels; c++) * { * UInt16 v = (UInt16)(GetStream().ReadByte() * 256 + GetStream().ReadByte()); * db.SetVoltage(c, i, v); * } * GetStream().ReadByte(); * } * else * { * GetResponse(header); * * //if command received then abort * for (; i < db.GetChannelLength(); i++) * { * for (int c = 0; c < db.m_channels; c++) * { * db.SetVoltage(c, i, 0); * } * } * * } */ byte[] header = new byte[1]; byte[] data = new byte[20]; Read(header, 1); if (header[0] < 128) { Read(data, 3 + 2 * db.m_channels); Console.WriteLine("{0} {1} {2} {3}", header[0], data[0], data[1], data[2]); } else { Read(data, 3); Console.WriteLine("* {0} {1} {2} {3}", header[0], data[0], data[1], data[2]); } } db.m_result = DataBlock.RESULT.OK; return(result); }
public bool Open(DataBlock db) { return(true); }
public FileDigitalVizForm(SerializationHelper sh) : base() { gd = new GraphDigital(sh.graph); dataBlock = sh.dataBlock; }
public void SetDataBlock(DataBlock db) { m_db.Copy(db); }
override public bool GetDataBlock(ref DataBlock db) { //need to make a copy of this variable just in case it changes //remember the ui lives in a different thread and can change values. bool copyFastMode; lock (thisLock) { PrepareConfigBuffer(); copyFastMode = fastMode; db.m_min = 0; db.m_max = 5; db.m_channels = fastMode ? 1 : GetNumberOfEnabledChannels(); db.m_channelsBitField = fastMode ? 1 : GetChannelBitField(); db.m_triggerVoltage = triggerVoltage; db.m_triggerPos = fastMode ? 3000 / 2 : 1500 / 2; db.m_sampleRate = GetSampleRate(); db.m_samplesPerChannel = fastMode ? 3000 : 1500; db.Alloc(); } if (db.m_sampleRate > 0) { serialPort.ReadTimeout = (2 * db.m_samplesPerChannel * 1000) / db.m_sampleRate; } if (serialPort.ReadTimeout < 200) { serialPort.ReadTimeout = 200; } serialPort.Write(configBuffer, 0, 9); Read(res, 1); if (res[0] == 85) { Read(parallaxBuffer, 3000); if (copyFastMode) { for (int i = 0; i < 3000; i++) { db.SetVoltage(0, i, parallaxBuffer[i]); } } else { int index = 0; if ((db.m_channelsBitField & 1) > 0) { for (int i = 0; i < 1500; i++) { db.SetVoltage(index, i, parallaxBuffer[i]); } index++; } if ((db.m_channelsBitField & 2) > 0) { for (int i = 0; i < 1500; i++) { db.SetVoltage(index, i, parallaxBuffer[i + 1500]); } index++; } } return(true); } return(false); }
override public bool GetDataBlock(ref DataBlock db) { db.Copy(m_db); return(true); }
public void LoadCSV(string file) { List<string> parsedData = new List<string>(); // Open the file, creating it if necessary. FileStream stream = File.Open(file, FileMode.Open); StreamReader reader = new StreamReader(stream); string line; while ((line = reader.ReadLine()) != null) { string[] row = line.Split(','); foreach (string s in row) { if (s != "") parsedData.Add(s); } } // Close the file. stream.Close(); DataBlock db = new DataBlock(); m_Buffer = new int[parsedData.Count]; for (int i = 0; i < parsedData.Count; i++) { m_Buffer[i] = int.Parse(parsedData[i]); } m_channels = 1; m_sampleRate = (115600 / 8); m_triggerVoltage = 0; //this.m_start = Time.now; }
override public void SetDataBlock(DataBlock db) { m_db = new DataBlock(); m_db.Copy(db); //List<int> PeakOffsets = GetMinMax(m_db); List <int> PeakOffsets = new List <int>(); List <int> deltas = new List <int>(); PeakFinder.InitLoopThoughWave(db); int t = 0; for (; ;) { int v = PeakFinder.LoopThoughWave(); if (v == 255) { break; } t = t + v; PeakOffsets.Add(t); deltas.Add(v); } db.m_Annotations = PeakOffsets.ToArray(); int offset = 0; for (; offset < deltas.Count; offset++) { if (deltas[offset] != 0) { break; } } if (offset >= 0) { //output.Text += string.Format("Clocked signal found: {0}\r\n", offset); string bitstream = ExtractBits(deltas); output.Text += bitstream + "\r\n"; //output.Text += string.Format("Errors as FSK: {0}\r\n", DetectFSK(bitstream)); output.Text += "\r\nText:\r\n"; output.Text += Decode4BitsToString(bitstream, false) + "\r\n"; //output.Text += string.Format("Alternating: \r\n"); //output.Text += GetBitStreamFromAlternating(bitstream) + "\r\n"; } else { output.Text += string.Format("Clocked signal not found, dumping timing values\r\n"); int last = 0; foreach (int i in PeakOffsets) { output.Text += string.Format("{0:0000}: {1}", i, i - last) + "\r\n"; last = i; } } }
public override bool GetDataBlock(ref DataBlock db) { bool result = true; lock (thisLock) { //assume it timed out db.m_min = 0; db.m_max = 5; db.m_channels = GetNumberOfEnabledChannels(); db.m_channelsBitField = GetChannelBitField(); db.m_triggerVoltage = 0; db.m_triggerPos = 0; db.m_sampleRate = GetSampleRate(); db.m_samplesPerChannel = GetNumberOfSamplesPerChannel(); db.m_dataType = DataBlock.DATA_TYPE.ANALOG; db.Alloc(); } for (int i = 0; i < db.GetChannelLength(); i++) { /* byte header = GetStream().ReadByte(); if (header < 128) { byte b1 = GetStream().ReadByte(); byte b2 = GetStream().ReadByte(); for (int c = 0; c < db.m_channels; c++) { UInt16 v = (UInt16)(GetStream().ReadByte() * 256 + GetStream().ReadByte()); db.SetVoltage(c, i, v); } GetStream().ReadByte(); } else { GetResponse(header); //if command received then abort for (; i < db.GetChannelLength(); i++) { for (int c = 0; c < db.m_channels; c++) { db.SetVoltage(c, i, 0); } } } */ byte[] header = new byte[1]; byte[] data = new byte[20]; Read(header, 1); if (header[0] < 128) { Read(data, 3 + 2 * db.m_channels); Console.WriteLine("{0} {1} {2} {3}", header[0], data[0], data[1], data[2]); } else { Read(data, 3); Console.WriteLine("* {0} {1} {2} {3}",header[0],data[0],data[1],data[2]); } } db.m_result = DataBlock.RESULT.OK; return result; }
public FileAnalogVizForm(SerializationHelper sh) : base() { ga = new GraphAnalog(sh.graph); dataBlock = sh.dataBlock; }
override public void Draw(Graphics g, DataBlock db) { Rectangle r = new Rectangle(); r = m_Bounds; if (f == null) { f = new fft(1024); } if (db.m_result != DataBlock.RESULT.OK) { pp.X = 0; pp.Y = 0; g.DrawString(string.Format("Waiting for a chunk of data to analyze"), parent.Font, Brushes.White, pp); return; } if (db.GetChannelLength() < f.GetNumOfSamples()) { pp.X = 0; pp.Y = 0; g.DrawString(string.Format("FFT needs at least 1024 samples to work, got only {0}, try increasing the measurement time", db.GetChannelLength()), parent.Font, Brushes.White, pp); return; } for (int i = 0; i < f.GetNumOfSamples(); i++) { f.x[i] = db.GetVoltage(0, i); f.y[i] = 0; } f.FFT(0); int maxFreq = db.m_sampleRate / 2; int minFreq = 0; //margin at the bottom r.Height -= 20; r.Width = 1024; r.X -= (int)MinXD; if (drawSlidingFFT) { DrawSlidingFFT(g, r, db); r.Y -= 256; DrawFFTBars(g, r); r.Y += 256; } else { DrawFFTBars(g, r); } int freqStep; for (freqStep = 500; freqStep < maxFreq; freqStep += 500) { int ft = lerp(0, f.GetNumOfSamples() / 2, minFreq, maxFreq, freqStep); if (ft > 30) { break; } } //draw legend for (int i = 0; i < (int)maxFreq; i += freqStep) { int x = lerp(0, 512, minFreq, maxFreq, i); pp.X = r.X + 2 * x; pp.Y = r.Bottom; g.DrawLine(Pens.Gray, pp.X, 0, pp.X, pp.Y); g.DrawString(string.Format("{0}", i), parent.Font, Brushes.White, pp); } if (m_mouse != null) { DrawCross(g, Pens.Blue, m_mouse.X, m_mouse.Y); pp.X = r.X; pp.Y = r.Y + 40; g.DrawString(string.Format("Freq: {0} Hz", ((m_mouse.X / 2) * maxFreq) / f.GetNumOfSamples() / 2), parent.Font, Brushes.White, pp); } }
private void DrawGraph(Graphics g, Pen p, DataBlock db, int channel) { float yy = 0; float xx = 0; int i = 0; int i0 = (int)Math.Floor(lerp(0, db.GetChannelLength(), 0, db.GetTotalTime(), MinXD)); int i1 = (int)Math.Ceiling(lerp(0, db.GetChannelLength(), 0, db.GetTotalTime(), MaxXD)) + 1; if (i1 > db.GetChannelLength()) { i1 = db.GetChannelLength(); } if (db.m_Annotations != null) { for (int an = 0; an < db.m_Annotations.Length; an++) { float time = db.GetTime(db.m_Annotations[an]); float x = ValueXToRect(time); g.DrawLine(Pens.Green, x, 0, x, ValueYToRect(5)); } } try { for (i = i0; i < i1; i++) { int rawvolt = db.GetVoltage(channel, i); float time = db.GetTime(i); float x = ValueXToRect(time); float y = ValueYToRect(rawvolt); if (i > 0) { g.DrawLine(p, xx, yy, x, y); if (showValueTicks) { g.DrawLine(p, x, y - 2, x, y + 2); g.DrawLine(p, x - 2, y, x + 2, y); } } yy = y; xx = x; } } catch { Console.WriteLine("{0} {1} {2}", db, m_Bounds, i); } //Cursor.Hide(); if (m_mouse != null) { DrawCross(g, Pens.Blue, m_mouse.X, m_mouse.Y); } { float t = (db.m_triggerPos * db.GetTotalTime()) / (float)db.GetChannelLength(); float x = ValueXToRect(t); g.DrawLine(Pens.Green, x, m_Bounds.Y, x, m_Bounds.Y + m_Bounds.Height); } Point pp = new Point(); pp.X = 0; pp.Y = 32; if (m_mouse != null) { float time = RectToValueX(m_mouse.X); float voltage = RectToValueY(m_mouse.Y); string info = string.Format("{0} ({1}, {2})", db.m_sample, ToEngineeringNotation(time), voltage); g.DrawString(info, parent.Font, Brushes.White, pp); pp.Y += 16; info = string.Format("({0}s/div, {1}Ks/s)", ToEngineeringNotation(DivX), db.m_sampleRate / 1000); g.DrawString(info, parent.Font, Brushes.White, pp); pp.Y += 16; } if (Selected()) { if ((m_selectT0 < db.GetTotalTime()) && (m_selectT1 < db.GetTotalTime())) { g.DrawString(string.Format("({0}, {1}) - ({2}, {3})", ToEngineeringNotation(m_selectT0), db.GetVoltage(0, m_selectT0), ToEngineeringNotation(m_selectT1), db.GetVoltage(0, m_selectT1)), parent.Font, Brushes.White, pp); pp.Y += 16; g.DrawString(string.Format("ΔVoltage = {0}", db.GetVoltage(0, m_selectT1) - db.GetVoltage(0, m_selectT0)), parent.Font, Brushes.White, pp); pp.Y += 16; } string time = string.Format("ΔTime = {0}", ToEngineeringNotation(m_selectT1 - m_selectT0)); if (m_selectT1 - m_selectT0 > 0) { time += string.Format(", {0} Hz", (int)(1.0f / (m_selectT1 - m_selectT0))); } g.DrawString(time, parent.Font, Brushes.White, pp); pp.Y += 16; } }
override public bool GetDataBlock(ref DataBlock db) { //need to make a copy of this variable just in case it changes //remember the ui lives in a different thread and can change values. bool copyFastMode; lock (thisLock) { PrepareConfigBuffer(); copyFastMode = fastMode; db.m_min = 0; db.m_max = 5; db.m_channels = fastMode ? 1 : GetNumberOfEnabledChannels(); db.m_channelsBitField = fastMode ? 1 : GetChannelBitField(); db.m_triggerVoltage = triggerVoltage; db.m_triggerPos = fastMode ? 3000 / 2 : 1500 / 2; db.m_sampleRate = GetSampleRate(); db.m_samplesPerChannel = fastMode ? 3000 : 1500; db.Alloc(); } if (db.m_sampleRate > 0) { serialPort.ReadTimeout = (2 * db.m_samplesPerChannel * 1000) / db.m_sampleRate; } if (serialPort.ReadTimeout < 200) { serialPort.ReadTimeout = 200; } serialPort.Write(configBuffer, 0, 9); Read(res, 1); if (res[0] == 85) { Read(parallaxBuffer, 3000); if (copyFastMode) { for (int i = 0; i < 3000; i++) { db.SetVoltage(0, i, parallaxBuffer[i]); } } else { int index = 0; if ((db.m_channelsBitField & 1) > 0) { for (int i = 0; i < 1500; i++) { db.SetVoltage(index, i, parallaxBuffer[i]); } index++; } if ((db.m_channelsBitField & 2) > 0) { for (int i = 0; i < 1500; i++) { db.SetVoltage(index, i, parallaxBuffer[i + 1500]); } index++; } } return true; } return false; }
virtual public bool GetDataBlock(ref DataBlock db) { return(false); }
override public void SetDataBlock(DataBlock db) { graphControl.SetScopeData(db); }
override public bool GetDataBlock(ref DataBlock db) { bool result; //assume it timed out db.m_result = DataBlock.RESULT.TIMEOUT; if (GetNumberOfEnabledChannels() == 0) { return(false); } //-------------Get settings this needs a crytical section) // int numberOfSamples; int numberOfEnabledChannels; uint channelsBitField; int sampleRate; lock (thisLock) { numberOfSamples = GetNumberOfSamplesPerChannel(); numberOfEnabledChannels = GetNumberOfEnabledChannels(); channelsBitField = GetChannelBitField(); sampleRate = GetSampleRate(); } //-------------Request data byte[] configBuffer = new byte[10]; configBuffer[0] = (byte)COMMANDS.READ_ADC_TRACE; configBuffer[1] = m_triggerValue; configBuffer[2] = (byte)(numberOfSamples >> 8); configBuffer[3] = (byte)(numberOfSamples & 0xff); configBuffer[4] = (byte)numberOfEnabledChannels; int index = 0; for (byte i = 0; i < 4; i++) { if (((channelsBitField >> i) & 1) != 0) { configBuffer[5 + index] = i; index++; } } configBuffer[9] = (byte)127; //pwm Write(configBuffer, configBuffer.Length); //-------------Get data Read(res, 1); if (res[0] == 85) { db.m_min = 0; db.m_max = 5; db.m_channels = numberOfEnabledChannels; db.m_channelsBitField = channelsBitField; db.m_triggerVoltage = 0; db.m_triggerPos = 0; db.m_sampleRate = (db.m_channels > 0) ? (sampleRate / db.m_channels) : 0; db.m_samplesPerChannel = numberOfSamples; db.m_dataType = DataBlock.DATA_TYPE.ANALOG; db.Alloc(); //read actual data if (m_arduinoBuffer.Length != db.m_samplesPerChannel * db.m_channels) { m_arduinoBuffer = new byte[db.m_samplesPerChannel * db.m_channels]; } result = Read(m_arduinoBuffer, m_arduinoBuffer.Length); index = 0; for (int ch = 0; ch < 2; ch++) { if (((db.m_channelsBitField >> ch) & 1) == 1) { for (int i = 0; i < db.GetChannelLength(); i++) { db.SetVoltage(index, i, m_arduinoBuffer[i * db.m_channels + index]); } index++; } } db.m_result = DataBlock.RESULT.OK; return(result); } return(false); }
virtual public bool GetDataBlock(ref DataBlock db) { return false; }
virtual public void SetDataBlock(DataBlock db) { }