Biblioteki |
Definicja klasy |
#region agentControlClass and declare agentControlClass
public class agentsControlClass
{
public DataElementCollection agentsCollection = DataElementEngine.NewDataElementCollection();
public DataElementCollection collectionReturned = DataElementEngine.NewDataElementCollection();
public MethodReturnInfo write_info;
public MethodReturnInfo read_info;
}
agentsControlClass agentsControl = new agentsControlClass();
#endregion
Funkcja zapisu agentów |
#region agentWrite
private void agentWrite(string agent_name, object agent_value)
{
DataElement input_agent = DataElementEngine.NewDataElement("Adroit." + agent_name);
input_agent.Value = agent_value;
agentsControl.agentsCollection.Clear();
agentsControl.agentsCollection.Add(input_agent);
try
{
agentsControl.write_info = MyConnection.UpdateDataElements(agentsControl.agentsCollection);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
}
#endregion
Funkcja odczytu agentów |
#region agentRead
private DataElement agentRead(string agent_name)
{
DataElement input_agent = DataElementEngine.NewDataElement("Adroit." + agent_name);
agentsControl.agentsCollection.Clear();
agentsControl.agentsCollection.Add(input_agent);
try
{
agentsControl.read_info = MyConnection.ReadDataElements(agentsControl.agentsCollection);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.ToString());
}
return (agentsControl.read_info.ReturnObject as DataElementCollection)["Adroit." + agent_name];
}
#endregion
Biblioteki |
Funkcja odczytu agentów |
#region Read Agent Server Collection
private DataElement[] agentCollectionRead(string[] agentsName)
{
int elements = agentsName.Length;
DataElement[] dataElements = new DataElement[elements];
DataElement[] returnDataElements = new DataElement[elements];
for (int i = 0; i < elements; i++)
{
dataElements[i] = DataElementEngine.NewDataElement("Adroit." + agentsName[i]);
}
try
{
DataElementCollection dec = DataElementEngine.NewDataElementCollection();
foreach (DataElement de in dataElements)
{
dec.Add(de);
}
MethodReturnInfo info = MyConnection.ReadDataElements(dec);
if (!info.Success)
{
MessageBox.Show("Error reading element, the error was: " + info.ReturnInformation);
}
else
{
DataElementCollection returnDEC = info.ReturnObject as DataElementCollection;
for (int i = 0; i < elements; i++)
{
returnDataElements[i] = returnDEC["Adroit." + agentsName[i]];
}
}
}
catch (Exception ex)
{
MessageBox.Show("An exception occurred: " + ex.ToString());
}
return returnDataElements;
}
#endregion
Funkcja odczytu agentów |
#region Write Agent Server Collection
private void agentCollectionWrite(DataElement[] dataElements)
{
int elements = dataElements.Length;
if (elements > 0)
{
try
{
DataElementCollection dec = DataElementEngine.NewDataElementCollection();
for (int i = 0; i < elements; i++)
{
dec.Add(dataElements[i]);
}
MethodReturnInfo info = MyConnection.UpdateDataElements(dec);
if (!info.Success)
{
MessageBox.Show("Error updating element, the error was: " + info.ReturnInformation);
}
else
{
MessageBox.Show("Successful update");
}
}
catch (Exception ex)
{
MessageBox.Show("An exception occurred: " + ex.ToString());
}
}
}
#endregion
Przykład użycia funkcji – Read Agent Collection |
private void button_readAgentCollection_Click(System.Object sender, System.EventArgs e)
{
string[] agentsName = new string[4];
agentsName[0] = "systeminfo.second";
agentsName[1] = "FX5_D0.value";
agentsName[2] = "FX5_D6_D7.value";
agentsName[3] = "FX5_D10FLOAT.value";
DataElement[] odczytaneDane = agentCollectionRead(agentsName);
DataElement returnDE = odczytaneDane[0];
DataElement returnD0 = odczytaneDane[1];
DataElement returnD6 = odczytaneDane[2];
DataElement returnD10 = odczytaneDane[3];
MessageBox.Show("The value of: " + returnDE.Name + " is: " + returnDE.Value.ToString());
MessageBox.Show("The value of: " + returnD0.Name + " is: " + returnD0.Value.ToString());
MessageBox.Show("The value of: " + returnD6.Name + " is: " + returnD6.Value.ToString());
MessageBox.Show("The value of: " + returnD10.Name + " is: " + returnD10.Value.ToString());
}
Przykład użycia funkcji – Write Agent Collection |
private void button_writeAgentCollection_Click(System.Object sender, System.EventArgs e)
{
int D0_value = int.Parse(tb_D0.Text);
int D6_value = int.Parse(tx_D6.Text);
decimal D10_value = decimal.Parse(tb_D10.Text.Replace(".", ","));
DataElement[] dataElements = new DataElement[3];
dataElements[0] = DataElementEngine.NewDataElement("Adroit.FX5_D0.value");
dataElements[0].Value = D0_value;
dataElements[1] = DataElementEngine.NewDataElement("Adroit.FX5_D6_D7.value");
dataElements[1].Value = D6_value;
dataElements[2] = DataElementEngine.NewDataElement("Adroit.FX5_D10FLOAT.value");
dataElements[2].Value = D10_value;
agentCollectionWrite(dataElements);
}
Należy wkleić po inicjalizacji obiektów
Kod ukrywający ramkę okna głównego |
((Form)((UserControl)VIZNET.UI.Runtime.ObjectManager.GetInstance().VIZNETMain).Parent).FormBorderStyle = FormBorderStyle.None;