Redes servidor opc

Classified in Other subjects

Written at on English with a size of 2.53 KB.

 

[PROTOCOL]    en fichero SCOREDP.txt

UseDemoBoard=1             TimeOutFirstCallbackBad=0

[DEMO(Slaves)]              [DEMO(Aliases)]                SensorPulso=Slave067EX0.0                 PulsadoresProducto=Slave061EB0          Leds=Slave063AB0

using OPCSiemensDAAutomation;

namespace OPC_DP_1

{ public partial class Form1:Form

{const int ENTRADA1=0;

const int SALIDA1=1;

OPCServer opc=new OPCServer();

OPCGroup g;

int[]SHandles=new int[2]{-1,-1};

public Form1()

{  InitializeComponent();  }

private void Form1_Load(object sender, EventArgs e)

{string nodo="localhost ip";

opc.Connect("OPC.SimaticNET",nodo);

   OPCGroups grs=opc.OPCGroups;

   grs.DefaultGroupIsActive=false;

   grs.DefaultGroupUpdateRate=500;

   grs.DefaultGroupDeadband=1.0F;

   g=grs.Add("GrupoOPC1");

   g.DataChange+=new DIOPGroupEvent_DataChangeEventHandler(g_DataChange);

   OPCItem opcitem =g.OPCItems.AddItem("[Examen]Program:MainProgram.entrada1", ENTRADA1);

   SHandles[ENTRADA1-1]=opc_entrada1.ServerHandle;

   g.IsSubscribed=true;               g.IsActive=true;          }

void g_DataChange(int TransactionID,int NumItems,ref Array ClientHandles,ref Array ItemValues,ref Array Qualities,ref Array TimeStamps)

{  int lw=ItemValues.GetLowerBound(0);

   int up=ItemValues.GetUpperBound(0);

   for(int i=lw;i<=NumItems, i++)

   {  int ch=(int)ClientHandless.GetValue(i);

      switch(ch)  {

     case ENTRADA1:

         {  bool valor=Convert.ToBoolean(ItemValues.GetValue(i));

           led1.Value=valor;

break;  } default:break}}}

private void Form1_FormClosed(object sender,FormClosedEventArgs e)

{ g.IsSubscribed=false;

 g.DataChange-=g_DataChange;

opc.Disconnect();   }

private void ch_ENTRADA1_CheckedChanged(object sender, EventArgs e)

{  OPCItem item=g.OPCItems.Item(ENTRADA1);

   item.Write(ch_ENTRADA1.Checked);   }

Entradas relacionadas: