Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

how can i program a usb interface using ni-visa

Hello i am developing a system conformed by an mC(M16c) and the interface USB device (ez-usb sx2 cy7c68001), i have made some tests with a tool to communicate with the usb interface provided by cypress and it works nicely i can send and read data from the USB device.
 
Now i want to communicate with my device but using NI-VISA. I tryed to find a driver for my USB  (ez-usb sx2 cy7c68001) and obviously i did not find it because is not an instrument.The ez-usb sx2 cy7c68001 is usb 2.0 certificated device and it is suposse to be an USBTMC but Max did not recognise it since the beginning,so i made its own driver with the  Driver Wizard if NI- VISA and i can see it in the MAX  like the next device :

USB0::0x04B4::0x1002::NI-VISA-0::RAWVI_ATTR_TMO_VALUE = 2000

And these are the settings that i got from the attributes setting panel for my device:


VI_ATTR_MAX_QUEUE_LENGTH = 50
VI_ATTR_TERMCHAR = 0x0A
VI_ATTR_TERMCHAR_EN = VI_FALSE
VI_ATTR_IO_PROT = 1
VI_ATTR_SUPPRESS_END_EN = VI_FALSE
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 tryed to send and read some data to my device but it does not work i don not why.I have read all the NI-VISA user manual to try to start to programming my device and also i did not find information related with how to program my device, there is only information available for Serial Interface but not for USB interface.

Could you help me to start with NI-VISA and continue with my project, I have lost so much time reading about NI-VISA and its manual and i have not  had any results.

Thanks

Luis Alberto Navarrete

 

 

 

0 Kudos
Message 1 of 15
(4,975 Views)
Luis,

Sorry you have been running into problems. Have you confirmed that these are the appropriate attributes for your device? I am not very familiar with the chip you are interfacing with, but how were you communicating with it when it worked?

 I don't know if you have seen any of these links, but I have found them very useful when working with USB instruments.

Developer Zone: Six Things You Need to Know about USB Instrument Control
Knowledge Base: What is USBTMC and How Can I Communicate with my USB Instrument

The tutorial bellow will tell you exactly how to set up your USB device if it is USB-TMC compliant (or if you have to make your own driver) this is the best place to get started.

Developer Zone: USB Instrument Control Tutorial

-Marshall R
National Instruments
Applications Engineer
One stop for all your NI-VISA Support

GPIB Support has a new homepage
0 Kudos
Message 2 of 15
(4,949 Views)
Marshall R Thanks for your answer in fact previusly i have read the links that yo sent me, i followed the steps to make the driver and i can see my devise with MAX,  today i was working with the project and i made a rutine on my main program to put information on FIFO6 (in) of the USB interface and fortunately i coul read from MAX the data that i wrote previusly on FIFO6 (read till 512 bytes using the viwrite() tab ). Here is the status of the registers that MAX can provide

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

Now i am one step forward but i want to send data to my device, so i muss use the function with the tab Write and in the window Buffer apears this command : *IDN?\n  that is for send to the device its identification, How can i write data to my device ? should I write ni-visa code on these window or what is the procedure...

I hope you can continue assisting to my case.

Thanks
0 Kudos
Message 3 of 15
(4,938 Views)
So I assume you are talking about using the VISA Interactive Control. Yes the write buffer it displays there will be written out to your device when you press execute. the default message of "*IDN?\n" is the standard 488.2 identify command. You will need to know what commands your chip is expecting(*IDN) and what termination character it is expecting (\n).

Also, you can use the VISA exampes found in the NI example finder as well to do basic VISA reads and writes.
-Marshall R
National Instruments
Applications Engineer
One stop for all your NI-VISA Support

GPIB Support has a new homepage
0 Kudos
Message 4 of 15
(4,913 Views)
So I assume you are talking about using the VISA Interactive Control. Yes the write buffer it displays there will be written out to your device when you press execute. the default message of "*IDN?\n" is the standard 488.2 identify command. You will need to know what commands your chip is expecting(*IDN) and what termination character it is expecting (\n).

Also, you can use the VISA exampes found in the NI example finder as well to do basic VISA reads and writes.

Hi Marshall, yes i am using Visa Interactive control, i have not found good exaples to clarify my doubts in NI exampler finder neither in the NI-VISA hel, so can you help me to make the basic operations...i just want to send data to my device, i do not know maybe to send 30 bytes...., remember that i do not have any problem to read data from my device

Thanks


0 Kudos
Message 5 of 15
(4,888 Views)
Try using the example in the example finder "USB RAW - Bulk.vi"  which is found in: Hardware Input and Output»VISA

Tell me how it goes.
-Marshall R
National Instruments
Applications Engineer
One stop for all your NI-VISA Support

GPIB Support has a new homepage
0 Kudos
Message 6 of 15
(4,867 Views)
Thanks a lot Marshall, 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 string as follows:
 
static char FF6[513]; 
 
Then i make some operations, reading, writing to this string and in the Variable window 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 instead of show the 512 data values i obtain the direction of the FF6 string that is represented by an rare simbol )
 
I hope you can help me.
 
Thanks
0 Kudos
Message 7 of 15
(4,769 Views)
I was able to use InsertTextBoxLine to print the string on the UI.  Though I did have to make sure the array was null terminated. I have attached the code that I used to test this.

I would also place a break after you do your viRead to make sure that you have the value you are expecting in FF6.
-Marshall R
National Instruments
Applications Engineer
One stop for all your NI-VISA Support

GPIB Support has a new homepage
0 Kudos
Message 8 of 15
(4,742 Views)

Hi Marshall i am here again :), I want to tank you for the programm that you sendt me, i think is the best way to help people, with an example. I tryed with your example on my program and it works nicely, but the problem persists when i use the command for reading from my device, i have checked carefully and i got the 512 values from FF6 and at the end is also included the '0' as you indicated in the example program. When i read from my device i can read only the first value of FF6, i mean only FF6[0], i don know why... i have the same code with the same type of data and i don not have the same results. Here is a part of my code:

 

int CVICALLBACK GetFF6 (int panel, int control, int event,void *callbackData, int eventData1, int eventData2)
{
 ViUInt32 retcount;
  int i = 0;

 switch (event)
  {
  case EVENT_COMMIT:
    ResetTextBox (panelHandle, PANEL_FF6, "");      //clear the text box before write on it
   
 /*  
     //Set values
   for (i=0;i<512;i++)
    {
    FF6[i] = 0xAA ;
     }
   //Ensure array is null terminated
   FF6[512] = 0;
 */
   
    
    viRead (instrument, FF6, 512, &retcount);      //read the values of fifo6
    InsertTextBoxLine (panelHandle, PANEL_FF6, -1, FF6);
  
      //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 hope you can find the solution, thanks for all your support.

0 Kudos
Message 9 of 15
(4,711 Views)
I forgot to say that  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.
0 Kudos
Message 10 of 15
(4,710 Views)