Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

I am not able to set and read the temperature from the temperature controller 9650 using visual C++ even thogh there is no error message??

the program always reads 0 inspite of setting different temperature..wud be really greatful if someone cud help...

0 Kudos
Message 1 of 15
(5,089 Views)

@skpoudel wrote:

the program always reads 0 inspite of setting different temperature..wud be really greatful if someone cud help...


I don't know what "wud" is. Cud is what a cow chews on.

 

There are C examples for NI-VISA installed on your computer. Try those first.

 

 

 

 

 

0 Kudos
Message 2 of 15
(5,084 Views)

The programs I tried for setting and reading the temperature are from the NI example programs installed on my computer.Still I am not able to set and read the temperature....

0 Kudos
Message 3 of 15
(5,069 Views)

@skpoudel wrote:

The programs I tried for setting and reading the temperature are from the NI example programs installed on my computer.Still I am not able to set and read the temperature....


You can try posting your C++ code. Otherwise, who knows what is wrong. No one is clairvoyant.

 

 

 

0 Kudos
Message 4 of 15
(5,067 Views)

// rmp.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdlib.h>
#include<conio.h>

#include "ni4882.h"
#include <stdio.h>


void GpibError(const char *msg);
void delay(unsigned int);


int Device = 0;                   /* Device unit descriptor                  */
int BoardIndex = 0;               /* Interface Index (GPIB0=0,GPIB1=1,etc.)  */

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
    
    int nRetCode = 0;
    
    
    // initialize MFC and print and error on failure
    if(!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0)){
        // TODO: change error code to suit your needs
        cerr << _T("Fatal Error: MFC initialization failed") << endl;
        nRetCode = 1;
    }
    else{        
    

       int   PrimaryAddress = 1;      /* Primary address of the device           */
       int   SecondaryAddress = 0;    /* Secondary address of the device         */
       char  Buffer[101];             /* Read buffer                             */

    /*****************************************************************************
     * Initialization - Done only once at the beginning of your application.
     *****************************************************************************/

    Device = ibdev(                /* Create a unit descriptor handle         */
        BoardIndex,              /* Board Index (GPIB0 = 0, GPIB1 = 1, ...) */
            PrimaryAddress,          /* Device primary address                  */
             SecondaryAddress,        /* Device secondary address                */
             T10s,                    /* Timeout setting (T10s = 10 seconds)     */
             1,                       /* Assert EOI line at end of write         */
             0);                      /* EOS termination mode                    */


    if (Ibsta() & ERR) {           /* Check for GPIB Error                    */
          GpibError("ibdev Error");
       }

    ibclr(Device);                 /* Clear the device                        */

    if (Ibsta() & ERR) {
        GpibError("ibclr Error");
    }

    /*****************************************************************************
     * Main Application Body - Write the majority of your GPIB code here.
     *****************************************************************************/

    ibwrt(Device, "S<cr>", 5);     /* Send the identification query command   */
    delay(100);
    if (Ibsta() & ERR) {
        GpibError("ibwrt Error");
    }
    //delay(50000);
    //ibwrt(Device, "S<cr>", 5 );     /* Send the identification query command   */
       //if (Ibsta() & ERR) {
    //   GpibError("ibwrt Error");
    //}

    
    ibrd(Device, Buffer, 100);     /* Read up to 100 bytes from the device    */
    if (Ibsta() & ERR) {
        GpibError("ibrd Error");    
    }

    Buffer[Ibcnt()] = '\0';        /* Null terminate the ASCII string         */

    printf("%s\n", Buffer);        /* Print the device identification         */
    
    
    /*****************************************************************************
     * Uninitialization - Done only once at the end of your application.
     *****************************************************************************/

       ibonl(Device, 0);              /* Take the device offline                 */
       //printf("\n device is offline");
       if (Ibsta() & ERR) {
              GpibError("ibonl Error");    
       }

      return nRetCode;
    }

}


