김성배 김성배 2022-06-23
초기 커밋.
@c02326f3783b7374e3915a7ed7a93fe432a41f63
 
KHModbus.sln (added)
+++ KHModbus.sln
@@ -0,0 +1,25 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.32002.261
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KHModbus", "ModbusTest\KHModbus.csproj", "{2A789031-AEE6-436C-B5E0-AB764F55FCD2}"
+EndProject
+Global
+	GlobalSection(SolutionConfigurationPlatforms) = preSolution
+		Debug|Any CPU = Debug|Any CPU
+		Release|Any CPU = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(ProjectConfigurationPlatforms) = postSolution
+		{2A789031-AEE6-436C-B5E0-AB764F55FCD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{2A789031-AEE6-436C-B5E0-AB764F55FCD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{2A789031-AEE6-436C-B5E0-AB764F55FCD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{2A789031-AEE6-436C-B5E0-AB764F55FCD2}.Release|Any CPU.Build.0 = Release|Any CPU
+	EndGlobalSection
+	GlobalSection(SolutionProperties) = preSolution
+		HideSolutionNode = FALSE
+	EndGlobalSection
+	GlobalSection(ExtensibilityGlobals) = postSolution
+		SolutionGuid = {9A1A26FC-96E9-4FF3-84D8-E1FED938441E}
+	EndGlobalSection
+EndGlobal
 
ModbusTest/App.config (added)
+++ ModbusTest/App.config
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+    <startup> 
+        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+    </startup>
+</configuration>(No newline at end of file)
 
ModbusTest/DBConnectionSingleton.cs (added)
+++ ModbusTest/DBConnectionSingleton.cs
@@ -0,0 +1,177 @@
+using System;
+using System.Collections.Generic;
+using System.Data;
+using System.Data.SqlClient;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace KHModbus
+{
+    public class DBConnectionSingleton
+    {
+        private static DBConnectionSingleton DBConnection;
+
+        // Connection 정보를 세팅한다.
+        private string DBURL = "192.168.1.17,1433";
+        private string DBPASSWORD = "signus1!";
+        //private string DBURL = "signus-smes.koreacentral.cloudapp.azure.com,14443";
+        //private string DBPASSWORD = "tlrmsjtm~1@3";
+        private string DBNAME = "U3SMES";
+        private string DBID = "sa";
+        SqlConnection mConn;
+
+        public struct DBValue
+        {
+            public string name;
+            public string value;
+            public SqlDbType type;
+        };
+
+
+        public static DBConnectionSingleton Instance()
+        {
+            if (DBConnection == null)
+            {
+                DBConnection = new DBConnectionSingleton();
+            }
+            return DBConnection;
+        }
+
+        public bool isConnect()
+        {
+            if (mConn == null) return false;
+            if(mConn.State == ConnectionState.Open)
+            {
+                return true;
+            }
+            return false;
+        }
+
+        public bool Connect()
+        {
+            string strconn = string.Format(" Data Source={0};Initial Catalog={1};Persist Security Info=false;Integrated Security=false;User ID={2};Password={3};enlist=true;Connect Timeout=2", DBURL, DBNAME, DBID, DBPASSWORD);
+            mConn = new SqlConnection(strconn);
+            try
+            {
+                // DB 연결
+                mConn.Open();
+
+                // 연결여부에 따라 다른 메시지를 보여준다
+                if (mConn.State == ConnectionState.Open)
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            catch (Exception ex)
+            {
+                return false;
+            }
+        }
+
+
+        public bool Close()
+        {
+            try
+            {
+                // DB 연결해제
+                mConn.Close();
+
+                // 연결여부에 따라 다른 메시지를 보여준다
+                if (mConn.State == ConnectionState.Closed)
+                {
+                    return true;
+                }
+                else
+                {
+                    return false;
+                }
+            }
+            catch (Exception ex)
+            {
+                return false;
+            }
+        }
+
+
+        public DBValue getParams(string name, string value)
+        {
+            DBValue d = new DBValue();
+
+            d.value = value;
+            d.name = name;
+
+            return d;
+
+        }
+
+
+        public bool SetCommand(string sql, params DBValue[] data)
+        {
+            if (!isConnect())
+            {
+                Connect();
+            }
+            try
+            {
+                SqlCommand com = new SqlCommand(sql, mConn);
+                com.CommandType = CommandType.StoredProcedure;
+                for (int i = 0; i < data.Length; i++)
+                {
+                    SqlParameter pInput = new SqlParameter("@" + data[i].name, SqlDbType.NVarChar, data[i].value.Length);
+                    pInput.Direction = ParameterDirection.Input;
+                    pInput.Value = data[i].value;
+                    com.Parameters.Add(pInput);
+                    //com.Parameters.AddWithValue("@" + data[i].name, data[i].value);
+                }
+
+                com.ExecuteNonQuery();
+
+                Close();
+            }
+            catch(Exception ex)
+            {
+                return false;
+            }
+            return true;
+
+        }
+
+
+        public DataTable GetSqlData(string sql)
+        {
+            try
+            {
+                if (!isConnect())
+                {
+                    if (!Connect())
+                    {
+                        return null;
+                    }
+                }
+                SqlDataAdapter da = new SqlDataAdapter(sql, mConn);
+                
+
+                DataTable dt = new DataTable();
+
+
+                da.Fill(dt);
+
+                Close();
+                return dt;
+            }catch(Exception ex)
+            {
+                return null;
+            }
+        }
+
+
+
+
+
+    }
+}
 
ModbusTest/FormModbus.Designer.cs (added)
+++ ModbusTest/FormModbus.Designer.cs
@@ -0,0 +1,831 @@
+
+namespace KHModbus
+{
+    partial class FormModbus
+    {
+        /// <summary>
+        /// 필수 디자이너 변수입니다.
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary>
+        /// 사용 중인 모든 리소스를 정리합니다.
+        /// </summary>
+        /// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region Windows Form 디자이너에서 생성한 코드
+
+        /// <summary>
+        /// 디자이너 지원에 필요한 메서드입니다. 
+        /// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.components = new System.ComponentModel.Container();
+            this.textBox_State = new System.Windows.Forms.TextBox();
+            this.timer_Connect = new System.Windows.Forms.Timer(this.components);
+            this.simpleButton2 = new DevExpress.XtraEditors.SimpleButton();
+            this.simpleButton1 = new DevExpress.XtraEditors.SimpleButton();
+            this.simpleButton3 = new DevExpress.XtraEditors.SimpleButton();
+            this.simpleButton4 = new DevExpress.XtraEditors.SimpleButton();
+            this.timer_AutoInput = new System.Windows.Forms.Timer(this.components);
+            this.toggleSwitch_Auto = new DevExpress.XtraEditors.ToggleSwitch();
+            this.label1 = new System.Windows.Forms.Label();
+            this.simpleButton5 = new DevExpress.XtraEditors.SimpleButton();
+            this.simpleButton6 = new DevExpress.XtraEditors.SimpleButton();
+            this.label2 = new System.Windows.Forms.Label();
+            this.textBox_DEV_ID = new System.Windows.Forms.TextBox();
+            this.textBox_FUNC = new System.Windows.Forms.TextBox();
+            this.label3 = new System.Windows.Forms.Label();
+            this.textBox_ADDR = new System.Windows.Forms.TextBox();
+            this.label4 = new System.Windows.Forms.Label();
+            this.simpleButton7 = new DevExpress.XtraEditors.SimpleButton();
+            this.simpleButton_InputRegister_1 = new DevExpress.XtraEditors.SimpleButton();
+            this.textBox_LENGTH_1 = new System.Windows.Forms.TextBox();
+            this.label5 = new System.Windows.Forms.Label();
+            this.textBox_Addr_1 = new System.Windows.Forms.TextBox();
+            this.label6 = new System.Windows.Forms.Label();
+            this.textBox_LENGTH_2 = new System.Windows.Forms.TextBox();
+            this.label7 = new System.Windows.Forms.Label();
+            this.textBox_Addr_2 = new System.Windows.Forms.TextBox();
+            this.label8 = new System.Windows.Forms.Label();
+            this.simpleButton_InputRegister_2 = new DevExpress.XtraEditors.SimpleButton();
+            this.textBox_LENGTH_3 = new System.Windows.Forms.TextBox();
+            this.label9 = new System.Windows.Forms.Label();
+            this.textBox_Addr_3 = new System.Windows.Forms.TextBox();
+            this.label10 = new System.Windows.Forms.Label();
+            this.simpleButton_InputRegister_3 = new DevExpress.XtraEditors.SimpleButton();
+            this.textBox_LENGTH_5 = new System.Windows.Forms.TextBox();
+            this.label13 = new System.Windows.Forms.Label();
+            this.textBox_Addr_5 = new System.Windows.Forms.TextBox();
+            this.label14 = new System.Windows.Forms.Label();
+            this.simpleButton_InputRegister_5 = new DevExpress.XtraEditors.SimpleButton();
+            this.textBox_LENGTH_4 = new System.Windows.Forms.TextBox();
+            this.label15 = new System.Windows.Forms.Label();
+            this.textBox_Addr_4 = new System.Windows.Forms.TextBox();
+            this.label16 = new System.Windows.Forms.Label();
+            this.simpleButton_InputRegister_4 = new DevExpress.XtraEditors.SimpleButton();
+            this.textBox_LENGTH_6 = new System.Windows.Forms.TextBox();
+            this.label17 = new System.Windows.Forms.Label();
+            this.textBox_Addr_6 = new System.Windows.Forms.TextBox();
+            this.label18 = new System.Windows.Forms.Label();
+            this.simpleButton_InputRegister_6 = new DevExpress.XtraEditors.SimpleButton();
+            this.textBox_LENGTH_2_2 = new System.Windows.Forms.TextBox();
+            this.label11 = new System.Windows.Forms.Label();
+            this.textBox_Addr_2_2 = new System.Windows.Forms.TextBox();
+            this.label12 = new System.Windows.Forms.Label();
+            this.simpleButton_InputRegister_2_2 = new DevExpress.XtraEditors.SimpleButton();
+            this.simpleButton_All = new DevExpress.XtraEditors.SimpleButton();
+            this.timer_DBInsert = new System.Windows.Forms.Timer(this.components);
+            this.panel_DBConnect = new System.Windows.Forms.Panel();
+            this.label19 = new System.Windows.Forms.Label();
+            this.label20 = new System.Windows.Forms.Label();
+            this.toggleSwitch_Log = new DevExpress.XtraEditors.ToggleSwitch();
+            this.timer_Log = new System.Windows.Forms.Timer(this.components);
+            this.textBox1 = new System.Windows.Forms.TextBox();
+            this.label21 = new System.Windows.Forms.Label();
+            this.simpleButton8 = new DevExpress.XtraEditors.SimpleButton();
+            ((System.ComponentModel.ISupportInitialize)(this.toggleSwitch_Auto.Properties)).BeginInit();
+            this.panel_DBConnect.SuspendLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.toggleSwitch_Log.Properties)).BeginInit();
+            this.SuspendLayout();
+            // 
+            // textBox_State
+            // 
+            this.textBox_State.Location = new System.Drawing.Point(12, 177);
+            this.textBox_State.Multiline = true;
+            this.textBox_State.Name = "textBox_State";
+            this.textBox_State.ScrollBars = System.Windows.Forms.ScrollBars.Both;
+            this.textBox_State.Size = new System.Drawing.Size(915, 234);
+            this.textBox_State.TabIndex = 1;
+            // 
+            // timer_Connect
+            // 
+            this.timer_Connect.Enabled = true;
+            this.timer_Connect.Interval = 5000;
+            this.timer_Connect.Tick += new System.EventHandler(this.timer_Connect_Tick);
+            // 
+            // simpleButton2
+            // 
+            this.simpleButton2.Location = new System.Drawing.Point(16, 88);
+            this.simpleButton2.Name = "simpleButton2";
+            this.simpleButton2.Size = new System.Drawing.Size(122, 85);
+            this.simpleButton2.TabIndex = 2;
+            this.simpleButton2.Text = "DataReadingTEST";
+            this.simpleButton2.Visible = false;
+            this.simpleButton2.Click += new System.EventHandler(this.simpleButton2_Click);
+            // 
+            // simpleButton1
+            // 
+            this.simpleButton1.Location = new System.Drawing.Point(272, 88);
+            this.simpleButton1.Name = "simpleButton1";
+            this.simpleButton1.Size = new System.Drawing.Size(122, 85);
+            this.simpleButton1.TabIndex = 3;
+            this.simpleButton1.Text = "DBTEST";
+            this.simpleButton1.Visible = false;
+            this.simpleButton1.Click += new System.EventHandler(this.simpleButton1_Click_1);
+            // 
+            // simpleButton3
+            // 
+            this.simpleButton3.Location = new System.Drawing.Point(144, 88);
+            this.simpleButton3.Name = "simpleButton3";
+            this.simpleButton3.Size = new System.Drawing.Size(122, 85);
+            this.simpleButton3.TabIndex = 4;
+            this.simpleButton3.Text = "DBIsertTest";
+            this.simpleButton3.Visible = false;
+            this.simpleButton3.Click += new System.EventHandler(this.simpleButton3_Click);
+            // 
+            // simpleButton4
+            // 
+            this.simpleButton4.Location = new System.Drawing.Point(444, 88);
+            this.simpleButton4.Name = "simpleButton4";
+            this.simpleButton4.Size = new System.Drawing.Size(122, 85);
+            this.simpleButton4.TabIndex = 5;
+            this.simpleButton4.Text = "[PLC]\r\nReading&&Insert";
+            this.simpleButton4.Visible = false;
+            this.simpleButton4.Click += new System.EventHandler(this.simpleButton4_Click);
+            // 
+            // timer_AutoInput
+            // 
+            this.timer_AutoInput.Enabled = true;
+            this.timer_AutoInput.Interval = 500;
+            this.timer_AutoInput.Tick += new System.EventHandler(this.timer_AutoInput_Tick);
+            // 
+            // toggleSwitch_Auto
+            // 
+            this.toggleSwitch_Auto.EditValue = true;
+            this.toggleSwitch_Auto.Location = new System.Drawing.Point(686, 146);
+            this.toggleSwitch_Auto.Name = "toggleSwitch_Auto";
+            this.toggleSwitch_Auto.Properties.OffText = "Off";
+            this.toggleSwitch_Auto.Properties.OnText = "On";
+            this.toggleSwitch_Auto.Size = new System.Drawing.Size(105, 25);
+            this.toggleSwitch_Auto.TabIndex = 6;
+            this.toggleSwitch_Auto.Toggled += new System.EventHandler(this.toggleSwitch_Auto_Toggled);
+            // 
+            // label1
+            // 
+            this.label1.AutoSize = true;
+            this.label1.Location = new System.Drawing.Point(684, 131);
+            this.label1.Name = "label1";
+            this.label1.Size = new System.Drawing.Size(61, 12);
+            this.label1.TabIndex = 7;
+            this.label1.Text = "AutoInsert";
+            // 
+            // simpleButton5
+            // 
+            this.simpleButton5.Location = new System.Drawing.Point(558, 12);
+            this.simpleButton5.Name = "simpleButton5";
+            this.simpleButton5.Size = new System.Drawing.Size(122, 57);
+            this.simpleButton5.TabIndex = 8;
+            this.simpleButton5.Text = "{SERIAL]\r\nReading&&Insert";
+            this.simpleButton5.Visible = false;
+            this.simpleButton5.Click += new System.EventHandler(this.simpleButton5_Click);
+            // 
+            // simpleButton6
+            // 
+            this.simpleButton6.Location = new System.Drawing.Point(444, 12);
+            this.simpleButton6.Name = "simpleButton6";
+            this.simpleButton6.Size = new System.Drawing.Size(98, 57);
+            this.simpleButton6.TabIndex = 9;
+            this.simpleButton6.Text = "[4Byte][SERIAL]\r\nCOMM_TEST";
+            this.simpleButton6.Visible = false;
+            this.simpleButton6.Click += new System.EventHandler(this.simpleButton6_Click);
+            // 
+            // label2
+            // 
+            this.label2.AutoSize = true;
+            this.label2.Location = new System.Drawing.Point(14, 28);
+            this.label2.Name = "label2";
+            this.label2.Size = new System.Drawing.Size(44, 12);
+            this.label2.TabIndex = 10;
+            this.label2.Text = "SLAVE";
+            this.label2.Visible = false;
+            // 
+            // textBox_DEV_ID
+            // 
+            this.textBox_DEV_ID.Location = new System.Drawing.Point(65, 23);
+            this.textBox_DEV_ID.Name = "textBox_DEV_ID";
+            this.textBox_DEV_ID.Size = new System.Drawing.Size(44, 21);
+            this.textBox_DEV_ID.TabIndex = 11;
+            this.textBox_DEV_ID.Text = "1";
+            this.textBox_DEV_ID.Visible = false;
+            // 
+            // textBox_FUNC
+            // 
+            this.textBox_FUNC.Location = new System.Drawing.Point(171, 22);
+            this.textBox_FUNC.Name = "textBox_FUNC";
+            this.textBox_FUNC.Size = new System.Drawing.Size(44, 21);
+            this.textBox_FUNC.TabIndex = 13;
+            this.textBox_FUNC.Text = "4";
+            this.textBox_FUNC.Visible = false;
+            // 
+            // label3
+            // 
+            this.label3.AutoSize = true;
+            this.label3.Location = new System.Drawing.Point(124, 27);
+            this.label3.Name = "label3";
+            this.label3.Size = new System.Drawing.Size(38, 12);
+            this.label3.TabIndex = 12;
+            this.label3.Text = "FUNC";
+            this.label3.Visible = false;
+            // 
+            // textBox_ADDR
+            // 
+            this.textBox_ADDR.Location = new System.Drawing.Point(276, 22);
+            this.textBox_ADDR.Name = "textBox_ADDR";
+            this.textBox_ADDR.Size = new System.Drawing.Size(44, 21);
+            this.textBox_ADDR.TabIndex = 15;
+            this.textBox_ADDR.Text = "220";
+            this.textBox_ADDR.Visible = false;
+            // 
+            // label4
+            // 
+            this.label4.AutoSize = true;
+            this.label4.Location = new System.Drawing.Point(229, 27);
+            this.label4.Name = "label4";
+            this.label4.Size = new System.Drawing.Size(37, 12);
+            this.label4.TabIndex = 14;
+            this.label4.Text = "ADDR";
+            this.label4.Visible = false;
+            // 
+            // simpleButton7
+            // 
+            this.simpleButton7.Location = new System.Drawing.Point(326, 12);
+            this.simpleButton7.Name = "simpleButton7";
+            this.simpleButton7.Size = new System.Drawing.Size(98, 57);
+            this.simpleButton7.TabIndex = 16;
+            this.simpleButton7.Text = "[2Byte][SERIAL]\r\nCOMM_TEST";
+            this.simpleButton7.Visible = false;
+            this.simpleButton7.Click += new System.EventHandler(this.simpleButton7_Click);
+            // 
+            // simpleButton_InputRegister_1
+            // 
+            this.simpleButton_InputRegister_1.Location = new System.Drawing.Point(1146, 39);
+            this.simpleButton_InputRegister_1.Name = "simpleButton_InputRegister_1";
+            this.simpleButton_InputRegister_1.Size = new System.Drawing.Size(122, 32);
+            this.simpleButton_InputRegister_1.TabIndex = 17;
+            this.simpleButton_InputRegister_1.Text = "InputRegister";
+            this.simpleButton_InputRegister_1.Visible = false;
+            this.simpleButton_InputRegister_1.Click += new System.EventHandler(this.simpleButton_InputRegister_1_Click);
+            // 
+            // textBox_LENGTH_1
+            // 
+            this.textBox_LENGTH_1.Location = new System.Drawing.Point(1085, 46);
+            this.textBox_LENGTH_1.Name = "textBox_LENGTH_1";
+            this.textBox_LENGTH_1.Size = new System.Drawing.Size(44, 21);
+            this.textBox_LENGTH_1.TabIndex = 21;
+            this.textBox_LENGTH_1.Text = "48";
+            this.textBox_LENGTH_1.Visible = false;
+            // 
+            // label5
+            // 
+            this.label5.AutoSize = true;
+            this.label5.Location = new System.Drawing.Point(1030, 51);
+            this.label5.Name = "label5";
+            this.label5.Size = new System.Drawing.Size(54, 12);
+            this.label5.TabIndex = 20;
+            this.label5.Text = "LENGTH";
+            this.label5.Visible = false;
+            // 
+            // textBox_Addr_1
+            // 
+            this.textBox_Addr_1.Location = new System.Drawing.Point(980, 46);
+            this.textBox_Addr_1.Name = "textBox_Addr_1";
+            this.textBox_Addr_1.Size = new System.Drawing.Size(44, 21);
+            this.textBox_Addr_1.TabIndex = 19;
+            this.textBox_Addr_1.Text = "400";
+            this.textBox_Addr_1.Visible = false;
+            // 
+            // label6
+            // 
+            this.label6.AutoSize = true;
+            this.label6.Location = new System.Drawing.Point(933, 51);
+            this.label6.Name = "label6";
+            this.label6.Size = new System.Drawing.Size(37, 12);
+            this.label6.TabIndex = 18;
+            this.label6.Text = "ADDR";
+            this.label6.Visible = false;
+            // 
+            // textBox_LENGTH_2
+            // 
+            this.textBox_LENGTH_2.Location = new System.Drawing.Point(1085, 84);
+            this.textBox_LENGTH_2.Name = "textBox_LENGTH_2";
+            this.textBox_LENGTH_2.Size = new System.Drawing.Size(44, 21);
+            this.textBox_LENGTH_2.TabIndex = 26;
+            this.textBox_LENGTH_2.Text = "20";
+            this.textBox_LENGTH_2.Visible = false;
+            // 
+            // label7
+            // 
+            this.label7.AutoSize = true;
+            this.label7.Location = new System.Drawing.Point(1030, 89);
+            this.label7.Name = "label7";
+            this.label7.Size = new System.Drawing.Size(54, 12);
+            this.label7.TabIndex = 25;
+            this.label7.Text = "LENGTH";
+            this.label7.Visible = false;
+            // 
+            // textBox_Addr_2
+            // 
+            this.textBox_Addr_2.Location = new System.Drawing.Point(980, 84);
+            this.textBox_Addr_2.Name = "textBox_Addr_2";
+            this.textBox_Addr_2.Size = new System.Drawing.Size(44, 21);
+            this.textBox_Addr_2.TabIndex = 24;
+            this.textBox_Addr_2.Text = "500";
+            this.textBox_Addr_2.Visible = false;
+            // 
+            // label8
+            // 
+            this.label8.AutoSize = true;
+            this.label8.Location = new System.Drawing.Point(933, 89);
+            this.label8.Name = "label8";
+            this.label8.Size = new System.Drawing.Size(37, 12);
+            this.label8.TabIndex = 23;
+            this.label8.Text = "ADDR";
+            this.label8.Visible = false;
+            // 
+            // simpleButton_InputRegister_2
+            // 
+            this.simpleButton_InputRegister_2.Location = new System.Drawing.Point(1146, 77);
+            this.simpleButton_InputRegister_2.Name = "simpleButton_InputRegister_2";
+            this.simpleButton_InputRegister_2.Size = new System.Drawing.Size(122, 32);
+            this.simpleButton_InputRegister_2.TabIndex = 22;
+            this.simpleButton_InputRegister_2.Text = "InputRegister";
+            this.simpleButton_InputRegister_2.Visible = false;
+            this.simpleButton_InputRegister_2.Click += new System.EventHandler(this.simpleButton_InputRegister_2_Click);
+            // 
+            // textBox_LENGTH_3
+            // 
+            this.textBox_LENGTH_3.Location = new System.Drawing.Point(1085, 171);
+            this.textBox_LENGTH_3.Name = "textBox_LENGTH_3";
+            this.textBox_LENGTH_3.Size = new System.Drawing.Size(44, 21);
+            this.textBox_LENGTH_3.TabIndex = 31;
+            this.textBox_LENGTH_3.Text = "19";
+            this.textBox_LENGTH_3.Visible = false;
+            // 
+            // label9
+            // 
+            this.label9.AutoSize = true;
+            this.label9.Location = new System.Drawing.Point(1030, 176);
+            this.label9.Name = "label9";
+            this.label9.Size = new System.Drawing.Size(54, 12);
+            this.label9.TabIndex = 30;
+            this.label9.Text = "LENGTH";
+            this.label9.Visible = false;
+            // 
+            // textBox_Addr_3
+            // 
+            this.textBox_Addr_3.Location = new System.Drawing.Point(980, 171);
+            this.textBox_Addr_3.Name = "textBox_Addr_3";
+            this.textBox_Addr_3.Size = new System.Drawing.Size(44, 21);
+            this.textBox_Addr_3.TabIndex = 29;
+            this.textBox_Addr_3.Text = "600";
+            this.textBox_Addr_3.Visible = false;
+            // 
+            // label10
+            // 
+            this.label10.AutoSize = true;
+            this.label10.Location = new System.Drawing.Point(933, 176);
+            this.label10.Name = "label10";
+            this.label10.Size = new System.Drawing.Size(37, 12);
+            this.label10.TabIndex = 28;
+            this.label10.Text = "ADDR";
+            this.label10.Visible = false;
+            // 
+            // simpleButton_InputRegister_3
+            // 
+            this.simpleButton_InputRegister_3.Location = new System.Drawing.Point(1146, 164);
+            this.simpleButton_InputRegister_3.Name = "simpleButton_InputRegister_3";
+            this.simpleButton_InputRegister_3.Size = new System.Drawing.Size(122, 32);
+            this.simpleButton_InputRegister_3.TabIndex = 27;
+            this.simpleButton_InputRegister_3.Text = "InputRegister";
+            this.simpleButton_InputRegister_3.Visible = false;
+            this.simpleButton_InputRegister_3.Click += new System.EventHandler(this.simpleButton_InputRegister_3_Click);
+            // 
+            // textBox_LENGTH_5
+            // 
+            this.textBox_LENGTH_5.Location = new System.Drawing.Point(1085, 247);
+            this.textBox_LENGTH_5.Name = "textBox_LENGTH_5";
+            this.textBox_LENGTH_5.Size = new System.Drawing.Size(44, 21);
+            this.textBox_LENGTH_5.TabIndex = 41;
+            this.textBox_LENGTH_5.Text = "40";
+            this.textBox_LENGTH_5.Visible = false;
+            // 
+            // label13
+            // 
+            this.label13.AutoSize = true;
+            this.label13.Location = new System.Drawing.Point(1030, 252);
+            this.label13.Name = "label13";
+            this.label13.Size = new System.Drawing.Size(54, 12);
+            this.label13.TabIndex = 40;
+            this.label13.Text = "LENGTH";
+            this.label13.Visible = false;
+            // 
+            // textBox_Addr_5
+            // 
+            this.textBox_Addr_5.Location = new System.Drawing.Point(980, 247);
+            this.textBox_Addr_5.Name = "textBox_Addr_5";
+            this.textBox_Addr_5.Size = new System.Drawing.Size(44, 21);
+            this.textBox_Addr_5.TabIndex = 39;
+            this.textBox_Addr_5.Text = "700";
+            this.textBox_Addr_5.Visible = false;
+            // 
+            // label14
+            // 
+            this.label14.AutoSize = true;
+            this.label14.Location = new System.Drawing.Point(933, 252);
+            this.label14.Name = "label14";
+            this.label14.Size = new System.Drawing.Size(37, 12);
+            this.label14.TabIndex = 38;
+            this.label14.Text = "ADDR";
+            this.label14.Visible = false;
+            // 
+            // simpleButton_InputRegister_5
+            // 
+            this.simpleButton_InputRegister_5.Location = new System.Drawing.Point(1146, 240);
+            this.simpleButton_InputRegister_5.Name = "simpleButton_InputRegister_5";
+            this.simpleButton_InputRegister_5.Size = new System.Drawing.Size(122, 32);
+            this.simpleButton_InputRegister_5.TabIndex = 37;
+            this.simpleButton_InputRegister_5.Text = "InputRegister";
+            this.simpleButton_InputRegister_5.Visible = false;
+            this.simpleButton_InputRegister_5.Click += new System.EventHandler(this.simpleButton_InputRegister_5_Click);
+            // 
+            // textBox_LENGTH_4
+            // 
+            this.textBox_LENGTH_4.Location = new System.Drawing.Point(1085, 209);
+            this.textBox_LENGTH_4.Name = "textBox_LENGTH_4";
+            this.textBox_LENGTH_4.Size = new System.Drawing.Size(44, 21);
+            this.textBox_LENGTH_4.TabIndex = 36;
+            this.textBox_LENGTH_4.Text = "19";
+            this.textBox_LENGTH_4.Visible = false;
+            // 
+            // label15
+            // 
+            this.label15.AutoSize = true;
+            this.label15.Location = new System.Drawing.Point(1030, 214);
+            this.label15.Name = "label15";
+            this.label15.Size = new System.Drawing.Size(54, 12);
+            this.label15.TabIndex = 35;
+            this.label15.Text = "LENGTH";
+            this.label15.Visible = false;
+            // 
+            // textBox_Addr_4
+            // 
+            this.textBox_Addr_4.Location = new System.Drawing.Point(980, 209);
+            this.textBox_Addr_4.Name = "textBox_Addr_4";
+            this.textBox_Addr_4.Size = new System.Drawing.Size(44, 21);
+            this.textBox_Addr_4.TabIndex = 34;
+            this.textBox_Addr_4.Text = "650";
+            this.textBox_Addr_4.Visible = false;
+            // 
+            // label16
+            // 
+            this.label16.AutoSize = true;
+            this.label16.Location = new System.Drawing.Point(933, 214);
+            this.label16.Name = "label16";
+            this.label16.Size = new System.Drawing.Size(37, 12);
+            this.label16.TabIndex = 33;
+            this.label16.Text = "ADDR";
+            this.label16.Visible = false;
+            // 
+            // simpleButton_InputRegister_4
+            // 
+            this.simpleButton_InputRegister_4.Location = new System.Drawing.Point(1146, 202);
+            this.simpleButton_InputRegister_4.Name = "simpleButton_InputRegister_4";
+            this.simpleButton_InputRegister_4.Size = new System.Drawing.Size(122, 32);
+            this.simpleButton_InputRegister_4.TabIndex = 32;
+            this.simpleButton_InputRegister_4.Text = "InputRegister";
+            this.simpleButton_InputRegister_4.Visible = false;
+            this.simpleButton_InputRegister_4.Click += new System.EventHandler(this.simpleButton_InputRegister_4_Click);
+            // 
+            // textBox_LENGTH_6
+            // 
+            this.textBox_LENGTH_6.Location = new System.Drawing.Point(1085, 350);
+            this.textBox_LENGTH_6.Name = "textBox_LENGTH_6";
+            this.textBox_LENGTH_6.Size = new System.Drawing.Size(44, 21);
+            this.textBox_LENGTH_6.TabIndex = 61;
+            this.textBox_LENGTH_6.Text = "2";
+            // 
+            // label17
+            // 
+            this.label17.AutoSize = true;
+            this.label17.Location = new System.Drawing.Point(1030, 355);
+            this.label17.Name = "label17";
+            this.label17.Size = new System.Drawing.Size(54, 12);
+            this.label17.TabIndex = 60;
+            this.label17.Text = "LENGTH";
+            // 
+            // textBox_Addr_6
+            // 
+            this.textBox_Addr_6.Location = new System.Drawing.Point(980, 350);
+            this.textBox_Addr_6.Name = "textBox_Addr_6";
+            this.textBox_Addr_6.Size = new System.Drawing.Size(44, 21);
+            this.textBox_Addr_6.TabIndex = 59;
+            this.textBox_Addr_6.Text = "620";
+            // 
+            // label18
+            // 
+            this.label18.AutoSize = true;
+            this.label18.Location = new System.Drawing.Point(933, 355);
+            this.label18.Name = "label18";
+            this.label18.Size = new System.Drawing.Size(37, 12);
+            this.label18.TabIndex = 58;
+            this.label18.Text = "ADDR";
+            // 
+            // simpleButton_InputRegister_6
+            // 
+            this.simpleButton_InputRegister_6.Location = new System.Drawing.Point(1146, 343);
+            this.simpleButton_InputRegister_6.Name = "simpleButton_InputRegister_6";
+            this.simpleButton_InputRegister_6.Size = new System.Drawing.Size(122, 32);
+            this.simpleButton_InputRegister_6.TabIndex = 57;
+            this.simpleButton_InputRegister_6.Text = "InputRegister";
+            this.simpleButton_InputRegister_6.Click += new System.EventHandler(this.simpleButton_InputRegister_6_Click);
+            // 
+            // textBox_LENGTH_2_2
+            // 
+            this.textBox_LENGTH_2_2.Location = new System.Drawing.Point(1085, 122);
+            this.textBox_LENGTH_2_2.Name = "textBox_LENGTH_2_2";
+            this.textBox_LENGTH_2_2.Size = new System.Drawing.Size(44, 21);
+            this.textBox_LENGTH_2_2.TabIndex = 66;
+            this.textBox_LENGTH_2_2.Text = "20";
+            this.textBox_LENGTH_2_2.Visible = false;
+            // 
+            // label11
+            // 
+            this.label11.AutoSize = true;
+            this.label11.Location = new System.Drawing.Point(1030, 127);
+            this.label11.Name = "label11";
+            this.label11.Size = new System.Drawing.Size(54, 12);
+            this.label11.TabIndex = 65;
+            this.label11.Text = "LENGTH";
+            this.label11.Visible = false;
+            // 
+            // textBox_Addr_2_2
+            // 
+            this.textBox_Addr_2_2.Location = new System.Drawing.Point(980, 122);
+            this.textBox_Addr_2_2.Name = "textBox_Addr_2_2";
+            this.textBox_Addr_2_2.Size = new System.Drawing.Size(44, 21);
+            this.textBox_Addr_2_2.TabIndex = 64;
+            this.textBox_Addr_2_2.Text = "520";
+            this.textBox_Addr_2_2.Visible = false;
+            // 
+            // label12
+            // 
+            this.label12.AutoSize = true;
+            this.label12.Location = new System.Drawing.Point(933, 127);
+            this.label12.Name = "label12";
+            this.label12.Size = new System.Drawing.Size(37, 12);
+            this.label12.TabIndex = 63;
+            this.label12.Text = "ADDR";
+            this.label12.Visible = false;
+            // 
+            // simpleButton_InputRegister_2_2
+            // 
+            this.simpleButton_InputRegister_2_2.Location = new System.Drawing.Point(1146, 115);
+            this.simpleButton_InputRegister_2_2.Name = "simpleButton_InputRegister_2_2";
+            this.simpleButton_InputRegister_2_2.Size = new System.Drawing.Size(122, 32);
+            this.simpleButton_InputRegister_2_2.TabIndex = 62;
+            this.simpleButton_InputRegister_2_2.Text = "InputRegister";
+            this.simpleButton_InputRegister_2_2.Visible = false;
+            this.simpleButton_InputRegister_2_2.Click += new System.EventHandler(this.simpleButton_InputRegister_2_2_Click);
+            // 
+            // simpleButton_All
+            // 
+            this.simpleButton_All.Location = new System.Drawing.Point(1293, 406);
+            this.simpleButton_All.Name = "simpleButton_All";
+            this.simpleButton_All.Size = new System.Drawing.Size(122, 32);
+            this.simpleButton_All.TabIndex = 67;
+            this.simpleButton_All.Text = "AllReading";
+            this.simpleButton_All.Visible = false;
+            this.simpleButton_All.Click += new System.EventHandler(this.simpleButton_All_Click);
+            // 
+            // timer_DBInsert
+            // 
+            this.timer_DBInsert.Enabled = true;
+            this.timer_DBInsert.Interval = 10000;
+            this.timer_DBInsert.Tick += new System.EventHandler(this.timer_DBConnect_Tick);
+            // 
+            // panel_DBConnect
+            // 
+            this.panel_DBConnect.BackColor = System.Drawing.Color.White;
+            this.panel_DBConnect.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
+            this.panel_DBConnect.Controls.Add(this.label19);
+            this.panel_DBConnect.Location = new System.Drawing.Point(797, 122);
+            this.panel_DBConnect.Name = "panel_DBConnect";
+            this.panel_DBConnect.Size = new System.Drawing.Size(130, 49);
+            this.panel_DBConnect.TabIndex = 68;
+            // 
+            // label19
+            // 
+            this.label19.AutoSize = true;
+            this.label19.Location = new System.Drawing.Point(30, 20);
+            this.label19.Name = "label19";
+            this.label19.Size = new System.Drawing.Size(72, 12);
+            this.label19.TabIndex = 0;
+            this.label19.Text = "DB Connect";
+            // 
+            // label20
+            // 
+            this.label20.AutoSize = true;
+            this.label20.Location = new System.Drawing.Point(573, 131);
+            this.label20.Name = "label20";
+            this.label20.Size = new System.Drawing.Size(51, 12);
+            this.label20.TabIndex = 70;
+            this.label20.Text = "AutoLog";
+            // 
+            // toggleSwitch_Log
+            // 
+            this.toggleSwitch_Log.EditValue = true;
+            this.toggleSwitch_Log.Location = new System.Drawing.Point(575, 146);
+            this.toggleSwitch_Log.Name = "toggleSwitch_Log";
+            this.toggleSwitch_Log.Properties.OffText = "Off";
+            this.toggleSwitch_Log.Properties.OnText = "On";
+            this.toggleSwitch_Log.Size = new System.Drawing.Size(105, 25);
+            this.toggleSwitch_Log.TabIndex = 69;
+            this.toggleSwitch_Log.Toggled += new System.EventHandler(this.toggleSwitch_Log_Toggled);
+            // 
+            // timer_Log
+            // 
+            this.timer_Log.Enabled = true;
+            this.timer_Log.Interval = 5000;
+            this.timer_Log.Tick += new System.EventHandler(this.timer_Log_Tick);
+            // 
+            // textBox1
+            // 
+            this.textBox1.Location = new System.Drawing.Point(789, 12);
+            this.textBox1.Name = "textBox1";
+            this.textBox1.Size = new System.Drawing.Size(73, 21);
+            this.textBox1.TabIndex = 72;
+            this.textBox1.Visible = false;
+            // 
+            // label21
+            // 
+            this.label21.AutoSize = true;
+            this.label21.Location = new System.Drawing.Point(719, 17);
+            this.label21.Name = "label21";
+            this.label21.Size = new System.Drawing.Size(64, 12);
+            this.label21.TabIndex = 71;
+            this.label21.Text = "MACH_CD";
+            this.label21.Visible = false;
+            // 
+            // simpleButton8
+            // 
+            this.simpleButton8.Location = new System.Drawing.Point(789, 39);
+            this.simpleButton8.Name = "simpleButton8";
+            this.simpleButton8.Size = new System.Drawing.Size(73, 30);
+            this.simpleButton8.TabIndex = 73;
+            this.simpleButton8.Text = "CHECK";
+            this.simpleButton8.Visible = false;
+            this.simpleButton8.Click += new System.EventHandler(this.simpleButton8_Click_1);
+            // 
+            // FormModbus
+            // 
+            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
+            this.ClientSize = new System.Drawing.Size(932, 450);
+            this.Controls.Add(this.simpleButton8);
+            this.Controls.Add(this.textBox1);
+            this.Controls.Add(this.label21);
+            this.Controls.Add(this.label20);
+            this.Controls.Add(this.toggleSwitch_Log);
+            this.Controls.Add(this.panel_DBConnect);
+            this.Controls.Add(this.simpleButton_All);
+            this.Controls.Add(this.textBox_LENGTH_2_2);
+            this.Controls.Add(this.label11);
+            this.Controls.Add(this.textBox_Addr_2_2);
+            this.Controls.Add(this.label12);
+            this.Controls.Add(this.simpleButton_InputRegister_2_2);
+            this.Controls.Add(this.textBox_LENGTH_6);
+            this.Controls.Add(this.label17);
+            this.Controls.Add(this.textBox_Addr_6);
+            this.Controls.Add(this.label18);
+            this.Controls.Add(this.simpleButton_InputRegister_6);
+            this.Controls.Add(this.textBox_LENGTH_5);
+            this.Controls.Add(this.label13);
+            this.Controls.Add(this.textBox_Addr_5);
+            this.Controls.Add(this.label14);
+            this.Controls.Add(this.simpleButton_InputRegister_5);
+            this.Controls.Add(this.textBox_LENGTH_4);
+            this.Controls.Add(this.label15);
+            this.Controls.Add(this.textBox_Addr_4);
+            this.Controls.Add(this.label16);
+            this.Controls.Add(this.simpleButton_InputRegister_4);
+            this.Controls.Add(this.textBox_LENGTH_3);
+            this.Controls.Add(this.label9);
+            this.Controls.Add(this.textBox_Addr_3);
+            this.Controls.Add(this.label10);
+            this.Controls.Add(this.simpleButton_InputRegister_3);
+            this.Controls.Add(this.textBox_LENGTH_2);
+            this.Controls.Add(this.label7);
+            this.Controls.Add(this.textBox_Addr_2);
+            this.Controls.Add(this.label8);
+            this.Controls.Add(this.simpleButton_InputRegister_2);
+            this.Controls.Add(this.textBox_LENGTH_1);
+            this.Controls.Add(this.label5);
+            this.Controls.Add(this.textBox_Addr_1);
+            this.Controls.Add(this.label6);
+            this.Controls.Add(this.simpleButton_InputRegister_1);
+            this.Controls.Add(this.simpleButton7);
+            this.Controls.Add(this.textBox_ADDR);
+            this.Controls.Add(this.label4);
+            this.Controls.Add(this.textBox_FUNC);
+            this.Controls.Add(this.label3);
+            this.Controls.Add(this.textBox_DEV_ID);
+            this.Controls.Add(this.label2);
+            this.Controls.Add(this.simpleButton6);
+            this.Controls.Add(this.simpleButton5);
+            this.Controls.Add(this.label1);
+            this.Controls.Add(this.toggleSwitch_Auto);
+            this.Controls.Add(this.simpleButton4);
+            this.Controls.Add(this.simpleButton3);
+            this.Controls.Add(this.simpleButton1);
+            this.Controls.Add(this.simpleButton2);
+            this.Controls.Add(this.textBox_State);
+            this.Name = "FormModbus";
+            this.Text = "SignusSensorUploader";
+            this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
+            this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Form1_FormClosing);
+            this.Load += new System.EventHandler(this.FormModbus_Load);
+            ((System.ComponentModel.ISupportInitialize)(this.toggleSwitch_Auto.Properties)).EndInit();
+            this.panel_DBConnect.ResumeLayout(false);
+            this.panel_DBConnect.PerformLayout();
+            ((System.ComponentModel.ISupportInitialize)(this.toggleSwitch_Log.Properties)).EndInit();
+            this.ResumeLayout(false);
+            this.PerformLayout();
+
+        }
+
+        #endregion
+        private System.Windows.Forms.TextBox textBox_State;
+        private System.Windows.Forms.Timer timer_Connect;
+        private DevExpress.XtraEditors.SimpleButton simpleButton2;
+        private DevExpress.XtraEditors.SimpleButton simpleButton1;
+        private DevExpress.XtraEditors.SimpleButton simpleButton3;
+        private DevExpress.XtraEditors.SimpleButton simpleButton4;
+        private System.Windows.Forms.Timer timer_AutoInput;
+        private DevExpress.XtraEditors.ToggleSwitch toggleSwitch_Auto;
+        private System.Windows.Forms.Label label1;
+        private DevExpress.XtraEditors.SimpleButton simpleButton5;
+        private DevExpress.XtraEditors.SimpleButton simpleButton6;
+        private System.Windows.Forms.Label label2;
+        private System.Windows.Forms.TextBox textBox_DEV_ID;
+        private System.Windows.Forms.TextBox textBox_FUNC;
+        private System.Windows.Forms.Label label3;
+        private System.Windows.Forms.TextBox textBox_ADDR;
+        private System.Windows.Forms.Label label4;
+        private DevExpress.XtraEditors.SimpleButton simpleButton7;
+        private DevExpress.XtraEditors.SimpleButton simpleButton_InputRegister_1;
+        private System.Windows.Forms.TextBox textBox_LENGTH_1;
+        private System.Windows.Forms.Label label5;
+        private System.Windows.Forms.TextBox textBox_Addr_1;
+        private System.Windows.Forms.Label label6;
+        private System.Windows.Forms.TextBox textBox_LENGTH_2;
+        private System.Windows.Forms.Label label7;
+        private System.Windows.Forms.TextBox textBox_Addr_2;
+        private System.Windows.Forms.Label label8;
+        private DevExpress.XtraEditors.SimpleButton simpleButton_InputRegister_2;
+        private System.Windows.Forms.TextBox textBox_LENGTH_3;
+        private System.Windows.Forms.Label label9;
+        private System.Windows.Forms.TextBox textBox_Addr_3;
+        private System.Windows.Forms.Label label10;
+        private DevExpress.XtraEditors.SimpleButton simpleButton_InputRegister_3;
+        private System.Windows.Forms.TextBox textBox_LENGTH_5;
+        private System.Windows.Forms.Label label13;
+        private System.Windows.Forms.TextBox textBox_Addr_5;
+        private System.Windows.Forms.Label label14;
+        private DevExpress.XtraEditors.SimpleButton simpleButton_InputRegister_5;
+        private System.Windows.Forms.TextBox textBox_LENGTH_4;
+        private System.Windows.Forms.Label label15;
+        private System.Windows.Forms.TextBox textBox_Addr_4;
+        private System.Windows.Forms.Label label16;
+        private DevExpress.XtraEditors.SimpleButton simpleButton_InputRegister_4;
+        private System.Windows.Forms.TextBox textBox_LENGTH_6;
+        private System.Windows.Forms.Label label17;
+        private System.Windows.Forms.TextBox textBox_Addr_6;
+        private System.Windows.Forms.Label label18;
+        private DevExpress.XtraEditors.SimpleButton simpleButton_InputRegister_6;
+        private System.Windows.Forms.TextBox textBox_LENGTH_2_2;
+        private System.Windows.Forms.Label label11;
+        private System.Windows.Forms.TextBox textBox_Addr_2_2;
+        private System.Windows.Forms.Label label12;
+        private DevExpress.XtraEditors.SimpleButton simpleButton_InputRegister_2_2;
+        private DevExpress.XtraEditors.SimpleButton simpleButton_All;
+        private System.Windows.Forms.Timer timer_DBInsert;
+        private System.Windows.Forms.Panel panel_DBConnect;
+        private System.Windows.Forms.Label label19;
+        private System.Windows.Forms.Label label20;
+        private DevExpress.XtraEditors.ToggleSwitch toggleSwitch_Log;
+        private System.Windows.Forms.Timer timer_Log;
+        private System.Windows.Forms.TextBox textBox1;
+        private System.Windows.Forms.Label label21;
+        private DevExpress.XtraEditors.SimpleButton simpleButton8;
+    }
+}
+
 
