Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Read and write using MAX ni-visa

Hello everybody i would like to know how to read and write to my usb device using the console of MAX from ni-visa, i can see my device that is an usb raw, also a made a routine in the usb device and i can read the data that i wrote with the viread tab, but i don not know how to write to my device..
 
I hope somebody can help me , thanks
0 Kudos
Message 1 of 12
(6,794 Views)
Hi siul,

You mentioned that you would like to read and write to the USB device using MAX. Do you mean to say that you do not want to communicate with the device in LabVIEW?

What kind of a device is it? Did you create a device driver for it using the VISA Driver Wizard? Also, do you know how you are supposed to interact with the USB device (Control/Bulk/Interrupt)? There is a good KnowledgeBase article here that goes through the different modes of communication with a USB Raw device.

There is also a good tutorial on general USB Instrument Control here. Let us know how it goes!
Rasheel
0 Kudos
Message 2 of 12
(6,765 Views)
  Hi Rasheel...

Answering to you question :You mentioned that you would like to read and write to the USB device using MAX. Do you mean to say that you do not want to communicate with the device in LabVIEW?

Yes i want to read y write from and to my device using Measurement and Automation Explorer MAX  part of ni-visa, here on this program i can see my device (previously i made its driver with Driver Wizard). And yes i will not use LabView only i want to see how my device behave using instructions with VISA and later (next step on my project) use Labwindows to make an interface foe my device. But first i need to check the operativility of visa using the instruccions for usb in MAX. I have made some test I wrote information with my mC on FIFO 6 that is for IN  and i cab read this data from MAX using the  VISA Test Panel, here on the tab Write i just specify the number of bytes that i want to read and inmediately a got the data that i habe written previously on my FIFO6, now i want to make the inverse operation send data from MAX VISA Test Panel to my device (FIFO2), i have tryed to do this on the tab Write where appears a window that say Buffer and is showed the next instrucion: *IDN?\n

That is for the say to my device to send information about itself, when i executed the this command i got 0x06 in the return value data, now I do not to sent this parameter, for me it will be better to send for example 100 bytes to my FIFO2, now my question comes, how acn i do that?


What kind of a device is it? Did you create a device driver for it using the VISA Driver Wizard? Also, do you know how you are supposed to interact with the USB device (Control/Bulk/Interrupt)? There is a good KnowledgeBase article here that goes through the different modes of communication with a USB Raw device.


My device is the CNY7c68001 from Cypress, yes i create a driver using VISA Driver Wizard, and i know how my device interacts specialy i am interested on control and bulk transfers.

I got this information from MAX

Attribute Settingd for USB::0x04b4::0x1002::NI-VISA-0::RAW  
VI_ATTR_TMO_VALUE = 50
VI_ATTR_MAX_QUEUE_LENGTH = 5
VI_ATTR_TERMCHAR = 0x00
VI_ATTR_TERMCHAR_EN = VI_FALSE
VI_ATTR_IO_PROT = 1
VI_ATTR_SUPPRESS_END_EN = VI_TRUE
VI_ATTR_USB_MAX_INTR_SIZE = 1
VI_ATTR_USB_CTRL_PIPE = 0x0000
VI_ATTR_USB_BULK_OUT_PIPE = 0x0002
VI_ATTR_USB_BULK_IN_PIPE = 0x0086
VI_ATTR_USB_INTR_IN_PIPE = 0xFFFF
VI_ATTR_USB_ALT_SETTING = 0
VI_ATTR_USB_BULK_OUT_STATUS = 0
VI_ATTR_USB_BULK_IN_STATUS = 0
VI_ATTR_USB_INTR_IN_STATUS = -1
VI_ATTR_USB_END_IN = 5


I have read the links that you send me, they are good, they clarified me some doubts

Well i hope that with this brief explanation you can gave a better solution to my problem...

Thanks


0 Kudos
Message 3 of 12
(6,747 Views)
Hi siul,

So if I am understanding correctly, you'd like to use the MAX test panels in order to send 100 bytes of data.

Do you know what command it is that you need to send to the device in order to tell it to take data? You will need to know what the command is, and this is going to be device specific. The MAX VISA test panel is also a very simple and communication interface, so it might be not be the appropriate method of communicating with the device if you would like to perform a more complex operation.
Rasheel
0 Kudos
Message 4 of 12
(6,729 Views)
Thanks a lot, now I am on the next phase of the project. I am programming with Labwindows CVi 7.1.
 