void GpibError(const char *msg) {

    printf("%s\n", msg);

    printf("Ibsta() = 0x%x  <", Ibsta());
    if (Ibsta() & ERR )  printf(" ERR");
    if (Ibsta() & TIMO)  printf(" TIMO");
    if (Ibsta() & END )  printf(" END");
    if (Ibsta() & SRQI)  printf(" SRQI");
    if (Ibsta() & RQS )  printf(" RQS");
    if (Ibsta() & CMPL)  printf(" CMPL");
    if (Ibsta() & LOK )  printf(" LOK");
    if (Ibsta() & REM )  printf(" REM");
    if (Ibsta() & CIC )  printf(" CIC");
    if (Ibsta() & ATN )  printf(" ATN");
    if (Ibsta() & TACS)  printf(" TACS");
    if (Ibsta() & LACS)  printf(" LACS");
    if (Ibsta() & DTAS)  printf(" DTAS");
    if (Ibsta() & DCAS)  printf(" DCAS");
    printf (" >\n");

    printf ("Iberr() = %d", Iberr());
    if (Iberr() == EDVR) printf(" EDVR <Driver error>\n");
    if (Iberr() == ECIC) printf(" ECIC <Not Controller-In-Charge>\n");
    if (Iberr() == ENOL) printf(" ENOL <No Listener>\n");
    if (Iberr() == EADR) printf(" EADR <Address error>\n");
    if (Iberr() == EARG) printf(" EARG <Invalid argument>\n");
    if (Iberr() == ESAC) printf(" ESAC <Not System Controller>\n");
    if (Iberr() == EABO) printf(" EABO <Operation aborted>\n");
    if (Iberr() == ENEB) printf(" ENEB <No GPIB board>\n");
    if (Iberr() == EOIP) printf(" EOIP <Async I/O in progress>\n");
    if (Iberr() == ECAP) printf(" ECAP <No capability>\n");
    if (Iberr() == EFSO) printf(" EFSO <File system error>\n");
    if (Iberr() == EBUS) printf(" EBUS <Command error>\n");
    if (Iberr() == ESTB) printf(" ESTB <Status byte lost>\n");
    if (Iberr() == ESRQ) printf(" ESRQ <SRQ stuck on>\n");
    if (Iberr() == ETAB) printf(" ETAB <Table Overflow>\n");
    if (Iberr() == ELCK) printf(" ELCK <Lock error>\n");
    if (Iberr() == EARM) printf(" EARM <Ibnotify rearm error>\n");
    if (Iberr() == EHDL) printf(" EHDL <Invalid Handle>\n");
    if (Iberr() == EWIP) printf(" EWIP <Wait already in progress>\n");
    if (Iberr() == ERST) printf(" ERST <Notification cancelled due to reset>\n");
    if (Iberr() == EPWR) printf(" EPWR <Power error>\n");

    printf("Ibcnt() = %u\n", Ibcnt());
    printf("\n");

    /* Call ibonl to take the device and interface offline */
    ibonl(Device, 0);

    exit(1);
}

void delay(unsigned int d){
    while(d){
        d--;
    }
}

0 Kudos
Message 5 of 15
(5,042 Views)

That code is suppose to query the instrument for an indentification string.

Do you get one back?

0 Kudos
Message 6 of 15
(5,035 Views)

The string"S<cr>" is suppose to return the present set point .....but in my case it always returns 0.00 even after i change the set point manually to different values.

0 Kudos
Message 7 of 15
(5,024 Views)
Try sending the correct termination character instead of that <CR>. That is not a carriage return.
0 Kudos
Message 8 of 15
(5,016 Views)

i tried sending the hex code of carriage return too...but still its giving the same result

0 Kudos
Message 9 of 15
(5,008 Views)
Let me ask a basic question. Did you test the command in MAX before trying to write any code?

Why are you using \ codes in the rest of your program but not with this? A compliant GPIB instrument does not require a CR anyway but you can configure MAX to send it and not have it in your code.

It would also help if you provided the vendor's name and not just a model number. Attaching the manual would also help.
0 Kudos
Message 10 of 15
(4,997 Views)