Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

string to serial VISA refnum

A problem which has bugged me often....

If I have a string, say "ASRL2::INSTR" as read from an ini file, how can I get a serial instrument refnum from this.

I am able to use the "VISA open" function which will accept a string as input, but this gives me a generic "Instrument" refnum.

How do I go about generating a proper "Serial" refnum.

I'm using LV 6.1

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 1 of 5
(4,809 Views)

Shane,

Could you explain what you mean by 'serial instrument refnum'? With LabVIEW 6.1 and VISA 3.2, the code in the attachment returns type 'serial'. I don't see any difference between using a string input or the actual VISA Resource Name data type.

Message Edited by Dennis Knutson on 09-18-2006 07:52 AM

0 Kudos
Message 2 of 5
(4,799 Views)
Hi Dennis,

Thanks for taking time to answer my question.  Indeed, the hardware is serial, but the CLASS (And I believe this word should have been in my original post) is "Instr", no?  At least on my machine if I use a string to open as your picture shows, then I receive an "instr" class refnum.  If I connect this to VIs expecting a "Serial Instr" class than I get a broken wire.  This basically means that I have no practical use for anything other than "Instr" classes in my code.

I have the feeling there's an easy way to cast to a more specific class, but I've never found it out.

Please refer to the attached pic:



Shane.

Message Edited by shoneill on 09-18-2006 04:04 PM

Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 3 of 5
(4,794 Views)

Shane,

What about doing a type cast?

Which VIs expect a specific class? I thought the generic 'INSTR' class would work with all.

Message Edited by Dennis Knutson on 09-18-2006 08:41 AM

Message 4 of 5
(4,790 Views)
I never thought of a type cast.  I have always stayed away from type casts when they're not needed because they assume characteristics of the source data which may not be valid under certain circumstances, and it seems this might have been a blind spot for me.

Thanks for the tip, I'll use this from now on.

As to mixing classes, if I define a sub-VI with a "Serial Instr" input and wire a "Instr" class refnum to it, I get a broken wire.  The other way around is fine, but up-casting so to speak gives an error.

I have a bad habit of writing all my serial VIs with "Serial Instr" inputs and outputs which then falls apart as soon as I read the values from an INI file, since I had no way of casting to a more specific class.....

Then I had the wonderful task of changing all the unputs and outputs back to "Instr".  Had I made a typedef, it would be an easy excercise of course, but that's another matter.

So the answer to your question "Which VIs expect a specific class?" would be: mine.

Anyway, thanks for the help.  I'll add this to my "Things I should have known but did wrong for years" list.

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 5 of 5
(4,781 Views)