Repository: xioTechnologies/Serial-Oscilloscope Branch: master Commit: 217e494a0c59 Files: 24 Total size: 150.5 KB Directory structure: gitextract_wgem7s09/ ├── .gitattributes ├── .gitignore ├── ArduinoPrintADC/ │ └── ArduinoPrintADC.ino ├── README.md └── Serial Oscilloscope/ ├── Serial Oscilloscope/ │ ├── CsvFileWriter.cs │ ├── FormGetValue.Designer.cs │ ├── FormGetValue.cs │ ├── FormGetValue.resx │ ├── FormTerminal.Designer.cs │ ├── FormTerminal.cs │ ├── FormTerminal.resx │ ├── Oscilloscope/ │ │ ├── Oscilloscope.cs │ │ └── Oscilloscope_settings.ini │ ├── Program.cs │ ├── Properties/ │ │ ├── AssemblyInfo.cs │ │ ├── Resources.Designer.cs │ │ ├── Resources.resx │ │ ├── Settings.Designer.cs │ │ └── Settings.settings │ ├── SampleCounter.cs │ ├── Serial Oscilloscope.csproj │ ├── TextBoxBuffer.cs │ └── VisualStudio_CleanUp.bat └── Serial Oscilloscope.sln ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ # Auto detect text files and perform LF normalization * text=auto # Custom for Visual Studio *.cs diff=csharp *.sln merge=union *.csproj merge=union *.vbproj merge=union *.fsproj merge=union *.dbproj merge=union # Standard to msysgit *.doc diff=astextplain *.DOC diff=astextplain *.docx diff=astextplain *.DOCX diff=astextplain *.dot diff=astextplain *.DOT diff=astextplain *.pdf diff=astextplain *.PDF diff=astextplain *.rtf diff=astextplain *.RTF diff=astextplain ================================================ FILE: .gitignore ================================================ ################# ## Eclipse ################# *.pydevproject .project .metadata bin/ tmp/ *.tmp *.bak *.swp *~.nib local.properties .classpath .settings/ .loadpath # External tool builders .externalToolBuilders/ # Locally stored "Eclipse launch configurations" *.launch # CDT-specific .cproject # PDT-specific .buildpath ################# ## Visual Studio ################# ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. # User-specific files *.suo *.user *.sln.docstates # Build results [Dd]ebug/ [Rr]elease/ *_i.c *_p.c *.ilk *.meta *.obj *.pch *.pdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.vspscc .builds *.dotCover ## TODO: If you have NuGet Package Restore enabled, uncomment this #packages/ # Visual C++ cache files ipch/ *.aps *.ncb *.opensdf *.sdf # Visual Studio profiler *.psess *.vsp # ReSharper is a .NET coding add-in _ReSharper* # Installshield output folder [Ee]xpress # DocProject is a documentation generator add-in DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC DocProject/Help/*.hhc DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 DocProject/Help/html # Click-Once directory publish # Others [Bb]in [Oo]bj sql TestResults *.Cache ClientBin stylecop.* ~$* *.dbmdl Generated_Code #added for RIA/Silverlight projects # Backup & report files from converting an old project file to a newer # Visual Studio version. Backup files are not needed, because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML ############ ## Windows ############ # Windows image file caches Thumbs.db # Folder config file Desktop.ini ############# ## Python ############# *.py[co] # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox #Translations *.mo #Mr Developer .mr.developer.cfg # Mac crap .DS_Store ################## # Binary archive ################## bin-archive/ ================================================ FILE: ArduinoPrintADC/ArduinoPrintADC.ino ================================================ /* ArduinoPrintADC.ino Author: Seb Madgwick Sends up to all 6 analogue inputs values in ASCII as comma separated values over serial. Each line is terminated with a carriage return character ('\r'). The number of channels is sent by sending a character value of '1' to '6' to the Arduino. Tested with "arduino-1.0.3" and "Arduino Uno". */ #include // div, div_t void setup() { // Enable pull-ups to avoid floating inputs digitalWrite(A0, HIGH); digitalWrite(A1, HIGH); digitalWrite(A2, HIGH); digitalWrite(A3, HIGH); digitalWrite(A6, HIGH); digitalWrite(A7, HIGH); // Init serial Serial.begin(115200); } void loop() { static int numChans = 1; // Received character sets number of active channels while(Serial.available() > 0) { char c = Serial.read(); if(c >= '1' && c <= '6') { numChans = c - '0'; } } // Print ADC results for active channels PrintInt(analogRead(A0)); if(numChans > 1) { Serial.write(','); PrintInt(analogRead(A1)); } if(numChans > 2) { Serial.write(','); PrintInt(analogRead(A2)); } if(numChans > 3) { Serial.write(','); PrintInt(analogRead(A3)); } if(numChans > 4) { Serial.write(','); PrintInt(analogRead(A6)); } if(numChans > 5) { Serial.write(','); PrintInt(analogRead(A7)); } Serial.write('\r'); // print new line } // Fast int to ASCII conversion void PrintInt(int i) { static const char asciiDigits[10] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; div_t n; int print = 0; if(i < 0) { Serial.write('-'); i = -i; } if(i >= 10000) { n = div(i, 10000); Serial.write(asciiDigits[n.quot]); i = n.rem; print = 1; } if(i >= 1000 || print) { n = div(i, 1000); Serial.write(asciiDigits[n.quot]); i = n.rem; print = 1; } if(i >= 100 || print) { n = div(i, 100); Serial.write(asciiDigits[n.quot]); i = n.rem; print = 1; } if(i >= 10 || print) { n = div(i, 10); Serial.write(asciiDigits[n.quot]); i = n.rem; } Serial.write(asciiDigits[i]); } ================================================ FILE: README.md ================================================ Serial-Oscilloscope =================== Serial Oscilloscope is a Windows application that plots comma-separated variables within any incoming serial steam as channels on a real-time oscilloscope. The application also functions as a basic serial terminal, received bytes are printed to the terminal and typed characters are transmitted. The project uses Michael Bernstein's [oscilloscope library](http://www.oscilloscope-lib.com/) to plot up to 9 channels on 3 different oscilloscope with view and trigger menus. Serial Oscilloscope is compatible with any serial stream containing comma-separated values terminated by a new-line character ("\r"). For example, "11,22,33\r" will be interpreted as values 11, 22 and 33 for channels 1, 2 and 3 respectively. The serial stream can also include non numerical characters which will be ignored. For example, "a=0.5,blue,x=3.14,t1t2t3,8\r\n" will be interpreted as values 0.5, 3.14, 123 and 8 for channels 1, 2, 3 and 4 respectively. The source files also include an Arduino sketch to send analogue input values over serial. Up to 6 ADC channels can be enabled by sending the characters "1" to "6" to the Arduino. Enabling more channels will reduce the sample rate. In the [YouTube video](http://www.youtube.com/watch?v=jgMG0UQ2_pc) I show the Arduino and Serial Oscilloscope being used to plot data from an [IR distance sensor]( https://www.sparkfun.com/products/242), a [triple-axis accelerometer]( https://www.sparkfun.com/products/9269) and a [microphone]( https://www.sparkfun.com/products/9964). Precompiled binary files can be [downloaded](http://www.x-io.co.uk/serial-oscilloscope/) from the x-io website. Version history --------------- * **v1.0** Initial release * **v1.1** Supports non-standard baud rates. Disable terminal feature added. * **v1.2** Fixed memory leak and bug that prevent plotting of negative numbers. * **v1.3** No longer ignores "." for plotting decimal values. * **v1.4** Clear terminal menu item added * **v1.5** Log to file tool. Remove non-numerical characters from port names. ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/CsvFileWriter.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Globalization; namespace Serial_Oscilloscope { class CsvFileWriter { /// /// File path of CSV file. /// public string FilePath { get; private set; } /// /// Internal flag used to disable writes during file close. /// private bool writesEnabled; /// /// Stream Writer to write to file. /// private StreamWriter streamWriter; /// /// Constructor. /// /// public CsvFileWriter(string filePath) { FilePath = filePath; writesEnabled = true; streamWriter = null; } /// /// Close CSV file. /// public void CloseFile() { List fileNames = new List(); writesEnabled = false; streamWriter.Close(); } /// /// Write array of values as line of CSVs in file. /// /// public void WriteCSVline(float[] values) { if (writesEnabled) { // Open file if (streamWriter == null) { streamWriter = new System.IO.StreamWriter(FilePath, false); } // Write line string csvLine = ""; for(int i = 0; i /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.textBoxValue = new System.Windows.Forms.TextBox(); this.labelValue = new System.Windows.Forms.Label(); this.buttonOK = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBoxValue // this.textBoxValue.Location = new System.Drawing.Point(55, 12); this.textBoxValue.Name = "textBoxValue"; this.textBoxValue.Size = new System.Drawing.Size(100, 20); this.textBoxValue.TabIndex = 1; this.textBoxValue.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBoxValue_KeyPress); // // labelValue // this.labelValue.AutoSize = true; this.labelValue.Location = new System.Drawing.Point(12, 15); this.labelValue.Name = "labelValue"; this.labelValue.Size = new System.Drawing.Size(37, 13); this.labelValue.TabIndex = 0; this.labelValue.Text = "Value:"; // // buttonOK // this.buttonOK.Location = new System.Drawing.Point(161, 10); this.buttonOK.Name = "buttonOK"; this.buttonOK.Size = new System.Drawing.Size(75, 23); this.buttonOK.TabIndex = 2; this.buttonOK.Text = "OK"; this.buttonOK.UseVisualStyleBackColor = true; this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click); // // FormGetValue // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(246, 48); this.Controls.Add(this.labelValue); this.Controls.Add(this.buttonOK); this.Controls.Add(this.textBoxValue); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "FormGetValue"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.Text = "Enter Value"; this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormGetValue_FormClosed); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.TextBox textBoxValue; private System.Windows.Forms.Label labelValue; private System.Windows.Forms.Button buttonOK; } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/FormGetValue.cs ================================================ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Serial_Oscilloscope { /// /// Dialog form to get text value from user. /// public partial class FormGetValue : Form { /// /// Value entered by user. /// public string value { get; private set; } /// /// Constructor. /// public FormGetValue() { InitializeComponent(); } /// /// textBoxValue KeyPress event to close form when Enter key pressed. /// private void textBoxValue_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == '\r') { Close(); } } /// /// buttonOK Click event to close form. /// private void buttonOK_Click(object sender, EventArgs e) { Close(); } /// /// FormGetValue FormClosed event to store value entered by user. /// private void FormGetValue_FormClosed(object sender, FormClosedEventArgs e) { value = textBoxValue.Text; } } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/FormGetValue.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/FormTerminal.Designer.cs ================================================ namespace Serial_Oscilloscope { partial class FormTerminal { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.menuStrip = new System.Windows.Forms.MenuStrip(); this.toolStripMenuItemSerialPort = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemBaudRate = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem9600 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem19200 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem38400 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem57600 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem115200 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem230400 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem460800 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem921600 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemOther = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemTerminal = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemEnabled = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemClear = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemOsciloscope = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemChannels123 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemChannels456 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemChannels789 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemHelp = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemAbout0 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemSourceCode = new System.Windows.Forms.ToolStripMenuItem(); this.statusStrip = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabelSamplesReceived = new System.Windows.Forms.ToolStripStatusLabel(); this.toolStripStatusLabelSampleRate = new System.Windows.Forms.ToolStripStatusLabel(); this.textBox = new System.Windows.Forms.TextBox(); this.toolStripMenuItemLogToFile = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemStartLogging = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItemStopLogging = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip.SuspendLayout(); this.statusStrip.SuspendLayout(); this.SuspendLayout(); // // menuStrip // this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItemSerialPort, this.toolStripMenuItemBaudRate, this.toolStripMenuItemTerminal, this.toolStripMenuItemOsciloscope, this.toolStripMenuItemLogToFile, this.toolStripMenuItemHelp}); this.menuStrip.Location = new System.Drawing.Point(0, 0); this.menuStrip.Name = "menuStrip"; this.menuStrip.Size = new System.Drawing.Size(584, 24); this.menuStrip.TabIndex = 0; this.menuStrip.Text = "menuStrip1"; // // toolStripMenuItemSerialPort // this.toolStripMenuItemSerialPort.Name = "toolStripMenuItemSerialPort"; this.toolStripMenuItemSerialPort.Size = new System.Drawing.Size(72, 20); this.toolStripMenuItemSerialPort.Text = "Serial Port"; this.toolStripMenuItemSerialPort.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.toolStripMenuItemSerialPort_DropDownItemClicked); // // toolStripMenuItemBaudRate // this.toolStripMenuItemBaudRate.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItem9600, this.toolStripMenuItem19200, this.toolStripMenuItem38400, this.toolStripMenuItem57600, this.toolStripMenuItem115200, this.toolStripMenuItem230400, this.toolStripMenuItem460800, this.toolStripMenuItem921600, this.toolStripMenuItemOther}); this.toolStripMenuItemBaudRate.Name = "toolStripMenuItemBaudRate"; this.toolStripMenuItemBaudRate.Size = new System.Drawing.Size(72, 20); this.toolStripMenuItemBaudRate.Text = "Baud Rate"; this.toolStripMenuItemBaudRate.DropDownItemClicked += new System.Windows.Forms.ToolStripItemClickedEventHandler(this.toolStripMenuItemBaudRate_DropDownItemClicked); // // toolStripMenuItem9600 // this.toolStripMenuItem9600.Name = "toolStripMenuItem9600"; this.toolStripMenuItem9600.Size = new System.Drawing.Size(110, 22); this.toolStripMenuItem9600.Text = "9600"; // // toolStripMenuItem19200 // this.toolStripMenuItem19200.Name = "toolStripMenuItem19200"; this.toolStripMenuItem19200.Size = new System.Drawing.Size(110, 22); this.toolStripMenuItem19200.Text = "19200"; // // toolStripMenuItem38400 // this.toolStripMenuItem38400.Name = "toolStripMenuItem38400"; this.toolStripMenuItem38400.Size = new System.Drawing.Size(110, 22); this.toolStripMenuItem38400.Text = "38400"; // // toolStripMenuItem57600 // this.toolStripMenuItem57600.Name = "toolStripMenuItem57600"; this.toolStripMenuItem57600.Size = new System.Drawing.Size(110, 22); this.toolStripMenuItem57600.Text = "57600"; // // toolStripMenuItem115200 // this.toolStripMenuItem115200.Name = "toolStripMenuItem115200"; this.toolStripMenuItem115200.Size = new System.Drawing.Size(110, 22); this.toolStripMenuItem115200.Text = "115200"; // // toolStripMenuItem230400 // this.toolStripMenuItem230400.Name = "toolStripMenuItem230400"; this.toolStripMenuItem230400.Size = new System.Drawing.Size(110, 22); this.toolStripMenuItem230400.Text = "230400"; // // toolStripMenuItem460800 // this.toolStripMenuItem460800.Name = "toolStripMenuItem460800"; this.toolStripMenuItem460800.Size = new System.Drawing.Size(110, 22); this.toolStripMenuItem460800.Text = "460800"; // // toolStripMenuItem921600 // this.toolStripMenuItem921600.Name = "toolStripMenuItem921600"; this.toolStripMenuItem921600.Size = new System.Drawing.Size(110, 22); this.toolStripMenuItem921600.Text = "921600"; // // toolStripMenuItemOther // this.toolStripMenuItemOther.Name = "toolStripMenuItemOther"; this.toolStripMenuItemOther.Size = new System.Drawing.Size(110, 22); this.toolStripMenuItemOther.Text = "Other"; // // toolStripMenuItemTerminal // this.toolStripMenuItemTerminal.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItemEnabled, this.toolStripMenuItemClear}); this.toolStripMenuItemTerminal.Name = "toolStripMenuItemTerminal"; this.toolStripMenuItemTerminal.Size = new System.Drawing.Size(66, 20); this.toolStripMenuItemTerminal.Text = "Terminal"; // // toolStripMenuItemEnabled // this.toolStripMenuItemEnabled.Checked = true; this.toolStripMenuItemEnabled.CheckOnClick = true; this.toolStripMenuItemEnabled.CheckState = System.Windows.Forms.CheckState.Checked; this.toolStripMenuItemEnabled.Name = "toolStripMenuItemEnabled"; this.toolStripMenuItemEnabled.Size = new System.Drawing.Size(116, 22); this.toolStripMenuItemEnabled.Text = "Enabled"; this.toolStripMenuItemEnabled.CheckStateChanged += new System.EventHandler(this.toolStripMenuItemEnabled_CheckStateChanged); // // toolStripMenuItemClear // this.toolStripMenuItemClear.Name = "toolStripMenuItemClear"; this.toolStripMenuItemClear.Size = new System.Drawing.Size(116, 22); this.toolStripMenuItemClear.Text = "Clear"; this.toolStripMenuItemClear.Click += new System.EventHandler(this.toolStripMenuItemClear_Click); // // toolStripMenuItemOsciloscope // this.toolStripMenuItemOsciloscope.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItemChannels123, this.toolStripMenuItemChannels456, this.toolStripMenuItemChannels789}); this.toolStripMenuItemOsciloscope.Name = "toolStripMenuItemOsciloscope"; this.toolStripMenuItemOsciloscope.Size = new System.Drawing.Size(83, 20); this.toolStripMenuItemOsciloscope.Text = "Osciloscope"; // // toolStripMenuItemChannels123 // this.toolStripMenuItemChannels123.CheckOnClick = true; this.toolStripMenuItemChannels123.Name = "toolStripMenuItemChannels123"; this.toolStripMenuItemChannels123.Size = new System.Drawing.Size(176, 22); this.toolStripMenuItemChannels123.Text = "Channels 1, 2 and 3"; this.toolStripMenuItemChannels123.CheckStateChanged += new System.EventHandler(this.toolStripMenuItemChannels123_CheckStateChanged); // // toolStripMenuItemChannels456 // this.toolStripMenuItemChannels456.CheckOnClick = true; this.toolStripMenuItemChannels456.Name = "toolStripMenuItemChannels456"; this.toolStripMenuItemChannels456.Size = new System.Drawing.Size(176, 22); this.toolStripMenuItemChannels456.Text = "Channels 3, 4 and 5"; this.toolStripMenuItemChannels456.Click += new System.EventHandler(this.toolStripMenuItemChannels456_CheckStateChanged); // // toolStripMenuItemChannels789 // this.toolStripMenuItemChannels789.CheckOnClick = true; this.toolStripMenuItemChannels789.Name = "toolStripMenuItemChannels789"; this.toolStripMenuItemChannels789.Size = new System.Drawing.Size(176, 22); this.toolStripMenuItemChannels789.Text = "Channels 7, 8 and 9"; this.toolStripMenuItemChannels789.CheckStateChanged += new System.EventHandler(this.toolStripMenuItemChannels789_CheckStateChanged); // // toolStripMenuItemHelp // this.toolStripMenuItemHelp.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItemAbout0, this.toolStripMenuItemSourceCode}); this.toolStripMenuItemHelp.Name = "toolStripMenuItemHelp"; this.toolStripMenuItemHelp.Size = new System.Drawing.Size(44, 20); this.toolStripMenuItemHelp.Text = "Help"; // // toolStripMenuItemAbout0 // this.toolStripMenuItemAbout0.Name = "toolStripMenuItemAbout0"; this.toolStripMenuItemAbout0.Size = new System.Drawing.Size(141, 22); this.toolStripMenuItemAbout0.Text = "About"; this.toolStripMenuItemAbout0.Click += new System.EventHandler(this.toolStripMenuItemAbout_Click); // // toolStripMenuItemSourceCode // this.toolStripMenuItemSourceCode.Name = "toolStripMenuItemSourceCode"; this.toolStripMenuItemSourceCode.Size = new System.Drawing.Size(141, 22); this.toolStripMenuItemSourceCode.Text = "Source Code"; this.toolStripMenuItemSourceCode.Click += new System.EventHandler(this.toolStripMenuItemSourceCode_Click); // // statusStrip // this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatusLabelSamplesReceived, this.toolStripStatusLabelSampleRate}); this.statusStrip.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.Flow; this.statusStrip.Location = new System.Drawing.Point(0, 342); this.statusStrip.Name = "statusStrip"; this.statusStrip.Size = new System.Drawing.Size(584, 20); this.statusStrip.TabIndex = 1; this.statusStrip.Text = "statusStrip1"; // // toolStripStatusLabelSamplesReceived // this.toolStripStatusLabelSamplesReceived.Name = "toolStripStatusLabelSamplesReceived"; this.toolStripStatusLabelSamplesReceived.Size = new System.Drawing.Size(203, 15); this.toolStripStatusLabelSamplesReceived.Text = "toolStripStatusLabelSamplesReceived"; // // toolStripStatusLabelSampleRate // this.toolStripStatusLabelSampleRate.Name = "toolStripStatusLabelSampleRate"; this.toolStripStatusLabelSampleRate.Size = new System.Drawing.Size(174, 15); this.toolStripStatusLabelSampleRate.Text = "toolStripStatusLabelSampleRate"; // // textBox // this.textBox.BackColor = System.Drawing.Color.Black; this.textBox.Dock = System.Windows.Forms.DockStyle.Fill; this.textBox.Font = new System.Drawing.Font("Courier New", 8.25F); this.textBox.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(0))))); this.textBox.Location = new System.Drawing.Point(0, 24); this.textBox.Multiline = true; this.textBox.Name = "textBox"; this.textBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.textBox.Size = new System.Drawing.Size(584, 318); this.textBox.TabIndex = 1; this.textBox.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox_KeyPress); // // toolStripMenuItemLogToFile // this.toolStripMenuItemLogToFile.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripMenuItemStartLogging, this.toolStripMenuItemStopLogging}); this.toolStripMenuItemLogToFile.Name = "toolStripMenuItemLogToFile"; this.toolStripMenuItemLogToFile.Size = new System.Drawing.Size(77, 20); this.toolStripMenuItemLogToFile.Text = "Log To File"; // // toolStripMenuItemStartLogging // this.toolStripMenuItemStartLogging.Name = "toolStripMenuItemStartLogging"; this.toolStripMenuItemStartLogging.Size = new System.Drawing.Size(152, 22); this.toolStripMenuItemStartLogging.Text = "Start Logging"; this.toolStripMenuItemStartLogging.Click += new System.EventHandler(this.toolStripMenuItemStartLogging_Click); // // toolStripMenuItemStopLogging // this.toolStripMenuItemStopLogging.Enabled = false; this.toolStripMenuItemStopLogging.Name = "toolStripMenuItemStopLogging"; this.toolStripMenuItemStopLogging.Size = new System.Drawing.Size(152, 22); this.toolStripMenuItemStopLogging.Text = "Stop Logging"; this.toolStripMenuItemStopLogging.Click += new System.EventHandler(this.toolStripMenuItemStopLogging_Click); // // FormTerminal // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(584, 362); this.Controls.Add(this.textBox); this.Controls.Add(this.statusStrip); this.Controls.Add(this.menuStrip); this.MainMenuStrip = this.menuStrip; this.Name = "FormTerminal"; this.Text = "FormTerminal"; this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FormTerminal_FormClosed); this.Load += new System.EventHandler(this.FormTerminal_Load); this.menuStrip.ResumeLayout(false); this.menuStrip.PerformLayout(); this.statusStrip.ResumeLayout(false); this.statusStrip.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.MenuStrip menuStrip; private System.Windows.Forms.StatusStrip statusStrip; private System.Windows.Forms.TextBox textBox; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSerialPort; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemOsciloscope; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemHelp; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSamplesReceived; private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSampleRate; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemBaudRate; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem9600; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem19200; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem38400; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem57600; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem115200; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem230400; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem460800; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItem921600; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemChannels123; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemChannels456; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemChannels789; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemAbout0; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemSourceCode; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemOther; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemTerminal; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemEnabled; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemClear; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemLogToFile; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemStartLogging; private System.Windows.Forms.ToolStripMenuItem toolStripMenuItemStopLogging; } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/FormTerminal.cs ================================================ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Reflection; using System.IO.Ports; using System.Text.RegularExpressions; using System.Globalization; namespace Serial_Oscilloscope { public partial class FormTerminal : Form { #region Variables and objects /// /// Timer to update terminal textbox at fixed interval. /// private System.Windows.Forms.Timer formUpdateTimer = new System.Windows.Forms.Timer(); /// /// SerialPort object. /// private SerialPort serialPort = new SerialPort(); /// /// Sample counter to calculate performance statics. /// private SampleCounter sampleCounter = new SampleCounter(); /// /// TextBoxBuffer containing text printed to terminal. /// private TextBoxBuffer textBoxBuffer = new TextBoxBuffer(4096); /// /// ASCII buffer for decoding CSVs in serial stream. /// private string asciiBuf = ""; /// /// Oscilloscope channel values decoded from serial stream. /// private float[] channels = new float[9] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f}; /// /// Oscilloscope for channels 1, 2 and 3. /// private Oscilloscope oscilloscope123 = Oscilloscope.CreateScope("Oscilloscope/Oscilloscope_settings.ini", ""); /// /// Oscilloscope for channels 4, 5 and 6. /// private Oscilloscope oscilloscope456 = Oscilloscope.CreateScope("Oscilloscope/Oscilloscope_settings.ini", ""); /// /// Oscilloscope for channels 7, 8 and 9. /// private Oscilloscope oscilloscope789 = Oscilloscope.CreateScope("Oscilloscope/Oscilloscope_settings.ini", ""); /// /// CSV file writer. /// private CsvFileWriter csvFileWriter = null; #endregion /// /// Constructor. /// public FormTerminal() { InitializeComponent(); } #region Form load and close /// /// From load event. /// private void FormTerminal_Load(object sender, EventArgs e) { // Set form caption this.Text = Assembly.GetExecutingAssembly().GetName().Name + " (Port Closed)"; // Set oscilloscope captions oscilloscope123.Caption = "Channels 1, 2 and 3"; oscilloscope456.Caption = "Channels 4, 5 and 6"; oscilloscope789.Caption = "Channels 7, 8 and 9"; // Refresh serial port list RefreshSerialPortList(); // Select default baud rate toolStripMenuItem115200.Checked = true; // Setup form update timer formUpdateTimer.Interval = 50; formUpdateTimer.Tick += new EventHandler(formUpdateTimer_Tick); formUpdateTimer.Start(); } /// /// Form close event. /// private void FormTerminal_FormClosed(object sender, FormClosedEventArgs e) { CloseSerialPort(); toolStripMenuItemStopLogging.PerformClick(); } #endregion #region Terminal textbox /// /// formUpdateTimer Tick event to update terminal textbox. /// void formUpdateTimer_Tick(object sender, EventArgs e) { // Print textBoxBuffer to terminal if (textBox.Enabled && !textBoxBuffer.IsEmpty()) { textBox.AppendText(textBoxBuffer.Get()); if (textBox.Text.Length > textBox.MaxLength) // discard first half of textBox when number of characters exceeds length { textBox.Text = textBox.Text.Substring(textBox.Text.Length / 2, textBox.Text.Length - textBox.Text.Length / 2); } } else { textBoxBuffer.Clear(); } // Update sample counter values toolStripStatusLabelSamplesReceived.Text = "Samples Recieved: " + sampleCounter.SamplesReceived.ToString(); toolStripStatusLabelSampleRate.Text = "Sample Rate: " + sampleCounter.SampleRate.ToString(); } /// /// textBox KeyPress to send character to serial port. /// private void textBox_KeyPress(object sender, KeyPressEventArgs e) { SendSerialPort(e.KeyChar); e.Handled = true; // don't print character } #endregion #region Menu strip /// /// toolStripMenuItemSerialPort DropDownItemClicke event to select or close serial port. /// private void toolStripMenuItemSerialPort_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { // Close serial port and refresh list is refresh item clicked if (e.ClickedItem.Text == "Refresh List") { CloseSerialPort(); RefreshSerialPortList(); return; } // Close serial port if checked port name clicked if (((ToolStripMenuItem)e.ClickedItem).Checked) { CloseSerialPort(); ((ToolStripMenuItem)e.ClickedItem).Checked = false; return; } // Check only selected item foreach (ToolStripMenuItem toolStripMenuItem in ((ToolStripMenuItem)toolStripMenuItemSerialPort).DropDownItems) { toolStripMenuItem.Checked = false; } ((ToolStripMenuItem)e.ClickedItem).Checked = true; // Open serial port if (!OpenSerialPort()) { ((ToolStripMenuItem)e.ClickedItem).Checked = false; // uncheck serial port if open fails } } /// /// toolStripMenuItemSerialPort DropDownItemClicke event to select baud rate. /// private void toolStripMenuItemBaudRate_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e) { if ((ToolStripMenuItem)e.ClickedItem == toolStripMenuItemOther) { FormGetValue formGetValue = new FormGetValue(); formGetValue.ShowDialog(); ((ToolStripMenuItem)e.ClickedItem).Text = "Other (" + formGetValue.value + ")"; ((ToolStripMenuItem)e.ClickedItem).Checked = false; } // Do nothing if baud already selected if (((ToolStripMenuItem)e.ClickedItem).Checked) { return; } // Check only selected item foreach (ToolStripMenuItem toolStripMenuItem in ((ToolStripMenuItem)toolStripMenuItemBaudRate).DropDownItems) { toolStripMenuItem.Checked = false; } ((ToolStripMenuItem)e.ClickedItem).Checked = true; // Open serial port if (!OpenSerialPort()) { RefreshSerialPortList(); // refresh port list if open fails, this also ensures port object is closed } } /// /// toolStripMenuItemEnabled CheckStateChanged event to toggle enabled state of the terminal text box. /// private void toolStripMenuItemEnabled_CheckStateChanged(object sender, EventArgs e) { if (toolStripMenuItemEnabled.Checked) { textBox.Enabled = true; } else { textBox.Enabled = false; } } /// /// toolStripMenuItemClear Click event to clear terminal text box. /// private void toolStripMenuItemClear_Click(object sender, EventArgs e) { textBox.Text = ""; } /// /// toolStripMenuItemChannels123 CheckStateChanged event to toggle show state of oscilloscope form. /// private void toolStripMenuItemChannels123_CheckStateChanged(object sender, EventArgs e) { if (toolStripMenuItemChannels123.Checked) { oscilloscope123.ShowScope(); } else { oscilloscope123.HideScope(); } } /// /// toolStripMenuItemChannels456 CheckStateChanged event to toggle show state of oscilloscope form. /// private void toolStripMenuItemChannels456_CheckStateChanged(object sender, EventArgs e) { if (toolStripMenuItemChannels456.Checked) { oscilloscope456.ShowScope(); } else { oscilloscope456.HideScope(); } } /// /// toolStripMenuItemChannels789 CheckStateChanged event to toggle show state of oscilloscope form. /// private void toolStripMenuItemChannels789_CheckStateChanged(object sender, EventArgs e) { if (toolStripMenuItemChannels789.Checked) { oscilloscope789.ShowScope(); } else { oscilloscope789.HideScope(); } } /// /// toolStripMenuItemStartLogging Click event to select file location and start logging /// private void toolStripMenuItemStartLogging_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Select File Location"; saveFileDialog.Filter = "CSV files (*.csv)|*.csv"; saveFileDialog.OverwritePrompt = false; saveFileDialog.FileName = "LoggedData"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { csvFileWriter = new CsvFileWriter(saveFileDialog.FileName.ToString()); toolStripMenuItemStartLogging.Enabled = false; toolStripMenuItemStopLogging.Enabled = true; } } /// /// toolStripMenuItemStopLogging Click event to stop logging and close file /// private void toolStripMenuItemStopLogging_Click(object sender, EventArgs e) { if (csvFileWriter != null) { csvFileWriter.CloseFile(); csvFileWriter = null; } toolStripMenuItemStartLogging.Enabled = true; toolStripMenuItemStopLogging.Enabled = false; } /// /// toolStripMenuItemAbout Click event to display version details. /// private void toolStripMenuItemAbout_Click(object sender, EventArgs e) { MessageBox.Show(Assembly.GetExecutingAssembly().GetName().Name + " " + Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "." + Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString(), "About", MessageBoxButtons.OK, MessageBoxIcon.Information); } /// /// toolStripMenuItemSourceCode Click event to open web browser. /// private void toolStripMenuItemSourceCode_Click(object sender, EventArgs e) { try { System.Diagnostics.Process.Start("https://github.com/xioTechnologies/Serial-Oscilloscope"); } catch { } } #endregion #region Serial port /// /// Updates toolStripMenuItemSerialPort DropDownItems to include all available serial port. /// private void RefreshSerialPortList() { ToolStripItemCollection toolStripItemCollection = toolStripMenuItemSerialPort.DropDownItems; toolStripItemCollection.Clear(); toolStripItemCollection.Add("Refresh List"); foreach (string portName in System.IO.Ports.SerialPort.GetPortNames()) { toolStripItemCollection.Add("COM" + Regex.Replace(portName.Substring("COM".Length, portName.Length - "COM".Length), "[^.0-9]", "\0")); } } /// /// Opens serial port. Displays error in MessageBox if unsuccessful. /// /// /// true if successful. /// private bool OpenSerialPort() { string portName = null; int baudRate = 0; // Get selected port name foreach (ToolStripMenuItem toolStripMenuItem in ((ToolStripMenuItem)toolStripMenuItemSerialPort).DropDownItems) { if (toolStripMenuItem.Checked) { portName = toolStripMenuItem.Text; break; } } if (portName == null) { return false; } // Get selected baud rate foreach (ToolStripMenuItem toolStripMenuItem in ((ToolStripMenuItem)toolStripMenuItemBaudRate).DropDownItems) { if (toolStripMenuItem.Checked) { try { baudRate = Convert.ToInt32((new Regex("[^0-9]")).Replace(toolStripMenuItem.Text, "")); // convert text to int ignoring all non-numerical characters } catch { baudRate = 0; } break; } } // Open serial port CloseSerialPort(); try { serialPort = new SerialPort(portName, baudRate, Parity.None, 8, StopBits.One); serialPort.DataReceived += new SerialDataReceivedEventHandler(serialPort_DataReceived); serialPort.Open(); this.Text = Assembly.GetExecutingAssembly().GetName().Name + " (" + portName + ", " + baudRate.ToString() + ")"; sampleCounter.Reset(); return true; } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); return false; } } /// /// Closes serial port. /// private void CloseSerialPort() { try { serialPort.Close(); } catch { } this.Text = Assembly.GetExecutingAssembly().GetName().Name + " (Port Closed)"; } /// /// Sends character to serial port. /// /// /// Character to send to serial port. /// private void SendSerialPort(char c) { try { serialPort.Write(new char[] { c }, 0, 1); } catch { } } /// /// serialPort DataReceived event to print characters to terminal and process bytes through serialDecoder. /// private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e) { try { // Get bytes from serial port int bytesToRead = serialPort.BytesToRead; byte[] readBuffer = new byte[bytesToRead]; serialPort.Read(readBuffer, 0, bytesToRead); // Process each byte foreach (byte b in readBuffer) { // Parse character to textBoxBuffer if ((b < 0x20 || b > 0x7F) && b != '\r') // replace non-printable characters with '.' { textBoxBuffer.Put("."); } else if (b == '\r') // replace carriage return with '↵' and valid new line { textBoxBuffer.Put("↵" + Environment.NewLine); } else { textBoxBuffer.Put(((char)b).ToString()); } // Extract CSVs and parse to Oscilloscope if (asciiBuf.Length > 128) { asciiBuf = ""; // prevent memory leak } if ((char)b == '\r') { // Split string to comma separated variables (ignore non numerical characters) string[] csvs = (new Regex(@"[^0-9\-,.]")).Replace(asciiBuf, "").Split(','); // Extract each CSV as oscilloscope channel int channelIndex = 0; foreach (string csv in csvs) { if (csv != "" && channelIndex < 9) { channels[channelIndex++] = float.Parse(csv, CultureInfo.InvariantCulture); } } // Update oscilloscopes if channel values changed if (channelIndex > 0) { oscilloscope123.AddScopeData(channels[0], channels[1], channels[2]); oscilloscope456.AddScopeData(channels[3], channels[4], channels[5]); oscilloscope789.AddScopeData(channels[6], channels[7], channels[8]); sampleCounter.Increment(); } // Write to file if enabled if (csvFileWriter != null) { csvFileWriter.WriteCSVline(channels); } // Reset buffer asciiBuf = ""; } else { asciiBuf += (char)b; } } } catch { } } #endregion } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/FormTerminal.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 17, 17 132, 17 79 ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/Oscilloscope/Oscilloscope.cs ================================================ using System; using System.Text; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; /* * C# Wrapper around the Oscilloscope DLL * * (C)2006 Dustin Spicuzza * * This library interface is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; only * version 2.1 of the License. * * Some comments/function declarations taken from the original * "oscilloscope-lib" documentation. * * Oscilloscope Properties added by: Frank Greenlee, April, 2010 * MessageBoxes replaced with Exceptions by: Sebastian Madgwick, February, 2011 * "Osc_DLL.dll" replaced with Osc_DLL_path by: Sebastian Madgwick, May, 2011 * */ /************************************************************************ * * Quick Reference: Publicly Available Methods and Properties * ************************************************************************* ************************************************************************* * * Public Methods * ************************************************************************* Method: CreateScope() Creates an instance of the Oscilloscope. The Initialization file is not used in this version of the method. Lifetime: static Parameters: void Return: reference of type Oscilloscope to the instance if successful null if not successful ************************************************************************* Method: CreateScope ( string, string ) Creates an instance of the Oscilloscope. The Initialization file is used (if found) in this version of the method. Lifetime: static Parameters: string: Filenmae of intialization file string: Filename suffix Return: reference of type Oscilloscope to the instance if successful null if not successful ************************************************************************* Method: ShowScope () Displays the Oscilloscope. After the instance is created it will not become visible until this method is called. Lifetime: instance Parameters: void Return: void ************************************************************************* Method: HideScope () Makes the Oscilloscope invisible non-destructively. Lifetime: instance Parameters: void Return: void ************************************************************************* Method: ClearScope () Clears the Oscilloscope's buffers. Lifetime: instance Parameters: void Return: void ************************************************************************* Method: AddScopeData ( double, double, double ) Adds one new data point to each of the three traces. Lifetime: instance Parameters: double: 3X New data points, one for each trace. Return: void ************************************************************************* Method: AddExternalScopeData ( double ) Sends a new data point to the external trigger input, which is used for triggering when the Oscilloscope's Trigger Source is set to EXTERNAL_TRIG. Lifetime: instance Parameters: double: External Trigger Data Point Return: void ************************************************************************* Method: UpdateScope () Quickly updates the Oscilloscope traces, for use when there is a gap in the dta stream. Lifetime: instance Parameters: void Return: void ************************************************************************* Method: Dispose () Releases the Oscilloscope resources back to the system and removes the Oscilloscope from the display. Also sets the _disposed flag to true. Any future calls or property accesses will be ignored and will set a SCOPE_DISPOSED_ERROR into LastError. Lifetime: instance Parameters: void Return: void ************************************************************************* * * Public Properties -- all of these are class instance members. * ************************************************************************* Property: LastError An application can check this to see if there has been an error, even when error message displays are turned off. If it is non-zero (!=NO_ERROR), there has been an error and the value refers to one of the listed error constants. When setting LastError the value is ignored and LastError is set to its defaul value, NO_ERROR. The application should do this after finding a non-zero error value, as it is not done automatically; the error code value will persist until it is manually reset. Value: int, equal to one of the error constants Access: Read/Write (any write resets LastError to NO_ERROR Default: 0 (NO_ERROR) ************************************************************************** Property: ErrorMessagesOn If set to "true", a throw new Exception will appear when there is an error. When debugging is completed it may be desirable to set ErrorMessagesOn to "false." The LastError variable will work regardless of this setting and may be checked even when there is no instance of the Oscilloscope class. Value: bool Access: Read/Write Default: true ************************************************************************** Property: ControlPanelVisible Displays or hides the control panel at the bottom of the oscilloscope display. Value: bool Access: Read/Write Default: true (also can be define in the intialization file, if it is used) ************************************************************************** Property: Left Sets the horizontal position of the oscilloscope on the screen, specified as the number of pixels from the left edge of the screen to the left edge of the oscilloscope form. Value: int, Range: 0-Current Screen Width Access: Read/Write Default: Somewhere on the Screen (also can be defined in the intialization file, if it is used) ************************************************************************** Property: Top Sets the vertical position of the oscilloscope on the screen, specified as the number of pixels from the top edge of the screen to the top edge of the oscilloscope form. Value: int, Range: 0-Current Screen Height Access: Read/Write Default: Somewhere on the Screen (also can be defined in the intialization file, if it is used) ************************************************************************** Property: Width Sets the Width of the oscilloscope form in pixels. Value: int, Range: 40-Current Screen Width Access: Read/Write Default: (->fill this in) (also can be defined in the initialization file, if it is used) ************************************************************************** Property: Height Sets the Height of the oscilloscope form in pixels. Value: int, Range: 40-Current Screen Height Access: Read/Write Default: (->fill this in) (also can be defined in the initialization file, if used) ************************************************************************** Property: CellSize Sets the size of a grid cell in pixels; sets both height and width of grid cells to this single property setting. Value: int, Range: 10-150 Access: Read/Write Default: 40 (also can be defined in the initialization file, if it is used) ************************************************************************** Property: SamplesPerGridCell Sets the number of samples per grid cell on the horizontal (time) axis. The value will be adjusted to closest valid number (see the DLL documentation). WARNING: if this setting is too low and the data stream is too fast a buffer overrun can be caused, which will have no indicator other than the DLL locking up. Value: double, Range 0.10000-20,000 Access: Read/Write Default: (->fill this in) (also can be defined in the initialization file, if it is used) ************************************************************************** Property: Caption Sets the caption at the top of the oscilloscope form. Value: string, Range 0-250 characters Access: Write Only Default: "Oscilloscope" (also can be defined in the initialization file, if it is used) ************************************************************************** Property: AmplitudeScale1 Sets the Amplitude Scale of Trace 1's grid divisions, in binary steps/grid cell. The value will be adjusted to closest valid number (see the DLL documentation). Value: double, Range: 0.00001-100,000.00000 Access: Read/Write Default: (->fill this in) (also can be defined in the initialization file, if it is used) ************************************************************************** Property: AmplitudeScale2 Sets the Amplitude Scale Trace 2's grid divisions, in binary steps/grid cell. The value will be adjusted to closest valid number (see the DLL documentation). Value: double, Range: 0.00001-100,000.00000 Access: Read/Write Default: (->fill this in) (also can be defined in the initialization file, if it is used) ************************************************************************** Property: AmplitudeScale3 Sets the Amplitude Scale Trace 3's grid divisions, in binary steps/grid cell. The value will be adjusted to closest valid number (see the DLL documentation). Value: double, Range: 0.00001-100,000.00000 Access: Read/Write Default: (->fill this in) (also can be defined in the initialization file, if it is used) ************************************************************************** Property: VerticalOffset1 Sets the Vertical Offset of Trace 1, in units of of Trace 1's AmplitudeScale. Value: double, Range: -1,000,000.00000-+1,000,000.00000 Access: Read/Write Default: 0.00000 (also can be defined in the initialization file, if it is used) ************************************************************************** Property: VerticalOffset2 Sets the Vertical Offset of Trace 2, in units of of Trace 2's AmplitudeScale. Value: double, Range: -1,000,000.00000-+1,000,000.00000 Access: Read/Write Default: 0.00000 (also can be defined in the initialization file, if it is used) ************************************************************************** Property: VerticalOffset3 Sets the Vertical Offset of Trace 3, in units of of Trace 3's AmplitudeScale. Value: double, Range: -1,000,000.00000-+1,000,000.00000 Access: Read/Write Default: 0.00000 (also can be defined in the initialization file, if it is used) ************************************************************************** Property: TriggerLevel1 Sets the Trigger Offset of Trace 1, in units of Trace 1's AmplitudeScale. Value: double, Range: -1,000,000.00000-+1,000,000.00000 Access: Read/Write Default: 0.00000 (also can be defined in the initialization file, if it is used) ************************************************************************** Property: TriggerLevel2 Sets the Trigger Offset of Trace 2, in units of Trace 2's AmplitudeScale. Value: double, Range: -1,000,000.00000-+1,000,000.00000 Access: Read/Write Default: 0.00000 (also can be defined in the initialization file, if it is used) ************************************************************************** Property: TriggerLevel3 Sets the Trigger Offset of Trace 3, in units of Trace 3's AmplitudeScale. Value: double, Range: -1,000,000.00000-+1,000,000.00000 Access: Read/Write Default: 0.00000 (also can be defined in the initialization file, if it is used) ************************************************************************** Property: TriggerSource Sets the Oscilloscope's Trigger Source. The constants TRACE1_TRIG, TRACE2_TRIG, TRACE3_TRIG and EXTERNAL_TRIG are provided for conenience. Value: int, Range 0-3 (TRACE1_TRIG-EXTERNAL_TRIG) Access: Read/Write Default: TRACE1_TRIG (also can be defined in the initialization file, if it is used) ************************************************************************** Property: TriggerEdge Sets the Trigger Edge Detection Mode. Any valid negative int sets it Negative Edge Triggered, any valid positive int sets it Positive Edge Triggered, and 0 set it to disabled. The constants FALLING_EDGE_TRIG, RISING_EDGE_TRIG and DISABLED_TRIG are provided for convenience. Value: int, Range: see above Access: Read/Write Default: DISABLED_TRIG (also can be defined in the initialization file, if it is used) ************************************************************************** Property: TriggerDelay Sets the Trigger Delay, in number of samples (see DLL Documentation). Value: int, RangeL 0-Any valid positive int value Access: Read/Write Default: 0 (also can be defined in the initialization file, if it is used) ************************************************************************** Property: TraceDisplayWidth Returns the width of the current trace display area in pixels. Value: int Access: Read Only Default: N/A ************************************************************************** Property: TraceDisplayHeight Returns the height of the current trace display area in pixels. Value: int Access: Read Only Default: N/A ************************************************************************** * * Miscellaneous Public Resources * ************************************************************************** --> Trigger Source Constants (int's): TRACE1_TRIG = 0; TRACE2_TRIG = 1; TRACE3_TRIG = 2; EXTERNAL_TRIG = 3; --> Trigger Mode Constants (int's): FALLING_EDGE_TRIG = -1; RISING_EDGE_TRIG = 1; DISABLED_TRIG = 0; --> Error Constants (int's): NO_ERROR = 0; SCOPE_CREATION_ERROR = 1; SCOPE_HANDLE_ERROR = 2; SCOPE_DISPOSED_ERROR = 3; LEFT_RANGE_ERROR = 4; TOP_RANGE_ERROR = 5; WIDTH_RANGE_ERROR = 6; HEIGHT_RANGE_ERROR = 7; CELLSIZE_RANGE_ERROR = 8; SAMPLESPERGRIDCELL_RANGE_ERROR = 9; CAPTIONSIZE_ERROR = 10; CELLAMPLITUDESCALE_RANGE_ERROR = 11; VERTICALOFFSET_RANGE_ERROR = 12; TRIGGERLEVEL_RANGE_ERROR = 13; TRIGGERSOURCE_RANGE_ERROR = 14; TRIGGERDELAY_RANGE_ERROR = 15; SCOPE_TRIGGERSOURCE_ERROR = 16; SCOPE_TRIGGEREDGE_ERROR = 17; SCOPE_NOT_VISIBLE = 18; **************************************************************************/ // Begin Oscilloscope DLL Wrapper Implementation namespace Serial_Oscilloscope { sealed class Oscilloscope : IDisposable { const string Osc_DLL_path = "Oscilloscope/Osc_DLL.dll"; #region External declarations /****************************************** * * * Import Essential Oscilloscope Functions * * * ******************************************/ [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int AtOpenLib (int Prm); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeCreate( int Prm, [MarshalAs(UnmanagedType.LPStr)] StringBuilder P_IniName, [MarshalAs(UnmanagedType.LPStr)] StringBuilder P_IniSuffix); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeDestroy (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeShow (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeHide (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeCleanBuffers (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ShowNext (int ScopeHandle, double[] PArrDbl); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ExternalNext (int ScopeHandle, ref double PDbl); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int QuickUpDate (int ScopeHandle); /****************************************** * * * Import Oscilloscope Attribute Controls * * * * **************************************** * * Import Set functions: */ [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetPanelState (int ScopeHandle, int VizState); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetFormPos (int ScopeHandle, int FormLeft, int FormTop); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetFormSize (int ScopeHandle, int FormWidth, int FormHeight); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetCellPixelSize (int ScopeHandle, int CellPixelSize); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetCellSampleSize (int ScopeHandle, double CellSampleSize); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetCaption (int ScopeHandle, [MarshalAs(UnmanagedType.LPStr)] StringBuilder P_ZeroTermStr); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetAmpScale (int ScopeHandle, int BeamNum, double AmpScale); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetAmpOffset (int ScopeHandle, int BeamNum, double AmpOffset); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetTriggerLevel (int ScopeHandle, int BeamNum, double TriggerLevel); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetTriggerSourse (int ScopeHandle, int BeamNum); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetActiveTriggerEdge (int ScopeHandle, int TriggerEdge); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeSetTrigHoldOffSmplsNum (int ScopeHandle, int HoldOffVsl); /* * Import Get functions: */ [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetFormLeft (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetFormTop (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetFormWidth (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetFormHeight (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetScreenWidth (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetScreenHeight (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetCellPixelSize (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern double ScopeGetCellSampleSize (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetPanelState (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern double ScopeGetAmpScale (int ScopeHandle, int Beam); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern double ScopeGetAmpOffset (int ScopeHandle, int Beam); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern double ScopeGetTriggerLevel (int ScopeHandle, int Beam); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetTriggerSourse (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetActiveTriggerEdge (int ScopeHandle); [DllImport(Osc_DLL_path, CallingConvention = CallingConvention.Cdecl)] private static extern int ScopeGetTrigHoldOffSmplsNum (int ScopeHandle); #endregion // Property Control Constants (provided for convenience) // // Trigger Source Constants public const int TRACE1_TRIG = 0, TRACE2_TRIG = 1, TRACE3_TRIG = 2, EXTERNAL_TRIG = 3; // // Trigger Type Constants public const int FALLING_EDGE_TRIG = -1, RISING_EDGE_TRIG = 1, DISABLED_TRIG = 0; /// /// Error Constants /// public const int NO_ERROR = 0; public const int SCOPE_CREATION_ERROR = 1; public const int SCOPE_HANDLE_ERROR = 2; public const int SCOPE_DISPOSED_ERROR = 3; public const int LEFT_RANGE_ERROR = 4; public const int TOP_RANGE_ERROR = 5; public const int WIDTH_RANGE_ERROR = 6; public const int HEIGHT_RANGE_ERROR = 7; public const int CELLSIZE_RANGE_ERROR = 8; public const int SAMPLESPERGRIDCELL_RANGE_ERROR = 9; public const int CAPTIONSIZE_ERROR = 10; public const int CELLAMPLITUDESCALE_RANGE_ERROR = 11; public const int VERTICALOFFSET_RANGE_ERROR = 12; public const int TRIGGERLEVEL_RANGE_ERROR = 13; public const int TRIGGERSOURCE_RANGE_ERROR = 14; public const int TRIGGERDELAY_RANGE_ERROR = 15; public const int SCOPE_TRIGGERSOURCE_ERROR = 16; public const int SCOPE_TRIGGEREDGE_ERROR = 17; public const int SCOPE_NOT_VISIBLE = 18; #region Static members static bool initialized = false; /// /// Creates a new Oscilloscope. Returns the object if successful, /// otherwise returns null. Generally, if it returns null then /// it cannot find the correct DLL to load /// /// Oscilloscope instance public static Oscilloscope CreateScope() { return CreateScope("NO_INI_FILE", "NON"); } /// /// Creates a new Oscilloscope. Returns the object if successful, /// otherwise returns null. Generally, if it returns null then /// it cannot find the correct DLL to load /// /// Name of INI file with scope settings /// Section name suffix (see manual) /// Oscilloscope instance public static Oscilloscope CreateScope(string IniName, string IniSuffix) { int handle; _Scope_Visible = false; try { if (!initialized) { // initialize if (AtOpenLib(0) == -1) { ShowError(SCOPE_CREATION_ERROR); return null; } // Set to true initialized = true; } } catch { // Return the Error ShowError(SCOPE_CREATION_ERROR); return null; } // Create the Oscilloscope Instance handle = ScopeCreate(0, new StringBuilder(IniName), new StringBuilder(IniSuffix)); if (handle != 0) { return new Oscilloscope(handle); } ShowError(SCOPE_CREATION_ERROR); return null; } #endregion private int scopeHandle; private bool _disposed = false; // Class Constructors private Oscilloscope() { } private Oscilloscope(int handle) { scopeHandle = handle; } // Class Destructor ~Oscilloscope() { Dispose(); } /// /// Shows the scope. /// public void ShowScope() { if (!_disposed) { _Scope_Visible = true; ScopeShow(scopeHandle); } else ShowError(SCOPE_DISPOSED_ERROR); } /// /// Hides the scope from view /// public void HideScope() { if (!_disposed) { _Scope_Visible = false; ScopeHide(scopeHandle); } else ShowError(SCOPE_DISPOSED_ERROR); } /// /// Clears the buffer of the scope /// public void ClearScope() { if (!_disposed) ScopeCleanBuffers(scopeHandle); else ShowError(SCOPE_DISPOSED_ERROR); } /// /// Add data to the scope traces. /// /// Data for first beam /// Data for second beam /// Data for third beam public void AddScopeData(double beam1, double beam2, double beam3) { if (!_disposed) { double[] PArrDbl = new double[3]; PArrDbl[0] = beam1; PArrDbl[1] = beam2; PArrDbl[2] = beam3; ShowNext(scopeHandle, PArrDbl); } else ShowError(SCOPE_DISPOSED_ERROR); } /// /// Add data to the 'external' trigger function signal. This value is used /// when TriggerSource == EXTERNAL_TRIG. /// /// The data public void AddExternalScopeData(double data) { if (!_disposed) ExternalNext(scopeHandle, ref data); else ShowError(SCOPE_DISPOSED_ERROR); } /// /// Quickly refreshes screen of oscilloscope. Calling this function is /// not usually required. Recommended for using in situations when /// intensive data stream is going into oscilloscope /// public void UpdateScope() { if (!_disposed) { QuickUpDate(scopeHandle); } else ShowError(SCOPE_DISPOSED_ERROR); } /***************************************** * * * C# wrapper for Oscilloscope Properties * * * *****************************************/ private static bool _ErrorMessagesOn = true; private static int _LastError = NO_ERROR; private static bool _Scope_Visible = false; /// /// Property: LastError /// /// An application can check this to see if there has been an /// error, even when error message displays are turned off. /// If it is non-zero (!=NO_ERROR), there has been an error /// and the value refers to one of the listed error constants. /// /// When setting LastError the value is ignored and LastError /// is set to its defaul value, NO_ERROR. The application /// should do this after finding an error value here, as it is /// not done automatically; the error code value will persist /// until it is manually reset. /// /// Value: int, equal to one of the error constants /// Access: Read/Write (any write resets LastError to NO_ERROR /// Default: 0 (NO_ERROR) /// public int LastError { set { _LastError = NO_ERROR; } get { return _LastError; } } /// /// Property: ErrorMessagesOn /// /// If ErrorMessagesOn is set to "true", a throw new Exception will appear /// when there is an error. When debugging is completed it may be /// desirable to set ErrorMessagesOn to "false." /// /// Value: bool /// Access: Read/Write /// Default: true /// public bool ErrorMessagesOn { set { _ErrorMessagesOn = value; } get { return _ErrorMessagesOn; } } /// /// Property: ControlPanelVisible /// /// Displays or hides the control panel at the bottom of the /// oscilloscope display /// /// Value: bool /// Access: Read/Write /// Default: true (also can be define in the intialization /// file, if used) /// public bool ControlPanelVisible { set { int Ret = 0; if (!_disposed) { if (value) Ret = ScopeSetPanelState(scopeHandle, 1); else Ret = ScopeSetPanelState(scopeHandle, 0); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } get { if (!_disposed) { if (ScopeGetPanelState(scopeHandle) == 1) return false; else return true; } else ShowError(SCOPE_DISPOSED_ERROR); return false; } } /// /// Property: Left /// /// Sets the horizontal position of the oscilloscope on the screen, /// specified as the number of pixels from the left edge of the screen /// to the left edge of the oscilloscope form. /// /// Value: int, Range: 0-Current Screen Width /// Access: Read/Write /// Default: Somewhere on the Screen (also can be defined in the /// intialization file, if used) /// public int Left { set { int MonitorWidth, MonitorHeight; GetMonitorDimensions(out MonitorWidth, out MonitorHeight); if ((value < 0) || (value > MonitorWidth)) ShowError(LEFT_RANGE_ERROR, value); else { if (!_disposed) { int Ret = 0, Top; Top = ScopeGetFormTop(scopeHandle); Ret = ScopeSetFormPos(scopeHandle, value, Top); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetFormLeft(scopeHandle); else ShowError(SCOPE_DISPOSED_ERROR); return 0; } } /// /// Property: Top /// /// Sets the vertical position of the oscilloscope on the screen, /// specified as the number of pixels from the top edge of the screen /// to the top edge of the oscilloscope form. /// /// Value: int, Range: 0-Current Screen Height /// Access: Read/Write /// Default: Somewhere on the Screen (also can be defined in /// the intialization file, if used) /// public int Top { set { int MonitorWidth, MonitorHeight; GetMonitorDimensions(out MonitorWidth, out MonitorHeight); if ((value < 0) || (value > MonitorHeight)) ShowError(TOP_RANGE_ERROR, value); else { if (!_disposed) { int Ret = 0, Left; Left = ScopeGetFormLeft(scopeHandle); Ret = ScopeSetFormPos(scopeHandle, Left, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetFormTop(scopeHandle); else ShowError(SCOPE_DISPOSED_ERROR); return 0; } } /// /// Property: Width /// /// Sets the Width of the oscilloscope form in pixels. /// /// Value: int, Range: 40-Current Screen Width /// Access: Read/Write /// Default: (->fill this in) (also can be defined in the /// initialization file, if used) /// public int Width { set { int MonitorWidth, MonitorHeight; GetMonitorDimensions(out MonitorWidth, out MonitorHeight); if ((value < 40) || (value > MonitorWidth)) ShowError(WIDTH_RANGE_ERROR, value); else { if (!_disposed) { int Ret = 0, Height; Height = ScopeGetFormHeight(scopeHandle); Ret = ScopeSetFormSize(scopeHandle, value, Height); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetFormWidth(scopeHandle); else ShowError(SCOPE_DISPOSED_ERROR); return 0; } } /// /// Property: Height /// /// Sets the Height of the oscilloscope form in pixels. /// /// Value: int, Range: 40-Current Screen Height /// Access: Read/Write /// Default: (->fill this in) (also can be defined in the /// initialization file, if used) /// public int Height { set { int MonitorWidth, MonitorHeight; GetMonitorDimensions(out MonitorWidth, out MonitorHeight); if ((value < 40) || (value > MonitorHeight)) ShowError(HEIGHT_RANGE_ERROR, value); else { if (!_disposed) { int Ret = 0, Width; Width = ScopeGetFormWidth(scopeHandle); Ret = ScopeSetFormSize(scopeHandle, Width, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetFormHeight(scopeHandle); else ShowError(SCOPE_HANDLE_ERROR); return 0; } } /// /// Property: CellSize /// /// Sets the size of a grid cell in pixels; sets both height /// and width of cells to the single parameter setting. /// /// Value: int, Range: 10-150 /// Access: Read/Write /// Default: 40 (also can be defined in the initialization file, if used) /// public int CellSize { set { if ((value < 10) || (value > 150)) ShowError(CELLSIZE_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetCellPixelSize(scopeHandle, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetCellPixelSize(scopeHandle); else ShowError(SCOPE_DISPOSED_ERROR); return 0; } } /// /// Property: SamplesPerGridCell /// /// Sets the number of samples per grid cell on the horizontal (time) axis. /// The value will be adjusted to closest valid number (see the DLL /// documentation). /// /// WARNING: if this setting is too low and the data stream is too fast /// a buffer overrun can be caused, which will have no indicator other /// than the DLL locking up. /// /// Value: double, Range 0.10000-20,000 /// Access: Read/Write /// Default: (->fill this in) (also can be defined in the /// initialization file, if used) /// public double SamplesPerGridCell { set { if ((value < 0.10000) || (value > 20000.00000)) ShowError(SAMPLESPERGRIDCELL_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetCellSampleSize(scopeHandle, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetCellSampleSize(scopeHandle); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: Caption /// /// Sets the caption at the top of the oscilloscope form. /// /// Value: string, Range 0-250 characters /// Access: Write Only /// Default: "Oscilloscope" (also can be defined in the /// initialization file, if used) /// public string Caption { set { if (value.Length > 250) ShowError(CAPTIONSIZE_ERROR); else { if (!_disposed) { int Ret = ScopeSetCaption(scopeHandle, new StringBuilder(value)); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } } /// /// Property: AmplitudeScale1 /// /// Sets the Amplitude Scale of Trace 1's grid divisions, in binary steps/grid cell /// The value will be adjusted to closest valid number (see the DLL documentation) /// /// Value: double, Range: 0.00001-100,000.00000 /// Access: Read/Write /// Default: (->fill this in) (also can be defined in the /// initialization file, if used) /// public double AmplitudeScale1 { set { if ((value < 0.00001) || (value > 100000.00000)) ShowError(CELLAMPLITUDESCALE_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetAmpScale(scopeHandle, 0, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetAmpScale(scopeHandle, 0); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: AmplitudeScale2 /// /// Sets the Amplitude Scale Trace 2's grid divisions, in binary steps/grid cell /// The value will be adjusted to closest valid number (see the DLL documentation) /// /// Value: double, Range: 0.00001-100,000.00000 /// Access: Read/Write /// Default: (->fill this in) (also can be defined in the /// initialization file, if used) /// public double AmplitudeScale2 { set { if ((value < 0.00001) || (value > 100000.00000)) ShowError(CELLAMPLITUDESCALE_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetAmpScale(scopeHandle, 1, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetAmpScale(scopeHandle, 1); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: AmplitudeScale3 /// /// Sets the Amplitude Scale of Trace 3's grid divisions, in binary steps/grid cell /// The value will be adjusted to closest valid number (see the DLL documentation) /// /// Value: double, Range: 0.00001-100,000.00000 /// Access: Read/Write /// Default: (->fill this in) (also can be defined in the /// initialization file, if used) /// public double AmplitudeScale3 { set { if ((value < 0.00001) || (value > 100000.00000)) ShowError(CELLAMPLITUDESCALE_RANGE_ERROR, 0); else { if (!_disposed) { int Ret = ScopeSetAmpScale(scopeHandle, 2, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetAmpScale(scopeHandle, 2); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: VerticalOffset1 /// /// Sets the Vertical Offset of Trace 1, in units of of Trace 1's /// AmplitudeScale. /// /// Value: double, Range: -1,000,000.00000-+1,000,000.00000 /// Access: Read/Write /// Default: 0.00000 (also can be defined in the initialization file, if used) /// public double VerticalOffset1 { set { if ((value < -1000000.0000) || (value > 1000000.00000)) ShowError(VERTICALOFFSET_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetAmpOffset(scopeHandle, 0, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetAmpOffset(scopeHandle, 0); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: VerticalOffset2 /// /// Sets the Vertical Offset of Trace 2, in units of of Trace 2's /// AmplitudeScale. /// /// Value: double, Range: -1,000,000.00000-+1,000,000.00000 /// Access: Read/Write /// Default: 0.00000 (also can be defined in the initialization file, if used) /// public double VerticalOffset2 { set { if ((value < -1000000.0000) || (value > 1000000.00000)) ShowError(VERTICALOFFSET_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetAmpOffset(scopeHandle, 1, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetAmpOffset(scopeHandle, 1); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: VerticalOffset3 /// /// Sets the Vertical Offset of Trace 3, in units of of Trace 3's /// AmplitudeScale. /// /// Value: double, Range: -1,000,000.00000-+1,000,000.00000 /// Access: Read/Write /// Default: 0.00000 (also can be defined in the initialization file, if used) /// public double VerticalOffset3 { set { if ((value < -1000000.0000) || (value > 1000000.00000)) ShowError(VERTICALOFFSET_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetAmpOffset(scopeHandle, 2, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetAmpOffset(scopeHandle, 2); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: TriggerLevel1 /// /// Sets the Trigger Offset Trace 1, in units of Trace 1's AmplitudeScale. /// /// Value: double, Range: -1,000,000.00000-+1,000,000.00000 /// Access: Read/Write /// Default: 0.00000 (also can be defined in the initialization file, if used) /// public double TriggerLevel1 { set { if ((value < -1000000.0000) || (value > 1000000.00000)) ShowError(TRIGGERLEVEL_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetTriggerLevel(scopeHandle, 0, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetTriggerLevel(scopeHandle, 0); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: TriggerLevel2 /// /// Sets the Trigger Offset Trace 2, in units of Trace 2's AmplitudeScale. /// /// Value: double, Range: -1,000,000.00000-+1,000,000.00000 /// Access: Read/Write /// Default: 0.00000 (also can be defined in the initialization file, if used) /// public double TriggerLevel2 { set { if ((value < -1000000.0000) || (value > 1000000.00000)) ShowError(TRIGGERLEVEL_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetTriggerLevel(scopeHandle, 1, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetTriggerLevel(scopeHandle, 1); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: TriggerLevel3 /// /// Sets the Trigger Offset Trace 3, in units of Trace 3's AmplitudeScale. /// /// Value: double, Range: -1,000,000.00000-+1,000,000.00000 /// Access: Read/Write /// Default: 0.00000 (also can be defined in the initialization file, if used) /// public double TriggerLevel3 { set { if ((value < -1000000.0000) || (value > 1000000.00000)) ShowError(TRIGGERLEVEL_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetTriggerLevel(scopeHandle, 2, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetTriggerLevel(scopeHandle, 2); else ShowError(SCOPE_DISPOSED_ERROR); return 0.00000; } } /// /// Property: TriggerSource /// /// Sets the Oscilloscope's Trigger Source. The Constants TRACE1_TRIG, /// TRACE2_TRIG, TRACE3_TRIG and EXTERNAL_TRIG are provided for conenience. /// /// Value: int, Range 0-3 (TRACE1_TRIG-EXTERNAL_TRIG) /// Access: Read/Write /// Default TRACE1_TRIG (also can be defined in the initialization file, if used) /// public int TriggerSource { set { if (!_Scope_Visible) ShowError(SCOPE_NOT_VISIBLE); else if ((value < TRACE1_TRIG) || (value > EXTERNAL_TRIG)) ShowError(TRIGGERSOURCE_RANGE_ERROR, value); else { if (!_disposed) { try { int Ret = ScopeSetTriggerSourse(scopeHandle, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } catch { ShowError(SCOPE_TRIGGERSOURCE_ERROR); Dispose(); } } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetTriggerSourse(scopeHandle); else ShowError(SCOPE_DISPOSED_ERROR); return 0; } } /// /// Property: TriggerEdge /// /// Sets the Trigger Edge Detection Mode. Any valid negative int sets it /// Negative Edge Triggered, any valid positive int sets it Positive Edge /// Triggered, and 0 set it to disabled. The constants FALLING_EDGE_TRIG, /// RISING_EDGE_TRIG and DISABLED_TRIG are provided for convenience. /// /// Value: int, Range: see above /// Access; Read/Write /// Default: DISABLED_TRIG (also can be defined in the initialization file, /// if used) /// public int TriggerEdge { set { if (!_Scope_Visible) ShowError(SCOPE_NOT_VISIBLE); else if (!_disposed) { int Edge; try { if (value < 0) Edge = -1; else if (value > 0) Edge = 1; else Edge = 0; int Ret = ScopeSetActiveTriggerEdge(scopeHandle, Edge); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } catch { ShowError(SCOPE_TRIGGEREDGE_ERROR); Dispose(); } } else ShowError(SCOPE_DISPOSED_ERROR); } get { if (!_disposed) return ScopeGetActiveTriggerEdge(scopeHandle); else ShowError(SCOPE_HANDLE_ERROR); return 0; } } /// /// Property: TriggerDelay /// /// Controls the Trigger Delay, in number of samples. /// (see DLL Documentation) /// /// Value: int, RangeL 0-Any valid positive int value /// Access: Read/Write /// Default: 0 (also can be defined in the initialization file, if used) /// public int TriggerDelay { set { if (value < 0) ShowError(TRIGGERDELAY_RANGE_ERROR, value); else { if (!_disposed) { int Ret = ScopeSetTrigHoldOffSmplsNum(scopeHandle, value); if (Ret != scopeHandle) ShowError(SCOPE_HANDLE_ERROR); } else ShowError(SCOPE_DISPOSED_ERROR); } } get { if (!_disposed) return ScopeGetTrigHoldOffSmplsNum(scopeHandle); else ShowError(SCOPE_DISPOSED_ERROR); return 0; } } /// /// Property: TraceDisplayWidth /// /// Returns the width of the current trace display area display in pixels. /// /// Value: int /// Access: Read Only /// Default: N/A /// public int TraceDisplayWidth { get { if (!_disposed) return (ScopeGetScreenWidth(scopeHandle)); else ShowError(SCOPE_DISPOSED_ERROR); return 0; } } /// /// Property: TraceDisplayHeight /// /// Returns the height of the current trace display area in pixels. /// /// Value: int /// Access: Read Only /// Default: N/A /// public int TraceDisplayHeight { get { if (!_disposed) return (ScopeGetScreenHeight(scopeHandle)); else ShowError(SCOPE_DISPOSED_ERROR); return 0; } } /// /// Method to Display Error Messages, overload for errors that have no associated /// data (fundamental DLL communication errors, except for CAPTIONSIZE_ERROR). /// /// int: Error Number private static void ShowError(int ErrorNum) { _LastError = ErrorNum; if (_ErrorMessagesOn) { switch (ErrorNum) { case SCOPE_CREATION_ERROR: throw new Exception("Oscilloscope Creation Failed."); case SCOPE_HANDLE_ERROR: throw new Exception("Oscilloscope Access Failed."); case SCOPE_DISPOSED_ERROR: throw new Exception("Oscilloscope has been Disposed."); case CAPTIONSIZE_ERROR: throw new Exception("Caption Too Long."); case SCOPE_TRIGGERSOURCE_ERROR: throw new Exception("The Oscilloscope threw a Set Trigger Source Exception and must be Closed."); case SCOPE_TRIGGEREDGE_ERROR: throw new Exception("The Oscilloscope threw a Set Trigger Edge Exception and must be Closed."); case SCOPE_NOT_VISIBLE: throw new Exception("This Property Cannot be Accessed when the Oscilloscope is in Hide Mode."); } } } /// /// Method to Display Error Messages, overload for range errors in property /// that are type integer. /// /// int: Error Number /// int: The Value That Caused the Error private static void ShowError(int ErrorNum, int ErrorValue) { _LastError = ErrorNum; if (_ErrorMessagesOn) { switch (ErrorNum) { case LEFT_RANGE_ERROR: throw new Exception(string.Format("Scope Left Out of Range: {0}.", ErrorValue)); case TOP_RANGE_ERROR: throw new Exception(string.Format("Scope Top Out Of Range: {0}.", ErrorValue)); case WIDTH_RANGE_ERROR: throw new Exception(string.Format("Scope Width Out of Range: {0}", ErrorValue)); case HEIGHT_RANGE_ERROR: throw new Exception(string.Format("Scope Height Out Of Range: {0}.", ErrorValue)); case CELLSIZE_RANGE_ERROR: throw new Exception(string.Format("Scope CellSize Out of Range: {0}.", ErrorValue)); case TRIGGERSOURCE_RANGE_ERROR: throw new Exception(string.Format("Scope Trigger Source Out of Range: {0}.", ErrorValue)); case TRIGGERDELAY_RANGE_ERROR: throw new Exception(string.Format("Scope Trigger Delay Out of Range: {0}.", ErrorValue)); } } } /// /// Method to Display Error Messages, overload for range errors in properties /// that are type double. /// /// int: Error Number /// double: The Value That Caused the Error private static void ShowError(int ErrorNum, double ErrorValue) { _LastError = ErrorNum; if (_ErrorMessagesOn) { switch (ErrorNum) { case SAMPLESPERGRIDCELL_RANGE_ERROR: throw new Exception(string.Format("Scope SamplesPerGridCell Out of Range: {0}", ErrorValue)); case CELLAMPLITUDESCALE_RANGE_ERROR: throw new Exception(string.Format("Scope CellAmplitideScale Out of Range: {0}", ErrorValue)); case VERTICALOFFSET_RANGE_ERROR: throw new Exception(string.Format("Vertical Offset Out of Range: {0}", ErrorValue)); case TRIGGERLEVEL_RANGE_ERROR: throw new Exception(string.Format("Trigger Level Out of Range: {0}", ErrorValue)); } } } public static void GetMonitorDimensions(out int Width, out int Height) { Size Monitor = SystemInformation.PrimaryMonitorSize; Width = Monitor.Width; Height = Monitor.Height; } #region IDisposable Members /// /// Dispose the object - call this to release the oscilloscope resources. /// public void Dispose() { if (!_disposed) { ScopeDestroy(scopeHandle); _disposed = true; } } /// /// Flag indicating if the object is already disposed. /// /// public bool IsDisposed { get { return _disposed; } } #endregion } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/Oscilloscope/Oscilloscope_settings.ini ================================================ [Oscilloscope] OscVrulFontName=Arial OscVrulFontSize=8 OscVrulFontStyleBold=0 OscVrulFontStyleItalic=0 OscBackColor=00222222 OscGridColor=00404040 OscHorScaleColor=00FFFFFF OscBeam0Color=000000FF OscBeam1Color=0000FF00 OscBeam2Color=00FF0000 OscVrulGenFontColor=00FFFFFF OscZeroLineColor=00FFFFFF OscOscCaption=Oscilloscope ShowSecondBeam=1 ShowThirdBeam=1 ShowTestButton=0 BuffersRecordType=1 CreateSecondBeam=1 CreateThirdBeam=1 SpreadViewTiming=1 EventsProcDivider=0 GridRefreshDivider=50 GridCellPixelsSize=15 TriggerEnable=0 TriggerSource=0 FirstTriggerLevel=0.0000000000 SecondTriggerLevel=0.0000000000 ThirdTriggerLevel=0.0000000000 ExtrnTriggerLevel=0.0000000000 TimeSamplesPerCell=20.0000000000 Beam0VertScale=10.0000000000 Beam1VertScale=10.0000000000 Beam2VertScale=10.0000000000 Beam0VertOffset=0.0000000000 Beam1VertOffset=0.0000000000 Beam2VertOffset=0.0000000000 ScopeFormHeight=400 ScopeFormWidth=600 ScopeStayOnTop=0 ShowTriggerControls=1 ShowOscJaggies=0 ShowOscHexVal=0 ShowHexCheckBox=0 ScopeShowAutoSweep=0 ScopeAutoSweep=0 ScopeAutoSweepDivider=4 ScopeShowHints=1 Producer_Vendor_Name=+972 507669424 Michael Bernstein, E_Mail: brnstin@cheerful.com BfrSmplSize=32000 ScopeInputDumpSize=32000 ScopePolylineOptimize=0 [Miscellaneous] ReadDelayPerSample=0 ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/Program.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace Serial_Oscilloscope { static class Program { /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FormTerminal()); } } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/Properties/AssemblyInfo.cs ================================================ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("Serial Oscilloscope")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("x-io Technologies Limited")] [assembly: AssemblyProduct("Serial Oscilloscope")] [assembly: AssemblyCopyright("Copyright © x-io Technologies Limited 2013")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // Setting ComVisible to false makes the types in this assembly not visible // to COM components. If you need to access a type in this assembly from // COM, set the ComVisible attribute to true on that type. [assembly: ComVisible(false)] // The following GUID is for the ID of the typelib if this project is exposed to COM [assembly: Guid("dd5e52ed-ab85-46f6-a820-4d740c7456af")] // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build Number // Revision // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.5.*")] //[assembly: AssemblyFileVersion("1.0.0.0")] ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/Properties/Resources.Designer.cs ================================================ //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.17929 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace Serial_Oscilloscope.Properties { /// /// A strongly-typed resource class, for looking up localized strings, etc. /// // This class was auto-generated by the StronglyTypedResourceBuilder // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] internal Resources() { } /// /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { get { if ((resourceMan == null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Serial_Oscilloscope.Properties.Resources", typeof(Resources).Assembly); resourceMan = temp; } return resourceMan; } } /// /// Overrides the current thread's CurrentUICulture property for all /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { get { return resourceCulture; } set { resourceCulture = value; } } } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/Properties/Resources.resx ================================================  text/microsoft-resx 2.0 System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/Properties/Settings.Designer.cs ================================================ //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.17929 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ namespace Serial_Oscilloscope.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); public static Settings Default { get { return defaultInstance; } } } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/Properties/Settings.settings ================================================  ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/SampleCounter.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Serial_Oscilloscope { /// /// Sample counter. Tracks number of packets received and packet rate. /// class SampleCounter { /// /// Timer to calculate packet rate. /// private System.Windows.Forms.Timer timer; /// /// Number of packets received. /// public int SamplesReceived { get; private set; } /// /// Sample receive rate as packets per second. /// public int SampleRate { get; private set; } /// /// Variable used to calculate packet rate. /// private int prevSamplesReceived; /// /// Constructor. /// public SampleCounter() { // Initialise variables prevSamplesReceived = 0; SamplesReceived = 0; // Setup timer timer = new System.Windows.Forms.Timer(); timer.Interval = 1000; timer.Tick += new EventHandler(timer_Tick); timer.Start(); } /// /// Increments packet counter. /// public void Increment() { SamplesReceived++; } // Zeros packet counter. public void Reset() { prevSamplesReceived = 0; SamplesReceived = 0; SampleRate = 0; } /// /// timer Tick event to calculate packet rate. /// void timer_Tick(object sender, EventArgs e) { SampleRate = SamplesReceived - prevSamplesReceived; prevSamplesReceived = SamplesReceived; } } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/Serial Oscilloscope.csproj ================================================  Debug x86 8.0.30703 2.0 {37F93890-5296-4350-8F67-28BCC26CD6F2} WinExe Properties Serial_Oscilloscope Serial Oscilloscope v3.5 512 x86 true full false bin\Debug\ DEBUG;TRACE prompt 4 x86 pdbonly true bin\Release\ TRACE prompt 4 Form FormGetValue.cs Form FormTerminal.cs FormGetValue.cs FormTerminal.cs ResXFileCodeGenerator Resources.Designer.cs Designer True Resources.resx PreserveNewest SettingsSingleFileGenerator Settings.Designer.cs True Settings.settings True PreserveNewest ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/TextBoxBuffer.cs ================================================ using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Serial_Oscilloscope { /// /// TextBox FIFO buffer. /// class TextBoxBuffer { /// /// Size of buffer in bytes. /// private int size; /// /// Buffer array. /// private char[] buffer; /// /// Buffer in position index. /// private int inPos = 0; /// /// Buffer out position index. /// private int outPos = 0; /// /// Constructor. /// /// /// Size of buffer. /// public TextBoxBuffer(int size) { this.size = size; buffer = new char[this.size]; } /// /// Returns value indicating if buffer is empty. /// /// /// Value indicating if buffer is empty. /// public bool IsEmpty() { return inPos == outPos; } /// /// Adds string to buffer. /// /// /// String to add to buffer. /// public void Put(string str) { foreach (char c in str) { buffer[inPos] = c; if (++inPos == size - 1) { inPos = 0; } } } /// /// Gets buffer contents. /// /// /// Buffer contents. /// public string Get() { string str = ""; while (inPos != outPos) { str += buffer[outPos]; if (++outPos == size - 1) { outPos = 0; } } return str; } /// /// Clears buffer. /// public void Clear() { inPos = 0; outPos = 0; } } } ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope/VisualStudio_CleanUp.bat ================================================ @echo off REM Remove files generated by compiler in this directory and all subdirectories. REM Essential release files are kept. echo Removing "*.csproj.user" files... for /f "delims==" %%i in ('dir /b /on /s "%~p0*.csproj.user"') do del "%%i" /f /q echo. echo Removing "*.exe.config" files... for /f "delims==" %%i in ('dir /b /on /s "%~p0*.exe.config"') do del "%%i" /f /q echo. echo Removing "*.vshost.exe.config" files... for /f "delims==" %%i in ('dir /b /on /s "%~p0*.vshost.exe.config"') do del "%%i" /f /q echo. echo Removing "*.pdb" files... for /f "delims==" %%i in ('dir /b /on /s "%~p0*.pdb"') do del "%%i" /f /q echo. echo Removing "*.vshost.application" files... for /f "delims==" %%i in ('dir /b /on /s "%~p0*.vshost.application"') do del "%%i" /f /q echo. echo Removing "*.vshost.exe" files... for /f "delims==" %%i in ('dir /b /on /s "%~p0*.vshost.exe "') do del "%%i" /f /q echo. echo Removing "*.vshost.exe.manifest" files... for /f "delims==" %%i in ('dir /b /on /s "%~p0*.vshost.exe.manifest "') do del "%%i" /f /q echo. echo Removing "obj" directory... rd "%~p0obj" /s /q echo. echo Removing "Debug" directories recursively... for /f "delims==" %%i in ('dir /b /on /s "%~p0*Debug"') do if "%%~ni"=="Debug" rd "%%i" /s /q echo. echo Removing "app.publish" directories recursively... for /f "delims==" %%i in ('dir /b /on /s "%~p0*app.publish"') do rd "%%i" /s /q echo. echo Removing "*_mcr" directories recursively... for /f "delims==" %%i in ('dir /b /on /s "%~p0*_mcr"') do rd "%%i" /s /q echo. echo "%~n0.bat" done. ================================================ FILE: Serial Oscilloscope/Serial Oscilloscope.sln ================================================  Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serial Oscilloscope", "Serial Oscilloscope\Serial Oscilloscope.csproj", "{37F93890-5296-4350-8F67-28BCC26CD6F2}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {37F93890-5296-4350-8F67-28BCC26CD6F2}.Debug|x86.ActiveCfg = Debug|x86 {37F93890-5296-4350-8F67-28BCC26CD6F2}.Debug|x86.Build.0 = Debug|x86 {37F93890-5296-4350-8F67-28BCC26CD6F2}.Release|x86.ActiveCfg = Release|x86 {37F93890-5296-4350-8F67-28BCC26CD6F2}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection EndGlobal