Subversion Repositories f9daq

Rev

Blame | Last modification | View Log | RSS feed

#ifdef _MAIN
#include <cvirte.h>            
#include <userint.h>
#include "mpod_uir.h"

#include "netsnmplib.h"
#include "WIENER_SNMP.h"

 
static int p1h;
HSNMP mpod;

void snmptest(void) {
 
 
  if(!mpod) return;
  printf("-----------------------------------------------------------------\n");

  double ret;
  double voltage;
  double vSet=0;
  int channel=2;
  int iret;
  int i, j;
 
  printf("Turning channel %i ON\n", channel);  
  setMainSwitch(mpod, 1);
  Sleep(1000);
  printf(".... Turning channel %i ON\n", channel);
  setChannelSwitch(mpod, channel, 1);
  Sleep(1000);
 
  //Test Channel Status
  iret=getChannelSwitch(mpod, channel);
  printf("Channel Status = %i\n\n", iret);
 
 
 
  //getOutputNumber
  iret=getOutputNumber(mpod);
  printf("getOutputNumber = %i\n\n", iret);
 
  //getOutputGroups
  iret=getOutputGroups(mpod);
  printf("getOutputGroups = %i\n\n", iret);
 
 

  //Test Setting and reading output Voltage
  vSet =getOutputVoltage(mpod, channel);
  printf("Output Voltage = %f.  I will now change it to 24.2\n", vSet);
  setOutputVoltage(mpod, channel, 24.2);
  vSet =getOutputVoltage(mpod, channel);
  printf("Output Voltage = %f.  I will now change it to 12.3\n", vSet);
  setOutputVoltage(mpod, channel, 12.3);
  vSet =getOutputVoltage(mpod, channel);
  printf("Output Voltage = %f.\n\n", vSet);

  //Test Reading the Sense Measurement
  ret = getOutputSenseMeasurement(mpod, channel);
  printf("Sense Voltage =  %f\n", ret);
  Sleep(1000);
  ret = getOutputSenseMeasurement(mpod, channel);
  printf("Sense Voltage =  %f.  It the channel is ramping it should have changed.\n\n", ret);

  //Test Reading the Current
  ret = getCurrentMeasurement(mpod, channel);
  printf("Current Measurement =  %f\n\n", ret);

  //Test the Ramp
  ret=getOutputRiseRate(mpod, channel);
  printf("Ramp Rate is %f, Let's make it 46.\n", ret);
  setOutputRiseRate(mpod, channel, 4.6);
  ret=getOutputRiseRate(mpod, channel);
  printf("Ramp Rate is %f, Let's make it 100.\n", ret);
  setOutputRiseRate(mpod, channel, 10.0);
  ret=getOutputRiseRate(mpod, channel);
  printf("Ramp Rate is %f.\n\n", ret);

  //Test Channel Status
  iret=getChannelSwitch(mpod, channel);
  printf("Channel Status = %i\n\n", iret);

 
 
  getMainSwitch(mpod);
  //setMainSwitch(mpod, 0);
  Sleep(1000);
  if (!getMainSwitch(mpod)) {
    printf("Crate is now Off\n");
  }


  printf("-----------------------------------------------------------------\n");
 

}


int main (int argc, char *argv[]) {
  if (InitCVIRTE (0, argv, 0) == 0)
    return -1;  // out of memory
  if ((p1h = LoadPanel (0, "mpod_uir.uir", PANEL)) < 0)
    return -1;
 
  if(!SnmpInit()) return;                     // basic init
  mpod = SnmpOpen("178.172.43.94");   // open TCP/IP socket
  SetCtrlVal(p1h,PANEL_MPODONOFF,1-getMainSwitch(mpod));
  DisplayPanel (p1h);
  RunUserInterface ();
  DiscardPanel (p1h);
   SnmpClose(mpod);
  SnmpCleanup();                              // finish
  return 0;
}

int CVICALLBACK StartCB (int panel, int control, int event,
                         void *callbackData, int eventData1, int eventData2) {
  switch (event) {
    case EVENT_COMMIT:
      snmptest();
      break;
  }
  return 0;
}

