Example #1
0
        public void IniIOTable()
        {
            int    point      = 0;
            int    address    = 0;
            string infomation = "";

            IOList.Clear();
            string SqlCommand = "SELECT * FROM IO;";

            using (connection = new SQLiteConnection())
            {
                //  建立SQLiteDataReader物件
                using (SQLiteDataReader reader = ExecuteReader(SqlCommand))
                {
                    while (reader.Read())
                    {
                        //讀取成功
                        IOInfo IO = new IOInfo
                        {
                            Address  = reader["Address"].ToString(),
                            Point    = reader["Point"].ToString(),
                            Location = reader["Location"].ToString(),
                            Info     = reader["Info"].ToString(),
                            Info_en  = reader["Info_Eng"].ToString()
                        };

                        IOList.Add(IO);
                    }
                }
            }
            foreach (Control Col in this.Controls)
            {
                if (Col is IO)
                {
                    IO io = Col as IO;


                    point   = (Convert.ToInt32(Col.Name.Substring(2, Col.Name.Length - 2))) % 16;
                    address = StartLocation + (Convert.ToInt32(Col.Name.Substring(2, Col.Name.Length - 2))) / 16;
                    IOInfo info = IOList.Single(s => s.Address == address.ToString() && s.Point == point.ToString());
                    io.Actual  = info;
                    infomation = info.Info;
                    if (infomation == null || infomation == "")
                    {
                        infomation = "待用";
                    }
                    io.IOName = infomation;
                    info.IO   = io;
                }
            }
        }
Example #2
0
        private void IOTimer_Tick(object sender, EventArgs e)
        {
            IOTimer.Enabled = false;

            if (StartLocation == 1560)
            {
                for (int i = 0; i < ReadSystemStatus.IOInputStatus.Length; i++)
                {
                    if (ReadSystemStatus.IOInputStatus[i] == null)
                    {
                        ReadSystemStatus.IOInputStatus[i] = "0000000000000000";
                    }
                    //ReadSystemStatus.IOInputStatus[i] = "1100110011001100";
                    string ReverseIOPoint = String.Join("", ReadSystemStatus.IOInputStatus[i].Select(s => s).Reverse());
                    for (int x = 0; x < ReverseIOPoint.Length; x++)
                    {
                        IOInfo info = IOList.Single(s => s.Address == (StartLocation + i).ToString() && s.Point == x.ToString());
                        IO     io   = info.IO;
                        if (io != null)
                        {
                            if (ReverseIOPoint[x] == '1')
                            {
                                io.OnOff = true;
                            }
                            else
                            {
                                io.OnOff = false;
                            }
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < ReadSystemStatus.IOOutputStatus.Length; i++)
                {
                    if (ReadSystemStatus.IOOutputStatus[i] == null)
                    {
                        ReadSystemStatus.IOOutputStatus[i] = "0000000000000000";
                    }
                    //ReadSystemStatus.IOInputStatus[i] = "1100110011001100";
                    string ReverseIOPoint = String.Join("", ReadSystemStatus.IOOutputStatus[i].Select(s => s).Reverse());
                    for (int x = 0; x < ReverseIOPoint.Length; x++)
                    {
                        IOInfo info = IOList.Single(s => s.Address == (StartLocation + i).ToString() && s.Point == x.ToString());
                        IO     io   = info.IO;

                        if (io != null)
                        {
                            if (ReverseIOPoint[x] == '1')
                            {
                                io.OnOff = true;
                            }
                            else
                            {
                                io.OnOff = false;
                            }
                        }
                    }
                }
            }


            IOTimer.Enabled = true;
        }