コード例 #1
0
 private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0)
     {
         DataGridViewRow row  = dataGridView1.Rows[e.RowIndex];
         Controller      ctrl = (Controller)row.Tag;
         if (this.dataGridView1.ColumnCount == e.ColumnIndex + 2)//修改IP
         {
             if (MessageBox.Show("确定修改设备地址?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
             {
                 ctrl.ip      = row.Cells[2].Value.ToString();
                 ctrl.mask    = row.Cells[3].Value.ToString();
                 ctrl.gateway = row.Cells[4].Value.ToString();
                 IAccessCore access = new WGAccess();
                 access.SetControllerIP(ctrl);
             }
         }
         else if (this.dataGridView1.ColumnCount == e.ColumnIndex + 1)//获取控制器状态
         {
             IAccessCore     access = new WGAccess();
             ControllerState state  = access.GetControllerState(ctrl);
             MessageBox.Show(state.lastRecordIndex + " " + state.reasonNo.ToString());
         }
     }
 }
コード例 #2
0
 private void Read()
 {
     try
     {
         while (_isRun)
         {
             try
             {
                 IAccessCore     ac    = new WGAccess();
                 ControllerState state = ac.GetControllerState(_controler);
                 //var s=  ac.GetControllerRecord(_controler, -1);
                 DoCallBack(state != null, state);
             }
             catch (ThreadAbortException)
             {
                 throw;
             }
             catch (Exception)
             {
                 if (!_isRun)
                 {
                     return;
                 }
                 DoCallBack(false, null);
             }
             Thread.Sleep(_scanInterval);
         }
     }
     catch (Exception)
     {
         return;
     }
 }
コード例 #3
0
        public void StartReadRecord()
        {
            log.Info("开始读取记录:" + _controller.sn);
            using (IAccessCore acc = new WGAccess())
            {
                try
                {
                    if (acc.BeginReadRecord(Controller))
                    {
                        try
                        {
                            while (true)
                            {
                                ControllerState record = acc.ReadNextRecord();
                                if (record == null || record.recordType == RecordType.NoRecord)
                                {
                                    log.Info("记录读取完毕:" + _controller.sn);
                                    break;
                                }
                                try
                                {
                                    RecordTaskService.Instance.SaveRecord(_controller.id, record);
                                }
                                catch (Exception ex)
                                {
                                    if (record.lastRecordIndex <= 0)
                                    {
                                        record.lastRecordIndex = 0xffffffff;
                                    }
                                    else
                                    {
                                        record.lastRecordIndex--;
                                    }
                                    acc.SetControllerReadedIndex(Controller, record.lastRecordIndex);
                                    return;
                                }
                            }
                        }
                        finally
                        {
                            acc.EndReadRecord();
                        }
                    }

                    ControllerState state = acc.GetControllerState(Controller);
                    if (state != null)
                    {
                        RecordTaskService.Instance.SaveState(_controller.id, state);
                    }
                }
                catch (Exception ex)
                {
                    RecordTaskService.Instance.SaveState(_controller.id, null);
                    throw ex;
                }
            }
        }