ModbusTest/FormModbus.cs (added)
+++ ModbusTest/FormModbus.cs
@@ -0,0 +1,1150 @@
+using EasyModbus;
+using Modbus.Device;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Diagnostics;
+using System.Drawing;
+using System.Linq;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+
+
+
+namespace KHModbus
+{
+    public partial class FormModbus : Form
+    {
+        string mipAddr = "192.168.1.200";
+        //string mipAddr = "127.0.0.1";
+        int mPortNumber = 502;
+
+        ModbusClient mModbusClient;
+        List<string[,]> m_Data = new List<string[,]>();
+        public FormModbus()
+        {
+            InitializeComponent();
+            mModbusClient = new ModbusClient(mipAddr, mPortNumber);    //Ip-Address and Port of Modbus-TCP-Server
+            //timer_Connect.Enabled = true;
+
+            SerialConnectionSingleton.Instance().InitialModBus();
+
+            SerialConnectionSingleton.Instance().PortName = "COM1";
+            SerialConnectionSingleton.Instance().BaudRate = 9600;
+            SerialConnectionSingleton.Instance().Parity = System.IO.Ports.Parity.None;
+            SerialConnectionSingleton.Instance().StopBits = System.IO.Ports.StopBits.One;
+            SerialConnectionSingleton.Instance().DataBits = 8;
+            SerialConnectionSingleton.Instance().SlaveNo = 1;
+        }
+
+        
+
+
+
+        public void KHModbus2()
+        {
+            //client로 연결하는 부분
+            ModbusClient modbusClient = new ModbusClient(mipAddr, mPortNumber);    //Ip-Address and Port of Modbus-TCP-Server
+            modbusClient.Connect();                                                    //Connect to Server
+            modbusClient.WriteMultipleCoils(0, new bool[] { true, true, true, true, true, true, true, true, true, true });    //Write Coils starting with Address 5
+            bool[] readCoils = modbusClient.ReadCoils(9, 10);                        //Read 10 Coils from Server, starting with address 10
+            int[] readHoldingRegisters = modbusClient.ReadHoldingRegisters(0, 10);    //Read 10 Holding Registers from Server, starting with Address 1
+
+            // Console Output
+            //for (int i = 0; i < readCoils.Length; i++)
+            //    textBox1.Text += "Value of Coil " + (9 + i + 1) + " " + readCoils[i].ToString() +"\r\n";
+
+            //for (int i = 0; i < readHoldingRegisters.Length; i++)
+            //    textBox1.Text += "Value of HoldingRegister " + (i + 1) + " " + readHoldingRegisters[i].ToString() + "\r\n";
+            modbusClient.Disconnect();                                                //Disconnect from Server
+            //Console.ReadKey(true);
+        }
+
+
+        public bool Connect()
+        {
+            try
+            {
+
+                if (!mModbusClient.Connected)
+                    mModbusClient.Connect();
+
+                if (mModbusClient.Connected)
+                {
+                    textBox_State.Text += "Connected\r\n";
+                    return true;
+                }else
+                {
+                    return false;
+                }
+            }
+            catch(Exception ex)
+            {
+                textBox_State.Text += "PLC Connect Error : "+ ex.Message+ "\r\n";
+                return false;
+            }
+        }
+
+        public bool[] DataReadCoils(int Addr, int Size)
+        {
+            if (mModbusClient.Connected)
+            {
+                bool[] read = mModbusClient.ReadCoils(Addr, Size);    //Read 10 Holding Registers from Server, starting with Address 1
+                return read;
+            }
+            else
+            {
+                return null;
+            }
+        }
+        public int[] DataReadHolding(int Addr, int Size)
+        {
+            try
+            {
+                if (mModbusClient.Connected)
+                {
+                    int[] readHoldingRegisters = mModbusClient.ReadHoldingRegisters(Addr, Size);    //Read 10 Holding Registers from Server, starting with Address 1
+                    return readHoldingRegisters;
+                }
+                else
+                {
+                    return null;
+                }
+            }catch(Exception ex)
+            {
+                textBox_State.Text += "DataReading Error : " + ex.Message + "\r\n";
+                mModbusClient.Disconnect();
+                return null;
+            }
+        }
+        public int[] DataReadInput(int Addr, int Size)
+        {
+            try
+            {
+                if (mModbusClient.Connected)
+                {
+                    int[] readHoldingRegisters = mModbusClient.ReadInputRegisters(Addr, Size);    //Read 10 Holding Registers from Server, starting with Address 1
+                    return readHoldingRegisters;
+                }
+                else
+                {
+                    return null;
+                }
+            }
+            catch (Exception ex)
+            {
+                textBox_State.Text += "DataReading Error : " + ex.Message + "\r\n";
+                mModbusClient.Disconnect();
+                return null;
+            }
+        }
+
+
+        public async void modbusReadWrite()
+        {
+            TcpClient tcpc = new TcpClient();
+            tcpc.BeginConnect("127.0.0.1", 502, null, null);
+            ModbusIpMaster master = ModbusIpMaster.CreateIp(tcpc);
+            try 
+            {
+
+                while(true)
+                {
+                    bool[] coil = master.ReadCoils(0, 1);
+
+                    textBox_State.Text += coil[0].ToString();
+
+                    ushort[] holding = master.ReadHoldingRegisters(0, 1);
+                    //textBox2.Text = holding[0].ToString();
+
+
+                    ushort[] input = master.ReadHoldingRegisters(0, 9);
+                    //textBox2.Text = input[0].ToString();
+
+                    await Task.Delay(500);
+                }
+            
+            }catch (Exception ex)
+            {
+
+            }
+        }
+
+        private void simpleButton1_Click(object sender, EventArgs e)
+        {
+            KHModbus2();
+        }
+
+        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
+        {
+            if (mModbusClient.Connected)
+            {
+                mModbusClient.Disconnect();
+            }
+            else
+            {
+            }
+        }
+
+        private void timer_Connect_Tick(object sender, EventArgs e)
+        {
+            if(mModbusClient != null)
+            {
+                if(mModbusClient.Connected == false)
+                {
+                    Connect();
+                }
+            }
+        }
+
+        private void simpleButton2_Click(object sender, EventArgs e)
+        {
+            int[] Data = DataReadInput(400, 47);
+            if (Data == null) return;
+
+            textBox_State.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")+ "[400,47]: ";
+            foreach (int i in Data)
+            {
+                textBox_State.Text += i.ToString() + " ";
+
+            }
+            textBox_State.Text += "\r\n";
+            textBox_State.Select(textBox_State.Text.Length, 0);
+            textBox_State.ScrollToCaret();
+
+        }
+
+        private void simpleButton1_Click_1(object sender, EventArgs e)
+        {
+            DBConnectionSingleton.Instance().GetSqlData("select * from T_STD_COMPANY");
+        }
+
+        private void simpleButton3_Click(object sender, EventArgs e)
+        {
+            if(DBConnectionSingleton.Instance().SetCommand("HTSaveRealData",
+                DBConnectionSingleton.Instance().getParams("COMP_CD", "0001"),
+                DBConnectionSingleton.Instance().getParams("MACH_CD", "M0001"),
+                DBConnectionSingleton.Instance().getParams("REAL_DATA", "1")))
+            {
+                textBox_State.Text += "DBInsert Complete\r\n";
+            }
+        }
+
+        private void simpleButton4_Click(object sender, EventArgs e)
+        {
+            //Stopwatch sw = new Stopwatch();
+
+            //sw.Reset();
+            //sw.Start();
+
+            //DB 설비정보내에서 온도계 정보를 가져옵니다.[온도계는 CODE정보로 E03으로 저장되어있다]
+            DataTable dt =  DBConnectionSingleton.Instance().GetSqlData("SELECT [COMP_CD],[MACH_CD],[MACH_NO],[MACH_NM] FROM [dbo].[T_STD_MACH] m where m.COMP_CD = '0001' and m.MACH_TYPE = '03' order by MACH_NO asc");
+
+            //sw.Stop();
+            //textBox_State.Text += "Timer Check 1 : "+sw.ElapsedMilliseconds.ToString() + "\r\n";
+            //sw.Start();
+
+            //ReadHolding데이터 0자리에서 10개를 가져온다
+            int[] Data = DataReadHolding(0, 10);
+
+            //데이터를 가져오지 못하면 도루묵
+            if (Data == null) return;
+
+            //sw.Stop();
+            //textBox_State.Text += "Timer Check 2 : " + sw.ElapsedMilliseconds.ToString() + "\r\n";
+            //sw.Start();
+
+            int Number= 1;
+            string input_Mach_CD = "";
+            string input_RealData = "";
+
+            //설비정보에서 번호(1~10)와 가져온 정보 0~9)를 매칭하여 설비코드와 데이터를 나열한다.
+            foreach (int i in Data)
+            {
+                for(int j = 0; j < dt.Rows.Count;j++)
+                {
+                    if(dt.Rows[j]["MACH_NO"].ToString() == Number.ToString())
+                    {
+                        input_Mach_CD += dt.Rows[j]["MACH_CD"].ToString() + ",";
+                        input_RealData += Data[i].ToString() + ",";
+                    }
+                }
+                Number++;
+            }
+
+            if(input_Mach_CD.LastIndexOf(',') == input_Mach_CD.Length-1)
+            {
+                input_Mach_CD = input_Mach_CD.Substring(0, input_Mach_CD.Length - 1);
+            }
+
+            if (input_RealData.LastIndexOf(',') == input_RealData.Length-1)
+            {
+                input_RealData = input_RealData.Substring(0, input_RealData.Length - 1);
+            }
+
+            //sw.Stop();
+            //textBox_State.Text += "Timer Check 3 : " + sw.ElapsedMilliseconds.ToString() + "\r\n";
+            //sw.Start();
+
+            if (DBConnectionSingleton.Instance().SetCommand("HTSaveRealDataAll",
+                DBConnectionSingleton.Instance().getParams("COMP_CD", "0001"),
+                DBConnectionSingleton.Instance().getParams("MACH_CD", input_Mach_CD),
+                DBConnectionSingleton.Instance().getParams("REAL_DATA", input_RealData)))
+            {
+                textBox_State.Text += "DBInsert Complete : " + input_Mach_CD + "\r\n";
+                textBox_State.Text += "DBInsert Complete : " + input_RealData + "\r\n";
+            }
+
+            //sw.Stop();
+
+            //textBox_State.Text += "Timer Check 4 : " + sw.ElapsedMilliseconds.ToString() + "\r\n";
+
+
+            textBox_State.Select(textBox_State.Text.Length, 0);
+            textBox_State.ScrollToCaret();
+
+        }
+
+        public int RunState = 0;
+        List<string[,]> lst = new List<string[,]>();
+        string[,] array;
+        private void timer_AutoInput_Tick(object sender, EventArgs e)
+        {
+            switch(RunState)
+            {
+                case 0:
+                    textBox_State.Text = "";
+                    lst = new List<string[,]>();
+                    break;
+                case 1:
+                    array = DataReadInputToInt64(textBox_Addr_1.Text, textBox_LENGTH_1.Text);
+                    if (array != null) if (array.Length > 1) lst.Add(array);
+                    break;
+                case 2:
+                    array = DataReadInputToInt64(textBox_Addr_2.Text, textBox_LENGTH_2.Text);
+                    if (array != null) if (array.Length > 1) lst.Add(array);
+                    break;
+                case 3:
+                    array = DataReadInput(textBox_Addr_2_2.Text, textBox_LENGTH_2_2.Text);
+                    if (array != null) if (array.Length > 1) lst.Add(array);
+                    break;
+                case 4:
+                    array = DataReadInput(textBox_Addr_3.Text, textBox_LENGTH_3.Text);
+                    if (array != null) if (array.Length > 1) lst.Add(array);
+                    break;
+                case 5:
+                    array = DataReadInput(textBox_Addr_4.Text, textBox_LENGTH_4.Text);
+                    if (array != null) if (array.Length > 1) lst.Add(array);
+                    break;
+                case 6:
+                    array = DataReadInputToInt64(textBox_Addr_5.Text, textBox_LENGTH_5.Text);
+                    if (array != null) if (array.Length > 1) lst.Add(array);
+                    break;
+                case 7:
+                    array = DataReadInputToBit(textBox_Addr_6.Text, textBox_LENGTH_6.Text);
+                    if (array != null) if (array.Length > 1) lst.Add(array);
+                    break;
+                case 8:
+                    DB_Input(lst);
+                    break;
+            }
+            RunState++;
+
+            if(RunState >=10)
+            {
+                RunState = 0;
+            }
+
+
+
+
+            //textBox_State.Text = "";
+            //List<string[,]> lst = new List<string[,]>();
+            //string[,] array;
+
+
+            //array = DataReadInputToInt64(textBox_Addr_1.Text, textBox_LENGTH_1.Text);
+            //if (array != null) if (array.Length > 1) lst.Add(array);
+            //array = DataReadInputToInt64(textBox_Addr_2.Text, textBox_LENGTH_2.Text);
+            //if (array != null) if (array.Length > 1) lst.Add(array);
+            //array = DataReadInput(textBox_Addr_2_2.Text, textBox_LENGTH_2_2.Text);
+            //if (array != null) if (array.Length > 1) lst.Add(array);
+            //array = DataReadInput(textBox_Addr_3.Text, textBox_LENGTH_3.Text);
+            //if (array != null) if (array.Length > 1) lst.Add(array);
+            //array = DataReadInput(textBox_Addr_4.Text, textBox_LENGTH_4.Text);
+            //if (array != null) if (array.Length > 1) lst.Add(array);
+            //array = DataReadInputToInt64(textBox_Addr_5.Text, textBox_LENGTH_5.Text);
+            //if (array != null) if (array.Length > 1) lst.Add(array);
+            //array = DataReadInputToBit(textBox_Addr_6.Text, textBox_LENGTH_6.Text);
+            //if (array != null) if (array.Length > 1) lst.Add(array);
+
+
+
+            //DB_Input(lst);
+
+
+
+            //if (SerialConnectionSingleton.Instance().IsOpen())
+            //{
+            //    try
+            //    {
+
+            //        array = SerialConnectionSingleton.Instance().DataReadHolding("220", "1");
+            //        if (array != null)
+            //        {
+            //            if (array.Length > 1)
+            //            {
+            //                lst.Add(array);
+            //                for (int i = 0; i < array.Length / 2; i++)
+            //                {
+            //                    textBox_State.Text += "[" + array[i, 0] + ":" + array[i, 1] + "]";
+            //                }
+
+            //                textBox_State.Text +=  "\r\n";
+            //            }
+            //        }
+
+
+            //        array = SerialConnectionSingleton.Instance().DataReadHolding("231", "1");
+            //        if (array != null)
+            //        {
+            //            if (array.Length > 1)
+            //            {
+            //                lst.Add(array);
+            //                for (int i = 0; i < array.Length / 2; i++)
+            //                {
+            //                    textBox_State.Text += "[" + array[i, 0] + ":" + array[i, 1] + "]";
+            //                }
+
+            //                textBox_State.Text += "\r\n";
+            //            }
+            //        }
+
+
+            //        array = SerialConnectionSingleton.Instance().DataReadHolding("242", "1");
+            //        if (array != null)
+            //        {
+            //            if (array.Length > 1)
+            //            {
+            //                lst.Add(array);
+            //                for (int i = 0; i < array.Length / 2; i++)
+            //                {
+            //                    textBox_State.Text += "[" + array[i, 0] + ":" + array[i, 1] + "]";
+            //                }
+
+            //                textBox_State.Text += "\r\n";
+            //            }
+            //        }
+
+
+            //        array = SerialConnectionSingleton.Instance().DataReadHolding("253", "1");
+            //        if (array != null)
+            //        {
+            //            if (array.Length > 1)
+            //            {
+            //                lst.Add(array);
+            //                for (int i = 0; i < array.Length / 2; i++)
+            //                {
+            //                    textBox_State.Text += "[" + array[i, 0] + ":" + array[i, 1] + "]";
+            //                }
+
+            //                textBox_State.Text += "\r\n";
+            //            }
+            //        }
+
+
+            //        array = SerialConnectionSingleton.Instance().DataReadHolding("264", "1");
+            //        if (array != null)
+            //        {
+            //            if (array.Length > 1)
+            //            {
+            //                lst.Add(array);
+            //                for (int i = 0; i < array.Length / 2; i++)
+            //                {
+            //                    textBox_State.Text += "[" + array[i, 0] + ":" + array[i, 1] + "]";
+            //                }
+
+            //                textBox_State.Text += "\r\n";
+            //            }
+            //        }
+
+
+            //        array = SerialConnectionSingleton.Instance().DataReadHolding("275", "1");
+            //        if (array != null)
+            //        {
+            //            if (array.Length > 1)
+            //            {
+            //                lst.Add(array);
+            //                for (int i = 0; i < array.Length / 2; i++)
+            //                {
+            //                    textBox_State.Text += "[" + array[i, 0] + ":" + array[i, 1] + "]";
+            //                }
+
+            //                textBox_State.Text += "\r\n";
+            //            }
+            //        }
+
+
+            //        DB_Input(lst);
+            //    }
+            //    catch (Exception ex)
+            //    {
+            //        textBox_State.Text += "시리얼통신 연결중..." + "\r\n";
+            //    }
+            //}
+        }
+
+        private void toggleSwitch_Auto_Toggled(object sender, EventArgs e)
+        {
+            timer_Connect.Enabled = toggleSwitch_Auto.IsOn;
+            timer_AutoInput.Enabled = toggleSwitch_Auto.IsOn;
+            timer_DBInsert.Enabled = toggleSwitch_Auto.IsOn;
+        }
+
+        private void simpleButton5_Click(object sender, EventArgs e)
+        {
+            if(SerialConnectionSingleton.Instance().IsOpen())
+            {
+                //ushort resultBit = SerialConnectionSingleton.Instance().ReadWords_To_ushort(4, 0, 2);
+                //ushort resultBit2 = SerialConnectionSingleton.Instance().ReadWords_To_ushort(4, 1, 1);
+
+
+
+                //for(int i = 1000; i<=1010;i++)
+                //{
+                //    int resultBit = SerialConnectionSingleton.Instance().ReadWords_To_int(1, 4, (ushort)i, 2);
+                //    textBox_State.Text += "Slave1_4_"+i+" : " + resultBit + "\r\n";
+
+                //    textBox_State.Select(textBox_State.Text.Length, 0);
+                //    textBox_State.ScrollToCaret();
+                //}
+
+
+
+                //for (int i = 31000; i <= 31010; i++)
+                //{
+                //    int resultBit = SerialConnectionSingleton.Instance().ReadWords_To_int(1, 4, (ushort)i, 2);
+                //    textBox_State.Text += "Slave1_4_" + i + " : " + resultBit + "\r\n";
+
+                //    textBox_State.Select(textBox_State.Text.Length, 0);
+                //    textBox_State.ScrollToCaret();
+                //}
+
+
+                //for (int i = 1000; i <= 1010; i++)
+                //{
+                //    int resultBit = SerialConnectionSingleton.Instance().ReadWords_To_int(2, 4, (ushort)i, 2);
+                //    textBox_State.Text += "Slave1_3_" + i + " : " + resultBit + "\r\n";
+
+                //    textBox_State.Select(textBox_State.Text.Length, 0);
+                //    textBox_State.ScrollToCaret();
+                //}
+
+
+                int resultBit1 = SerialConnectionSingleton.Instance().ReadWords_To_int(2, 4, 1002, 2);
+                textBox_State.Text += "[SV]Slave2_4_" + 1002 + " : " + resultBit1 + "\r\n";
+
+
+
+                int resultBit2 = SerialConnectionSingleton.Instance().ReadWords_To_int(2, 4, 1005, 2);
+                textBox_State.Text += "[PV]Slave2_4_" + 1005 + " : " + resultBit2 + "\r\n";
+
+
+
+                //for (int i = 31000; i <= 31010; i++)
+                //{
+                //    int resultBit = SerialConnectionSingleton.Instance().ReadWords_To_int(1, 3, (ushort)i, 2);
+                //    textBox_State.Text += "Slave1_3_" + i + " : " + resultBit + "\r\n";
+
+                //    textBox_State.Select(textBox_State.Text.Length, 0);
+                //    textBox_State.ScrollToCaret();
+                //}
+
+
+
+
+
+                //int resultBit3 = SerialConnectionSingleton.Instance().ReadWords_To_int(1, 4, 1005, 2);
+
+                //int resultBit4 = SerialConnectionSingleton.Instance().ReadWords_To_int(2, 4, 31004, 2);
+
+
+
+                //int resultBit3 = SerialConnectionSingleton.Instance().ReadWords_To_int(1, 4, 1005, 2);
+
+
+
+
+
+
+
+
+
+
+
+                //int resultBit4 = SerialConnectionSingleton.Instance().ReadWords_To_int(4, 0, 2);
+
+                //textBox_State.Text += "ReadSerial1 : " + resultBit + "\r\n";
+                //textBox_State.Text += "ReadSerial2 : " + resultBit2 + "\r\n";
+                //textBox_State.Text += "Slave1_4_31004 : " + resultBit3 + "\r\n";
+                //textBox_State.Text += "Slave2_4_31004 : " + resultBit4 + "\r\n";
+            }
+        }
+
+        private void simpleButton6_Click(object sender, EventArgs e)
+        {
+            if (SerialConnectionSingleton.Instance().IsOpen())
+            {
+                try
+                {
+                    int resultBit1 = SerialConnectionSingleton.Instance().ReadWords_To_int(Convert.ToByte(textBox_DEV_ID.Text), Convert.ToByte(textBox_FUNC.Text), Convert.ToUInt16(textBox_ADDR.Text), 2);
+                    textBox_State.Text += "[4Byte]Slave"+ textBox_DEV_ID.Text + "_"+ textBox_FUNC.Text + "_" + textBox_ADDR.Text + " : " + resultBit1 + "\r\n";
+
+
+                    textBox_State.Select(textBox_State.Text.Length, 0);
+                    textBox_State.ScrollToCaret();
+                }catch(Exception ex)
+                {
+                    textBox_State.Text += ex.Message+"\r\n";
+                    textBox_State.Select(textBox_State.Text.Length, 0);
+                    textBox_State.ScrollToCaret();
+                }
+            }
+        }
+
+        private void simpleButton7_Click(object sender, EventArgs e)
+        {
+            if (SerialConnectionSingleton.Instance().IsOpen())
+            {
+                try
+                {
+                    ushort resultBit1 = SerialConnectionSingleton.Instance().ReadWords_To_ushort(Convert.ToByte(textBox_DEV_ID.Text), Convert.ToByte(textBox_FUNC.Text), Convert.ToUInt16(textBox_ADDR.Text), 1);
+                    textBox_State.Text += "[2Byte]Slave" + textBox_DEV_ID.Text + "_" + textBox_FUNC.Text + "_" + textBox_ADDR.Text + " : " + resultBit1 + "\r\n";
+
+
+                    textBox_State.Select(textBox_State.Text.Length, 0);
+                    textBox_State.ScrollToCaret();
+                }
+                catch (Exception ex)
+                {
+                    textBox_State.Text += ex.Message + "\r\n";
+                    textBox_State.Select(textBox_State.Text.Length, 0);
+                    textBox_State.ScrollToCaret();
+                }
+            }
+        }
+
+        private void FormModbus_Load(object sender, EventArgs e)
+        {
+
+        }
+
+
+        public string[,] DataReadHolding(string Addr, string Length)
+        {
+
+            int[] Data = DataReadHolding(Convert.ToInt32(Addr), Convert.ToInt32(Length));
+            if (Data == null) return null;
+
+
+            string[,] result = new string[Data.Length, 2];
+
+            textBox_State.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": ";
+            int aa = 0;
+            foreach (int i in Data)
+            {
+                textBox_State.Text += "[" + (Convert.ToInt32(Addr) + aa).ToString() + ":" + i.ToString() + "].";
+                result[aa, 0] = (Convert.ToInt32(Addr) + aa).ToString();
+                result[aa, 1] = i.ToString();
+                aa++;
+            }
+            textBox_State.Text += "\r\n";
+            textBox_State.Select(textBox_State.Text.Length, 0);
+            textBox_State.ScrollToCaret();
+            return result;
+        }
+
+
+        public string[,] DataReadInput(string Addr, string Length)
+        {
+
+            int[] Data = DataReadInput(Convert.ToInt32(Addr), Convert.ToInt32(Length));
+            if (Data == null) return null;
+
+
+            string[,] result = new string[Data.Length, 2];
+
+            textBox_State.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": ";
+            int aa = 0;
+            foreach (int i in Data)
+            {
+                textBox_State.Text += "[" + (Convert.ToInt32(Addr) + aa).ToString() + ":" + i.ToString() + "].";
+                result[aa, 0] = (Convert.ToInt32(Addr) + aa).ToString();
+                result[aa, 1] = i.ToString();
+                aa++;
+            }
+            textBox_State.Text += "\r\n";
+            textBox_State.Select(textBox_State.Text.Length, 0);
+            textBox_State.ScrollToCaret();
+            return result;
+        }
+
+        public string[,] DataReadInputToBit(string Addr, string Length)
+        {
+            int[] Data = DataReadInput(Convert.ToInt32(Addr), Convert.ToInt32(Length));
+            if (Data == null) return null;
+
+            string[,] result = new string[Data.Length*32, 2];
+
+
+            textBox_State.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": ";
+            int aa = 0;
+            string Result = "";
+            for (int i = 0; i < Data.Length; i++)
+            {
+                byte[] a = BitConverter.GetBytes(Convert.ToInt32(Data[i]));
+
+
+                textBox_State.Text += "[" + (Convert.ToInt32(Addr) + i).ToString() + ":";
+                for (int j = 0; j < a.Length; j++)
+                {
+                    string s = Convert.ToString(a[j], 2).PadLeft(8, '0');
+                    char[] sa = s.ToCharArray();
+                    Array.Reverse(sa);
+
+                    for (int r = 0; r < sa.Length; r++)
+                    {
+                        result[((i * a.Length * 8) + (j * 8)) + r, 0] = (Convert.ToInt32(Addr) + i).ToString()+"."+((j*8)+r).ToString();
+                        result[((i * a.Length * 8) + (j * 8)) + r, 1] = sa[r].ToString();
+                    }
+
+                    textBox_State.Text += new string(sa);
+                    Result += new string(sa);
+
+                }
+                textBox_State.Text += "].";
+            }
+
+
+            textBox_State.Text += "\r\n";
+            textBox_State.Select(textBox_State.Text.Length, 0);
+            textBox_State.ScrollToCaret();
+
+            return result;
+        }
+
+        public void ByteToBit(byte b)
+        {
+
+
+        }
+
+        public string[,] DataReadInputTouUint64(string Addr, string Length)
+        {
+            //Stopwatch sw = new Stopwatch();
+            //sw.Start();
+            int[] Data = DataReadInput(Convert.ToInt32(Addr), Convert.ToInt32(Length));
+            if (Data == null) return null;
+
+
+
+            string[,] result = new string[Data.Length / 2 + ((Data.Length & 2) == 1 ? 1 : 0), 2];
+            //sw.Stop();
+            //textBox_State.Text += "[Time1: " + sw.ElapsedMilliseconds + "] \r\n";
+
+            //sw.Reset();
+            //sw.Start();
+            textBox_State.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": ";
+            int aa = 0;
+            for (int i = 0; i < Data.Length - 1; i++)
+            {
+                byte[] a = BitConverter.GetBytes(Convert.ToInt16(Data[i]));
+                byte[] b = null;
+                if (Data.Length > i + 1)
+                {
+                    b = BitConverter.GetBytes(Convert.ToInt16(Data[i + 1]));
+                }
+                else
+                {
+                    b = new byte[2] { 0, 0 };
+                }
+
+                byte[] c = new byte[4];
+
+                Array.Copy(a, 0, c, 0, a.Length);
+                Array.Copy(b, 0, c, a.Length, b.Length);
+
+
+                textBox_State.Text += "[" + (Convert.ToInt32(Addr) + i).ToString() + ":" + BitConverter.ToInt32(c, 0).ToString() + "].";
+
+
+                result[aa, 0] = (Convert.ToInt32(Addr) + i).ToString();
+                result[aa, 1] = BitConverter.ToUInt32(c, 0).ToString();
+
+
+                aa++;
+                i++;
+            }
+
+            foreach (int i in Data)
+            {
+            }
+            textBox_State.Text += "\r\n";
+            textBox_State.Select(textBox_State.Text.Length, 0);
+            textBox_State.ScrollToCaret();
+
+            //sw.Stop();
+            //textBox_State.Text += "[Time2: " + sw.ElapsedMilliseconds + "] \r\n";
+            return result;
+        }
+
+
+
+        public string[,] DataReadInputToInt64(string Addr, string Length)
+        {
+            //Stopwatch sw = new Stopwatch();
+            //sw.Start();
+            int[] Data = DataReadInput(Convert.ToInt32(Addr), Convert.ToInt32(Length));
+            if (Data == null) return null;
+
+
+
+            string[,] result = new string[Data.Length/2+((Data.Length&2)==1?1:0), 2];
+            //sw.Stop();
+            //textBox_State.Text += "[Time1: " + sw.ElapsedMilliseconds + "] \r\n";
+
+            //sw.Reset();
+            //sw.Start();
+           textBox_State.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ": ";
+            int aa = 0;
+            for(int i=0 ; i<Data.Length-1;i++)
+            {
+                byte[] a = BitConverter.GetBytes(Convert.ToInt16(Data[i]));
+                byte[] b = null;
+                if (Data.Length > i+1)
+                {
+                    b = BitConverter.GetBytes(Convert.ToInt16(Data[i + 1]));
+                }else
+                {
+                    b = new byte[2] {0,0};
+                }
+
+                byte[] c = new byte[4];
+
+                Array.Copy(a, 0, c, 0, a.Length);
+                Array.Copy(b, 0, c, a.Length, b.Length);
+
+
+                textBox_State.Text += "[" + (Convert.ToInt32(Addr) + i).ToString() + ":" + BitConverter.ToInt32(c,0).ToString() + "].";
+
+
+                result[aa, 0] = (Convert.ToInt32(Addr) + i).ToString();
+                result[aa, 1] = BitConverter.ToInt32(c, 0).ToString();
+
+
+                aa++;
+                i++;
+            }
+
+            foreach (int i in Data)
+            {
+            }
+            textBox_State.Text += "\r\n";
+            textBox_State.Select(textBox_State.Text.Length, 0);
+            textBox_State.ScrollToCaret();
+
+            //sw.Stop();
+            //textBox_State.Text += "[Time2: " + sw.ElapsedMilliseconds + "] \r\n";
+            return result;
+        }
+
+
+
+        private void simpleButton_InputRegister_1_Click(object sender, EventArgs e)
+        {
+            textBox_State.Text = "";
+            string[,] Data = DataReadInputToInt64(textBox_Addr_1.Text, textBox_LENGTH_1.Text);
+            DB_Input(Data);
+        }
+
+        private void simpleButton_InputRegister_2_Click(object sender, EventArgs e)
+        {
+            textBox_State.Text = "";
+            string[,] Data = DataReadInputToInt64(textBox_Addr_2.Text, textBox_LENGTH_2.Text);
+            DB_Input(Data);
+        }
+
+        private void simpleButton_InputRegister_3_Click(object sender, EventArgs e)
+        {
+            textBox_State.Text = "";
+            string[,] Data = DataReadInput(textBox_Addr_3.Text, textBox_LENGTH_3.Text);
+            DB_Input(Data);
+        }
+
+        private void simpleButton_InputRegister_4_Click(object sender, EventArgs e)
+        {
+            textBox_State.Text = "";
+            string[,] Data = DataReadInput(textBox_Addr_4.Text, textBox_LENGTH_4.Text);
+            DB_Input(Data);
+        }
+
+        private void simpleButton_InputRegister_5_Click(object sender, EventArgs e)
+        {
+            textBox_State.Text = "";
+            string[,] Data = DataReadInputTouUint64(textBox_Addr_5.Text, textBox_LENGTH_5.Text);
+            DB_Input(Data);
+        }
+
+        private void simpleButton_InputRegister_6_Click(object sender, EventArgs e)
+        {
+            //textBox_State.Text = "";
+            string[,] Data = DataReadInputToBit(textBox_Addr_6.Text, textBox_LENGTH_6.Text);
+            //for (int i = 0; i < Data.Length / 2; i++)
+            //{
+            //    textBox_State.Text += "["+Data[i,0]+ " : "+Data[i,1]+"]";
+            //}
+            //textBox_State.Text += "\r\n";
+            DB_Input(Data);
+        }
+
+        private void simpleButton_InputRegister_2_2_Click(object sender, EventArgs e)
+        {
+            textBox_State.Text = "";
+            string[,] Data = DataReadInput(textBox_Addr_2_2.Text, textBox_LENGTH_2_2.Text);
+            DB_Input(Data);
+        }
+
+
+        public void DB_Input(List<string[,]> Data)
+        {
+            m_Data = Data;
+        }
+
+        public void DB_Input(string[,]Data)
+        {
+            if (!DBConnectionSingleton.Instance().isConnect()) return;
+
+            //DB 설비정보내에서 온도계 정보를 가져옵니다.[온도계는 CODE정보로 E03으로 저장되어있다]
+            DataTable dt = DBConnectionSingleton.Instance().GetSqlData("SELECT [COMP_CD],[MACH_CD],[MACH_NO],[MACH_NM] FROM [dbo].[T_STD_MACH] m where m.COMP_CD = '0001' order by MACH_NO asc");
+            if (dt == null) return;
+
+
+            string input_Mach_CD = "";
+            string input_RealData = "";
+
+            textBox_State.Text += "TEST START \r\n";
+            if (Data != null)
+            {
+                for (int i = 0; i < Data.Length / 2; i++)
+                {
+                    for (int j = 0; j < dt.Rows.Count; j++)
+                    {
+                        if (dt.Rows[j]["MACH_NO"].ToString() == Data[i,0].ToString())
+                        {
+                            textBox_State.Text += "["+ dt.Rows[j]["MACH_CD"].ToString() + ":"+ Data[i, 1].ToString() + "]";
+                            input_Mach_CD += dt.Rows[j]["MACH_CD"].ToString() + ",";
+                            input_RealData += Data[i,1].ToString() + ",";
+                            break;
+                        }
+                    }
+                }
+            }
+            textBox_State.Text += "TEST END\r\n";
+
+
+            if (input_Mach_CD.LastIndexOf(',') == input_Mach_CD.Length - 1 && input_Mach_CD.LastIndexOf(',') != -1)
+            {
+                input_Mach_CD = input_Mach_CD.Substring(0, input_Mach_CD.Length - 1);
+            }
+
+            if (input_RealData.LastIndexOf(',') == input_RealData.Length - 1 && input_RealData.LastIndexOf(',') != -1)
+            {
+                input_RealData = input_RealData.Substring(0, input_RealData.Length - 1);
+            }
+
+            //sw.Stop();
+
+            //textBox_State.Text += "Timer Check 3 : " + sw.ElapsedMilliseconds.ToString() + "\r\n";
+
+            //sw.Start();
+
+            if (input_Mach_CD == "" || input_RealData == "") return;
+
+            if (DBConnectionSingleton.Instance().SetCommand("HTSaveRealDataAll",
+                DBConnectionSingleton.Instance().getParams("COMP_CD", "0001"),
+                DBConnectionSingleton.Instance().getParams("MACH_CD", input_Mach_CD),
+                DBConnectionSingleton.Instance().getParams("REAL_DATA", input_RealData)))
+            {
+                textBox_State.Text += "DBInsert Complete : " + input_Mach_CD + "\r\n";
+                textBox_State.Text += "DBInsert Complete : " + input_RealData + "\r\n";
+            }
+
+
+        }
+
+        class MACHDATA
+        {
+            public string MACH_NO { get; set; }
+            public string DATA { get; set; }
+        }
+
+        public void All_Data_Insert()
+        {
+            //DB 설비정보내에서 온도계 정보를 가져옵니다.[온도계는 CODE정보로 E03으로 저장되어있다]
+            DataTable dt = DBConnectionSingleton.Instance().GetSqlData("SELECT [COMP_CD],[MACH_CD],[MACH_NO],[MACH_NM] FROM [dbo].[T_STD_MACH] m where m.COMP_CD = '0001' order by MACH_CD asc");
+            if (dt == null) return;
+
+
+            string input_Mach_CD = "";
+            string input_RealData = "";
+
+            List<MACHDATA> inputData = new List<MACHDATA>();
+
+            if (m_Data != null)
+            {
+                if (m_Data.Count >= 1)
+                {
+                    foreach (string[,] strData in m_Data)
+                    {
+                        for (int i = 0; i < strData.Length / 2; i++)
+                        {
+                            for (int j = 0; j < dt.Rows.Count; j++)
+                            {
+                                if (dt.Rows[j]["MACH_NO"].ToString() == strData[i, 0].ToString())
+                                {
+                                    MACHDATA MData = new MACHDATA();
+                                    MData.MACH_NO = dt.Rows[j]["MACH_CD"].ToString();
+                                    MData.DATA = strData[i, 1].ToString();
+                                    inputData.Add(MData);
+
+                                    //input_Mach_CD += dt.Rows[j]["MACH_CD"].ToString() + ",";
+                                    //input_RealData += strData[i, 1].ToString() + ",";
+                                    break;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            List<MACHDATA> sortList = inputData.OrderBy(x => x.MACH_NO).ThenBy(x => x.DATA).ToList();
+
+            foreach(MACHDATA md in sortList)
+            {
+                input_Mach_CD += md.MACH_NO + ",";
+                input_RealData += md.DATA + ",";
+            }
+
+
+
+            if (input_Mach_CD.LastIndexOf(',') == input_Mach_CD.Length - 1 && input_Mach_CD.LastIndexOf(',') != -1)
+            {
+                input_Mach_CD = input_Mach_CD.Substring(0, input_Mach_CD.Length - 1);
+            }
+
+            if (input_RealData.LastIndexOf(',') == input_RealData.Length - 1 && input_RealData.LastIndexOf(',') != -1)
+            {
+                input_RealData = input_RealData.Substring(0, input_RealData.Length - 1);
+            }
+
+            //sw.Stop();
+
+            //textBox_State.Text += "Timer Check 3 : " + sw.ElapsedMilliseconds.ToString() + "\r\n";
+
+            //sw.Start();
+
+            if (input_Mach_CD == "" || input_RealData == "") return;
+
+            if (DBConnectionSingleton.Instance().SetCommand("HTSaveRealDataAll",
+                DBConnectionSingleton.Instance().getParams("COMP_CD", "0001"),
+                DBConnectionSingleton.Instance().getParams("MACH_CD", input_Mach_CD),
+                DBConnectionSingleton.Instance().getParams("REAL_DATA", input_RealData)))
+            {
+                textBox_State.Text += "DBInsert Complete : " + input_Mach_CD + "\r\n";
+                textBox_State.Text += "DBInsert Complete : " + input_RealData + "\r\n";
+            }
+
+
+
+
+        }
+
+
+
+
+
+        private void simpleButton_All_Click(object sender, EventArgs e)
+        {
+            textBox_State.Text = "";
+            var lst = new List<string[,]>();
+            string[,] array;
+            array = DataReadInputToInt64(textBox_Addr_1.Text, textBox_LENGTH_1.Text);
+            if(array!=null) if (array.Length > 1) lst.Add(array);
+            array = DataReadInputToInt64(textBox_Addr_2.Text, textBox_LENGTH_2.Text);
+            if (array != null) if (array.Length > 1) lst.Add(array);
+            array = DataReadInput(textBox_Addr_2_2.Text, textBox_LENGTH_2_2.Text);
+            if (array != null) if (array.Length > 1) lst.Add(array);
+            array = DataReadInput(textBox_Addr_3.Text, textBox_LENGTH_3.Text);
+            if (array != null) if (array.Length > 1) lst.Add(array);
+            array = DataReadInput(textBox_Addr_4.Text, textBox_LENGTH_4.Text);
+            if (array != null) if (array.Length > 1) lst.Add(array);
+            array = DataReadInputToInt64(textBox_Addr_5.Text, textBox_LENGTH_5.Text);
+            if (array != null) if (array.Length > 1) lst.Add(array);
+            array = DataReadInputToBit(textBox_Addr_6.Text, textBox_LENGTH_6.Text);
+            if (array != null) if (array.Length > 1) lst.Add(array);
+
+
+            DB_Input(lst);
+        }
+
+        private void timer_DBConnect_Tick(object sender, EventArgs e)
+        {
+                try
+                {
+                    if (!DBConnectionSingleton.Instance().isConnect())
+                    if (DBConnectionSingleton.Instance().Connect())
+                    {
+                        textBox_State.Text += "DB_Connected\r\n";
+                        panel_DBConnect.BackColor = Color.FromArgb(192, 255, 192);
+                    }
+                    else
+                    {
+                        panel_DBConnect.BackColor = Color.FromArgb(255, 192, 192);
+                    }
+                }
+                catch (Exception ex)
+                {
+                    textBox_State.Text += "Connect Error : " + ex.Message + "\r\n";
+                }
+
+
+            if (DBConnectionSingleton.Instance().isConnect())
+            {
+
+                All_Data_Insert();
+            }
+        }
+
+
+        private void timer_Log_Tick(object sender, EventArgs e)
+        {
+            if (DBConnectionSingleton.Instance().SetCommand("HTInsertRealToLog"))
+            {
+                //textBox_State.Text += "DBInsert Complete : Log Insert\r\n";
+            }
+        }
+
+        private void toggleSwitch_Log_Toggled(object sender, EventArgs e)
+        {
+            timer_Log.Enabled = toggleSwitch_Log.IsOn;
+        }
+
+        private void simpleButton8_Click_1(object sender, EventArgs e)
+        {
+        }
+    }
+}
 
ModbusTest/FormModbus.resx (added)
+++ ModbusTest/FormModbus.resx
@@ -0,0 +1,132 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="timer_Connect.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>17, 17</value>
+  </metadata>
+  <metadata name="timer_AutoInput.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>149, 17</value>
+  </metadata>
+  <metadata name="timer_DBInsert.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>291, 17</value>
+  </metadata>
+  <metadata name="timer_Log.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
+    <value>424, 17</value>
+  </metadata>
+</root>(No newline at end of file)
 
ModbusTest/KHModbus.csproj (added)
+++ ModbusTest/KHModbus.csproj
@@ -0,0 +1,98 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{2A789031-AEE6-436C-B5E0-AB764F55FCD2}</ProjectGuid>
+    <OutputType>WinExe</OutputType>
+    <RootNamespace>ModbusTest</RootNamespace>
+    <AssemblyName>ModbusTest</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <Deterministic>true</Deterministic>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <PlatformTarget>AnyCPU</PlatformTarget>
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="DevExpress.Data.v14.1, Version=14.1.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
+    <Reference Include="DevExpress.Printing.v14.1.Core, Version=14.1.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
+    <Reference Include="DevExpress.Sparkline.v14.1.Core, Version=14.1.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
+    <Reference Include="DevExpress.Utils.v14.1, Version=14.1.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" />
+    <Reference Include="DevExpress.XtraEditors.v14.1, Version=14.1.10.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a, processorArchitecture=MSIL" />
+    <Reference Include="EasyModbus, Version=5.6.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\packages\EasyModbusTCP.5.6.0\lib\net40\EasyModbus.dll</HintPath>
+    </Reference>
+    <Reference Include="NModbus4, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\packages\NModbus4.2.1.0\lib\net40\NModbus4.dll</HintPath>
+    </Reference>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Data.Linq" />
+    <Reference Include="System.Printing" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Deployment" />
+    <Reference Include="System.Drawing" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Windows.Forms" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="DBConnectionSingleton.cs" />
+    <Compile Include="FormModbus.cs">
+      <SubType>Form</SubType>
+    </Compile>
+    <Compile Include="FormModbus.Designer.cs">
+      <DependentUpon>FormModbus.cs</DependentUpon>
+    </Compile>
+    <Compile Include="Program.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="SerialConnectionSingleton.cs" />
+    <EmbeddedResource Include="FormModbus.resx">
+      <DependentUpon>FormModbus.cs</DependentUpon>
+    </EmbeddedResource>
+    <EmbeddedResource Include="Properties\Resources.resx">
+      <Generator>ResXFileCodeGenerator</Generator>
+      <LastGenOutput>Resources.Designer.cs</LastGenOutput>
+      <SubType>Designer</SubType>
+    </EmbeddedResource>
+    <Compile Include="Properties\Resources.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Resources.resx</DependentUpon>
+    </Compile>
+    <None Include="packages.config" />
+    <None Include="Properties\Settings.settings">
+      <Generator>SettingsSingleFileGenerator</Generator>
+      <LastGenOutput>Settings.Designer.cs</LastGenOutput>
+    </None>
+    <Compile Include="Properties\Settings.Designer.cs">
+      <AutoGen>True</AutoGen>
+      <DependentUpon>Settings.settings</DependentUpon>
+      <DesignTimeSharedInput>True</DesignTimeSharedInput>
+    </Compile>
+  </ItemGroup>
+  <ItemGroup>
+    <None Include="App.config" />
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+</Project>(No newline at end of file)
 
ModbusTest/Program.cs (added)
+++ ModbusTest/Program.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace KHModbus
+{
+    static class Program
+    {
+        /// <summary>
+        /// 해당 애플리케이션의 주 진입점입니다.
+        /// </summary>
+        [STAThread]
+        static void Main()
+        {
+            Application.EnableVisualStyles();
+            Application.SetCompatibleTextRenderingDefault(false);
+
+            DBConnectionSingleton.Instance();
+
+            Application.Run(new FormModbus());
+        }
+    }
+}
 
ModbusTest/Properties/AssemblyInfo.cs (added)
+++ ModbusTest/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 
+// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
+// 이러한 특성 값을 변경하세요.
+[assembly: AssemblyTitle("KHModbus")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("KHModbus")]
+[assembly: AssemblyCopyright("Copyright ©  2022")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 
+// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
+// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
+[assembly: ComVisible(false)]
+
+// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
+[assembly: Guid("2a789031-aee6-436c-b5e0-ab764f55fcd2")]
+
+// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
+//
+//      주 버전
+//      부 버전 
+//      빌드 번호
+//      수정 버전
+//
+// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
+// 기본값으로 할 수 있습니다.
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
 
ModbusTest/Properties/Resources.Designer.cs (added)
+++ ModbusTest/Properties/Resources.Designer.cs
@@ -0,0 +1,70 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     이 코드는 도구를 사용하여 생성되었습니다.
+//     런타임 버전:4.0.30319.42000
+//
+//     파일 내용을 변경하면 잘못된 동작이 발생할 수 있으며, 코드를 다시 생성하면
+//     이러한 변경 내용이 손실됩니다.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+
+namespace KHModbus.Properties
+{
+    /// <summary>
+    ///   지역화된 문자열 등을 찾기 위한 강력한 형식의 리소스 클래스입니다.
+    /// </summary>
+    // 이 클래스는 ResGen 또는 Visual Studio와 같은 도구를 통해 StronglyTypedResourceBuilder
+    // 클래스에서 자동으로 생성되었습니다.
+    // 멤버를 추가하거나 제거하려면 .ResX 파일을 편집한 다음 /str 옵션을 사용하여
+    // ResGen을 다시 실행하거나 VS 프로젝트를 다시 빌드하십시오.
+    [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()
+        {
+        }
+
+        /// <summary>
+        ///   이 클래스에서 사용하는 캐시된 ResourceManager 인스턴스를 반환합니다.
+        /// </summary>
+        [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("KHModbus.Properties.Resources", typeof(Resources).Assembly);
+                    resourceMan = temp;
+                }
+                return resourceMan;
+            }
+        }
+
+        /// <summary>
+        ///   이 강력한 형식의 리소스 클래스를 사용하여 모든 리소스 조회에 대해 현재 스레드의 CurrentUICulture 속성을
+        ///   재정의합니다.
+        /// </summary>
+        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+        internal static global::System.Globalization.CultureInfo Culture
+        {
+            get
+            {
+                return resourceCulture;
+            }
+            set
+            {
+                resourceCulture = value;
+            }
+        }
+    }
+}
 
ModbusTest/Properties/Resources.resx (added)
+++ ModbusTest/Properties/Resources.resx
@@ -0,0 +1,117 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+</root>(No newline at end of file)
 
ModbusTest/Properties/Settings.Designer.cs (added)
+++ ModbusTest/Properties/Settings.Designer.cs
@@ -0,0 +1,29 @@
+//------------------------------------------------------------------------------
+// <auto-generated>
+//     This code was generated by a tool.
+//     Runtime Version:4.0.30319.42000
+//
+//     Changes to this file may cause incorrect behavior and will be lost if
+//     the code is regenerated.
+// </auto-generated>
+//------------------------------------------------------------------------------
+
+
+namespace KHModbus.Properties
+{
+    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.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;
+            }
+        }
+    }
+}
 
ModbusTest/Properties/Settings.settings (added)
+++ ModbusTest/Properties/Settings.settings
@@ -0,0 +1,7 @@
+<?xml version='1.0' encoding='utf-8'?>
+<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
+  <Profiles>
+    <Profile Name="(Default)" />
+  </Profiles>
+  <Settings />
+</SettingsFile>
 
ModbusTest/SerialConnectionSingleton.cs (added)
+++ ModbusTest/SerialConnectionSingleton.cs
@@ -0,0 +1,375 @@
+using System;
+using System.Collections.Generic;
+using System.IO.Ports;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace KHModbus
+{
+    class SerialConnectionSingleton
+    {
+        private static SerialConnectionSingleton SerialConnection;
+
+        public object lockSend = new object();
+
+        private SerialPort mSerialPort;
+
+        List<byte> _readPacket;
+        ManualResetEvent _eventReset = new ManualResetEvent(false);
+        int responseLength;
+        bool isWatingResponse;
+
+        public static SerialConnectionSingleton Instance()
+        {
+            if (SerialConnection == null)
+            {
+                SerialConnection = new SerialConnectionSingleton();
+            }
+            return SerialConnection;
+        }
+
+        public void InitialModBus()
+        {
+            mSerialPort = new SerialPort();
+            mSerialPort.PortName = "COM1";
+            mSerialPort.BaudRate = 9600;
+            mSerialPort.Parity = Parity.None;
+            mSerialPort.StopBits = StopBits.One;
+            mSerialPort.DataBits = 8;
+            //_serialPort.ReadTimeout = 500;
+            SlaveNo = 1;
+            responseLength = 0;
+            isWatingResponse = false;
+
+            _readPacket = new List<byte>();
+            mSerialPort.DataReceived += DataReceived;
+        }
+
+        private void DataReceived(object sender, SerialDataReceivedEventArgs e)
+        {
+            if (isWatingResponse)
+            {
+                Thread.Sleep(100);
+                SerialPort port = (SerialPort)sender;
+                // 현재까지 도착한 데이타 모두 읽기
+                byte[] vs = new byte[responseLength];
+                port.Read(vs, 0, responseLength);
+                _readPacket.AddRange(vs);
+                isWatingResponse = false;
+                _eventReset.Set();
+            }
+        }
+
+
+        public bool IsOpen()
+        {
+            try
+            {
+                if(mSerialPort.IsOpen)
+                {
+                    return true;
+                }else
+                {
+                    return Open();
+                }
+            }
+            catch (Exception ex)
+            {
+                return false;
+            }
+        }
+
+        public bool Open()
+        {
+            try
+            {
+                mSerialPort.Open();
+                return true;
+            }
+            catch (Exception ex)
+            {
+                return false;
+            }
+        }
+
+
+
+        public byte[] ReadBit(byte functionCode, ushort startAddress, ushort numberOfBit)
+        {
+            lock (lockSend)
+            {
+                byte[] byteStartAddress = BitConverter.GetBytes(startAddress);
+                byte[] byteLength = BitConverter.GetBytes(numberOfBit);
+                List<byte> packet = new List<byte>() { SlaveNo, functionCode, byteStartAddress[1], byteStartAddress[0], byteLength[1], byteLength[0] };
+
+                packet.AddRange(BitConverter.GetBytes(ComputeCrc(packet.ToArray())));
+
+                _readPacket.Clear();
+
+                // slave, functionCode, length, (byte high, byte low)n + crc1 + crc2
+                responseLength = 3 + numberOfBit / 8 + 2;
+
+                isWatingResponse = true;
+                mSerialPort.Write(packet.ToArray(), 0, packet.Count);
+
+                _eventReset.WaitOne(500);
+                _eventReset.Reset();
+
+                //byte[] readPacket = new byte[3 + length * 2 + 2];
+                if (_readPacket.Count == 0)
+                {
+                    return new byte[1] { 0 };
+                }
+
+                var crcCheck = _readPacket.Take(_readPacket.Count - 2).ToArray();
+                byte[] computedReadCrc = BitConverter.GetBytes(ComputeCrc(crcCheck));
+                if (_readPacket[_readPacket.Count - 2] != computedReadCrc[0] || _readPacket[_readPacket.Count - 1] != computedReadCrc[1])
+                {
+                    return new byte[1] { 0 };
+                }
+                else
+                {
+                    _readPacket.RemoveAt(0);
+                    _readPacket.RemoveAt(0);
+                    _readPacket.RemoveAt(0);
+                    _readPacket.RemoveAt(_readPacket.Count - 1);
+                    _readPacket.RemoveAt(_readPacket.Count - 1);
+                    return _readPacket.ToArray();
+                }
+            }
+        }
+
+
+
+        public string[,] DataReadHolding(string Addr, string Length)
+        {
+            byte[] Data = SerialConnectionSingleton.Instance().ReadWords(1, 4, Convert.ToUInt16(Addr), Convert.ToUInt16(Length));
+            if (Data == null) return null;
+
+
+            ushort resultushort = 0;
+            if (Data.Length == 2)
+            {
+                resultushort = (ushort)((((byte)Data[0]) * 256) + ((byte)Data[1]));
+            }
+
+
+            string[,] result = new string[1, 2];
+
+            result[0, 0] = (Convert.ToInt32(Addr)).ToString();
+            result[0, 1] = resultushort.ToString();
+
+
+            return result;
+        }
+
+
+
+        public ushort ReadWords_To_ushort(byte SetSlaveNo, byte functionCode, ushort startAddress, ushort length)
+        {
+
+            var resultBit = SerialConnectionSingleton.Instance().ReadWords(SetSlaveNo, functionCode, startAddress, length);
+            ushort resultushort = 0;
+            if (resultBit.Length == 2)
+            {
+                resultushort = (ushort)((((byte)resultBit[0]) * 256) + ((byte)resultBit[1]));
+            }
+            return resultushort;
+        }
+
+        public int ReadWords_To_int(byte SetSlaveNo, byte functionCode, ushort startAddress, ushort length)
+        {
+
+            var resultBit = SerialConnectionSingleton.Instance().ReadWords(SetSlaveNo, functionCode, startAddress, length);
+            int resultushort = 0;
+            if (resultBit.Length == 4)
+            {
+                resultushort = (int)((((int)resultBit[0]) * (256 * 256 * 256)) + (((int)resultBit[1]) * 65536) + (((int)resultBit[2]) * 256) + ((int)resultBit[3]));
+            }
+            return resultushort;
+        }
+
+
+
+        public byte[] ReadWords(byte SetSlaveNo, byte functionCode, ushort startAddress, ushort length)
+        {
+            lock (lockSend)
+            {
+                byte[] byteStartAddress = BitConverter.GetBytes(startAddress);
+                byte[] byteLength = BitConverter.GetBytes(length);
+                List<byte> packet = new List<byte>() { SetSlaveNo, functionCode, byteStartAddress[1], byteStartAddress[0], byteLength[1], byteLength[0] };
+
+                packet.AddRange(BitConverter.GetBytes(ComputeCrc(packet.ToArray())));
+
+                _readPacket.Clear();
+
+                // slave, functionCode, length, (byte high, byte low)n + crc1 + crc2
+                responseLength = 3 + length * 2 + 2;
+
+                isWatingResponse = true;
+                mSerialPort.Write(packet.ToArray(), 0, packet.Count);
+
+                _eventReset.WaitOne(500);
+                _eventReset.Reset();
+
+                //byte[] readPacket = new byte[3 + length * 2 + 2];
+                if (_readPacket.Count == 0)
+                {
+                    return new byte[1] { 0 };
+                }
+
+                var crcCheck = _readPacket.Take(_readPacket.Count - 2).ToArray();
+                byte[] computedReadCrc = BitConverter.GetBytes(ComputeCrc(crcCheck));
+                if (_readPacket[_readPacket.Count - 2] != computedReadCrc[0] || _readPacket[_readPacket.Count - 1] != computedReadCrc[1])
+                {
+                    return new byte[1] { 0 };
+                }
+                else
+                {
+                    _readPacket.RemoveAt(0);
+                    _readPacket.RemoveAt(0);
+                    _readPacket.RemoveAt(0);
+                    _readPacket.RemoveAt(_readPacket.Count - 1);
+                    _readPacket.RemoveAt(_readPacket.Count - 1);
+                    return _readPacket.ToArray();
+                }
+            }
+        }
+
+
+        //public byte[] ReadWords(byte functionCode, ushort startAddress, ushort length)
+        //{
+        //    lock (lockSend)
+        //    {
+        //        byte[] byteStartAddress = BitConverter.GetBytes(startAddress);
+        //        byte[] byteLength = BitConverter.GetBytes(length);
+        //        List<byte> packet = new List<byte>() { SlaveNo, functionCode, byteStartAddress[1], byteStartAddress[0], byteLength[1], byteLength[0] };
+
+        //        packet.AddRange(BitConverter.GetBytes(ComputeCrc(packet.ToArray())));
+
+        //        _readPacket.Clear();
+
+        //        // slave, functionCode, length, (byte high, byte low)n + crc1 + crc2
+        //        responseLength = 3 + length * 2 + 2;
+
+        //        isWatingResponse = true;
+        //        mSerialPort.Write(packet.ToArray(), 0, packet.Count);
+
+        //        _eventReset.WaitOne(500);
+        //        _eventReset.Reset();
+
+        //        //byte[] readPacket = new byte[3 + length * 2 + 2];
+        //        if (_readPacket.Count == 0)
+        //        {
+        //            return new byte[1] { 0 };
+        //        }
+
+        //        var crcCheck = _readPacket.Take(_readPacket.Count - 2).ToArray();
+        //        byte[] computedReadCrc = BitConverter.GetBytes(ComputeCrc(crcCheck));
+        //        if (_readPacket[_readPacket.Count - 2] != computedReadCrc[0] || _readPacket[_readPacket.Count - 1] != computedReadCrc[1])
+        //        {
+        //            return new byte[1] { 0 };
+        //        }
+        //        else
+        //        {
+        //            _readPacket.RemoveAt(0);
+        //            _readPacket.RemoveAt(0);
+        //            _readPacket.RemoveAt(0);
+        //            _readPacket.RemoveAt(_readPacket.Count - 1);
+        //            _readPacket.RemoveAt(_readPacket.Count - 1);
+        //            return _readPacket.ToArray();
+        //        }
+        //    }
+        //}
+
+        public UInt16 ComputeCrc(byte[] data)
+        {
+            ushort crc = 0xFFFF;
+
+            foreach (byte datum in data)
+            {
+                crc = (ushort)((crc >> 8) ^ CrcTable[(crc ^ datum) & 0xFF]);
+            }
+
+            return crc;
+        }
+
+
+
+        private readonly ushort[] CrcTable = {
+            0X0000, 0XC0C1, 0XC181, 0X0140, 0XC301, 0X03C0, 0X0280, 0XC241,
+            0XC601, 0X06C0, 0X0780, 0XC741, 0X0500, 0XC5C1, 0XC481, 0X0440,
+            0XCC01, 0X0CC0, 0X0D80, 0XCD41, 0X0F00, 0XCFC1, 0XCE81, 0X0E40,
+            0X0A00, 0XCAC1, 0XCB81, 0X0B40, 0XC901, 0X09C0, 0X0880, 0XC841,
+            0XD801, 0X18C0, 0X1980, 0XD941, 0X1B00, 0XDBC1, 0XDA81, 0X1A40,
+            0X1E00, 0XDEC1, 0XDF81, 0X1F40, 0XDD01, 0X1DC0, 0X1C80, 0XDC41,
+            0X1400, 0XD4C1, 0XD581, 0X1540, 0XD701, 0X17C0, 0X1680, 0XD641,
+            0XD201, 0X12C0, 0X1380, 0XD341, 0X1100, 0XD1C1, 0XD081, 0X1040,
+            0XF001, 0X30C0, 0X3180, 0XF141, 0X3300, 0XF3C1, 0XF281, 0X3240,
+            0X3600, 0XF6C1, 0XF781, 0X3740, 0XF501, 0X35C0, 0X3480, 0XF441,
+            0X3C00, 0XFCC1, 0XFD81, 0X3D40, 0XFF01, 0X3FC0, 0X3E80, 0XFE41,
+            0XFA01, 0X3AC0, 0X3B80, 0XFB41, 0X3900, 0XF9C1, 0XF881, 0X3840,
+            0X2800, 0XE8C1, 0XE981, 0X2940, 0XEB01, 0X2BC0, 0X2A80, 0XEA41,
+            0XEE01, 0X2EC0, 0X2F80, 0XEF41, 0X2D00, 0XEDC1, 0XEC81, 0X2C40,
+            0XE401, 0X24C0, 0X2580, 0XE541, 0X2700, 0XE7C1, 0XE681, 0X2640,
+            0X2200, 0XE2C1, 0XE381, 0X2340, 0XE101, 0X21C0, 0X2080, 0XE041,
+            0XA001, 0X60C0, 0X6180, 0XA141, 0X6300, 0XA3C1, 0XA281, 0X6240,
+            0X6600, 0XA6C1, 0XA781, 0X6740, 0XA501, 0X65C0, 0X6480, 0XA441,
+            0X6C00, 0XACC1, 0XAD81, 0X6D40, 0XAF01, 0X6FC0, 0X6E80, 0XAE41,
+            0XAA01, 0X6AC0, 0X6B80, 0XAB41, 0X6900, 0XA9C1, 0XA881, 0X6840,
+            0X7800, 0XB8C1, 0XB981, 0X7940, 0XBB01, 0X7BC0, 0X7A80, 0XBA41,
+            0XBE01, 0X7EC0, 0X7F80, 0XBF41, 0X7D00, 0XBDC1, 0XBC81, 0X7C40,
+            0XB401, 0X74C0, 0X7580, 0XB541, 0X7700, 0XB7C1, 0XB681, 0X7640,
+            0X7200, 0XB2C1, 0XB381, 0X7340, 0XB101, 0X71C0, 0X7080, 0XB041,
+            0X5000, 0X90C1, 0X9181, 0X5140, 0X9301, 0X53C0, 0X5280, 0X9241,
+            0X9601, 0X56C0, 0X5780, 0X9741, 0X5500, 0X95C1, 0X9481, 0X5440,
+            0X9C01, 0X5CC0, 0X5D80, 0X9D41, 0X5F00, 0X9FC1, 0X9E81, 0X5E40,
+            0X5A00, 0X9AC1, 0X9B81, 0X5B40, 0X9901, 0X59C0, 0X5880, 0X9841,
+            0X8801, 0X48C0, 0X4980, 0X8941, 0X4B00, 0X8BC1, 0X8A81, 0X4A40,
+            0X4E00, 0X8EC1, 0X8F81, 0X4F40, 0X8D01, 0X4DC0, 0X4C80, 0X8C41,
+            0X4400, 0X84C1, 0X8581, 0X4540, 0X8701, 0X47C0, 0X4680, 0X8641,
+            0X8201, 0X42C0, 0X4380, 0X8341, 0X4100, 0X81C1, 0X8081, 0X4040 };
+
+
+        public int BaudRate
+        {
+            get { return mSerialPort.BaudRate; }
+            set { mSerialPort.BaudRate = value; }
+        }
+        public Parity Parity
+        {
+            get { return mSerialPort.Parity; }
+            set { mSerialPort.Parity = value; }
+        }
+        public StopBits StopBits
+        {
+            get { return mSerialPort.StopBits; }
+            set { mSerialPort.StopBits = value; }
+        }
+        public int DataBits
+        {
+            get { return mSerialPort.DataBits; }
+            set { mSerialPort.DataBits = value; }
+        }
+        public string PortName
+        {
+            get { return mSerialPort.PortName; }
+            set { mSerialPort.PortName = value; }
+        }
+        public int ReadTimeout
+        {
+            get { return mSerialPort.ReadTimeout; }
+            set { mSerialPort.ReadTimeout = value; }
+        }
+
+        private byte _slaveNo;
+        public byte SlaveNo
+        {
+            get { return _slaveNo; }
+            set { _slaveNo = value; }
+        }
+
+    }
+}
 
ModbusTest/packages.config (added)
+++ ModbusTest/packages.config
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="EasyModbusTCP" version="5.6.0" targetFramework="net45" />
+  <package id="NModbus4" version="2.1.0" targetFramework="net45" />
+</packages>(No newline at end of file)
Add a comment
List