示例#1
0
        private async void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 & e.ColumnIndex >= 0)
            {
                if (dgv.Columns[e.ColumnIndex].Name == "Write")
                {
                    int        writeValue = Convert.ToInt32(dgv.Rows[e.RowIndex].Cells[writeValueColumn].Value);
                    FlagModule flag       = binding[e.RowIndex];

                    await Task.Run(() =>
                    {
                        FlagBusiness.Write(flag.Id, writeValue);
                    });
                }
            }
        }
示例#2
0
 private void UpdateUI()
 {
     Task.Run(() =>
     {
         while (true)
         {
             try
             {
                 foreach (var item in binding)
                 {
                     var result = FlagBusiness.Read(item.Id);
                     //item.CurrentValue = result.Content;
                     //PlcBase plc = manager.plcs.Find(item1 => item1.Id == item.PlcId);
                     //var result = plc?.Read(item.Address);
                     //if (result !=null && result.IsSuccess)
                     //{
                     //    item.CurrentValue = result.Content;
                     //}
                     //else
                     //{
                     //    item.CurrentValue = -1;
                     //}
                     if (result.IsSuccess)
                     {
                         dgv.Invoke((MethodInvoker)(() =>
                         {
                             dgv.Invalidate();
                         }));
                     }
                     Thread.Sleep(5);
                 }
                 Thread.Sleep(10);
             }
             catch (Exception)
             {
                 Thread.Sleep(1000);
             }
         }
     });
 }