pvbrowser manual
Zurück Inhalt Vor

OPC XML-DA

rlopcxmlda.h wird in pvapp.h includiert.

//***************************************************************************
//                          pvapp.h  -  description
//                             -------------------
//  begin            : Mo Aug 27 10:17:41 2007
//  generated by     : pvdevelop (C) 2000-2007 by Lehrig Software Engineering
//  email            : lehrig@t-online.de
//***************************************************************************
#ifndef _PVAPP_H_
#define _PVAPP_H_

#include "processviewserver.h"
#include "rlopcxmlda.h"
// todo: comment me out
//#include "rlmodbusclient.h"
//#include "rlsiemenstcpclient.h"
//#include "rlppiclient.h"
//#include "modbusdaemon.h"             // this is generated
//#include "siemensdaemon.h"            // this is generated
//#include "ppidaemon.h"                // this is generated

int show_mask1(PARAM *p);

#endif

Eine Instanz von rlOpcXmlDa wird in main.cpp definiert.

//***************************************************************************
//                          main.cpp  -  description
//                             -------------------
//  begin            : Mo Aug 27 10:17:41 2007
//  generated by     : pvdevelop (C) 2000-2007 by Lehrig Software Engineering
//  email            : lehrig@t-online.de
//***************************************************************************
#include "pvapp.h"
// todo: comment me out. you can insert these objects as extern in your masks.
//rlModbusClient     modbus(modbusdaemon_MAILBOX,modbusdaemon_SHARED_MEMORY,modbusdaemon_SHARED_MEMORY_SIZE);
//rlSiemensTCPClient siemensTCP(siemensdaemon_MAILBOX,siemensdaemon_SHARED_MEMORY,siemensdaemon_SHARED_MEMORY_SIZE);
//rlPPIClient        ppi(ppidaemon_MAILBOX,ppidaemon_SHARED_MEMORY,ppidaemon_SHARED_MEMORY_SIZE);
rlOpcXmlDa opc;

maskX_slots.h kann dann wie folgt aussehen.

//###############################################################
//# mask1_slots.h for ProcessViewServer created: Mo Aug 27 10:17:41 2007
//# please fill out these slots
//# here you find all possible events
//# Yours: Lehrig Software Engineering
//###############################################################
//***************************************************************************
//                          main.cpp  -  description
//                             -------------------
//  begin            : Mo Aug 27 10:17:41 2007
//  generated by     : pvdevelop (C) 2000-2007 by Lehrig Software Engineering
//  email            : lehrig@t-online.de
//***************************************************************************
#include "pvapp.h"
// todo: comment me out. you can insert these objects as extern in your masks.
//rlModbusClient     modbus(modbusdaemon_MAILBOX,modbusdaemon_SHARED_MEMORY,modbusdaemon_SHARED_MEMORY_SIZE);
//rlSiemensTCPClient siemensTCP(siemensdaemon_MAILBOX,siemensdaemon_SHARED_MEMORY,siemensdaemon_SHARED_MEMORY_SIZE);
//rlPPIClient        ppi(ppidaemon_MAILBOX,ppidaemon_SHARED_MEMORY,ppidaemon_SHARED_MEMORY_SIZE);

// todo: uncomment me if you want to use this data aquisiton
// also uncomment this classes in main.cpp and pvapp.h
// also remember to uncomment rllib in the project file
//extern rlModbusClient     modbus;
//extern rlSiemensTCPClient siemensTCP;
//extern rlPPIClient        ppi;
extern rlOpcXmlDa opc;

typedef struct // (todo: define your data structure here)
{
}
DATA;

static int slotInit(PARAM *p, DATA *d)
{
  if(p == NULL || d == NULL) return -1;
  //memset(d,0,sizeof(DATA));
  return 0;
}

static int slotNullEvent(PARAM *p, DATA *d)
{
  if(p == NULL || d == NULL) return -1;
  int i;
  const char *cptr;

  for(i=ID_MAIN_WIDGET+1; i<ID_END_OF_WIDGETS; i++)
  {
    cptr = toolTip[i];
    if(*cptr != '#' && *cptr > ' ') // if there is a variable name
    {
      pvPrintf(p,i,"%s=%s",cptr,opc.stringValue(cptr));
    }
  }

  pvPrintf(p,labelReadErrorCount,"readErrorCount=%d",opc.readErrorCount());
  pvPrintf(p,labelWriteErrorCount,"writeErrorCount=%d",opc.writeErrorCount());
  return 0;
}

static int slotButtonEvent(PARAM *p, int id, DATA *d)
{
  if(p == NULL || id == 0 || d == NULL) return -1;
  int   ival;
  float fval;
  switch(id)
  {
    case buttonInt16:
      ival = opc.intValue("test/Int16");
      ival += 1;      
      opc.writeIntValue("test/Int16",ival);
      break;
    case buttonInt32:
      ival = opc.intValue("test/Int32");      
      ival += 1;      
      opc.writeIntValue("test/Int32",ival);
      break;
    case buttonFloat:
      fval = opc.floatValue("test/float");      
      fval += 1.0f;      
      opc.writeFloatValue("test/float",fval);
      break;
    case buttonDouble:
      fval = opc.floatValue("test/double");      
      fval += 1.0f;      
      opc.writeFloatValue("test/double",fval);
      break;
    case buttonHello:
      opc.writeStringValue("test/string","hello");
      break;
    case buttonWorld:
      opc.writeStringValue("test/string","world");
      break;
    default:
      break;
  }
  return 0;
}

Beachten Sie, dass in diesem Beispiel die OPC Wertenamen innerhalb des Designers als "toolTip" definiert werden. Daher ist der Programmieraufwand minimal.


Zurück Inhalt Vor