AICtrl.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Aitex.Core.RT.Simulator;
  10. namespace Aitex.Core.Backend
  11. {
  12. public partial class AICtrl : UserControl
  13. {
  14. private string _ioName;
  15. public AICtrl()
  16. {
  17. InitializeComponent();
  18. }
  19. public void SetName(string name)
  20. {
  21. labelName.Text = name;
  22. }
  23. public void SetIoName(string group, string ioName)
  24. {
  25. _ioName = ioName;
  26. }
  27. public void SetValue(float value)
  28. {
  29. textBox1.Text = String.Format("{0:f2}", value);
  30. }
  31. private void checkBox1_CheckedChanged(object sender, EventArgs e)
  32. {
  33. if (checkBox1.Checked)
  34. {
  35. textBox2.Text = textBox1.Text;
  36. float value;
  37. float.TryParse(textBox2.Text.Trim(), out value);
  38. AiForce.Instance.Set(_ioName, value);
  39. button1.Enabled = true;
  40. textBox2.Enabled = true;
  41. this.BackColor = Color.DodgerBlue;
  42. }
  43. else
  44. {
  45. AiForce.Instance.Unset(_ioName);
  46. button1.Enabled = false;
  47. textBox2.Enabled = false;
  48. this.BackColor = Color.White;
  49. }
  50. }
  51. private void button1_Click(object sender, EventArgs e)
  52. {
  53. float value;
  54. if (float.TryParse(textBox2.Text.Trim(), out value))
  55. AiForce.Instance.Set(_ioName, value);
  56. }
  57. }
  58. }