LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Timeout expired before operation completed

I am trying to control a digital attenuator using GPIB and VISA. I am using viWrite to write the control string to the device. What happens is the control message is written to the device and the attenuaton is set, but the write operation doesn't return until it timesout. Also after it timesout the attenuator does not respond to anymore commands and I have to power cycle it to get it to work again. The strange thing is that if I use the VISA Interactive Control to manually do viWrite commands to the attenuator, it works every time. It seems that Im not doing something right in my code since the viWrite in the interactive control works flawlessly.


The two functions I made to call and set the attenuator, first I call AttenConfig to open a connection to the device, then AttenSet to set the attenuation.
//----------------------------------------------------------------------------------------
// Function:    AttenConfig   
// Description: Configures and opens a connection to the digial attenuator
// Paramaters:   
// Returns:    int 0 for success       
//----------------------------------------------------------------------------------------
int __stdcall AttenConfig(int client, void *Data){
    int status = 0;

    //Get session
    viOpenDefaultRM(&RmViSession);
    //Open device
    status = viOpen(RmViSession, "GPIB::10::INSTR", VI_NULL, VI_NULL, &AttenViSession);
    if(status != 0){
        fpUILog("...Weinschel 8310 Driver Open Device Error");
        GeneralReturn(-1, client);
    }else{
        GeneralReturn(0, client);
    }
   
    return 0;
}


//----------------------------------------------------------------------------------------
// Function:    AttenSet
// Description: Sets the attenuator
// Paramaters:   
// Returns:    int 0 for success       
//----------------------------------------------------------------------------------------
int __stdcall AttenSet(int client, void *Data){
    int *temp, status = 0;
    char Command[10];
   
    temp = Data;
   
    memset(Command, '\0', 10);
    strcpy(Command, "ATTN ");
   
    Fmt(&Command[strlen(Command)], "%s<%i", *temp);
   
    status = viWrite(AttenViSession, Command, sizeof(Command), VI_NULL);
   
    if(status != 0){
        fpUILog("...Weinschel 8310 Driver Set Atten Error");
        GeneralReturn(-1, client);
    }else{
        GeneralReturn(0, client);
    }
   
    return 0;
}



Any thoughts?

0 Kudos
Message 1 of 2
(3,226 Views)
Ha, I found the problem.


status = viWrite(AttenViSession, Command, sizeof(Command), VI_NULL);

I meant strlen and not sizeof.

status = viWrite(AttenViSession, Command, strlen(Command), VI_NULL);



Thanks anyways.


0 Kudos
Message 2 of 2
(3,222 Views)