﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace Setting
{
	/// <summary>
	/// Summary description for InOutSet.
	/// </summary>
	public class InOutSet : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.Label Label6;
		internal System.Windows.Forms.GroupBox GroupBox2;
		internal System.Windows.Forms.Label Label11;
		internal System.Windows.Forms.Label Label10;
		internal System.Windows.Forms.Label Label9;
		internal System.Windows.Forms.Label Label5;
		internal System.Windows.Forms.Label Label4;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.Label Label7;
		internal System.Windows.Forms.GroupBox GroupBox1;
		internal System.Windows.Forms.Label Label8;
		internal System.Windows.Forms.Label Label2;
		internal System.Windows.Forms.Label Label1;
		private System.Windows.Forms.Button btnReturn;
		internal System.Windows.Forms.ComboBox cboSdMode;
		internal System.Windows.Forms.ComboBox cboIn6;
		internal System.Windows.Forms.ComboBox cboIn4;
		internal System.Windows.Forms.ComboBox cboIn2;
		internal System.Windows.Forms.ComboBox cboIn5;
		internal System.Windows.Forms.ComboBox cboIn3;
		internal System.Windows.Forms.ComboBox cboIn1;
		internal System.Windows.Forms.ComboBox cboOut3;
		internal System.Windows.Forms.ComboBox cboOut2;
		internal System.Windows.Forms.ComboBox cboOut1;
		internal System.Windows.Forms.ComboBox cboInFilter;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public InOutSet()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.cboSdMode = new System.Windows.Forms.ComboBox();
			this.Label6 = new System.Windows.Forms.Label();
			this.GroupBox2 = new System.Windows.Forms.GroupBox();
			this.cboIn6 = new System.Windows.Forms.ComboBox();
			this.cboIn4 = new System.Windows.Forms.ComboBox();
			this.cboIn2 = new System.Windows.Forms.ComboBox();
			this.Label11 = new System.Windows.Forms.Label();
			this.Label10 = new System.Windows.Forms.Label();
			this.Label9 = new System.Windows.Forms.Label();
			this.cboIn5 = new System.Windows.Forms.ComboBox();
			this.cboIn3 = new System.Windows.Forms.ComboBox();
			this.cboIn1 = new System.Windows.Forms.ComboBox();
			this.Label5 = new System.Windows.Forms.Label();
			this.Label4 = new System.Windows.Forms.Label();
			this.Label3 = new System.Windows.Forms.Label();
			this.Label7 = new System.Windows.Forms.Label();
			this.GroupBox1 = new System.Windows.Forms.GroupBox();
			this.cboOut2 = new System.Windows.Forms.ComboBox();
			this.Label8 = new System.Windows.Forms.Label();
			this.cboOut3 = new System.Windows.Forms.ComboBox();
			this.cboOut1 = new System.Windows.Forms.ComboBox();
			this.Label2 = new System.Windows.Forms.Label();
			this.Label1 = new System.Windows.Forms.Label();
			this.cboInFilter = new System.Windows.Forms.ComboBox();
			this.btnReturn = new System.Windows.Forms.Button();
			this.GroupBox2.SuspendLayout();
			this.GroupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// cboSdMode
			// 
			this.cboSdMode.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboSdMode.Location = new System.Drawing.Point(81, 288);
			this.cboSdMode.Name = "cboSdMode";
			this.cboSdMode.Size = new System.Drawing.Size(184, 23);
			this.cboSdMode.TabIndex = 11;
			this.cboSdMode.SelectedIndexChanged += new System.EventHandler(this.cboSdMode_SelectedIndexChanged);
			// 
			// Label6
			// 
			this.Label6.AutoSize = true;
			this.Label6.Location = new System.Drawing.Point(16, 256);
			this.Label6.Name = "Label6";
			this.Label6.Size = new System.Drawing.Size(46, 14);
			this.Label6.TabIndex = 10;
			this.Label6.Text = "In Filter";
			// 
			// GroupBox2
			// 
			this.GroupBox2.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.cboIn6,
																					this.cboIn4,
																					this.cboIn2,
																					this.Label11,
																					this.Label10,
																					this.Label9,
																					this.cboIn5,
																					this.cboIn3,
																					this.cboIn1,
																					this.Label5,
																					this.Label4,
																					this.Label3});
			this.GroupBox2.Location = new System.Drawing.Point(16, 112);
			this.GroupBox2.Name = "GroupBox2";
			this.GroupBox2.Size = new System.Drawing.Size(506, 128);
			this.GroupBox2.TabIndex = 9;
			this.GroupBox2.TabStop = false;
			this.GroupBox2.Text = "IN Setting";
			// 
			// cboIn6
			// 
			this.cboIn6.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboIn6.Location = new System.Drawing.Point(312, 88);
			this.cboIn6.Name = "cboIn6";
			this.cboIn6.Size = new System.Drawing.Size(184, 23);
			this.cboIn6.TabIndex = 9;
			this.cboIn6.SelectedIndexChanged += new System.EventHandler(this.cboIn6_SelectedIndexChanged);
			// 
			// cboIn4
			// 
			this.cboIn4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboIn4.Location = new System.Drawing.Point(312, 56);
			this.cboIn4.Name = "cboIn4";
			this.cboIn4.Size = new System.Drawing.Size(184, 23);
			this.cboIn4.TabIndex = 7;
			this.cboIn4.SelectedIndexChanged += new System.EventHandler(this.cboIn4_SelectedIndexChanged);
			// 
			// cboIn2
			// 
			this.cboIn2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboIn2.Location = new System.Drawing.Point(312, 24);
			this.cboIn2.Name = "cboIn2";
			this.cboIn2.Size = new System.Drawing.Size(184, 23);
			this.cboIn2.TabIndex = 5;
			this.cboIn2.SelectedIndexChanged += new System.EventHandler(this.cboIn2_SelectedIndexChanged);
			// 
			// Label11
			// 
			this.Label11.AutoSize = true;
			this.Label11.Location = new System.Drawing.Point(264, 96);
			this.Label11.Name = "Label11";
			this.Label11.Size = new System.Drawing.Size(27, 14);
			this.Label11.TabIndex = 8;
			this.Label11.Text = "IN 6";
			// 
			// Label10
			// 
			this.Label10.AutoSize = true;
			this.Label10.Location = new System.Drawing.Point(264, 64);
			this.Label10.Name = "Label10";
			this.Label10.Size = new System.Drawing.Size(27, 14);
			this.Label10.TabIndex = 7;
			this.Label10.Text = "IN 4";
			// 
			// Label9
			// 
			this.Label9.AutoSize = true;
			this.Label9.Location = new System.Drawing.Point(264, 32);
			this.Label9.Name = "Label9";
			this.Label9.Size = new System.Drawing.Size(27, 14);
			this.Label9.TabIndex = 6;
			this.Label9.Text = "IN 2";
			// 
			// cboIn5
			// 
			this.cboIn5.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboIn5.Location = new System.Drawing.Point(64, 88);
			this.cboIn5.Name = "cboIn5";
			this.cboIn5.Size = new System.Drawing.Size(184, 23);
			this.cboIn5.TabIndex = 8;
			this.cboIn5.SelectedIndexChanged += new System.EventHandler(this.cboIn5_SelectedIndexChanged);
			// 
			// cboIn3
			// 
			this.cboIn3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboIn3.Location = new System.Drawing.Point(64, 56);
			this.cboIn3.Name = "cboIn3";
			this.cboIn3.Size = new System.Drawing.Size(184, 23);
			this.cboIn3.TabIndex = 6;
			this.cboIn3.SelectedIndexChanged += new System.EventHandler(this.cboIn3_SelectedIndexChanged);
			// 
			// cboIn1
			// 
			this.cboIn1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboIn1.Location = new System.Drawing.Point(64, 24);
			this.cboIn1.Name = "cboIn1";
			this.cboIn1.Size = new System.Drawing.Size(184, 23);
			this.cboIn1.TabIndex = 4;
			this.cboIn1.SelectedIndexChanged += new System.EventHandler(this.cboIn1_SelectedIndexChanged);
			// 
			// Label5
			// 
			this.Label5.AutoSize = true;
			this.Label5.Location = new System.Drawing.Point(8, 96);
			this.Label5.Name = "Label5";
			this.Label5.Size = new System.Drawing.Size(27, 14);
			this.Label5.TabIndex = 2;
			this.Label5.Text = "IN 5";
			// 
			// Label4
			// 
			this.Label4.AutoSize = true;
			this.Label4.Location = new System.Drawing.Point(8, 64);
			this.Label4.Name = "Label4";
			this.Label4.Size = new System.Drawing.Size(27, 14);
			this.Label4.TabIndex = 1;
			this.Label4.Text = "IN 3";
			// 
			// Label3
			// 
			this.Label3.AutoSize = true;
			this.Label3.Location = new System.Drawing.Point(8, 32);
			this.Label3.Name = "Label3";
			this.Label3.Size = new System.Drawing.Size(27, 14);
			this.Label3.TabIndex = 0;
			this.Label3.Text = "IN 1";
			// 
			// Label7
			// 
			this.Label7.AutoSize = true;
			this.Label7.Location = new System.Drawing.Point(16, 288);
			this.Label7.Name = "Label7";
			this.Label7.Size = new System.Drawing.Size(56, 14);
			this.Label7.TabIndex = 12;
			this.Label7.Text = "SD Mode";
			// 
			// GroupBox1
			// 
			this.GroupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
																					this.cboOut2,
																					this.Label8,
																					this.cboOut3,
																					this.cboOut1,
																					this.Label2,
																					this.Label1});
			this.GroupBox1.Location = new System.Drawing.Point(16, 8);
			this.GroupBox1.Name = "GroupBox1";
			this.GroupBox1.Size = new System.Drawing.Size(506, 96);
			this.GroupBox1.TabIndex = 8;
			this.GroupBox1.TabStop = false;
			this.GroupBox1.Text = "OUT Setting";
			// 
			// cboOut2
			// 
			this.cboOut2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboOut2.Location = new System.Drawing.Point(312, 27);
			this.cboOut2.Name = "cboOut2";
			this.cboOut2.Size = new System.Drawing.Size(184, 23);
			this.cboOut2.TabIndex = 2;
			this.cboOut2.SelectedIndexChanged += new System.EventHandler(this.cboOut2_SelectedIndexChanged);
			// 
			// Label8
			// 
			this.Label8.AutoSize = true;
			this.Label8.Location = new System.Drawing.Point(264, 30);
			this.Label8.Name = "Label8";
			this.Label8.Size = new System.Drawing.Size(41, 14);
			this.Label8.TabIndex = 4;
			this.Label8.Text = "OUT 2";
			// 
			// cboOut3
			// 
			this.cboOut3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboOut3.Location = new System.Drawing.Point(64, 61);
			this.cboOut3.Name = "cboOut3";
			this.cboOut3.Size = new System.Drawing.Size(184, 23);
			this.cboOut3.TabIndex = 3;
			this.cboOut3.SelectedIndexChanged += new System.EventHandler(this.cboOut3_SelectedIndexChanged);
			// 
			// cboOut1
			// 
			this.cboOut1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboOut1.Location = new System.Drawing.Point(64, 27);
			this.cboOut1.Name = "cboOut1";
			this.cboOut1.Size = new System.Drawing.Size(184, 23);
			this.cboOut1.TabIndex = 1;
			this.cboOut1.SelectedIndexChanged += new System.EventHandler(this.cboOut1_SelectedIndexChanged);
			// 
			// Label2
			// 
			this.Label2.AutoSize = true;
			this.Label2.Location = new System.Drawing.Point(8, 64);
			this.Label2.Name = "Label2";
			this.Label2.Size = new System.Drawing.Size(41, 14);
			this.Label2.TabIndex = 1;
			this.Label2.Text = "OUT 3";
			// 
			// Label1
			// 
			this.Label1.AutoSize = true;
			this.Label1.Location = new System.Drawing.Point(8, 30);
			this.Label1.Name = "Label1";
			this.Label1.Size = new System.Drawing.Size(41, 14);
			this.Label1.TabIndex = 0;
			this.Label1.Text = "OUT 1";
			// 
			// cboInFilter
			// 
			this.cboInFilter.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cboInFilter.Location = new System.Drawing.Point(81, 256);
			this.cboInFilter.Name = "cboInFilter";
			this.cboInFilter.Size = new System.Drawing.Size(184, 23);
			this.cboInFilter.TabIndex = 10;
			this.cboInFilter.SelectedIndexChanged += new System.EventHandler(this.cboInFilter_SelectedIndexChanged);
			// 
			// btnReturn
			// 
			this.btnReturn.Location = new System.Drawing.Point(402, 320);
			this.btnReturn.Name = "btnReturn";
			this.btnReturn.Size = new System.Drawing.Size(120, 32);
			this.btnReturn.TabIndex = 1;
			this.btnReturn.Text = "Return";
			this.btnReturn.Click += new System.EventHandler(this.btnReturn_Click);
			// 
			// InOutSet
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(536, 366);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.btnReturn,
																		  this.cboSdMode,
																		  this.Label6,
																		  this.GroupBox2,
																		  this.Label7,
																		  this.GroupBox1,
																		  this.cboInFilter});
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "InOutSet";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "In/Out Setting";
			this.Load += new System.EventHandler(this.InOutSet_Load);
			this.GroupBox2.ResumeLayout(false);
			this.GroupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void btnReturn_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void InOutSet_Load(object sender, System.EventArgs e)
		{
			// OUT1 ComboBox
			cboOut1.Items.Clear();
			cboOut1.Items.Add("General-Purpose output");
			cboOut1.Items.Add("Alarm Clear");
			cboOut1.Items.Add("Counter Clear (ERC)");
			cboOut1.Items.Add("OutPulse Count Match(CP1)");
			cboOut1.Items.Add("Encoder Count Match(CP2)");
			cboOut1.Items.Add("Hold OFF");

			// OUT2 ComboBox
			cboOut2.Items.Clear();
			cboOut2.Items.Add("General-Purpose output");
			cboOut2.Items.Add("Alarm Clear");
			cboOut2.Items.Add("Counter Clear (ERC)");
			cboOut2.Items.Add("OutPulse Count Match(CP1)");
			cboOut2.Items.Add("Encoder Count Match(CP2)");
			cboOut2.Items.Add("Hold OFF");

			// OUT3 ComboBox
			cboOut3.Items.Clear();
			cboOut3.Items.Add("General-Purpose output");
			cboOut3.Items.Add("Alarm Clear");
			cboOut3.Items.Add("Counter Clear (ERC)");
			cboOut3.Items.Add("OutPulse Count Match(CP1)");
			cboOut3.Items.Add("Encoder Count Match(CP2)");
			cboOut3.Items.Add("Hold OFF");
	
			// IN1 ComboBox
			cboIn1.Items.Clear();
			cboIn1.Items.Add("General-Purpose input");
			cboIn1.Items.Add("ALM");
    
			// IN2 ComboBox
			cboIn2.Items.Clear();
			cboIn2.Items.Add("General-Purpose input");
			cboIn2.Items.Add("INP");
    
			// IN3 ComboBox
			cboIn3.Items.Clear();
			cboIn3.Items.Add("General-Purpose input");
			cboIn3.Items.Add("SD");
    
			// IN4 ComboBox
			cboIn4.Items.Clear();
			cboIn4.Items.Add("General-Purpose input");
			cboIn4.Items.Add("LTC");
    
			// IN5 ComboBox
			cboIn5.Items.Clear();
			cboIn5.Items.Add("General-Purpose input");
			cboIn5.Items.Add("PCS");
    
			// IN6 ComboBox
			cboIn6.Items.Clear();
			cboIn6.Items.Add("General-Purpose input");
			cboIn6.Items.Add("CLR" );

			// ComboBox Initialise
			cboOut1.SelectedIndex = Setting.CtrlOut1;
			cboOut2.SelectedIndex = Setting.CtrlOut2;
			cboOut3.SelectedIndex = Setting.CtrlOut3;

			// CtrlIn = 0x3F
			if( (Setting.CtrlIn & 0x1) != 0 )	cboIn1.SelectedIndex = 1;
			else cboIn1.SelectedIndex = 0;

			if( (Setting.CtrlIn & 0x2) != 0 )	cboIn2.SelectedIndex = 1;
			else cboIn2.SelectedIndex = 0;

			if( (Setting.CtrlIn & 0x4) != 0 )	cboIn3.SelectedIndex = 1;
			else cboIn3.SelectedIndex = 0;

			if( (Setting.CtrlIn & 0x8) != 0 )	cboIn4.SelectedIndex = 1;
			else cboIn4.SelectedIndex = 0;

			if( (Setting.CtrlIn & 0x10) != 0 )	cboIn5.SelectedIndex = 1;
			else cboIn5.SelectedIndex = 0;

			if( (Setting.CtrlIn & 0x20) != 0 )	cboIn6.SelectedIndex = 1;
			else cboIn6.SelectedIndex = 0;

			// InFilter ComboBox
			cboInFilter.Items.Clear();
			cboInFilter.Items.Add("Not Use");
			cboInFilter.Items.Add("Disregard 3.2 [usec] or less");
			cboInFilter.Items.Add("Disregard 25 [usec] or less");
			cboInFilter.Items.Add("Disregard 200 [usec] or less");
			cboInFilter.Items.Add("Disregard 1.6 [msec] or less");
			cboInFilter.SelectedIndex = Setting.FilterType;

			// SDMode ComboBox
			cboSdMode.Items.Clear();
			cboSdMode.Items.Add("Slow Down & Stop");
			cboSdMode.Items.Add("Slow Down");
			cboSdMode.SelectedIndex = Setting.SDMode;
		}

		private void cboOut1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Setting.CtrlOut1 = (short)cboOut1.SelectedIndex;
		}

		private void cboOut2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Setting.CtrlOut2 = (short)cboOut2.SelectedIndex;
		}

		private void cboOut3_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Setting.CtrlOut3 = (short)cboOut3.SelectedIndex;
		}

		private void cboIn1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int	wbit=0x1;
			int	tmp=Setting.CtrlIn;
			if( cboIn1.SelectedIndex == 1 )
			{
				tmp |= wbit;
				Setting.CtrlIn = (short)tmp;
			}
			else
			{
				tmp = tmp & (~wbit);
				Setting.CtrlIn = (short)tmp;
			}
		}

		private void cboIn2_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int	wbit=0x2;
			int	tmp=Setting.CtrlIn;
			if( cboIn2.SelectedIndex == 1 )
			{
				tmp |= wbit;
				Setting.CtrlIn = (short)tmp;
			}
			else
			{
				tmp = tmp & (~wbit);
				Setting.CtrlIn = (short)tmp;
			}
		}

		private void cboIn3_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int	wbit=0x4;
			int	tmp=Setting.CtrlIn;
			if( cboIn3.SelectedIndex == 1 )
			{
				tmp |= wbit;
				Setting.CtrlIn = (short)tmp;
			}
			else
			{
				tmp = tmp & (~wbit);
				Setting.CtrlIn = (short)tmp;
			}
		}

		private void cboIn4_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int	wbit=0x8;
			int	tmp=Setting.CtrlIn;
			if( cboIn4.SelectedIndex == 1 )
			{
				tmp |= wbit;
				Setting.CtrlIn = (short)tmp;
			}
			else
			{
				tmp = tmp & (~wbit);
				Setting.CtrlIn = (short)tmp;
			}
		}

		private void cboIn5_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int	wbit=0x10;
			int	tmp=Setting.CtrlIn;
			if( cboIn5.SelectedIndex == 1 )
			{
				tmp |= wbit;
				Setting.CtrlIn = (short)tmp;
			}
			else
			{
				tmp = tmp & (~wbit);
				Setting.CtrlIn = (short)tmp;
			}
		}

		private void cboIn6_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			int	wbit=0x20;
			int	tmp=Setting.CtrlIn;
			if( cboIn6.SelectedIndex == 1 )
			{
				tmp |= wbit;
				Setting.CtrlIn = (short)tmp;
			}
			else
			{
				tmp = tmp & (~wbit);
				Setting.CtrlIn = (short)tmp;
			}
		}

		private void cboInFilter_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Setting.FilterType = (short)cboInFilter.SelectedIndex;
		}

		private void cboSdMode_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			Setting.SDMode = (short)cboSdMode.SelectedIndex;
		}
	}
}
