diff --git a/.vs/DigitalAnalyzer/v15/.suo b/.vs/DigitalAnalyzer/v15/.suo new file mode 100644 index 0000000..24e32e7 Binary files /dev/null and b/.vs/DigitalAnalyzer/v15/.suo differ diff --git a/.vscode/arduino.json b/.vscode/arduino.json new file mode 100644 index 0000000..b8cfe43 --- /dev/null +++ b/.vscode/arduino.json @@ -0,0 +1,6 @@ +{ + "board": "esp8266:esp8266:d1_mini", + "configuration": "CpuFrequency=80,UploadSpeed=921600,FlashSize=4M3M", + "port": "COM10", + "sketch": "Arduino sketches\\analyzer-WeMosD1miniPro\\analyzer-WeMosD1miniPro.ino" +} \ No newline at end of file diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..ddefbe7 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -0,0 +1,19 @@ +{ + "configurations": [ + { + "name": "Win32", + "includePath": [ + "C:\\Users\\anteo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.3.0\\cores\\esp8266" + ], + "browse": { + "limitSymbolsToIncludedHeaders": false, + "path": [ + "C:\\Users\\anteo\\AppData\\Local\\Arduino15\\packages\\esp8266\\hardware\\esp8266\\2.3.0\\cores\\esp8266", + "${workspaceRoot}" + ] + }, + "intelliSenseMode": "msvc-x64" + } + ], + "version": 3 +} \ No newline at end of file diff --git a/analyzer.ino b/Arduino sketches/analyzer - Arduino Uno/analyzer - Arduino Uno.ino similarity index 100% rename from analyzer.ino rename to Arduino sketches/analyzer - Arduino Uno/analyzer - Arduino Uno.ino diff --git a/Arduino sketches/analyzer-WeMosD1miniPro/analyzer-WeMosD1miniPro.ino b/Arduino sketches/analyzer-WeMosD1miniPro/analyzer-WeMosD1miniPro.ino new file mode 100644 index 0000000..05b17c9 --- /dev/null +++ b/Arduino sketches/analyzer-WeMosD1miniPro/analyzer-WeMosD1miniPro.ino @@ -0,0 +1,110 @@ +#define green1 D0 +#define green2 D1 +#define yellow1 D2 +#define yellow2 D3 +#define purple1 D4 +#define purple2 D5 +#define purple3 D6 +#define purple4 D7 +#define data0 D8 +#define data1 18 +#define data2 17 +#define data3 16 +#define data4 15 +#define data5 14 +#define data6 10 +#define data7 11 +#define powerPin 12 + +void setup() { + + pinMode(green1, INPUT); + pinMode(green2, INPUT); + pinMode(yellow1, INPUT); + pinMode(yellow2, INPUT); + + pinMode(purple1, INPUT); + pinMode(purple2, INPUT); + pinMode(purple3, INPUT); + pinMode(purple4, INPUT); + /* + pinMode(data0, INPUT); + pinMode(data1, INPUT); + pinMode(data2, INPUT); + pinMode(data3, INPUT); + + pinMode(data4, INPUT); + pinMode(data5, INPUT); + pinMode(data6, INPUT); + pinMode(data7, INPUT); + */ + + /* + pinMode(powerPin, OUTPUT); + digitalWrite(powerPin, LOW); + delay(1000); + digitalWrite(powerPin, HIGH); + */ + + Serial.begin(115200); + while (!Serial) { ; } +} + + + +byte in; +int buff; +unsigned long times; + +void loop() { + times = micros(); + + //for(int i = 0; i < 100; i++){ + + buff = 2; + + if (digitalRead(green1) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(green2) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(yellow1) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(yellow2) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(purple1) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(purple2) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(purple3) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(purple4) == HIGH) buff = buff | 1; + buff = buff << 1; + /* + if (digitalRead(data0) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(data1) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(data2) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(data3) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(data4) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(data5) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(data6) == HIGH) buff = buff | 1; + buff = buff << 1; + if (digitalRead(data7) == HIGH) buff = buff | 1; + //buff = buff << 1;*/ + Serial.println(buff); + //delay(4); + + delay(4); //testing how the code wil handle slow refresh rate + + //} + /* + Serial.println("Time test:"); + Serial.println(micros() - times); + delay(1000);*/ + +} diff --git a/DigitalAnalyzer.sln b/DigitalAnalyzer.sln index 0ae2b2c..3e32e7c 100644 --- a/DigitalAnalyzer.sln +++ b/DigitalAnalyzer.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26430.15 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DigitalAnalyzer", "DigitalAnalyzer\DigitalAnalyzer.csproj", "{9CA1AD68-092B-422B-8983-A0D5D8ADE182}" EndProject diff --git a/DigitalAnalyzer/Form1.Designer.cs b/DigitalAnalyzer/Form1.Designer.cs index 94e3497..12e82df 100644 --- a/DigitalAnalyzer/Form1.Designer.cs +++ b/DigitalAnalyzer/Form1.Designer.cs @@ -69,6 +69,9 @@ private void InitializeComponent() { this.bit13 = new System.Windows.Forms.CheckBox(); this.bit14 = new System.Windows.Forms.CheckBox(); this.bit15 = new System.Windows.Forms.CheckBox(); + this.SerialPortComboBox = new System.Windows.Forms.ComboBox(); + this.SerialSpeedComboBox = new System.Windows.Forms.ComboBox(); + this.DelayTextBox = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); this.SuspendLayout(); // @@ -78,24 +81,24 @@ private void InitializeComponent() { this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 1; - this.button1.Text = "save data"; + this.button1.Text = "Save data"; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // button2 // - this.button2.Location = new System.Drawing.Point(255, 7); + this.button2.Location = new System.Drawing.Point(542, 6); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(75, 23); this.button2.TabIndex = 2; - this.button2.Text = "close"; + this.button2.Text = "Close"; this.button2.UseVisualStyleBackColor = true; this.button2.Click += new System.EventHandler(this.button2_Click); // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(499, 12); + this.label1.Location = new System.Drawing.Point(746, 12); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(126, 13); this.label1.TabIndex = 5; @@ -239,7 +242,7 @@ private void InitializeComponent() { this.button4.Name = "button4"; this.button4.Size = new System.Drawing.Size(75, 23); this.button4.TabIndex = 8; - this.button4.Text = "save control"; + this.button4.Text = "Save control"; this.button4.UseVisualStyleBackColor = true; // // ctrlList @@ -260,18 +263,18 @@ private void InitializeComponent() { // // button3 // - this.button3.Location = new System.Drawing.Point(174, 7); + this.button3.Location = new System.Drawing.Point(461, 6); this.button3.Name = "button3"; this.button3.Size = new System.Drawing.Size(75, 23); this.button3.TabIndex = 11; - this.button3.Text = "open"; + this.button3.Text = "Open"; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button1_Click); // // resetChk // this.resetChk.AutoSize = true; - this.resetChk.Location = new System.Drawing.Point(336, 11); + this.resetChk.Location = new System.Drawing.Point(623, 11); this.resetChk.Name = "resetChk"; this.resetChk.Size = new System.Drawing.Size(106, 17); this.resetChk.TabIndex = 12; @@ -284,7 +287,7 @@ private void InitializeComponent() { this.load.Name = "load"; this.load.Size = new System.Drawing.Size(75, 23); this.load.TabIndex = 13; - this.load.Text = "load"; + this.load.Text = "Load"; this.load.UseVisualStyleBackColor = true; this.load.Click += new System.EventHandler(this.load_Click); // @@ -294,17 +297,17 @@ private void InitializeComponent() { this.save.Name = "save"; this.save.Size = new System.Drawing.Size(75, 23); this.save.TabIndex = 14; - this.save.Text = "save"; + this.save.Text = "Save"; this.save.UseVisualStyleBackColor = true; this.save.Click += new System.EventHandler(this.save_Click); // // button5 // - this.button5.Location = new System.Drawing.Point(790, 7); + this.button5.Location = new System.Drawing.Point(900, 7); this.button5.Name = "button5"; this.button5.Size = new System.Drawing.Size(75, 23); this.button5.TabIndex = 15; - this.button5.Text = "fill lists"; + this.button5.Text = "Fill lists"; this.button5.UseVisualStyleBackColor = true; this.button5.Click += new System.EventHandler(this.button5_Click); // @@ -500,11 +503,40 @@ private void InitializeComponent() { this.bit15.TabIndex = 16; this.bit15.UseVisualStyleBackColor = false; // + // SerialPortComboBox + // + this.SerialPortComboBox.FormattingEnabled = true; + this.SerialPortComboBox.Location = new System.Drawing.Point(173, 8); + this.SerialPortComboBox.Margin = new System.Windows.Forms.Padding(2); + this.SerialPortComboBox.Name = "SerialPortComboBox"; + this.SerialPortComboBox.Size = new System.Drawing.Size(92, 21); + this.SerialPortComboBox.TabIndex = 17; + this.SerialPortComboBox.DropDown += new System.EventHandler(this.SerialPortComboBox_DropDown); + // + // SerialSpeedComboBox + // + this.SerialSpeedComboBox.FormattingEnabled = true; + this.SerialSpeedComboBox.Location = new System.Drawing.Point(268, 7); + this.SerialSpeedComboBox.Margin = new System.Windows.Forms.Padding(2); + this.SerialSpeedComboBox.Name = "SerialSpeedComboBox"; + this.SerialSpeedComboBox.Size = new System.Drawing.Size(92, 21); + this.SerialSpeedComboBox.TabIndex = 18; + // + // DelayTextBox + // + this.DelayTextBox.Location = new System.Drawing.Point(365, 7); + this.DelayTextBox.Name = "DelayTextBox"; + this.DelayTextBox.Size = new System.Drawing.Size(84, 20); + this.DelayTextBox.TabIndex = 19; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1197, 462); + this.Controls.Add(this.DelayTextBox); + this.Controls.Add(this.SerialSpeedComboBox); + this.Controls.Add(this.SerialPortComboBox); this.Controls.Add(this.bit15); this.Controls.Add(this.bit14); this.Controls.Add(this.bit13); @@ -533,8 +565,11 @@ private void InitializeComponent() { this.Controls.Add(this.label1); this.Controls.Add(this.button2); this.Controls.Add(this.button1); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Name = "Form1"; - this.Text = "Form1"; + this.ShowIcon = false; + this.Text = "LogicAnalyzer"; + this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.chart1)).EndInit(); this.ResumeLayout(false); this.PerformLayout(); @@ -570,6 +605,9 @@ private void InitializeComponent() { private System.Windows.Forms.CheckBox bit13; private System.Windows.Forms.CheckBox bit14; private System.Windows.Forms.CheckBox bit15; + private System.Windows.Forms.ComboBox SerialPortComboBox; + private System.Windows.Forms.ComboBox SerialSpeedComboBox; + private System.Windows.Forms.TextBox DelayTextBox; } } diff --git a/DigitalAnalyzer/Form1.cs b/DigitalAnalyzer/Form1.cs index 2918bde..bdba1ae 100644 --- a/DigitalAnalyzer/Form1.cs +++ b/DigitalAnalyzer/Form1.cs @@ -1,27 +1,50 @@ using System; using System.Collections.Generic; -using System.ComponentModel; using System.Data; using System.Diagnostics; -using System.Drawing; using System.IO.Ports; using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; + + +// TODO Fix infinite memory use - currently all teh data is saved, maybe celear every 10000 samples +// TODO Compression - don't store data, store events like state change +// TODO decimation - show every Nth sample +// TODO Move to oxycharts or live charts +// TODO clear data +// TODO auto program the arduino +// TODO add data to send to the board +// TODO show time between readings +// TODO send serial data as BIN not string, or add something for determinism +// TODO self calibrate code for e.g. fixed 1 khz sample rate +// TODO make resizable +// TODO group into vectors + + namespace DigitalAnalyzer { public partial class Form1:Form { - private static SerialPort com; - private int prevX = 0; + private static SerialPort _com; + private int _prevX = 0; + private int _prevXrem = 0; private delegate void GetTextDeleg(List strings); private delegate void GetStringDeleg(string data); public Form1() { InitializeComponent(); chart1.MouseWheel += new MouseEventHandler(chart1_MouseWheel); + + SerialSpeedComboBox.Items.Add(19200); + SerialSpeedComboBox.Items.Add(115200); + SerialSpeedComboBox.SelectedItem = 115200; + + + string[] ports = SerialPort.GetPortNames(); + foreach(string port in ports) { + SerialPortComboBox.Items.Add(port); + SerialPortComboBox.SelectedItem = port; + } } private void chart1_MouseWheel(object sender, MouseEventArgs e) { @@ -64,37 +87,39 @@ private void chart1_MouseWheel(object sender, MouseEventArgs e) { } private void button1_Click(object sender, EventArgs e) { - try { com.Close(); } catch { } + try { _com.Close(); } catch { } try { - com = new SerialPort("COM3", 19200); - com.DataReceived += new SerialDataReceivedEventHandler(gotSomething); - com.DtrEnable = resetChk.Checked; - com.Open(); - } catch { MessageBox.Show("something went wrong!"); } + _com = new SerialPort((string) SerialPortComboBox.SelectedItem, (int) SerialSpeedComboBox.SelectedItem); + _com.DataReceived += new SerialDataReceivedEventHandler(GotSomething); + _com.DtrEnable = resetChk.Checked; + _com.Open(); + _com.Write(DelayTextBox.Text); + } catch (Exception exe) { MessageBox.Show($"Something went wrong!\n{exe.ToString()}"); } } - void gotSomething(object sender, SerialDataReceivedEventArgs e) { + void GotSomething(object sender, SerialDataReceivedEventArgs e) { String input = String.Empty; //input = com.ReadLine(); //BeginInvoke(new GetStringDeleg(processInputString), new object[] { input }); - int bytes = com.BytesToRead; + int bytes = _com.BytesToRead; byte[] buffer = new byte[bytes]; - com.Read(buffer, 0, bytes); + _com.Read(buffer, 0, bytes); - if (buffer != null) bytesToStrings(buffer); + //TODO don't check if null but check if empty + if (buffer.Length != 0) BytesToStrings(buffer); } - void bytesToStrings(byte[] bytes) { + void BytesToStrings(byte[] bytes) { List strings = new List(); string temp = String.Empty; - for (int i = 0; i < bytes.Length; i++) { - if ((char)bytes[i] != '\r') { - temp += (char)bytes[i]; + foreach (byte t in bytes) { + if ((char)t != '\r') { + temp += (char)t; } else { if (temp != String.Empty) { strings.Add(temp); @@ -103,12 +128,12 @@ void bytesToStrings(byte[] bytes) { } } - BeginInvoke(new GetTextDeleg(processInput), new object[] { strings }); + BeginInvoke(new GetTextDeleg(ProcessInput), new object[] { strings }); } - private void processInput(List strings) { + private void ProcessInput(List strings) { for (int s = 0; s < strings.Count; s++) { - processInputString(strings[s]); + ProcessInputString(strings[s]); } /* @@ -119,7 +144,8 @@ private void processInput(List strings) { }*/ } - private void processInputString(string data) { + private void ProcessInputString(string data) { + // TODO somehow handle this exception string bin = Convert.ToString(Int32.Parse(data), 2).PadLeft(16, '0'); chart1.Series.SuspendUpdates(); @@ -131,31 +157,53 @@ private void processInputString(string data) { for (int i = 15; i >= 0; i--) { //if (bin[i] == '\n' || data[i] == ';') continue; + + + + + if (!((CheckBox)Controls.Find("bit" + i, false)[0]).Checked) { offset += 2; + chart1.Series[i].Points.Clear(); continue; } double y = offset + (bin[i] == '1' ? 1 : 0); - chart1.Series[i].Points.AddXY(prevX, y); - chart1.Series[i].Points.AddXY(prevX + 1, y); + chart1.Series[i].Points.AddXY(_prevX, y); + chart1.Series[i].Points.AddXY(_prevX + 1, y); + + + // HACK Each loop adds 2 points. Removing first 2 points each loop stops working, but removing 3 works fine? + // I think that somehow changing the number of point triggers view update + if(chart1.Series[i].Points.Count >= 200) { + chart1.Series[i].Points.RemoveAt(0); + chart1.Series[i].Points.RemoveAt(0); + //chart1.Series[i].Points.RemoveAt(0); + } + offset += 2; } - prevX++; + _prevX++; + + // Hack part 2 - yea this fixes from few lines up + chart1.ResetAutoValues(); + + DelayTextBox.Text = chart1.Series[1].Points.Count.ToString(); + chart1.Series.ResumeUpdates(); chart1.ChartAreas[0].AxisX.ScaleView.Scroll(chart1.ChartAreas[0].AxisX.Maximum); - ctrlList.Items.Add(bin.Substring(0, 8)); - dataList.Items.Add(bin.Substring(8, 8)); + //ctrlList.Items.Add(bin.Substring(0, 8)); + //dataList.Items.Add(bin.Substring(8, 8)); } private void button2_Click(object sender, EventArgs e) { - try { com.Close(); } catch { } - com.DataReceived -= gotSomething; + try { _com.Close(); } catch { } + _com.DataReceived -= GotSomething; } private void chart1_MouseEnter(object sender, EventArgs e) { @@ -163,13 +211,13 @@ private void chart1_MouseEnter(object sender, EventArgs e) { } private void chart1_CursorPositionChanged(object sender, CursorEventArgs e) { + // FIX This throws exception if selected during acquisition ctrlList.SelectedIndex = (int)e.NewPosition; dataList.SelectedIndex = (int)e.NewPosition; } private void load_Click(object sender, EventArgs e) { - OpenFileDialog loadFile = new OpenFileDialog(); - loadFile.Title = "Load data"; + OpenFileDialog loadFile = new OpenFileDialog {Title = "Load data"}; loadFile.ShowDialog(); if (loadFile.FileName != "") { @@ -178,8 +226,7 @@ private void load_Click(object sender, EventArgs e) { } private void save_Click(object sender, EventArgs e) { - SaveFileDialog saveFile = new SaveFileDialog(); - saveFile.Title = "Save data"; + SaveFileDialog saveFile = new SaveFileDialog {Title = "Save data"}; saveFile.ShowDialog(); if (saveFile.FileName != "") { @@ -206,5 +253,26 @@ private void button5_Click(object sender, EventArgs e) { dataList.Items.Add(bin.Substring(8, 8)); } } + + private void SerialPortComboBox_DropDown(object sender, EventArgs e) { + SerialPortComboBox.Items.Clear(); + string[] ports = SerialPort.GetPortNames(); + foreach(string port in ports) { + SerialPortComboBox.Items.Add(port); + } + } + + private void Form1_Load(object sender, EventArgs e) { + + } + + protected override void OnFormClosing(FormClosingEventArgs e) { + base.OnFormClosing(e); + + if(e.CloseReason == CloseReason.WindowsShutDown) + return; + + Environment.Exit(0); + } } }