Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

How to open an Instrument using it's known USB Serial Number?

Solved!
Go to solution

Hello,

I write an application to open two the same counters CNT-91 (Pendulum) to be connected to USB of one PC.

These counters have an identical USB VID, PID and are distinguished by Serial Number (SN).

But I can't open the counter using USB SN.

 

My app correctly sends and gets the NI VISA commands because I can open and control one CNT-91 using it's VID (VI_ATTR_MANF_ID==0x14EB) and get the SN.

Here are NI VISA used and correctly worked NI VISA functions, the status after execution and the SN in answer of CNT-91:

 

viOpenDefaultRM(@RM) : OK (Status=0)

    SN1=PChar('USB?*INSTR{VI_ATTR_MANF_ID==0x14EB}')
viFindRsrc(RM, SN1, @findList, @numInstrs, Resource1) : OK

viOpen(RM, Resource1, 0, 0, @CNT1) : OK
viSetAttribute(CNT1, VI_ATTR_TMO_VALUE, 1000) : OK

viWrite(CNT1,'*IDN?\n',b,@RetCount) : OK
viRead(CNT1,buf,MAX_CNT,@RetCount) : OK
   PENDULUM, CNT-91, 976722, V1.21 03 Dec 2007 :Result for '*IDN?\n' request, it contains the Serial Number 976722
viClose(CNT1) : OK
viClose(RM) : OK

 

The SN is 976722 in answer of CNT-91.
I also check this SN in Windows' Device Manager when connecting CNT-91 to USB.

 

But there are errors when I try to open the instrument using SN:

viOpenDefaultRM(@RM) : OK (Status=0)

    SN1=PChar('USB?*RAW{VI_ATTR_USB_SERIAL_NUM==976722}')
viFindRsrc(RM, SN1, @findList, @numInstrs, Resource1)          : VI_ERROR_RSRC_NFOUND (Status=0xBFFF0011)

 

In datasheet for CNT-91 the feasibility to use SN to open the instrument is proclaimed.

 

How one may correctly find and open the instrument using SN?

 

==

I also tried

    SN1=PChar('USB?*INSTR{VI_ATTR_USB_SERIAL_NUM==976722}')     //*INSTR vs *RAW

but with the same error.

 

I read the topic viFindRsrc using VI_ATTR_USB_SERIAL_NUM

but link in the second post for 'How do I Find All VISA Instrument Resources Using LabWindows?' is wrong.

 

 

0 Kudos
Message 1 of 4
(236 Views)

I checked the type of VI_ATTR_USB_SERIAL_NUM and this is not a value but string,

so I replaced

USB?*RAW{VI_ATTR_USB_SERIAL_NUM==976722}

with

USB?*RAW{VI_ATTR_USB_SERIAL_NUM=="976722"}

 

May be this will cure.

 

0 Kudos
Message 2 of 4
(221 Views)

The use SN as string also doesn't work (both variants: "976722" and '976722'):

 

status:=viOpenDefaultRM(@RM); // OK (Status=0)

SN1:=PChar(Edit1.Text);

status:=viFindRsrc(RM, SN1, @findList, @numInstrs, Resource1);

// status=VI_ERROR_RSRC_NFOUND (status=0xBFFF0011)

 

Edit1 is Delphi's visual component TEdit.

In the Edit1 box I tried to type the next strings:

 USB?*RAW{VI_ATTR_USB_SERIAL_NUM=='976722'}

 USB?*RAW{VI_ATTR_USB_SERIAL_NUM=="976722"}

 USB?*RAW{VI_ATTR_USB_SERIAL_NUM==976722}

 USB?*INSTR{VI_ATTR_USB_SERIAL_NUM==976722}

 USB?*INSTR{(VI_ATTR_MANF_ID==0x14EB)&&(VI_ATTR_USB_SERIAL_NUM==976722)}

all strings above give the status=VI_ERROR_RSRC_NFOUND (status=0xBFFF0011)

but only

 USB?*INSTR{(VI_ATTR_MANF_ID==0x14EB)}

shows status=0 (see the 1st post)

Later I'll try '976722' and "976722" for the strings USB?*INSTR{},

but VI_ATTR_USB_SERIAL_NUM belongs to RAW group, not to INSTR. So I don't expect any changes

 

Any ideas?

0 Kudos
Message 3 of 4
(185 Views)
Solution
Accepted by topic author bvn123

USB?*INSTR{VI_ATTR_USB_SERIAL_NUM=="976722"}

properly works as SN1 (SN1 is PChar) in the sequence:

  status:=viFindRsrc(RM, SN1, @findList, @numInstrs, Resource1);

  status:= viOpen(RM, Resource1, 0, 0, @CNT1);

 

or viOpen() without viFindRsrc():

//below VID=0x14EB, PID=0x0091, SN=976722:

  USB::0x14EB::0x0091::976722::INST

as ready Resource1 (null-terminated string) for

  status:= viOpen(RM, Resource1, 0, 0, @CNT1);

 

It is strange, that VI_ATTR_USB_SERIAL_NUM works as INSTR attribute, but it is absend on HELP page for INSTR resources:

https://zone.ni.com/reference/en-XX/help/370131S-01/ni-visa/instr_resource/

 

 

0 Kudos
Message 4 of 4
(154 Views)