Showing results for 
Search instead for 
Did you mean: 

viOpen error+time out expired before operation completed

  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
//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);
 //The default resource manager manages initializes the VISA system
 if (VISAstatus!=VI_SUCCESS)
  printf("Error on viOpen: %s \n",statdsc);
 //opens a communication session with the instrument at address "add"
    VISAstatus=viOpen(defrm,add,VI_NULL,timeout,&session);////error here
 if (VISAstatus!=VI_SUCCESS)
  printf("Error on viOpen: %s \n",statdsc);
 viPrintf(session,"INST:SELECT %d \n",ps_address);
 viPrintf(session,"SYST:ERR? \n");
 printf("Error: %s \n",err);
 //Set voltage
 viPrintf(session,":VOLT %f \n",voltsetting);
 //Set the over voltage level
// viPrintf(session,":VOLTROT:LEV %f \n",overvoltsetting);
 //Turn on over current protection
 //viPrintf(session,":CURRROT:STAT %d \n",overcurron);
 //Set current level
 viPrintf(session,":CURR %f \n",currsetting);
 //Enable the output
 viPrintf(session,"OUTP ON \n");
 //measure the voltage
 viPrintf(session, "MEAS:VOLT? \n");
 //readback the voltage from the instrument
 //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
 //print out current measurement
 printf("current measured to be: %s \n",currmeasurement);
 //measure the overvoltage
 viPrintf(session, ":VOLTROT:LEV? \n");
 //readback the overvoltage from the instrument
 //print out overvoltage measurement
 printf("overvoltage measured to be: %s \n",overvoltmeasurement);
 //check for errors
 viPrintf(session,"SYST:ERR? \n");
 printf("Error: %s \n",err);

 //This frees up all of the resources

Download All
0 Kudos
Message 1 of 2

Hi bsp,

What version of NI-VISA are you using?  You may want to upgrade to the latest version by going to this page.  Make sure you have a compatible operating system prior to installing.  You mentioned that you are using LabVIEW and Measurement and Automation Explorer (MAX).  Are you sending commands successfully in MAX or in LabVIEW?  MAX will automatically open and close sessions for you, so you may want to check that this is done in your code on each run.  Also, make sure that you have proper timing (for example, make sure there is enough time programmed into your code for the instrument to respond properly).  I see several errors in the code you say is working.  Are any of these error causing problems?

Please answer these questions and try these suggestions and let me know an updates.  Have a great day!

Chris R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2