LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Looking for CVI code to communicate with Ophir USBI device

Solved!
Go to solution

I am hoping to find someone who has used the Ophir USB Smart Head Interface Device (USBI). 

 

I am running CVI 9.0 and I am very confused about how to talk directly to the device.  The USB device connects to a laser power meter head.  Ophir has LabView drivers, but not CVI.  There is an ActiveX configuration, but almost zero documentation on how to properly set it up.

 

IF anyone has used this device sucessfully in CVI, I would be extremely eager to speak with them.  I can provide the NI-VISA code I have tried (and used similar code sucessfully in the past) and the ActiveX driver calls that can be including in CVI.

 

Thank you in advance for any response.

0 Kudos
Message 1 of 7
(4,666 Views)

Gromit,

 

I personally have never used the Ophir USBI LabVIEW VI's but I did download them and looked at their source code. The VI's are almost entirely just wrappers for VISA functions, which CVI does support. I'd recommend taking a look at "Ophir InitCom" and "Ophir SendRec" for more guidance on how the VISA communication works in LabVIEW and then view some of the example CVI NI-VISA code in C:\Documents and Settings\All Users\Documents\National Instruments\NI-VISA\Examples\C\ (by default).

 

Regards,

 

Steven Zittrower

Applications Engineer

National Instruments

http://www.ni.com/support

Message 2 of 7
(4,645 Views)

Steven,

 

First of all, Thanks much for taking a look.  I am proficient in LabWindows but NOT LabView.  I can open the OphInstr.llb using LabView and see the vi's you mentioned, but do not know how to see the "code" behind them, or how to include them in LabWindows.  Can you elaborate?  I am, however very familar with NI-VISA.

 

Thank you,

Gromit

0 Kudos
Message 3 of 7
(4,630 Views)

Gromit,

 

In the LabVIEW development environment you can view the block diagram (Window»Show Block Diagram) and see the underlying graphical source code. If you then double-click on the VI's that I previously mentioned you will notice it brings up more source code (you are navigating inside the SubVI). If you view the block diagram of those individual VI's you can see the NI-VISA commands that it calls in the order that it calls them in. For example, in Ophir InitCom.VI this simply calls VISA Open (LabVIEW equivalent to CVI function viOpenDefaultRM and viOpen) and a property node to set its attributes (LabVIEW for CVI function viSetAttribute) where as Ophir SendReceive.VI just makes calls to VISA Write and VISA Read (CVI equilavents are viWrite and viRead).

 

By looking at the process flow of the LabVIEW code hopefully you can incorporate the same NI-VISA commands as well in CVI.

 

Regards,

 

Steven Zittrower

Applications Engineer

National Instruments

http://www.ni.com/support

Message 4 of 7
(4,609 Views)

Thanks again for the reply Steve.. the VIs still appear a little cryptic due to my inexperience with LabVIEW, but the method you describe is exactly what I have tried, and fails.  I've included code below, which compiles and runs, but the viWrite will fail complaining about bad attributes.  I have experimented, up to and including, removing (and changing) all the attributes that are being set.

 

There appears to be something missing.. not sure what that is. 

 

The exact error message displayed when attempting to write is:  "Unable to start write operation because setup is invalid (due to attributes being set to an inconsistent state)."

 

Again, thanks for your help.

 

========================================================

////////////////// OPHIR /////////////////////////////////////////////

  // ignore library errors: code will handle errors
  bPrevBreak = SetBreakOnLibraryErrors (FALSE);

 // open default resource
 vistatus = viOpenDefaultRM(&OphirRM);
 
 // check for open error
 if (vistatus < VI_SUCCESS)
 {
  // display error
  status = print_error("viOpenOphirRM Error    ", vistatus);
  return vistatus;
 }
 
 // find specific ITA USB device
 vistatus = viFindRsrc (OphirRM, "?*USB?*{VI_ATTR_MANF_ID==0x0BD3 && VI_ATTR_MODEL_CODE==0x0222}",
     &findList, &numInstrs, instrDescriptor);
 // find specific ITA USB device
// vistatus = viFindRsrc (OphirRM, "USB?*",
//     &findList, &numInstrs, instrDescriptor);
 
