12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using Aitex.Core.RT.IOCore;
- using Aitex.Core.Util;
- namespace Aitex.Core.Backend
- {
- public partial class AI : UserControl, IIOView
- {
- PeriodicJob _thread;
- public AI()
- {
- InitializeComponent();
- this.Load += new EventHandler(AI_Load);
- }
- void AI_Load(object sender, EventArgs e)
- {
- if (this.Controls.Count > 0)
- return;
- List<Tuple<int, int, string>> ioList = IO.GetIONameList(IOType.AI);
- int index = 0;
- foreach (var item in ioList)
- {
- AICtrl aiCtrl1 = new AICtrl();
- aiCtrl1.Location = new System.Drawing.Point(index % 6 * 162, index / 6 * 38);
- aiCtrl1.SetName(string.Format("{0}.{1}", item.Item1, item.Item3));
- aiCtrl1.Name = string.Format("AI_{0}", item.Item1);
- aiCtrl1.Size = new System.Drawing.Size(161, 37);
- aiCtrl1.Visible = true;
- aiCtrl1.Tag = item.Item3;
- this.Controls.Add(aiCtrl1);
- index++;
- }
- _thread = new PeriodicJob(500, OnTimer, "AITimer", false, true);
- VisibleChanged += (sender1, e1) =>
- {
- if (Visible) _thread.Start(); else _thread.Pause();
- };
- }
- bool OnTimer()
- {
- Invoke(new Action(() =>
- {
- foreach (AICtrl ctrl in Controls)
- {
- if (ctrl != null)
- {
- ctrl.SetValue(IO.AI[(string)ctrl.Tag].Value);
- }
- }
- }));
- return true;
- }
- public void EnableTimer(bool enable)
- {
- if (enable)
- _thread.Start();
- else
- _thread.Pause();
- }
- public void Close()
- {
- if (_thread != null)
- _thread.Stop();
- }
- }
- }
|