Hello,
My problem is: I have a spectrometer HR 4000 from Ocean Optics. I want to control it from labwindows and, from that, integrate it to other labwindows program.
I have .vi from NI to control the spectrometer from labview:
http://sine.ni.com/apps/utf8/niid_web_display.download_page?p_id_guid=7833BD4A31DA1274E04400144FB7D21D
The .vi works perfectly with the spectrometer.
Then, I build a shared libraries with the usual procedure with the .vi I need. I have now a .h, .lib and .dll.
.h is given at the end.
What I do is:
I use the viFindRsrc function to have a char of my instrument.
The function from the labview needs a VISA ressource name.
From this subject: http://forums.ni.com/t5/LabVIEW/How-to-pass-Visa-Resoure-Name-parameter-to-labview-dll-in/td-p/2498400
I know that I need to put a string control to a VISA ressource name.
What I did: I use that program:
http://digital.ni.com/public.nsf/allkb/4737E4A5E44A81D38625698500576617
I rebuilt the shared libraries with this program and the other .vi I need to control the spectrometer.
Then I call StrToVISAIo first, and the reste after.
What I have is:
uintptr_t VISAResourceNameOut;
Cluster SpectralWaveform;
int32 elmtCount=32000;
AllocateDoubleArray1 (elmtCount);
AllocateDoubleArray (elmtCount);
StrToVisaIO(instrDescriptor, &VISAResourceNameOut);
OceanOptics20004000_Initialize(&VISAResourceNameOut, &VISAResourceNameOut);
OceanOptics20004000_ReadSpectralWaveform(&VISAResourceNameOut, &VISAResourceNameOut, &SpectralWaveform);
OceanOptics20004000_Close(&VISAResourceNameOut);
Where instrDescriptor is a char I get with viFindRsrc, that's not the problem.
Everything compile fine, but, when I want to know what's in SpectralWaveform, I get:
SpectralWaveform.elt1 and SpectralWaveform.elt2 are unitilialized.
Here is the full .h
#include "extcode.h"
#pragma pack(push)
#pragma pack(1)
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
int32_t dimSize;
double elt[1];
} DoubleArrayBase;
typedef DoubleArrayBase **DoubleArray;
typedef struct {
int32_t dimSize;
double Numeric[1];
} DoubleArray1Base;
typedef DoubleArray1Base **DoubleArray1;
typedef struct {
DoubleArray elt1;
DoubleArray1 elt2;
} Cluster;
/*!
* StrToVisaIO
*/
void __cdecl StrToVisaIO(char String[], uintptr_t *VISAResourceName);
/*!
* Establishes communication with the instrument and optionally performs an
* instrument identification query and/or an instrument reset. It also places
* the instrument in a default state needed for other instrument driver
* operations. Therefore, call this VI before calling other instrument driver
* VIs for this instrument. Generally, you need to call the Initialize VI
* only once at the beginning of an application.
*/
int32_t __cdecl OceanOptics20004000_Initialize(uintptr_t *VISAResourceName,
uintptr_t *VISAResourceNameOut);
/*!
* Performs an instrument error query before terminating the software
* connection to the instrument.
*/
int32_t __cdecl OceanOptics20004000_Close(uintptr_t *VISAResourceName);
/*!
* Configures the integration time of the spectrometer. The integration time
* is the amount of time that the device collects light before digitizing it
* and sending it out over the USB. The longer the integration time, the more
* light it may collect.
*/
int32_t __cdecl OceanOptics20004000_ConfigureIntegrationTime(
uintptr_t *VISAResourceName, uint32_t IntegrationTime6000,
uintptr_t *VISAResourceNameOut);
/*!
* Displays the spectrum vs wavelength in a waveform graph.
*
* <b>Note:</b> Do not put this VI in a loop if performance is a concern.
* Please see the <b>Ocean Optics 2000 4000 Acquire Continuous Waveform</b>
* example for an example of how to do continuous acquisition.
*
*
*/
int32_t __cdecl OceanOptics20004000_ReadSpectralWaveform(
uintptr_t *VISAResourceName, uintptr_t *VISAResourceNameOut,
Cluster *SpectralWaveform);
/*!
* Returns the intrument status information. Information included are number
* of pixels, intergration time, packets in spectra, packet count, USB speed
* and Lamp status.
*
* <B>Note:</b>
* Not supported by USB2000 and HR2000
*/
int32_t __cdecl OceanOptics20004000_QueryStatus(uintptr_t *VISAResourceName,
uint16_t *USBSpeed, LVBoolean *LampStatus, uint8_t *PacketCount,
uint8_t *PacketsInSpectra, uint32_t *IntegrationTime,
uintptr_t *VISAResourceNameOut, uint16_t *NumberOfPixels);
MgErr __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
/*
* Memory Allocation/Resize/Deallocation APIs for type 'DoubleArray'
*/
DoubleArray __cdecl AllocateDoubleArray (int32 elmtCount);
MgErr __cdecl ResizeDoubleArray (DoubleArray *hdlPtr, int32 elmtCount);
MgErr __cdecl DeAllocateDoubleArray (DoubleArray *hdlPtr);
/*
* Memory Allocation/Resize/Deallocation APIs for type 'DoubleArray1'
*/
DoubleArray1 __cdecl AllocateDoubleArray1 (int32 elmtCount);
MgErr __cdecl ResizeDoubleArray1 (DoubleArray1 *hdlPtr, int32 elmtCount);
MgErr __cdecl DeAllocateDoubleArray1 (DoubleArray1 *hdlPtr);
#ifdef __cplusplus
} // extern "C"
#endif
#pragma pack(pop)
Everything compile fine, and when I run it, I have no error.
So whether I'm not giving it the good VISA ressource name (maybe I should change the string inside the .vi, but not sure how to do that), whether something with the pointer is quite wrong (see the prototype function in the .h). Maybe I need to initialize SpectralWaveform.elt1 and SpectralWaveform.elt2 corrrectly. But not sure how to do this either, with this struct.
What I want at the end is to display the spectrum.
Any idea ?
Best Regards,
Geoffrey.