printf("numInstrs=%d, findlist=%d, instrD='%s' \n",numInstrs, findList, instrDescriptor); 


 if (vistatus < VI_SUCCESS)
 {
  // display error
  status = print_error("viFindRsrc OphirRM Error    ", vistatus);
  return vistatus;
 }
 
 // open USB ITA device
 vistatus = viOpen(OphirRM, instrDescriptor, VI_NULL, VI_NULL, &OphirUSB);

 if (vistatus < VI_SUCCESS)
 {
  // display error
  status = print_error("viOpen OphirRM Error    ", vistatus);
  return vistatus;
 }
 
 // enable i/o completion event 
 vistatus = viEnableEvent (OphirUSB, VI_EVENT_IO_COMPLETION, VI_QUEUE, VI_NULL);         <==== have play with all of these attributes
// vistatus = viEnableEvent (OphirUSB, VI_EVENT_SERVICE_REQ, VI_QUEUE, VI_NULL);

 // Initialize the timeout attribute to 20 ms
 viSetAttribute(OphirUSB, VI_ATTR_TMO_VALUE, 1000);
  
 // Set termination character 
 viSetAttribute(OphirUSB, VI_ATTR_TERMCHAR, 0x0A);                               <==== have play with all of these attributes
 viSetAttribute(OphirUSB, VI_ATTR_SUPPRESS_END_EN, VI_FALSE);
 viSetAttribute(OphirUSB, VI_ATTR_IO_PROT, 1);
 viSetAttribute(OphirUSB, VI_ATTR_USB_MAX_INTR_SIZE, 64);
 viSetAttribute(OphirUSB, VI_ATTR_TERMCHAR_EN, VI_FALSE);
 
 strcpy(stringinput, "$VE\0");    <==== using the Ophir manual, tried to include or exclude the terminator, this is a simple command to check the version
 
// OpenUSB(Ophir_L_Warning);
 
 viSetBuf (OphirUSB, VI_WRITE_BUF, strlen(stringinput));   <==== this command fails


    vistatus = viWrite(OphirUSB, (ViBuf)stringinput, strlen(stringinput), retCount);
 Delay(0.100);
 if (vistatus < VI_SUCCESS)   
    {
  
  // display error
  status = print_error("Ophir WRITE Error    ", vistatus);

  // display error message
  RW_Error_Display();

  viClose(OphirRM);
  viClose(OphirUSB);
  return -1;
 }
 
 vistatus = viRead(OphirUSB, (ViPBuf)USB_buf, 0, retCount);
 Delay(0.100);
 if (vistatus < VI_SUCCESS)   
    {
  
  // display error
  status = print_error("Ophir READ Error    ", vistatus);

  // display error message
  RW_Error_Display();

  viClose(OphirRM);
  viClose(OphirUSB);
  return -1;
 }
 
 printf("viRead USB_buf = '%s \n",USB_buf);
 
 // restore previous library break condition
 SetBreakOnLibraryErrors (bPrevBreak);
 

 

0 Kudos
Message 5 of 7
(4,607 Views)

Grommit,

 

First of all I'm not entirely sure why that is erroring. I don't have enough intimate knowledge with the driver to know all of the settings and configurations and their options. A couple of paths that may work better for you are the following.

 

1. Create a DLL out of the current LabVIEW code and then just call that.

Distributing Applications with the LabVIEW Application Builder

http://zone.ni.com/devzone/cda/tut/p/id/3303

 

2. Try out this legacy program which will do the creating C DLL wrapers for you. (Note: This only works with LabVIEW versions 8.0-8.2 and needs a project-style instrument driver,  you're driver is not project-style and thus would have to be converted).

LabVIEW Instrument Driver Export Wizard (C Interface Generator for LabVIEW Project-Style Instrument Drivers)

http://lumen.ni.com/nicif/us/gb_infolvdriver/content.xhtml

 

Regards,

 

Steven Zittrower

Applications Engineer

National Instruments

http://www.ni.com/support

Message 6 of 7
(4,561 Views)
Solution
Accepted by topic author Gromit

Thanks again StevieZ..

 

I was able to finally coerce a sample code from Ophir... Actually their s/w designers in Israel.  It took a day to get it converted to work within my GUI, but it does now work.  They gave ActiveX examples that do not use NI-VISA at all.

 

Thanks again for all your help. 

0 Kudos
Message 7 of 7
(4,559 Views)