コード例 #1
0
ファイル: Form1.cs プロジェクト: seckinumur/ArduinoConn
 private void Form1_Load(object sender, EventArgs e)
 {
     Control.CheckForIllegalCrossThreadCalls = false;
     try
     {
         comboBox1.DataSource   = SerialPort.GetPortNames();
         serialPort1.PortName   = comboBox1.SelectedItem.ToString();
         serialPort2.PortName   = comboBox1.SelectedItem.ToString();
         comboBox2.SelectedItem = "PASSIVE";
     }
     catch
     {
         MessageBox.Show("ERR. Serial Port NOT FOUND");
     }
     try
     {
         using (DBEntities2 db = new DBEntities2())
         {
             var bul = db.Active.Where(p => p.State == 1).FirstOrDefault();
             if (bul.State == 1)
             {
                 CONTROL = true;
             }
         }
     }
     catch
     {
         CONTROL = false;
     }
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: seckinumur/ArduinoConn
        private async void timer1_Tick(object sender, EventArgs e)
        {
            serialPort1.Open();
            serialPort1.Write("1");
            await Task.Delay(100);

            serialPort2.Open();
            serialPort2.Write("0");
            await Task.Delay(100);

            try
            {
                using (DBEntities2 db = new DBEntities2())
                {
                    MainLog Record = new MainLog();
                    Record.Days        = DateTime.Now.Day.ToString();
                    Record.Month       = DateTime.Now.Month.ToString();
                    Record.Time        = DateTime.Now.ToShortTimeString();
                    Record.Years       = DateTime.Now.Year.ToString();
                    Record.Light       = value1;
                    Record.Temperature = value;
                    Record.Damp        = "NO DATA";
                    db.MainLog.Add(Record);
                    db.SaveChanges();
                    value1 = "";
                    value  = "";
                }
            }
            catch
            {
                MessageBox.Show("ERR. Serial Port NOT FOUND");
                toolStripStatusLabel2.Text = "ERR. Serial Port NOT FOUND";
            }
        }
コード例 #3
0
 private void button1_Click(object sender, EventArgs e)
 {
     label2.Visible      = true;
     pictureBox1.Visible = true;
     using (DBEntities2 db = new DBEntities2())
     {
         Active ekle = new Active();
         ekle.State = 1;
         db.Active.Add(ekle);
         db.SaveChanges();
         MessageBox.Show("LOCAL DATABASE ACTIVE");
         eris.CONTROL    = true;
         button1.Visible = false;
     }
 }