using System; using System.IO; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Collections.Generic; using System.Text; using INIUtilities; using csRepeat; using AsciiCmdUtilities; namespace ReadCfg { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.TextBox txtFilename; private System.Windows.Forms.TextBox txtAsciiCommands; private Button btnReadConfig; private Button btnFilterCfg; private TextBox txtFilteredCmds; private GroupBox groupBox1; private RadioButton radbtnDppType2; private RadioButton radbtnDppType1; private RadioButton radbtnDppType0; private RadioButton radbtnDppType5; private RadioButton radbtnDppType4; private RadioButton radbtnDppType3; private byte DppType; bool PC5_PRESENT; bool isDP5_RevDxGains; byte DPP_ECO; private CheckBox chkPC5_PRESENT; private CheckBox chkRevDxGains; private GroupBox groupBox2; private RadioButton radbtnB; private RadioButton radbtnA; private RadioButton radbtn0; private TextBox txtStatus; private FW6DppStatus DppStat; private CommandFilters CmdFilters; private Label lblFilename; private Label label1; private Label label3; private Button btnFullConfigReadback; private Label lblCfgReadbackInd; private Label lblCfgOR; private Label lblCfgFilterInd; /// /// Required designer variable. /// private System.ComponentModel.Container components = null; 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() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); this.txtFilename = new System.Windows.Forms.TextBox(); this.txtAsciiCommands = new System.Windows.Forms.TextBox(); this.btnReadConfig = new System.Windows.Forms.Button(); this.btnFilterCfg = new System.Windows.Forms.Button(); this.txtFilteredCmds = new System.Windows.Forms.TextBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.radbtnDppType5 = new System.Windows.Forms.RadioButton(); this.radbtnDppType4 = new System.Windows.Forms.RadioButton(); this.radbtnDppType3 = new System.Windows.Forms.RadioButton(); this.radbtnDppType2 = new System.Windows.Forms.RadioButton(); this.radbtnDppType1 = new System.Windows.Forms.RadioButton(); this.radbtnDppType0 = new System.Windows.Forms.RadioButton(); this.chkPC5_PRESENT = new System.Windows.Forms.CheckBox(); this.chkRevDxGains = new System.Windows.Forms.CheckBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.radbtnB = new System.Windows.Forms.RadioButton(); this.radbtnA = new System.Windows.Forms.RadioButton(); this.radbtn0 = new System.Windows.Forms.RadioButton(); this.txtStatus = new System.Windows.Forms.TextBox(); this.lblFilename = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.btnFullConfigReadback = new System.Windows.Forms.Button(); this.lblCfgReadbackInd = new System.Windows.Forms.Label(); this.lblCfgOR = new System.Windows.Forms.Label(); this.lblCfgFilterInd = new System.Windows.Forms.Label(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // txtFilename // this.txtFilename.AllowDrop = true; this.txtFilename.Location = new System.Drawing.Point(11, 25); this.txtFilename.Name = "txtFilename"; this.txtFilename.Size = new System.Drawing.Size(651, 20); this.txtFilename.TabIndex = 0; this.txtFilename.DragDrop += new System.Windows.Forms.DragEventHandler(this.txtFilename_DragDrop); this.txtFilename.DragEnter += new System.Windows.Forms.DragEventHandler(this.txtFilename_DragEnter); // // txtAsciiCommands // this.txtAsciiCommands.Location = new System.Drawing.Point(105, 101); this.txtAsciiCommands.Multiline = true; this.txtAsciiCommands.Name = "txtAsciiCommands"; this.txtAsciiCommands.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.txtAsciiCommands.Size = new System.Drawing.Size(558, 179); this.txtAsciiCommands.TabIndex = 1; // // btnReadConfig // this.btnReadConfig.Location = new System.Drawing.Point(10, 51); this.btnReadConfig.Name = "btnReadConfig"; this.btnReadConfig.Size = new System.Drawing.Size(133, 27); this.btnReadConfig.TabIndex = 2; this.btnReadConfig.Text = "Read Configuration"; this.btnReadConfig.UseVisualStyleBackColor = true; this.btnReadConfig.Click += new System.EventHandler(this.btnReadConfig_Click); // // btnFilterCfg // this.btnFilterCfg.Location = new System.Drawing.Point(150, 51); this.btnFilterCfg.Name = "btnFilterCfg"; this.btnFilterCfg.Size = new System.Drawing.Size(209, 27); this.btnFilterCfg.TabIndex = 3; this.btnFilterCfg.Text = "Filter Configuration by Device Type"; this.btnFilterCfg.UseVisualStyleBackColor = true; this.btnFilterCfg.Click += new System.EventHandler(this.btnFilterCfg_Click); // // txtFilteredCmds // this.txtFilteredCmds.Location = new System.Drawing.Point(105, 377); this.txtFilteredCmds.Multiline = true; this.txtFilteredCmds.Name = "txtFilteredCmds"; this.txtFilteredCmds.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.txtFilteredCmds.Size = new System.Drawing.Size(558, 179); this.txtFilteredCmds.TabIndex = 4; // // groupBox1 // this.groupBox1.Controls.Add(this.radbtnDppType5); this.groupBox1.Controls.Add(this.radbtnDppType4); this.groupBox1.Controls.Add(this.radbtnDppType3); this.groupBox1.Controls.Add(this.radbtnDppType2); this.groupBox1.Controls.Add(this.radbtnDppType1); this.groupBox1.Controls.Add(this.radbtnDppType0); this.groupBox1.Location = new System.Drawing.Point(12, 84); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(87, 153); this.groupBox1.TabIndex = 5; this.groupBox1.TabStop = false; this.groupBox1.Text = "DPP Device"; // // radbtnDppType5 // this.radbtnDppType5.AutoSize = true; this.radbtnDppType5.Location = new System.Drawing.Point(11, 128); this.radbtnDppType5.Name = "radbtnDppType5"; this.radbtnDppType5.Size = new System.Drawing.Size(53, 17); this.radbtnDppType5.TabIndex = 5; this.radbtnDppType5.TabStop = true; this.radbtnDppType5.Text = "DP5X"; this.radbtnDppType5.UseVisualStyleBackColor = true; this.radbtnDppType5.CheckedChanged += new System.EventHandler(this.radbtnDppType5_CheckedChanged); // // radbtnDppType4 // this.radbtnDppType4.AutoSize = true; this.radbtnDppType4.Location = new System.Drawing.Point(11, 106); this.radbtnDppType4.Name = "radbtnDppType4"; this.radbtnDppType4.Size = new System.Drawing.Size(45, 17); this.radbtnDppType4.TabIndex = 4; this.radbtnDppType4.TabStop = true; this.radbtnDppType4.Text = "TB5"; this.radbtnDppType4.UseVisualStyleBackColor = true; this.radbtnDppType4.CheckedChanged += new System.EventHandler(this.radbtnDppType4_CheckedChanged); // // radbtnDppType3 // this.radbtnDppType3.AutoSize = true; this.radbtnDppType3.Location = new System.Drawing.Point(11, 84); this.radbtnDppType3.Name = "radbtnDppType3"; this.radbtnDppType3.Size = new System.Drawing.Size(80, 17); this.radbtnDppType3.TabIndex = 3; this.radbtnDppType3.TabStop = true; this.radbtnDppType3.Text = "MCA8000D"; this.radbtnDppType3.UseVisualStyleBackColor = true; this.radbtnDppType3.CheckedChanged += new System.EventHandler(this.radbtnDppType3_CheckedChanged); // // radbtnDppType2 // this.radbtnDppType2.AutoSize = true; this.radbtnDppType2.Location = new System.Drawing.Point(11, 62); this.radbtnDppType2.Name = "radbtnDppType2"; this.radbtnDppType2.Size = new System.Drawing.Size(54, 17); this.radbtnDppType2.TabIndex = 2; this.radbtnDppType2.TabStop = true; this.radbtnDppType2.Text = "DP5G"; this.radbtnDppType2.UseVisualStyleBackColor = true; this.radbtnDppType2.CheckedChanged += new System.EventHandler(this.radbtnDppType2_CheckedChanged); // // radbtnDppType1 // this.radbtnDppType1.AutoSize = true; this.radbtnDppType1.Location = new System.Drawing.Point(11, 40); this.radbtnDppType1.Name = "radbtnDppType1"; this.radbtnDppType1.Size = new System.Drawing.Size(45, 17); this.radbtnDppType1.TabIndex = 1; this.radbtnDppType1.TabStop = true; this.radbtnDppType1.Text = "PX5"; this.radbtnDppType1.UseVisualStyleBackColor = true; this.radbtnDppType1.CheckedChanged += new System.EventHandler(this.radbtnDppType1_CheckedChanged); // // radbtnDppType0 // this.radbtnDppType0.AutoSize = true; this.radbtnDppType0.Location = new System.Drawing.Point(11, 18); this.radbtnDppType0.Name = "radbtnDppType0"; this.radbtnDppType0.Size = new System.Drawing.Size(46, 17); this.radbtnDppType0.TabIndex = 0; this.radbtnDppType0.TabStop = true; this.radbtnDppType0.Text = "DP5"; this.radbtnDppType0.UseVisualStyleBackColor = true; this.radbtnDppType0.CheckedChanged += new System.EventHandler(this.radbtnDppType0_CheckedChanged); // // chkPC5_PRESENT // this.chkPC5_PRESENT.AutoSize = true; this.chkPC5_PRESENT.Location = new System.Drawing.Point(11, 246); this.chkPC5_PRESENT.Name = "chkPC5_PRESENT"; this.chkPC5_PRESENT.Size = new System.Drawing.Size(85, 17); this.chkPC5_PRESENT.TabIndex = 6; this.chkPC5_PRESENT.Text = "PC5 Present"; this.chkPC5_PRESENT.UseVisualStyleBackColor = true; this.chkPC5_PRESENT.CheckedChanged += new System.EventHandler(this.chkPC5_PRESENT_CheckedChanged); // // chkRevDxGains // this.chkRevDxGains.AutoSize = true; this.chkRevDxGains.Location = new System.Drawing.Point(11, 269); this.chkRevDxGains.Name = "chkRevDxGains"; this.chkRevDxGains.Size = new System.Drawing.Size(86, 17); this.chkRevDxGains.TabIndex = 7; this.chkRevDxGains.Text = "RevDxGains"; this.chkRevDxGains.UseVisualStyleBackColor = true; this.chkRevDxGains.CheckedChanged += new System.EventHandler(this.chkRevDxGains_CheckedChanged); // // groupBox2 // this.groupBox2.Controls.Add(this.radbtnB); this.groupBox2.Controls.Add(this.radbtnA); this.groupBox2.Controls.Add(this.radbtn0); this.groupBox2.Location = new System.Drawing.Point(4, 289); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(94, 71); this.groupBox2.TabIndex = 8; this.groupBox2.TabStop = false; this.groupBox2.Text = "DPP ECO"; // // radbtnB // this.radbtnB.AutoSize = true; this.radbtnB.Location = new System.Drawing.Point(7, 51); this.radbtnB.Name = "radbtnB"; this.radbtnB.Size = new System.Drawing.Size(57, 17); this.radbtnB.TabIndex = 2; this.radbtnB.TabStop = true; this.radbtnB.Text = "ECO B"; this.radbtnB.UseVisualStyleBackColor = true; this.radbtnB.CheckedChanged += new System.EventHandler(this.radbtnB_CheckedChanged); // // radbtnA // this.radbtnA.AutoSize = true; this.radbtnA.Location = new System.Drawing.Point(7, 33); this.radbtnA.Name = "radbtnA"; this.radbtnA.Size = new System.Drawing.Size(57, 17); this.radbtnA.TabIndex = 1; this.radbtnA.TabStop = true; this.radbtnA.Text = "ECO A"; this.radbtnA.UseVisualStyleBackColor = true; this.radbtnA.CheckedChanged += new System.EventHandler(this.radbtnA_CheckedChanged); // // radbtn0 // this.radbtn0.AutoSize = true; this.radbtn0.Location = new System.Drawing.Point(7, 15); this.radbtn0.Name = "radbtn0"; this.radbtn0.Size = new System.Drawing.Size(56, 17); this.radbtn0.TabIndex = 0; this.radbtn0.TabStop = true; this.radbtn0.Text = "ECO 0"; this.radbtn0.UseVisualStyleBackColor = true; this.radbtn0.CheckedChanged += new System.EventHandler(this.radbtn0_CheckedChanged); // // txtStatus // this.txtStatus.Location = new System.Drawing.Point(474, 297); this.txtStatus.Multiline = true; this.txtStatus.Name = "txtStatus"; this.txtStatus.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; this.txtStatus.Size = new System.Drawing.Size(182, 63); this.txtStatus.TabIndex = 9; // // lblFilename // this.lblFilename.AutoSize = true; this.lblFilename.Location = new System.Drawing.Point(9, 8); this.lblFilename.Name = "lblFilename"; this.lblFilename.Size = new System.Drawing.Size(212, 13); this.lblFilename.TabIndex = 10; this.lblFilename.Text = "Drag Drop Configuration File to the TextBox"; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(105, 85); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(113, 13); this.label1.TabIndex = 11; this.label1.Text = "Configuration as String"; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(320, 300); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(144, 13); this.label3.TabIndex = 13; this.label3.Text = "Device Selection Parameters"; // // btnFullConfigReadback // this.btnFullConfigReadback.Location = new System.Drawing.Point(365, 51); this.btnFullConfigReadback.Name = "btnFullConfigReadback"; this.btnFullConfigReadback.Size = new System.Drawing.Size(171, 27); this.btnFullConfigReadback.TabIndex = 14; this.btnFullConfigReadback.Text = "Full Configuration Readback"; this.btnFullConfigReadback.UseVisualStyleBackColor = true; this.btnFullConfigReadback.Click += new System.EventHandler(this.btnFullConfigReadback_Click); // // lblCfgReadbackInd // this.lblCfgReadbackInd.AutoSize = true; this.lblCfgReadbackInd.Location = new System.Drawing.Point(324, 361); this.lblCfgReadbackInd.Name = "lblCfgReadbackInd"; this.lblCfgReadbackInd.Size = new System.Drawing.Size(126, 13); this.lblCfgReadbackInd.TabIndex = 17; this.lblCfgReadbackInd.Text = "Full Readback Command"; // // lblCfgOR // this.lblCfgOR.AutoSize = true; this.lblCfgOR.Location = new System.Drawing.Point(295, 361); this.lblCfgOR.Name = "lblCfgOR"; this.lblCfgOR.Size = new System.Drawing.Size(23, 13); this.lblCfgOR.TabIndex = 18; this.lblCfgOR.Text = "OR"; // // lblCfgFilterInd // this.lblCfgFilterInd.AutoSize = true; this.lblCfgFilterInd.Location = new System.Drawing.Point(105, 361); this.lblCfgFilterInd.Name = "lblCfgFilterInd"; this.lblCfgFilterInd.Size = new System.Drawing.Size(184, 13); this.lblCfgFilterInd.TabIndex = 19; this.lblCfgFilterInd.Text = "Configuration Filtered by Device Type"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(668, 568); this.Controls.Add(this.lblCfgFilterInd); this.Controls.Add(this.lblCfgOR); this.Controls.Add(this.lblCfgReadbackInd); this.Controls.Add(this.btnFullConfigReadback); this.Controls.Add(this.label3); this.Controls.Add(this.label1); this.Controls.Add(this.lblFilename); this.Controls.Add(this.txtStatus); this.Controls.Add(this.groupBox2); this.Controls.Add(this.chkRevDxGains); this.Controls.Add(this.chkPC5_PRESENT); this.Controls.Add(this.groupBox1); this.Controls.Add(this.txtFilteredCmds); this.Controls.Add(this.btnFilterCfg); this.Controls.Add(this.btnReadConfig); this.Controls.Add(this.txtAsciiCommands); this.Controls.Add(this.txtFilename); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "Form1"; this.Text = "Configuration Test Application"; this.Load += new System.EventHandler(this.Form1_Load); this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing); this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { } private void UpdateStatus() { string strStatus; //strStatus = "\r\n"; strStatus = ""; strStatus += "DPP Type: "; strStatus += DppStat.GetDeviceNameFromVal(DppType); strStatus += "\r\n"; strStatus += "is PC5 PRESENT: "; strStatus += PC5_PRESENT.ToString(); strStatus += "\r\n"; strStatus += "is DP5 RevDxGains: "; strStatus += isDP5_RevDxGains.ToString(); strStatus += "\r\n"; strStatus += "DPP ECO: 0x"; strStatus += DPP_ECO.ToString("X2"); strStatus += ""; txtStatus.Text = strStatus; } private void Form1_Load(object sender, System.EventArgs e) { DppStat = new FW6DppStatus(); CmdFilters = new CommandFilters(); DppType = FW6DppStatus.dppDP5; PC5_PRESENT = true; isDP5_RevDxGains = false; DPP_ECO = 0; radbtnDppType0.Select(); radbtn0.Select(); chkPC5_PRESENT.Checked = true; chkRevDxGains.Checked = false; UpdateStatus(); } private void radbtnDppType0_CheckedChanged(object sender, EventArgs e) { DppType = FW6DppStatus.dppDP5; UpdateStatus(); } private void radbtnDppType1_CheckedChanged(object sender, EventArgs e) { DppType = FW6DppStatus.dppPX5; UpdateStatus(); } private void radbtnDppType2_CheckedChanged(object sender, EventArgs e) { DppType = FW6DppStatus.dppDP5G; UpdateStatus(); } private void radbtnDppType3_CheckedChanged(object sender, EventArgs e) { DppType = FW6DppStatus.dppMCA8000D; UpdateStatus(); } private void radbtnDppType4_CheckedChanged(object sender, EventArgs e) { DppType = FW6DppStatus.dppTB5; UpdateStatus(); } private void radbtnDppType5_CheckedChanged(object sender, EventArgs e) { DppType = FW6DppStatus.dppDP5X; UpdateStatus(); } private void radbtn0_CheckedChanged(object sender, EventArgs e) { DPP_ECO = 0x00; UpdateStatus(); } private void radbtnA_CheckedChanged(object sender, EventArgs e) { DPP_ECO = 0x0A; UpdateStatus(); } private void radbtnB_CheckedChanged(object sender, EventArgs e) { DPP_ECO = 0x0B; UpdateStatus(); } private void chkPC5_PRESENT_CheckedChanged(object sender, EventArgs e) { PC5_PRESENT = chkPC5_PRESENT.Checked; UpdateStatus(); } private void chkRevDxGains_CheckedChanged(object sender, EventArgs e) { isDP5_RevDxGains = chkRevDxGains.Checked; UpdateStatus(); } private void txtFilename_DragDrop(object sender, DragEventArgs e) { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); int iCount = 0; foreach (string file in files) { if (iCount < 1) { txtFilename.Text = file; } iCount++; } } private void txtFilename_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Copy; } else { e.Effect = DragDropEffects.None; } } private void btnReadConfig_Click(object sender, EventArgs e) { string strCfgFilename = ""; strCfgFilename = txtFilename.Text; if (! File.Exists(strCfgFilename)) { txtAsciiCommands.Text = "File Error"; return; } IniFile iniFile = new IniFile(strCfgFilename); // IniFile iniFile = new IniFile(".\\FS432.txt"); // IniFile iniFile = new IniFile(".\\X123 Configuration.txt"); txtFilename.Text = iniFile.Path; //Read section/key names List> keyValuePairs; //string[] sections = iniFile.GetSectionNames(); string strRawValue; string strValue; int iComment; string strCmds = ""; string strCmd = ""; string section = "DP5 Configuration File"; //foreach (string section in sections) //{ keyValuePairs = iniFile.GetSectionValuesAsList(section); foreach (KeyValuePair keyValuePair in keyValuePairs) { strRawValue = keyValuePair.Value; iComment = strRawValue.IndexOf(";"); if (iComment > 0) { strValue = strRawValue.Substring(0, iComment + 1); } else { strValue = strRawValue; } strCmd = keyValuePair.Key + "=" + strValue; strCmds += strCmd; } txtAsciiCommands.Text = strCmds; //} } private void btnFilterCfg_Click(object sender, EventArgs e) { string strCfg = ""; string strFilteredCfg = ""; strCfg = txtAsciiCommands.Text; if ((strCfg == "File Error") || (strCfg == "")) { txtFilteredCmds.Text = "Load DPP configuration before running filter."; txtFilteredCmds.Text += "\r\n"; txtFilteredCmds.Text += strCfg; return; } int iCmdEnd = -1; int iDataEnd = -1; iCmdEnd = strCfg.IndexOf("="); iDataEnd = strCfg.IndexOf(";"); if ((iCmdEnd != 4) || (iCmdEnd > iDataEnd)) { txtFilteredCmds.Text = "DPP configuration error."; txtFilteredCmds.Text += "\r\n"; txtFilteredCmds.Text += strCfg; return; } strFilteredCfg = CmdFilters.RemoveCmdByDeviceType(strCfg, PC5_PRESENT, DppType, isDP5_RevDxGains, DPP_ECO); txtFilteredCmds.Text = strFilteredCfg; lblCfgFilterInd.BackColor = Color.DarkSeaGreen; lblCfgReadbackInd.BackColor = Color.Transparent; } private void btnFullConfigReadback_Click(object sender, EventArgs e) { string strFilteredCfg = ""; strFilteredCfg = CmdFilters.CreateFullReadBackCmd(PC5_PRESENT, DppType, isDP5_RevDxGains, DPP_ECO); txtFilteredCmds.Text = strFilteredCfg; lblCfgFilterInd.BackColor = Color.Transparent; lblCfgReadbackInd.BackColor = Color.LightBlue; } } }