AnimatLab  2
Test
AnimatSerial.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using AnimatGUI.Framework;
6 
7 namespace RoboticsGUI
8 {
9  namespace RobotIOControls
10  {
11 
12  public class AnimatSerial : AnimatGUI.DataObjects.Robotics.RemoteControl
13  {
14  #region " Attributes "
15 
16  protected string m_strPort = "";
17  protected int m_iBaudRate = 38400;
18 
22  protected int m_iChangeSimStepCount = 5;
23 
24  #endregion
25 
26  #region " Attributes "
27 
28  public override string Description {get {return "Performs serial communication with a target device to send data from the simulation and back.";} set { }}
29  public override string ButtonImageName {get {return "RoboticsGUI.Graphics.AnimatSerial.gif";}}
30  public override string WorkspaceImageName { get { return "RoboticsGUI.Graphics.AnimatSerialSmall.gif"; } }
31  public override string PartType {get { return "AnimatSerial"; }}
32  public override string ModuleName { get { return "RoboticsAnimatSim"; } }
33 
34  public virtual string Port
35  {
36  get
37  {
38  return m_strPort;
39  }
40  set
41  {
42  SetSimData("Port", value, true);
43  m_strPort = value;
44  }
45  }
46 
47  public virtual int BaudRate
48  {
49  get
50  {
51  return m_iBaudRate;
52  }
53  set
54  {
55  if(value <= 0)
56  throw new System.Exception("Invalid baud rate specified. Rate: " + value.ToString());
57 
58  SetSimData("BaudRate", value.ToString(), true);
59  m_iBaudRate = value;
60  }
61  }
62 
63  public virtual int ChangeSimStepCount
64  {
65  get
66  {
67  return m_iChangeSimStepCount;
68  }
69  set
70  {
71  if (value <= 0)
72  throw new System.Exception("Invalid pulse sim step count specified. Rate: " + value.ToString());
73 
74  SetSimData("ChangeSimStepCount", value.ToString(), true);
75  m_iChangeSimStepCount = value;
76  }
77  }
78 
79  #endregion
80 
81  #region " Methods "
82 
83  public AnimatSerial(AnimatGUI.Framework.DataObject doParent)
84  : base(doParent)
85  {
86  m_strName = "Animat Serial";
87 
88  //AnimatSerial controller has the user define the data it will deal with dynamically when
89  //defining the remote control linkages.
90  m_bUseRemoteDataTypes = false;
91 
92  m_aryLinks.Clear();
93  }
94 
95  public override AnimatGUI.Framework.DataObject Clone(AnimatGUI.Framework.DataObject doParent, bool bCutData, AnimatGUI.Framework.DataObject doRoot)
96  {
97  AnimatSerial doInterface = new AnimatSerial(doParent);
98  return doInterface;
99  }
100 
101  protected override void CloneInternal(DataObject doOriginal, bool bCutData, DataObject doRoot)
102  {
103  base.CloneInternal(doOriginal, bCutData, doRoot);
104 
105  AnimatSerial doOrig = (AnimatSerial)doOriginal;
106 
107  if (doOrig != null)
108  {
109  m_strPort = doOrig.m_strPort;
110  m_iBaudRate = doOrig.m_iBaudRate;
111  m_iChangeSimStepCount = doOrig.m_iChangeSimStepCount;
112  }
113  }
114 
115  public override void BuildProperties(ref AnimatGuiCtrls.Controls.PropertyTable propTable)
116  {
117  base.BuildProperties(ref propTable);
118 
119  propTable.Properties.Add(new AnimatGuiCtrls.Controls.PropertySpec("Com Port", this.Port.GetType(), "Port", "Properties", "Com port", this.Port));
120  propTable.Properties.Add(new AnimatGuiCtrls.Controls.PropertySpec("Baud Rate", this.BaudRate.GetType(), "BaudRate", "Properties", "Baud rate to use for communications", this.BaudRate));
121  propTable.Properties.Add(new AnimatGuiCtrls.Controls.PropertySpec("Pulse Sim Step Count", this.ChangeSimStepCount.GetType(), "ChangeSimStepCount", "Properties", "Number of simulation step slices to keep a start/stop signal active", this.ChangeSimStepCount));
122  }
123 
124  public override void LoadData(ManagedAnimatInterfaces.IStdXml oXml)
125  {
126  base.LoadData(oXml);
127 
128  oXml.IntoElem();
129 
130  m_strPort = oXml.GetChildString("Port", m_strPort);
131  m_iBaudRate = oXml.GetChildInt("BaudRate", m_iBaudRate);
132  m_iChangeSimStepCount = oXml.GetChildInt("ChangeSimStepCount", m_iChangeSimStepCount);
133 
134  oXml.OutOfElem();
135  }
136 
137  public override void SaveData(ManagedAnimatInterfaces.IStdXml oXml)
138  {
139  base.SaveData(oXml);
140 
141  oXml.IntoElem();
142 
143  oXml.AddChildElement("Port", m_strPort);
144  oXml.AddChildElement("BaudRate", m_iBaudRate);
145  oXml.AddChildElement("ChangeSimStepCount", m_iChangeSimStepCount);
146 
147  oXml.OutOfElem();
148  }
149 
150  public override void SaveSimulationXml(ManagedAnimatInterfaces.IStdXml oXml, ref DataObject nmParentControl, string strName = "")
151  {
152  base.SaveSimulationXml(oXml, ref nmParentControl, strName);
153 
154  oXml.IntoElem();
155 
156  oXml.AddChildElement("Port", m_strPort);
157  oXml.AddChildElement("BaudRate", m_iBaudRate);
158  oXml.AddChildElement("ChangeSimStepCount", m_iChangeSimStepCount);
159 
160  oXml.OutOfElem();
161  }
162 
163  #endregion
164 
165  }
166  }
167 }
int m_iChangeSimStepCount
The number of time slices to keep a start/stop signal active.
Definition: AnimatSerial.cs:22