MAPS agents programs example PL

MAPS agents programs example PL

Artykuł zawiera przykładowe programy obsługi agentów w programie MAPS
This project contains example programs of agents in MAPS

Przykładowe programy 

Odczyt/zapis agentów z pozycji C# (pojedyncze agenty)

Biblioteki

using VIZNET.Shared.DataElements.Engine;

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

Odczyt/zapis agentów z pozycji C# (kolekcja agentów)

Biblioteki

using VIZNET.Shared.DataElements.Engine;


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);

 }

Ukrycie ramki okna

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;


    • Related Articles

    • MAPS - Logging and extract data to CSV

      This manual shows how to logging data during the process and extract this logs to CSV after finishing process. Every process is saved to other CSV file. "Copyright © Mitsubishi Electric Europe B.V. IMPORTANT ! These Function Blocks are demo versions ...
    • ME96 and MAPS connected by Modbus RTU

      This document shows how to connect electronic multi-measuring instrument ME96-MB to MAPS SCADA via Modbus RTU. Connection is using MOXA 1130 converter RS485 to USB Configuration MOXA converter Searching MOXA in device manager   The most important ...
    • ME96 and MAPS connected by Modbus TCP_IP

      This document shows how to connect electronic multi-measuring instrument ME96-MB to MAPS SCADA via Modbus TCP/IP Configuring Local Network Parameters Set static address IP on local network     MAPS Config Editor  Install new driver First install new ...
    • Iconics Suite - Installation of GENESIS64 Basic and Advanced in Secured and Unsecured mode

      Instruction bellow will help you step by step with installation of ICONICS in unsecured mode and secured mode version 10.97.2 + Critical Rollup CFR2 Installation of GENESIS64 Basic and Advanced will be also highlighted Installation of GENESIS64 Basic ...
    • DIGITAL: Maps driver list

      Summary: In the attachment you can download a sheet in which you can find information about the drivers for Scada Adroit Maps.