LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

error in viOpen

hi,
  I need a help...
  I am using a VISA test application (NI VISA) to communicate with our firmware through tcp/ip ....This includes a power supply control instructions.But whenever I run my code i am getting an error message-"error in viOpen.Timeout expired before operation completed"
   But If I use the measurement and automation of labview n initialize with the ip address , the test app will work properly...
          even if i close the measurement and automation after that it would work for some more time (10 minutes) n again will give the same error.
   That means, I think , this measurement and automation program does some initialization ,or calls some functions which I miss in my test application.
 Plz look into the problem...shall we need to do some initialization step before running the code in Visual  C++ IDE.
   I am attaching the code n the spylogs taken when time out occurs n when no timeout(with measurement and automation activated)...if anyone know the solution plz reply soon...I am in a hurry
               thanks n regards
                   seren
//This is a simple program that sets a voltage, current, overvoltage, and the
//status of over current protection. All of the variables
//can be changed by the user.
#include "visa.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
int main()
{
 ViSession session,defrm;
 ViStatus VISAstatus;
 char statdsc[100];
 char err[100];
 char voltmeasurement[16]="0";
 char currmeasurement[16]="0";
  char overvoltmeasurement[16]="6";
 int overcurron, ps_address =1;
 float voltsetting,currsetting,overvoltsetting;
 
 char add[]="TCPIP0::x.x.x.2";
 
 
 //this variable controls the voltage
 //it can be hard coded into the viPrintf command as well
 voltsetting=3; //in volts
 //this variable controls the current
 //it can be hard coded into the viPrintf command as well
 currsetting=1.5; //in amps
 
 //these vaiables control the over voltage protection setting
 //overvoltsetting=6;  //in volts
 //this variable controls the over current protection (1 for on, 0 for off);
 overcurron=1;
 //The default resource manager manages initializes the VISA system
 VISAstatus=viOpenDefaultRM(&defrm);
 if (VISAstatus!=VI_SUCCESS)
 {
  viStatusDesc(defrm,VISAstatus,statdsc);
  printf("Error on viOpen: %s \n",statdsc);
  exit(EXIT_FAILURE);
 }
 //opens a communication session with the instrument at address "add"
    VISAstatus=viOpen(defrm,add,VI_NULL,timeout,&session);////error here
 //VISAstatus=viOpen(defrm,add,VI_NULL,timeout,&session);
 if (VISAstatus!=VI_SUCCESS)
 {
  viStatusDesc(session,VISAstatus,statdsc);
  printf("Error on viOpen: %s \n",statdsc);
  exit(EXIT_FAILURE);
 }
 viPrintf(session,"INST:SELECT %d \n",ps_address);
 viPrintf(session,"SYST:ERR? \n");
 Sleep(1000);
 viScanf(session,"%t",&err);
 
 printf("Error: %s \n",err);
 //Set voltage
 viPrintf(session,":VOLT %f \n",voltsetting);
 //Set the over voltage level
// viPrintf(session,":VOLT:PROT:LEV %f \n",overvoltsetting);
 //Turn on over current protection
 //viPrintf(session,":CURR:PROT:STAT %d \n",overcurron);
 
 //Set current level
 viPrintf(session,":CURR %f \n",currsetting);
 
 //Enable the output
 viPrintf(session,"OUTP ON \n");
 Sleep(500);
 
 //measure the voltage
 viPrintf(session, "MEAS:VOLT? \n");
 //readback the voltage from the instrument
 viScanf(session,"%s",&voltmeasurement);
 //print out voltage measurement
 printf("voltage measured to be: %s \n",voltmeasurement);
 
 
 //measure the programmed current
 viPrintf(session, ":CURRENT? \n");
 //readback the current from the instrument
 viScanf(session,"%s",&currmeasurement);
 //print out current measurement
 printf("current measured to be: %s \n",currmeasurement);
 
 
 //measure the overvoltage
 viPrintf(session, ":VOLT:PROT:LEV? \n");
 //readback the overvoltage from the instrument
 viScanf(session,"%s",&overvoltmeasurement);
 //print out overvoltage measurement
 printf("overvoltage measured to be: %s \n",overvoltmeasurement);
 //check for errors
 viPrintf(session,"SYST:ERR? \n");
 Sleep(1000);
 viScanf(session,"%t",&err);
 
 printf("Error: %s \n",err);

 //This frees up all of the resources
 viClose(session);
 viClose(defrm);
 return EXIT_SUCCESS;
 

}
 

Message Edited by bsp on 10-12-2006 07:00 AM

Download All
0 Kudos
Message 1 of 2
(2,841 Views)
Even though you have 'LabVIEW' in the names of your .spy files, I don't see any relationship to the LabVIEW language in your post. You would probably be better off re-posting this to the GPIB or Measurement Studio for C++ forum where you'll have better luck finding someone who uses text instead of pictures for progamming.Smiley Wink
0 Kudos
Message 2 of 2
(2,824 Views)