Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

controlling a USB to I2C module from NI -VISA and LabWindows

Hi,

Here is my situation: I have a USB to I2C adapter built using a Silabs microcontroller. The physical connection to that is done obviously via an USB cable. I want to send/receive information to/from it using NI-VISA. I created an USB driver for RAW usb device and installed  it. Everything works fine and in the Measurement and Automation Explorer I can see my device listed.
Now I have put together  the following code to communicate with my USB to I2c module:
#define MAX_CNT 200
ViChar buffer[MAX_CNT];                       /* Buffer for string I/O */
ViSession rsrcMgrHandle, instrHandle;     /* Communication channels */
ViUInt32 retCount;                                 /* Return count from string I/O*/
int status;

// Open Resources
if ((status = viOpenDefaultRM (&rsrcMgrHandle)) != VI_SUCCESS) { /* Error Initializing VISA...exiting */ return -1; }
if ((status = viOpen (rsrcMgrHandle, "USB0::0x10C4::0x84D6::FF::RAW", VI_NULL, VI_NULL, &instrHandle)) != VI_SUCCESS) {/* Error Initializing VISA...exiting */ return -1; }

//Ask the device for identification
if ((status =viWrite (instrHandle, "*IDN?\n", 7, &retCount)) != VI_SUCCESS) {/* Error Initializing VISA...exiting */ return -1;}
….
….
// Close Resources
if ((status = viClose (instrHandle)) !=VI_SUCCESS) {/* Error ClosingVISA...exiting */ return -1;}
if ((status = viClose (rsrcMgrHandle)) !=VI_SUCCESS) {/* Error Closing VISA...exiting */ return -1;}

I need to transmit a command that in c looks like:
int WriteCmd(unsigned char cmd, int device, int address, int numBytes, unsigned char* buffer)

Can anybody tell me haw would I do that? Any examples of similar programs ?

Many Thanks,

ZZippo

0 Kudos
Message 1 of 6
(4,628 Views)
0 Kudos
Message 2 of 6
(4,612 Views)

Thank you muks!

We will keep this one to help Zzippo out.

 

Kind Regards,

Michael S.
Applications Engineer
NI UK & Ireland

0 Kudos
Message 3 of 6
(4,606 Views)

Hi,

 

Sorry for the double post. The formating of my first post was not right and I could not delete the post ....

 

Thanks,

ZZippo

0 Kudos
Message 4 of 6
(4,585 Views)

sahpek

 

Any specific reason for changing the polarity?

0 Kudos
Message 5 of 6
(4,576 Views)

Hello ZZippo,

 

I can see that no replies have been posted here in my absence, I do apologise I should have asked a colleague to keep an eye on it.

Can you let me know how you are getting on and whether this is still an issue? I can have a look at possible solutions and help you myself.

 

muks, can I ask what your question is referring to?

 

Kind Regards,

Michael S.
Applications Engineer
NI UK & Ireland

0 Kudos
Message 6 of 6
(4,490 Views)