pvbrowser manual
Back Content

pvserver

Здесь показан простейший pvserver для работы с PROFIBUS. Доступ реализован с помощью rlHilscherCIF из библиотеки rllib.

main.cpp

//***************************************************************************
//                          main.cpp  -  description
//                             -------------------
//  begin            : Mi Feb 14 10:18:44 2007
//  generated by     : pvdevelop (C) 2000-2006 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);

#include "rlhilschercif.h"
rlHilscherCIF cif;
unsigned char sendData[512];
unsigned char receiveData[512];
rlThread pbus;

void *profibus(void *arg)
{
  THREAD_PARAM *p = (THREAD_PARAM *) arg;
  cif.debug = 1;
  if(cif.open() == DRV_NO_ERROR)
  {
    cif.debug = 0;
    while(p->running)
    {
      rlsleep(50);
      pbus.lock();
      cif.devExchangeIO(0,4,sendData,
                        0,4,receiveData,
                        1000);
      pbus.unlock();
    }
  }
  return arg;
}

int pvMain(PARAM *p)
{
int ret;

  pvSetCaption(p,"pvs");
  pvResize(p,0,1280,1024);
  //pvScreenHint(p,1024,768); // this may be used to automatically set the zoomfactor
  ret = 1;
  pvGetInitialMask(p);
  if(strcmp(p->initial_mask,"mask1") == 0) ret = 1;

  while(1)
  {
    switch(ret)
    {
      case 1:
        pvStatusMessage(p,-1,-1,-1,"mask1");
        ret = show_mask1(p);
        break;
      default:
        return 0;
    }
  }
}

#ifdef USE_INETD
int main(int ac, char **av)
{
PARAM p;

  pvInit(ac,av,&p);
  /* here you may interpret ac,av and set p->user to your data */
  pvMain(&p);
  return 0;
}
#else  // multi threaded server
int main(int ac, char **av)
{
PARAM p;
int   s;

  pvInit(ac,av,&p);
  /* here you may interpret ac,av and set p->user to your data */
  memset(sendData,0,sizeof(sendData));
  memset(receiveData,0,sizeof(receiveData));
  pbus.create(profibus,NULL);
  while(1)
  {
    s = pvAccept(&p);
    if(s != -1) pvCreateThread(&p,s);
    else        break;
  }
  return 0;
}
#endif

mask1_slots.h

//###############################################################

// 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 unsigned char sendData[512];
extern unsigned char receiveData[512];
extern rlThread pbus;

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;
  pvPrintf(p,labelInput0,"%2X",receiveData[0]);
  pvPrintf(p,labelInput1,"%2X",receiveData[1]);
  return 0;
}

<snip>

static int slotSliderEvent(PARAM *p, int id, DATA *d, int val)
{
  if(p == NULL || id == 0 || d == NULL || val < -1000) return -1;
  pbus.lock();
  if(id == spinOutput0) sendData[0] = val;
  if(id == spinOutput1) sendData[1] = val;
  pbus.unlock();  
  return 0;
}

pvapp.h

//***************************************************************************
//                          pvapp.h  -  description
//                             -------------------
//  begin            : Mi Feb 14 10:18:44 2007
//  generated by     : pvdevelop (C) 2000-2006 by Lehrig Software Engineering
//  email            : lehrig@t-online.de
//***************************************************************************
#ifndef _PVAPP_H_
#define _PVAPP_H_

#include "processviewserver.h"
#include "rltime.h"
#include "rlthread.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

Back Content