int CVICALLBACK StopCB (int panel, int control, int event,
                        void *callbackData, int eventData1, int eventData2) {
  switch (event) {
    case EVENT_COMMIT:

      break;
  }
  return 0;
}

int CVICALLBACK ExitCB (int panel, int control, int event,
                        void *callbackData, int eventData1, int eventData2) {
  switch (event) {
    case EVENT_COMMIT:
      QuitUserInterface (0);
      break;
  }
  return 0;
}


int CVICALLBACK MpodOnOffCB (int panel, int control, int event,
                             void *callbackData, int eventData1, int eventData2) {
  int val;
  switch (event) {
    case EVENT_COMMIT:
      GetCtrlVal(panel,control,&val);
      getMainSwitch(mpod);
      setMainSwitch(mpod, 1-val);
      Sleep(100);
      if (!getMainSwitch(mpod)) {
         printf("Crate is now Off\n");
      }  else  {
         printf("Crate is now On\n");
      }
      break;
  }
  return 0;
}


int CVICALLBACK MpodChannelsOutputVoltageCB (int panel, int control, int event,
                                     void *callbackData, int eventData1, int eventData2) {
  double vset,iset;
  switch (event) {
    case EVENT_COMMIT:
      GetCtrlVal(panel,PANEL_VSET,&vset);
      GetCtrlVal(panel,PANEL_ISET,&iset);
      for( int i = 0; i < 4; i++) {
        int j=i*100;
        for( int k = 0; k < 8; k++) {
          int channel = j+k;
          char *cName= getOutputName(mpod, channel);
          if (!cName) continue;
          if (channel==0) continue;
          printf("%d  Vset=%f Iset=%f \n", channel, vset,iset);
          setOutputVoltage(mpod, channel, vset);
          setOutputCurrent(mpod, channel, iset);
       
        }
      }
      break;
  }
  return 0;
}



int CVICALLBACK MpodChannelsOnOffCB (int panel, int control, int event,
                                     void *callbackData, int eventData1, int eventData2) {
  int val;
  switch (event) {
    case EVENT_COMMIT:
       GetCtrlVal(panel,control,&val);
       val=1-val;
      for( int i = 0; i < 4; i++) {
        int j=i*100;
        for( int k = 0; k < 8; k++) {
          int channel = j+k;
          char *cName= getOutputName(mpod, channel);
          if (!cName) continue;
          if (channel==0) continue;
          int state=getChannelSwitch(mpod, channel);
          if (state!= val) setChannelSwitch(mpod, channel, val);
       
        }
      }
      break;
  }
  return 0;
}






int CVICALLBACK GetStatus (int panel, int control, int event,
                           void *callbackData, int eventData1, int eventData2) {
  switch (event) {
    case EVENT_COMMIT:
       // scan MPOD crate, now 4 loops for MPODmini can be changed to 10 for full size crate
  for( int i = 0; i < 4; i++)
  {
          int j=i*100;
          for( int k = 0; k < 8; k++)
          {
        int channel = j+k;
        char * cName= getOutputName(mpod, channel);
        if (!cName) continue;
       
                    int iret=getChannelSwitch(mpod, channel);
                    double vSet      =getOutputVoltage(mpod, channel);
        double iSet      =getOutputCurrent(mpod, channel);
        double vTerminal =getOutputTerminalMeasurement(mpod, channel);
        double vSense    =getOutputSenseMeasurement(mpod, channel);
        double iMon      =getCurrentMeasurement(mpod, channel);
        double vRpUp     =getOutputRiseRate(mpod, channel);  
        double vRpDown   =getOutputFallRate(mpod, channel);  
                    printf("%3i %s\t[%i]\tVset=%g\tIset=%g\tImon=%g\tVmon=%g\tVterm=%g\tRUp=%g\tRDn=%g\n", channel, cName, iret, vSet, iSet, iMon, vSense, vTerminal, vRpUp, vRpDown);
          }
  }
 
  break;
  }
  return 0;
}
#endif