LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create VISA Resource Name from String

Solved!
Go to solution

Hi all.

 

I'm newbie working with VISA VIs. I'd like to create a VISA Resource Name from a String containing only the VISA alias, from example, COM4. The reason for this is that the serial port is chosen via a dialog box created by a Call Library Function Node.

 

Thanks in advance,

Francisco

0 Kudos
Message 1 of 9
(20,798 Views)
Solution
Accepted by Porras

Hi,


You can use a type cast for this. Check the example.

 

zzzz.PNG


Regards,


Nitzz

(Give kudos to good Answers and Mark it as a Solution if your problem is Solved;)) 

Message 2 of 9
(20,793 Views)

Hey!, thanks a lot!

 

This was just what I was looking for.

0 Kudos
Message 3 of 9
(20,787 Views)

The typecast is not at all necessary. Just wire the string directly.

Message 4 of 9
(20,769 Views)

I thought coercion dots were 'bad' - and that preference is to explicitly change representation.

 

Is there an exception to the best practices that I was taught?

0 Kudos
Message 5 of 9
(20,733 Views)

There are always exceptions to "best practices".  In fact, many "best practices" serve mainly to prevent incompetent programmers from creating totally atrocious code.

In this case, coercion dot is OK because: 1) The coercion from string to VISA name won't cause any problem, and 2) If someone looking at the code doesn't notice the coercion dot, it won't cause any misunderstanding of the code.

 

Message 6 of 9
(20,521 Views)

@Fill wrote:

I thought coercion dots were 'bad' - and that preference is to explicitly change representation.

 

Is there an exception to the best practices that I was taught?


They are not necessarily bad. They are just an implicit conversion. In this case the typecast and the red dot are essentially the same code. The typecast takes more block diagram real estate. You can think of a coercion dot as a warning and not an error. The coercion dot does use memory and CPU but an explicit conversion does too. Explicit conversion functions just tell whoever is reading the code that "I know what I am doing". There are likely exceptions such as when branching a wire to many sinks of a different type. If you do an explicit conversion prior to the branch you might get better performance. I say "might" because the compiler is very smart and it would therefore depend on the LabVIEW version.

 

=====================
LabVIEW 2012


Message 7 of 9
(20,512 Views)

In some cases there is even a small increase in performance with the coersion as opposed to the conversion.  I've seen companys that demand "all coesion dot be abolished" as a development policy.  I don't advocate the policy. BUT, my coesrion dots are the uglyist and most eye-appaling color I could find so I do catch them on every review-  Sometimes I even find a bug I wrote by chosing a bad representation for a data and the coersion makes it apparent where a conversion wouldn't. 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 9
(20,494 Views)

I know this is an old thread; but just for the record, I disagree with you about the need for the typecast.

 

Yes, it isn't necessary for the correct operation of the program; the implicit cast will function correctly.

 

What it DOES add is proof that the programmer didn't typecast by mistake. I *never* allow coercion dots in my code unless it's because due to lack of knowledge I don't know how to get rid of them. 

 

This has another benefit: you can use the VI Analyzer to find all instances where you DIDN'T think about it...

0 Kudos
Message 9 of 9
(7,783 Views)