using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO.Ports; using System.IO; using System.Text.RegularExpressions; using System.Configuration; using System.Timers; using ZedGraph; namespace Daya_Bay_Princeton_2009 { public partial class MainForm : Form { //Good Stuff public int NumberOfUsablePorts = Properties.Settings.Default.Comports; public int StartingPortNumber = (int)(Properties.Settings.Default.ComportStartingNumber); // Finds the Saved Starting Port Number from Properties.ComportStartingNumber public string filename = null; private int error; // Holds Error Number (Not Used at this time) // Reference to BubblerFunctions GraphBubbler GraphForm; // Reference to GraphForm string permanantfilename; string fileWithPAppended; // Receive buffer private byte[] serialnumber = new byte[8]; // Hold Serial Number public GraphGasMixture instanceGasGraph; public Bubbler BF; public Microcontroller SP; public FileSystemHandler FS; public Gases GasClassInstance; public MainForm() { InitializeComponent(); SP = new Microcontroller(this); BF = new Bubbler(this); FS = new FileSystemHandler(); //Reference to CLASS FileSystemHandler GasClassInstance = new Gases(); } private void Form1_Load(object sender, EventArgs e) { GasClassInstance.CreateWatcher(); //Adds some file path info to the text box textBoxStatus.AppendText("The default directory is " + Properties.Settings.Default.DefaultDirectory + "\r\n"); textBoxStatus.AppendText("To change these go to File-Options\r\n"); textBoxStatus.Refresh(); //Shows the current default directory from Properties.DefaultDirectory labelDefaultDirectory.Text = Properties.Settings.Default.DefaultDirectory; } private void menucheckCommunicationToolStripMenuItem_Click(object sender, EventArgs e) { BF.CheckCommunication(NumberOfUsablePorts, StartingPortNumber); } private void menuopenToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog opnFile = new OpenFileDialog(); opnFile.Filter = "txt files (*.txt)|*.txt|All files(*.*)|*.*"; //FileForUpload is where we store the .txt file that runs on the Microcontroller opnFile.InitialDirectory = Properties.Settings.Default.FileforUpload; if (opnFile.ShowDialog() == DialogResult.OK) { filename = opnFile.FileName; } else { opnFile.Dispose(); } btnUploadFileToMicrochip.Enabled = true; } private void btnUploadFileToMicroController_Click(object sender, EventArgs e) { textBoxStatus.Text = ""; btnUploadFileToMicrochip.Enabled = false; UploadBubbleData.Enabled = false; btnUploadFileToMicrochip.Enabled = true; UploadBubbleData.Enabled = true; RunProgram.Enabled = true; BF.UploadProgramToMicrocontroller(NumberOfUsablePorts, StartingPortNumber); } private void btnRunProgram_Click(object sender, EventArgs e) { BF.RunProgram(this.SP); } private void btnDownloadBubbleData_Click(object sender, EventArgs e) { this.FS.SetUpSearchforDate(); string currentfiledir = FS.CreateTimeDirectory(); progressBar1.Minimum = 0x1100; progressBar1.Maximum = 0x38FF; progressBar1.Step = ((0x4F9C - 0x6800)/0x00fa); BF.DownLoadData(currentfiledir); timer1.Enabled = true; timer1.Interval = Convert.ToInt32((numericUpDown1.Value * 1000 * 60)); //CGL } private void menucloseToolStripMenuItem_Click(object sender, EventArgs e) { Dispose(); } private void btnChangeDirectory(object sender, EventArgs e) { FolderBrowserDialog changeFolder = new FolderBrowserDialog(); changeFolder.RootFolder = Environment.SpecialFolder.MyComputer; changeFolder.ShowNewFolderButton= true; if (changeFolder.ShowDialog() == DialogResult.OK) { Properties.Settings.Default.DefaultDirectory = changeFolder.SelectedPath; Properties.Settings.Default.Save(); labelDefaultDirectory.Text = Properties.Settings.Default.DefaultDirectory; } } private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { } private void menuaboutToolStripMenuItem_Click(object sender, EventArgs e) { MessageBox.Show("Copyright 2009 Princeton University Physics Dept", "Bubble Rate Acquisition Program"); } private void timer1_Tick(object sender, EventArgs e) { BF.RunProgramFromTimer(); } private void btnStartStopTimer_Click(object sender, EventArgs e) { if (timer1.Enabled == true) { timer1.Enabled = false; StartStopTimer.Text = "Start Timer"; } else { timer1.Enabled = true; StartStopTimer.Text = "Stop Timer"; } } public void UpdateTextBox1(string p) { textBoxStatus.AppendText(p); } private void numericUpDown1_ValueChanged_1(object sender, EventArgs e) { if ((numericUpDown1.Value > 0)) //CGL | { timer1.Interval = Convert.ToInt32((numericUpDown1.Value * 1000 * 60)); //CGL } } private void menuCheckSerialNumbersToolStripMenuItem_Click(object sender, EventArgs e) { SetSerialNumber Sn = new SetSerialNumber(this); Sn.Show(); } private void menupercentagesToolStripMenuItem_Click(object sender, EventArgs e) { GraphGasMixture GG = new GraphGasMixture(); GG.ReadGasDataFromDatabase(); GG.Show(); } private void menurunUpdateToolStripMenuItem_Click(object sender, EventArgs e) { Gases GT = new Gases(); GT.ReadGasFile("xx","xx"); } } }