Unfortunately I have problem to show in the user panel an string that i have in memory.
I declared my stribg as follows:
 
static char FF6[513]; 
 
Then i make some operations, reading, writing to this string and in the Variables windos all is nice when i run the program, in the user interface I have made a Text box to show the FF6 string but i can not read the data of the string, only i can read the value of the direction of the string.This is the code.
 
 
int CVICALLBACK GetFF6 (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)
{
 ViUInt32 retcount;
 
 switch (event)
  {
  case EVENT_COMMIT:
    ResetTextBox (panelHandle, PANEL_FF6, "");      //clear the text box before write on it
    viRead (instrument, FF6, 512, &retcount);      //read the values of fifo6
       //InsertTextBoxLine (panelHandle, PANEL_FF6, -1, FF6);   //show the value of FF6
   // SetCtrlVal (panelHandle, PANEL_FF6, FF6);      //show the fifo6 values
    SetCtrlAttribute (panelHandle, PANEL_SAVE, ATTR_DIMMED, 0); //enable the button SAVE
    SetCtrlAttribute (panelHandle, PANEL_GETFF6, ATTR_DIMMED, 1); //disenable the button GETFF6 because it is empty,we tx always the entire FIFO6
   
   break;
  case EVENT_RIGHT_CLICK:
   break;
  }
 return 0;
}
 
I tried with the instrucions SetCrtrlVal und with InsertTextBoxLine and with both i obtain the same valu, i don not know maybe i declarated wrong my array or what can be the problem? in another parts of the program i don not have any problem to get the value data of the string, but the problem is when i want to show that vaues on the user interface(on the test box)
 
I hope you can help me.
 
Thanks
0 Kudos
Message 5 of 12
(6,659 Views)
Hi siul82mx,

What do you mean by value of the direction of the string? Do you know what format the data of the string is in?

So to clarify, you can manipulate the data that you have coming from the device, but you are having trouble displaying the data on the front panel? I think if we knew what the format of the data is (string, integer, etc) we could try formatting it to the right one.

Let me know!
Rasheel
0 Kudos
Message 6 of 12
(6,628 Views)
Hi what I mean is that when i run the program and insert a breakpoint in the instruction that reads my string array FF6[ ]   ( viRead (instrument, FF6, 512, &retcount);     instruction)
and if i check the variable windows i can see all the 512 values that has the FF6 array, but in the next instruction  what ever that i use: InsertTextBoxLine (panelHandle, PANEL_FF6, -1, FF6)  or  SetCtrlVal (panelHandle, PANEL_FF6, FF6);   here it's suposse to be that i just need to put the name of my array FF6 at the end of the instruction to have all the values inside of the array but  I don not have displayed any of all the values of the FF6 that are 512 values, it's only displayed the next character "ª" , i suppose that is a problem with the declaration of the array (static char FF6[513];  ) or with the pointer, i am not sure, what do you recommend to me? 
0 Kudos
Message 7 of 12
(6,604 Views)

I mean that i could only show the FF6[0] on the user interface even when i want to show the 512 values of FF6, the problem is not the adquisition of data because i can see using the variable window each data (from 512) of FF6, the problem is to displayed this data. I don not why only points to the first direction FF6[0] instead of show all the array. The data that i have in FF6 are integers.

Maybe as you comment i have to convert the data to an specific format before i could display on the user interface. I am using a text box to display my FF6 data. Another interesting thing is that i can see the valuues of FF6 in the memory window, also in the array display, BUT when i use the string display i can see only the FF6[0], that is the only data displayed on the front panel.

I hope now you have a better idea of my problem, thanks.

0 Kudos
Message 8 of 12
(6,600 Views)
Hi siul,

So the "SetCtrlVal (panelHandle, PANEL_FF6, FF6);" line should be the one you are using, and the code looks fine. Please do the following so we can debug this:

-Place a breakpoint in the SetCtrlVal line
-Run the code
-When the program gets to the breakpoint, right-click on the FF6 and choose "Add Watch Expression"
-In the window that opens below, expand the tree, right click on the variable, and choose View > String Display

Here, a window should open up with the string. Please take a screenshot of that and upload it here so we can take a look.

Let us know how it goes!
Rasheel
0 Kudos
Message 9 of 12
(6,522 Views)
I have found the problem, it was that my second value on the string was \0, so that finished the srting.
 
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 10 of 12
(6,472 Views)