Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

problems with data type

Hi everybody I have a problem with respect the data Type.I read some attributes from my device but the problem comes when I want to show them on the pront panel of the user interface because the commands need a diferente type of values. For example when i use this function:  viGetAttribute (instrument, VI_ATTR_USB_BULK_OUT_PIPE, &bulkoutpipe); i can only put the name of the variable that i will use to save the value of the data, and by default this variable is an integer (teh program uses ViInt16) and till here is ok, i got the value from my device with any problem, but now the next step is display this value on the user interface using a text box and i have to use the next command:      InsertListItem (panelHandle, PANEL_CONFIG, 1, bulkoutpipe, bulkoutpipe); but here by default the variable to show is a character array and i can not select another type of variable, so when i run the program i got the message error that says: Type error in argument 4 to 'InsertListItem';found 'ViInt16' expected 'pointer to const char'
Here is the code in the function where i have the problem:
 
int CVICALLBACK GetConfig (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)
{
// char bulkoutpipe[256];
 ViInt16 bulkoutpipe;
 ViChar name[256];
 unsigned char idnresult[72];
 ViUInt32 retcount;
 
 switch (event)
  {
  case EVENT_COMMIT:
    DeleteListItem (panelHandle, PANEL_CONFIG, 0, -1);
    viGetAttribute (instrument, VI_ATTR_RSRC_NAME, name);
       InsertListItem (panelHandle, PANEL_CONFIG, 0, name, 0);
    viGetAttribute (instrument, VI_ATTR_USB_BULK_OUT_PIPE, &bulkoutpipe);
  
  
  //  viGetAttribute (instrument, VI_ATTR_USB_BULK_IN_PIPE, &bulkinpipe);
    InsertListItem (panelHandle, PANEL_CONFIG, 1, bulkoutpipe, bulkoutpipe);
   
   
    //viGetAttribute (instrument, VI_ATTR_USB_BULK_IN_PIPE, &bulkinpipe[0]);
          
   
  //  viWrite (instrument, "*IDN?\n", 6, &retcount);
  //  viRead (instrument, idnresult, 72, &retcount);
  //  InsertListItem (panelHandle, PANEL_CONFIG, 1, idnresult, 0);
      
    SetCtrlAttribute (panelHandle, PANEL_SAVE, ATTR_DIMMED, 1); //enable the button SAVE 
   break;
  case EVENT_RIGHT_CLICK:
   break;
  }
 return 0;
}
 
 
 
I hope and someone can help me. Thanks , bye
0 Kudos
Message 1 of 5
(4,103 Views)
Hello siul82mx,

To convert your ViInt16 to a string, you can use the sprintf C function.  This function can be used to insert various data types including integers into a string.  Below is an example of how you would call this function.  The quoted text is simply added to the string.  The %d is used to inform the function that I am inserting an integer, rather than a floating point, character, pointer address, etc.  The variable bulkOutPipe is then used to specify the integer I am inserting into the string.  You can have multiple variable insertions in one function call if you like.


    // Declare variables
    ViInt16 bulkOutPipe;
    char bulkOutPipeString [50];
    
    // Assign bulkOutPipe value
    ...
    
    // Add value to string
    sprintf(bulkOutPipeString, "Here is my ViInt value in a string: %d", bulkOutPipe);
            
            
There are many additional resources for this function online, as in this website:
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf.html

I hope that helps!
Regards,


Marty H.
National Instruments
0 Kudos
Message 2 of 5
(4,038 Views)
Thanks your last advice was very helfull for my program
 
Now i have another problem may be you can help me. I am sending data from my USB RAW and i want to enable the USB interrupt with visa commands in order that when there is an interrupt my program in CVI gets the values from the USB.
 
i have tryed in diferent ways but always i got an error setup on the function, and the programm dos not run.I have read the only example that is on the user manual but i have still the problem, i have declarated my funciton, installed the handler, but when i want to eneble the VI_EVENT_USB_INT is when the problem appears, the error code says :
 
ViEnableEvent : Unable to start operation because setup is invalid (due to attributes being set to an inconsistent state)
 
The code that i am using is the next:
 
//headers files
static unsigned char FF6[513];
static ViStatus status;
static ViSession defaultRM;
static ViSession instrument;
static ViObject instrument;   
static int panelHandle;
static int start=0; 
static ViBuf Userhandle;
static ViEvent eventContext;
static ViUInt32 retcount; 
static ViEventType etype; 
//USB int event handler
ViStatus _VI_FUNCH myCallback(ViSession instrument, ViEventType etype, ViEvent eventContext, ViAddr UserHandle)
{
//printf("hola");
//ViUInt32 retcount;
//ViJobId jobID;
//ViUInt16 stb;
//status = viReadSTB (instrument, &stb);
//status = viReadSTB(vi, &stb);
//status = viReadAsync(vi,(ViBuf)UserHandle,512,&jobID);
 
status = viRead (instrument, FF6, 512, &retcount);      //read the values of fifo6
  
return VI_SUCCESS;
}
 
int main (int argc, char *argv[])
{
// ViBuf Userhandle;
// ViEvent eventContext;
// ViEventType etype;

 if (InitCVIRTE (0, argv, 0) == 0)
  return -1; /* out of memory */
 if ((panelHandle = LoadPanel (0, "usb.uir", PANEL)) < 0)
  return -1;
 status = viOpenDefaultRM (&defaultRM);   //we open the Resource Manager
 if (status < VI_SUCCESS)      /*Check if we have an Error Initializing VISA...exiting*/
  return -1;
    status = viOpen (defaultRM, "USB0::0x04B4::0x1002::NI-VISA-0::RAW", VI_NULL, VI_NULL, &instrument); //we open the communication with our instrument
 if (status < VI_SUCCESS)      /*Check if we have an Error Initializing instrument...exiting*/
  return -1;
 viFlush (instrument, VI_WRITE_BUF_DISCARD);
 viFlush (instrument, VI_READ_BUF_DISCARD);
 
 Userhandle = (ViBuf)malloc(512);
 status = viInstallHandler (instrument, VI_EVENT_USB_INTR, myCallback, Userhandle);
 if (status < VI_SUCCESS)      /*Check if we have an Error to istall the handler for the USB INT */
  return -1;
 
 status = viEnableEvent (instrument, VI_EVENT_USB_INTR, VI_HNDLR, VI_NULL);
 if (status < VI_SUCCESS)      /*Check if we have an Error to istall the handler for the USB INT ************************** Here is the problem ***************************/
  return -1;

 DisplayPanel (panelHandle);
 RunUserInterface ();
 DiscardPanel (panelHandle);
 
 return 0;
}
 
 
I hope you can indentify where is my mistake, also i would like to know if you can send me and example using events, that will be very usefull for me, Thanks
0 Kudos
Message 3 of 5
(4,018 Views)
Hello siul82mx,

I see that this question is a duplicate post to this forum: how to configure an event

We like to keep separate issues in separate forums, so please refer to the linked forum for future posts regarding this issue.

Thanks!
Regards,


Marty H.
National Instruments
0 Kudos
Message 4 of 5
(4,000 Views)
Ok , so you mean i have to wait more time for the support , anyway thanks for your help, bye
0 Kudos
Message 5 of 5
(3,996 Views)