using System; using System.IO; using System.Text; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Drawing.Drawing2D; using System.Threading; using WinUsb; using csRepeat; using csRepeat.FW6; using System.Collections.Generic; using AsciiCmdUtilities; namespace csDP5 { /// /// Summary description for Form1. /// public unsafe class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.PictureBox picPlot; public Button buttonFindUsbDevices; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; private const String WINUSB_GUID_STRING = "{5A8ED6A1-7FC3-4b6a-A536-95DF35D03448}"; private Label labelFW6Devices; private ListBox listboxDevices; public Button buttonRunFW6Tests; private TabControl tabControl1; private TabPage tabStatus; private TabPage tabCfgInit; private TabPage tabCfgTest; private Label label5; private Label lblChannels; private Label labelPlot; private TextBox textCfgInit; private TextBox textCfgTest; private TextBox textStatus; // Convert the device interface GUID String to a GUID object: private static Guid winUsbGuid = new System.Guid(WINUSB_GUID_STRING); public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (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.picPlot = new System.Windows.Forms.PictureBox(); this.buttonFindUsbDevices = new System.Windows.Forms.Button(); this.labelFW6Devices = new System.Windows.Forms.Label(); this.listboxDevices = new System.Windows.Forms.ListBox(); this.buttonRunFW6Tests = new System.Windows.Forms.Button(); this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabStatus = new System.Windows.Forms.TabPage(); this.textStatus = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.lblChannels = new System.Windows.Forms.Label(); this.labelPlot = new System.Windows.Forms.Label(); this.tabCfgInit = new System.Windows.Forms.TabPage(); this.textCfgInit = new System.Windows.Forms.TextBox(); this.tabCfgTest = new System.Windows.Forms.TabPage(); this.textCfgTest = new System.Windows.Forms.TextBox(); ((System.ComponentModel.ISupportInitialize)(this.picPlot)).BeginInit(); this.tabControl1.SuspendLayout(); this.tabStatus.SuspendLayout(); this.tabCfgInit.SuspendLayout(); this.tabCfgTest.SuspendLayout(); this.SuspendLayout(); // // picPlot // this.picPlot.BackColor = System.Drawing.SystemColors.Window; this.picPlot.Location = new System.Drawing.Point(8, 254); this.picPlot.Name = "picPlot"; this.picPlot.Size = new System.Drawing.Size(424, 256); this.picPlot.TabIndex = 9; this.picPlot.TabStop = false; // // buttonFindUsbDevices // this.buttonFindUsbDevices.Location = new System.Drawing.Point(10, 35); this.buttonFindUsbDevices.Name = "buttonFindUsbDevices"; this.buttonFindUsbDevices.Size = new System.Drawing.Size(158, 24); this.buttonFindUsbDevices.TabIndex = 11; this.buttonFindUsbDevices.Text = "Find RS232/USB Devices"; this.buttonFindUsbDevices.Click += new System.EventHandler(this.buttonFindUsbDevices_Click); // // labelFW6Devices // this.labelFW6Devices.AutoSize = true; this.labelFW6Devices.Location = new System.Drawing.Point(8, 99); this.labelFW6Devices.Name = "labelFW6Devices"; this.labelFW6Devices.Size = new System.Drawing.Size(131, 13); this.labelFW6Devices.TabIndex = 13; this.labelFW6Devices.Text = "Select FW6 device to run:"; // // listboxDevices // this.listboxDevices.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.listboxDevices.BackColor = System.Drawing.SystemColors.Info; this.listboxDevices.FormattingEnabled = true; this.listboxDevices.Location = new System.Drawing.Point(8, 118); this.listboxDevices.Name = "listboxDevices"; this.listboxDevices.Size = new System.Drawing.Size(424, 56); this.listboxDevices.TabIndex = 12; this.listboxDevices.SelectedIndexChanged += new System.EventHandler(this.listboxDevices_SelectedIndexChanged); // // buttonRunFW6Tests // this.buttonRunFW6Tests.Enabled = false; this.buttonRunFW6Tests.Location = new System.Drawing.Point(10, 64); this.buttonRunFW6Tests.Name = "buttonRunFW6Tests"; this.buttonRunFW6Tests.Size = new System.Drawing.Size(158, 24); this.buttonRunFW6Tests.TabIndex = 14; this.buttonRunFW6Tests.Text = "Run FW6 Tests"; this.buttonRunFW6Tests.Click += new System.EventHandler(this.buttonRunFW6Tests_Click); // // tabControl1 // this.tabControl1.Controls.Add(this.tabStatus); this.tabControl1.Controls.Add(this.tabCfgInit); this.tabControl1.Controls.Add(this.tabCfgTest); this.tabControl1.Location = new System.Drawing.Point(438, 10); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; this.tabControl1.Size = new System.Drawing.Size(329, 504); this.tabControl1.TabIndex = 16; // // tabStatus // this.tabStatus.Controls.Add(this.textStatus); this.tabStatus.Controls.Add(this.label5); this.tabStatus.Controls.Add(this.lblChannels); this.tabStatus.Controls.Add(this.labelPlot); this.tabStatus.Location = new System.Drawing.Point(4, 22); this.tabStatus.Name = "tabStatus"; this.tabStatus.Padding = new System.Windows.Forms.Padding(3); this.tabStatus.Size = new System.Drawing.Size(321, 478); this.tabStatus.TabIndex = 0; this.tabStatus.Text = "Test Status"; this.tabStatus.UseVisualStyleBackColor = true; // // textStatus // this.textStatus.Location = new System.Drawing.Point(6, 8); this.textStatus.Multiline = true; this.textStatus.Name = "textStatus"; this.textStatus.ReadOnly = true; this.textStatus.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.textStatus.Size = new System.Drawing.Size(309, 414); this.textStatus.TabIndex = 15; // // label5 // this.label5.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.label5.Location = new System.Drawing.Point(26, 435); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(52, 16); this.label5.TabIndex = 14; this.label5.Text = "Channels"; this.label5.TextAlign = System.Drawing.ContentAlignment.TopRight; // // lblChannels // this.lblChannels.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; this.lblChannels.Location = new System.Drawing.Point(88, 435); this.lblChannels.Name = "lblChannels"; this.lblChannels.Size = new System.Drawing.Size(88, 16); this.lblChannels.TabIndex = 13; // // labelPlot // this.labelPlot.BackColor = System.Drawing.Color.Transparent; this.labelPlot.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; this.labelPlot.Location = new System.Drawing.Point(6, 455); this.labelPlot.Name = "labelPlot"; this.labelPlot.Size = new System.Drawing.Size(96, 16); this.labelPlot.TabIndex = 12; this.labelPlot.Text = "Spectrum Plot"; // // tabCfgInit // this.tabCfgInit.AutoScroll = true; this.tabCfgInit.Controls.Add(this.textCfgInit); this.tabCfgInit.Location = new System.Drawing.Point(4, 22); this.tabCfgInit.Name = "tabCfgInit"; this.tabCfgInit.Padding = new System.Windows.Forms.Padding(3); this.tabCfgInit.Size = new System.Drawing.Size(321, 478); this.tabCfgInit.TabIndex = 1; this.tabCfgInit.Text = "DPP Status Display"; this.tabCfgInit.UseVisualStyleBackColor = true; // // textCfgInit // this.textCfgInit.Location = new System.Drawing.Point(6, 8); this.textCfgInit.Multiline = true; this.textCfgInit.Name = "textCfgInit"; this.textCfgInit.ReadOnly = true; this.textCfgInit.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.textCfgInit.Size = new System.Drawing.Size(309, 464); this.textCfgInit.TabIndex = 4; // // tabCfgTest // this.tabCfgTest.AutoScroll = true; this.tabCfgTest.Controls.Add(this.textCfgTest); this.tabCfgTest.Location = new System.Drawing.Point(4, 22); this.tabCfgTest.Name = "tabCfgTest"; this.tabCfgTest.Padding = new System.Windows.Forms.Padding(3); this.tabCfgTest.Size = new System.Drawing.Size(321, 478); this.tabCfgTest.TabIndex = 2; this.tabCfgTest.Text = "DPP Test Configuration"; this.tabCfgTest.UseVisualStyleBackColor = true; // // textCfgTest // this.textCfgTest.Location = new System.Drawing.Point(6, 8); this.textCfgTest.Multiline = true; this.textCfgTest.Name = "textCfgTest"; this.textCfgTest.ReadOnly = true; this.textCfgTest.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.textCfgTest.Size = new System.Drawing.Size(309, 464); this.textCfgTest.TabIndex = 5; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(776, 520); this.Controls.Add(this.tabControl1); this.Controls.Add(this.buttonRunFW6Tests); this.Controls.Add(this.labelFW6Devices); this.Controls.Add(this.listboxDevices); this.Controls.Add(this.buttonFindUsbDevices); this.Controls.Add(this.picPlot); this.Name = "Form1"; this.Text = "CSharp FW6 Example"; this.Load += new System.EventHandler(this.Form1_Load); ((System.ComponentModel.ISupportInitialize)(this.picPlot)).EndInit(); this.tabControl1.ResumeLayout(false); this.tabStatus.ResumeLayout(false); this.tabStatus.PerformLayout(); this.tabCfgInit.ResumeLayout(false); this.tabCfgInit.PerformLayout(); this.tabCfgTest.ResumeLayout(false); this.tabCfgTest.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } //------------------------------------------------------------------- // PlotData // Calculates and saves the plot buffer data then calls UpdatePlot // OptScaleType = false; //linear // OptScaleType = true; //log //------------------------------------------------------------------- public void PlotData(int[] DataBuffer, int NumChan, bool OptScaleType) { int i; long YMAX; long XPlotMAX; long YPlotMAX; int[] PlotBuffer = new int[8192]; XPlotMAX = NumChan - 1; if (NumChan > 0) { //if number of channels > 0 plot data YMAX = 0; for(i = 0; i < NumChan; i++) { //get the largest value to be displayed if (OptScaleType) { //get the Y maximum value for the select scale if (Math.Log(1.0 + DataBuffer[i]) > YMAX) { YMAX = (int)Math.Log(1.0 + DataBuffer[i]); } } else { if (DataBuffer[i] > YMAX) { YMAX = DataBuffer[i]; } } } if (YMAX < 1) { return; } //if no y scale exit sub if (OptScaleType) { //adjust plot to include entire high peak YMAX = (YMAX * 10) + 10; } else { if (YMAX < 20) { YMAX = YMAX + 2; } else { YMAX = YMAX + 10; } } for (i = 0; i < NumChan;i++ ) { //get the largest value to be displayed if (OptScaleType) { PlotBuffer[i] = (int)Math.Log(1.0 + DataBuffer[i]) * 10; } else { PlotBuffer[i] = DataBuffer[i]; } } YPlotMAX = YMAX; UpdatePlot(PlotBuffer,XPlotMAX,YPlotMAX); } } //------------------------------------------------------------------- // UpdatePlot // Draws the plot display with the current plot buffer //------------------------------------------------------------------- private void UpdatePlot(int[] PlotBuffer, long XPlotMAX, long YPlotMAX) { picPlot.CreateGraphics().Clear(this.BackColor); picPlot.Refresh(); Graphics picGraphic = this.picPlot.CreateGraphics(); Pen picPen = new Pen(Color.Red); //Pen picPen = new Pen(Color.Black); double XScaleFactor = (double) this.picPlot.Width; if (XPlotMAX > 0) XScaleFactor /= (double)(XPlotMAX + 1); //XScaleFactor *= 2; double YScaleFactor = (double) this.picPlot.Height; if (YPlotMAX > 0) YScaleFactor /= (double)(YPlotMAX + 1); int pH = this.picPlot.Height; //YScaleFactor *= -1.0; double x0, y0, x1, y1, x2, y2; x0 = 0; y0 = 0; y0++; for(int X=0; X<=XPlotMAX; X++) { x1 = X; y1 = PlotBuffer[X]; if (y1 < 0) { y1 = 0; } y1++; x2 = X + 1; y2 = PlotBuffer[X + 1]; if (y2 < 0) { y2 = 0; } y2++; picGraphic.DrawLine(picPen, (int)x0, pH - (int)y0, (int)(x1 * XScaleFactor), pH - (int)(y1 * YScaleFactor)); picGraphic.DrawLine(picPen, (int)(x1 * XScaleFactor), pH - (int)(y1 * YScaleFactor), (int)(x2 * XScaleFactor), pH - (int)(y2 * YScaleFactor)); picGraphic.DrawLine(picPen, (int)(x1 * XScaleFactor), pH - 0, (int)(x1 * XScaleFactor), pH - (int)(y1 * YScaleFactor)); picGraphic.DrawLine(picPen, (int)(x2 * XScaleFactor), pH - 0, (int)(x2 * XScaleFactor), pH - (int)(y2 * YScaleFactor)); x0 = (int)(x2 * XScaleFactor); y0 = (int)(y2 * YScaleFactor); y0++; } } // Gets the data from the DPP and stores it in file private void SaveMCADataPlotToPath(string strFileName, int[] DataBuffer, int NumChan, FW6DppStatus DppStatus, string strDppConfig) { int adc; int idxChan; string strStatus = DppStatus.ShowStatusValueStrings(); switch (NumChan) { case 8192: { adc = 5; break; } case 4096: { adc = 4; break; } case 2048: { adc = 3; break; } case 1024: { adc = 2; break; } case 512: { adc = 1; break; } case 256: { adc = 0; break; } default: { adc = 2; break; } } //end switch StreamWriter swSpectrum = new StreamWriter(strFileName, false, Encoding.ASCII); swSpectrum.WriteLine("<>"); swSpectrum.WriteLine("TAG - DPPAPI"); swSpectrum.WriteLine("DESCRIPTION - " + strFileName); swSpectrum.WriteLine("GAIN - " + (adc).ToString()); swSpectrum.WriteLine("THRESHOLD - 0"); swSpectrum.WriteLine("LIVE_MODE - 0"); swSpectrum.WriteLine("PRESET_TIME - "); // + Strings.Trim(((double)CfgSet.PresetTime / 10).ToString("0.0"))); swSpectrum.WriteLine("LIVE_TIME - "); swSpectrum.WriteLine("REAL_TIME - "); // + Conversion.Str(StatusLst.AccumulationTime)); swSpectrum.WriteLine("START_TIME - "); // + AcqStartTime); swSpectrum.WriteLine("SERIAL_NUMBER - "); // + Conversion.Str(StatusLst.SerialNumber)); swSpectrum.WriteLine("<>"); for(idxChan=0; idxChan<=(NumChan-1); idxChan++) { swSpectrum.WriteLine(DataBuffer[idxChan].ToString()); } // idxChan swSpectrum.WriteLine("<>"); //MCA File DPP Settings for Amptek configutation and status data swSpectrum.WriteLine("<>"); swSpectrum.Write(strDppConfig); swSpectrum.WriteLine("<>"); swSpectrum.WriteLine("<>"); swSpectrum.Write(strStatus); swSpectrum.WriteLine("<>"); swSpectrum.Close(); } private void Form1_Load(object sender, System.EventArgs e) { } public void buttonFindUsbDevices_Click(object sender, EventArgs e) { List devicePathNames; string strDevices; strDevices = ""; buttonRunFW6Tests.Enabled = false; // Fill an array with the device path names of all attached devices with matching GUIDs. bool devicesFound = DeviceManagement.FindDeviceFromGuid(winUsbGuid, out devicePathNames); for (int iDpp = 0; iDpp < devicePathNames.Count; iDpp++) { strDevices += devicePathNames[iDpp] + "\n\r"; } StartAutodetection(); } protected void StartAutodetection() { ThreadPool.QueueUserWorkItem(DiscoverDevices, null); } protected bool detectingDevices = false; protected void DiscoverDevices(object ThreadContext) { // don't allow multiple detection to happen if (detectingDevices) return; detectingDevices = true; Invoke(new MethodInvoker(delegate() { buttonFindUsbDevices.Enabled = false; listboxDevices.Enabled = false; listboxDevices.Items.Clear(); listboxDevices.Items.Add("Discovering devices, please wait..."); // make sure to disable the groupbox and // clear out the text boxes since we have no items //groupBox1.Enabled = false; //currentFirmwareTextbox.Text = string.Empty; //currentFpgaTextbox.Text = string.Empty; })); List devices = DPDevice.PerformDeviceDetection(); Invoke(new MethodInvoker(delegate() { listboxDevices.Items.Clear(); })); bool foundDevices = true; if (devices.Count == 0) { foundDevices = false; } if (!foundDevices) { Invoke(new MethodInvoker(delegate() { listboxDevices.Items.Add("No devices found"); })); } else { Invoke(new MethodInvoker(delegate() { bool ethernetFound = false; foreach (DPDevice d in devices) { if (d.FpgaState == DPDevice.FpgaStates.EncryptionFailure) { string MessageText = string.Format("Device {0}, S/N {1:D6} failed the Encryption Check, Contact Amptek for further information.", d.DeviceType, d.SerialNumber); MessageBox.Show(MessageText); } if (!ethernetFound && (d.InterfaceType == DPDevice.InterfaceTypes.ethernet)) { if (listboxDevices.Items.Count > 0) { listboxDevices.Items.Add("================================================================="); } ethernetFound = true; } listboxDevices.Items.Add(d); } listboxDevices.Enabled = true; } )); } detectingDevices = false; // re-enable the refresh device button Invoke(new MethodInvoker(delegate() { buttonFindUsbDevices.Enabled = true; })); } private void listboxDevices_SelectedIndexChanged(object sender, EventArgs e) { ListBox lb = (ListBox)sender; try { DPDevice device = (DPDevice)lb.SelectedItem; //MessageBox.Show(device.SerialNumber.ToString()); //MessageBox.Show(device.InterfaceType.ToString()); buttonRunFW6Tests.Enabled = true; } catch { MessageBox.Show("No Devices Selected"); } } public void buttonRunFW6Tests_Click(object sender, EventArgs e) { int idxSpectrum; string strFileName = ""; int idxPlot; string strAppPath = Environment.CurrentDirectory; string strCfgFilename = strAppPath + @"\DPP.cfg"; byte[] szCfgFilename = System.Text.Encoding.UTF8.GetBytes(strCfgFilename); int NumChan=0; int[] DataBuffer = new int[8192]; int idxData = 0; int idxChan = 0; string strStatus = ""; int dblPresetTime = 10; string strCommands = ""; string strPresetTimeSave = ""; byte[] readBuffer = null; uint bytesRead = 0; string strCmdReadback = ""; string strDppConfig = ""; bool bRunTests = false; int mcaChannels = 0; textCfgInit.Text = ""; textCfgTest.Text = ""; textStatus.Text = ""; //PRET=10.0; //PRET=OFF; //string strDeviceInfo = ""; buttonRunFW6Tests.Enabled = false; buttonFindUsbDevices.Enabled = false; listboxDevices.Enabled = false; DPDevice device = (DPDevice)listboxDevices.SelectedItem; FW6Device deviceDppIO = null; FW6DppStatus DppStatus = new FW6DppStatus(); bool success = false; int channels = 0; //deviceDppIO.mcaChannels = 1024; // Get/display Initial Status and Configuration // send preset or test config, then readback and display if (device.InterfaceType == DPDevice.InterfaceTypes.usb) { textStatus.Text = "Connecting to USB device..."; deviceDppIO = (DPDeviceUsb)device; bRunTests = true; } else if (device.InterfaceType == DPDevice.InterfaceTypes.rs232) { textStatus.Text = "Connecting to RS232 device..."; deviceDppIO = (DPDeviceSerialFW6)device; deviceDppIO.mcaChannels = 1024; // set default bRunTests = true; } if (bRunTests) { try { success = deviceDppIO.ConnectForTesting(); // open device for testing if (success) { textStatus.Text = "Connected For Testing"; } else { textStatus.Text = "Connect Error"; return; } } catch { textStatus.Text = "Connect Error"; return; } if (device.InterfaceType == DPDevice.InterfaceTypes.rs232) { strCommands = "MCAC=?;"; //012345678901 //"MCAC=?;" //012345678901 //"MCAC=1024;" success = deviceDppIO.GetConfiguration(strCommands, ref readBuffer, out bytesRead); // Get the configuration if ((!success) || (bytesRead < 7)) { success = deviceDppIO.GetConfiguration(strCommands, ref readBuffer, out bytesRead); // Get the configuration } if (success) { byte[] cfgBuffer = new byte[bytesRead]; for (int idxCfg = 0; idxCfg < bytesRead; idxCfg++) { cfgBuffer[idxCfg] = readBuffer[idxCfg]; } strDppConfig = ASCIIEncoding.ASCII.GetString(cfgBuffer); strDppConfig = strDppConfig.Substring(5, ((int)bytesRead - 6)); mcaChannels = Convert.ToInt32(strDppConfig); if (TestMCAChannels(mcaChannels)) { textStatus.Text = textStatus.Text + "\r\n MCA Channels " + strDppConfig; deviceDppIO.mcaChannels = mcaChannels; } } } Application.DoEvents(); Thread.Sleep(1000); // get original preset time // device is open, get status strCommands = "PRET=?;"; success = deviceDppIO.GetConfiguration(strCommands, ref readBuffer, out bytesRead); // Get the configuration if ((!success) || (bytesRead < 7)) { success = deviceDppIO.GetConfiguration(strCommands, ref readBuffer, out bytesRead); // Get the configuration } //48-90 if (success) { byte[] cfgBuffer = new byte[bytesRead]; for (int idxCfg = 0; idxCfg < bytesRead; idxCfg++) { cfgBuffer[idxCfg] = readBuffer[idxCfg]; } strPresetTimeSave = ASCIIEncoding.ASCII.GetString(cfgBuffer); textStatus.Text = "Saving original preset time: " + strPresetTimeSave; Application.DoEvents(); Thread.Sleep(1000); } else { textStatus.Text = "Preset time read Error"; return; } // set preset time to 10.0 seconds textStatus.Text = "Setting preset time to 10.0 seconds"; strCommands = "PRET=10.0;"; success = deviceDppIO.SendConfiguration(strCommands); Application.DoEvents(); Thread.Sleep(1000); Application.DoEvents(); if (!success) { textStatus.Text = "Preset time set Error"; return; } textStatus.Text = "Verifying preset time is 10.0 seconds"; strCommands = "PRET=?;"; success = deviceDppIO.GetConfiguration(strCommands, ref readBuffer, out bytesRead); // Get the configuration if (!success) { success = deviceDppIO.GetConfiguration(strCommands, ref readBuffer, out bytesRead); // Get the configuration } if (!success) { success = deviceDppIO.GetConfiguration(strCommands, ref readBuffer, out bytesRead); // Get the configuration } if (success) { byte[] cfgBuffer = new byte[bytesRead]; for (int idxCfg = 0; idxCfg < bytesRead; idxCfg++) { cfgBuffer[idxCfg] = readBuffer[idxCfg]; } strCmdReadback = ASCIIEncoding.ASCII.GetString(cfgBuffer); textStatus.Text = "Test preset time: " + strCmdReadback; if (strCmdReadback == "PRET=10.0;") { textStatus.Text += "\r\n ready"; Application.DoEvents(); Thread.Sleep(1000); } else { textStatus.Text += "\r\n error"; return; } } textStatus.Text = "Starting Dpp Data Acquisition..."; for (idxPlot = 1; idxPlot <= 2; idxPlot++) { labelPlot.Text = "Spectrum Plot " + (idxPlot).ToString(); deviceDppIO.PauseDppData(); //textStatus.Text = "Pausing Dpp Data..."; Application.DoEvents(); Thread.Sleep(100); deviceDppIO.ClearDppData(); //textStatus.Text = "Clearing Dpp Data..."; Application.DoEvents(); Thread.Sleep(100); deviceDppIO.StartDppData(); //textStatus.Text = "Starting Dpp Data Acquisition..."; Application.DoEvents(); Thread.Sleep(100); for (idxSpectrum = 0; idxSpectrum <= (dblPresetTime + 10); idxSpectrum++) { Application.DoEvents(); Thread.Sleep(1000); success = deviceDppIO.GetSpectrumData(ref readBuffer, out bytesRead); // Get the spectrum data if (success) { channels = (int)(bytesRead / 3); string strChannels = String.Format("Channels {0:d}", channels); for (idxChan = 0; idxChan < channels; idxChan++) { idxData = idxChan + 6; DataBuffer[idxChan] = (int)(readBuffer[idxData * 3]) + (int)(readBuffer[idxData * 3 + 1]) * 256 + (int)(readBuffer[idxData * 3 + 2]) * 65536; } for (idxData = 0; idxData < channels * 0.03; idxData++) { DataBuffer[(channels - 1) - idxData] = 0; // do not plot upper 3% of spectrum } NumChan = channels; lblChannels.Text = NumChan.ToString(); PlotData(DataBuffer, NumChan, false); } success = deviceDppIO.GetRawStatus(ref readBuffer, out bytesRead); if (success) { if (bytesRead == 64) { DppStatus.Process_Status(readBuffer); strStatus = DppStatus.GetStatusValueStrings(); textCfgInit.Text = strStatus; } else { textCfgInit.Text = "Status bytes less than 72 -> " + bytesRead.ToString(); } } else { textCfgInit.Text = " Get Status failed "; } textStatus.Text = strStatus + "Plot Number: " + (idxPlot).ToString(); this.textStatus.Refresh(); if (DppStatus.MCA_EN && (DppStatus.AccumulationTime < dblPresetTime)) { //acquiring data } else { //saving data strFileName = "MCA" + (idxPlot).ToString() + ".mca"; strCmdReadback = deviceDppIO.GetFullConfiguration(DppStatus.PC5_PRESENT, DppStatus.DEVICE_ID, DppStatus.isDP5_RevDxGains, DppStatus.DPP_ECO); strDppConfig = deviceDppIO.DisplayConfiguration(strCmdReadback); AsciiCmdUtilities.CommandFilters CmdUtil = new CommandFilters(); string strMcaCfg = CmdUtil.CreateSpectrumConfig(strDppConfig); textCfgTest.Text = strDppConfig; SaveMCADataPlotToPath(strFileName, DataBuffer, NumChan, DppStatus, strMcaCfg); break; } } } } textStatus.Text += "\r\nRestoring preset time to original setting"; //strCommands = "PRET=OFF;"; success = deviceDppIO.SendConfiguration(strPresetTimeSave); Application.DoEvents(); Thread.Sleep(1000); if (!success) { textStatus.Text = "Preset time set Error"; return; } textStatus.Text += "\r\nTests Done."; deviceDppIO.DisconnectForTesting(); buttonRunFW6Tests.Enabled = true; buttonFindUsbDevices.Enabled = true; listboxDevices.Enabled = true; } private void radioFW6_Test_CheckedChanged(object sender, EventArgs e) { buttonFindUsbDevices.Visible = true; buttonRunFW6Tests.Visible = true; labelFW6Devices.Visible = true; listboxDevices.Visible = true; } private void radioDPPAPI_Test_CheckedChanged(object sender, EventArgs e) { buttonFindUsbDevices.Visible = false; buttonRunFW6Tests.Visible = false; labelFW6Devices.Visible = false; listboxDevices.Visible = false; } private bool TestMCAChannels(int NumChan) { bool isOK = true; switch (NumChan) { case 8192: { break; } case 4096: { break; } case 2048: { break; } case 1024: { break; } case 512: { break; } case 256: { break; } default: { isOK = false; break; } } return isOK; } } }