Jump to content

I found an interesting scripting bug.


Sparkette

Recommended Posts

I found a bug that's reproducible using VI scripting. I was trying to programmatically place the entire contents of a VI onto a block diagram given the diagram's refnum, hoping it would help me make XNodes. (It's important to note that this bug does not involve XNodes at all, as if it did, I'd write it off as one of the reasons they weren't really released.) First, here's the code I used--notice that all the property/invoke nodes are cyan or yellow, not brown!
 
8I97d.png
 
Drop that into a new VI, and then put any old VI in the VI reference node. It should be one with at least some controls/indicators, so don't just create a blank VI.

Now run the VI. A new front panel window with the same controls as the reference VI should open, but the block diagram will be empty. Double-clicking on one of the controls to jump to its respective terminal just opens the blank diagram. Just for the hell of it, I looked in Heap Peek, and no Front Panel Terminals were listed.

 

Finally, duplicate one of the controls and click Run Continuously. LabVIEW will crash.

Edited by flarn2006
Link to comment
Scripting has a lot of these holes. The fact that it is official now does not mean it is fully debugged.

 

In this case, I don't think the Top Level Diagram should implement the Move method, as moving a diagram doesn't seem to make too much sense.

 

I thought maybe it would move/copy the entire contents of the diagram. Anyone know how I can do that? Keep in mind that all I have is the refnum for the diagram to put it in, since I'd like to use this in an XNode's GenerateCode ability VI.

Link to comment

Well, I don't have that much practical experience with scripting and I don't have LV in front of me, so excluding some proper method which may exist, here are a few quick ideas:

  1. Make Selection on all objects[] of the diagram, then copy and paste. I believe this won't work if the VI isn't idle.
  2. Enclose the content in a sequence structure, then move the structure and remove it.
  3. Use a VIT. This is simpler in that you have a starting point without requiring any code, but it won't work if you already have an existing VI you want to put the code into.

Link to comment
I thought maybe it would move/copy the entire contents of the diagram. Anyone know how I can do that? Keep in mind that all I have is the refnum for the diagram to put it in, since I'd like to use this in an XNode's GenerateCode ability VI.

 

- Move is as the name says not meant to copy code around for one thing.

- Also you make the mistake to try to copy a TopLevelDiagram into another TopLevelDiagram. For one thing a diagram can NOT contain a diagram but instead is an internal property of some other object, such as a VI or a loop, case or sequence structure.

- Please also notice that there is in fact a difference between a TopLevelDiagram and a Diagram(Section) you can for instance get from a loop or for every case in a case structure. They are similar but not the same, since they are owned by two very different objects, as VIs existed before there was a proper object hierarchy in LabVIEW.

 

For another thing I would believe it is there to move nodes around to another part of the same VI, not copy it to an entirely different VI.

 

Clarification: objects existed in LabVIEW from at least version 2.0 internally and were used extensively despite LabVIEW having been programmed in standard C exclusively back then (all the C++ compilers back then were not up to the task of compiling a code base like LabVIEW without bugs and horrible performance of the resulting executable), but that object hierarchy was not exposed anywhere, and was not fully formalized, as C has no means to enforce any object hierarchy formalization and all had to be done by hand and agreement between developers.

 

The first versions of VI Server around LabVIEW 4.0 only allowed access on VI level, and only around 5.0 was the VI server interface to the object hierarchy of frontpanel objects added and around 6.0 extended with what we know as scripting interface now.

Link to comment
And just in case you were thinking it ;) . You won't be able to use scripting to "peek" inside a password protected diagram. :P
Don't worry, I already have a better way to do that, as you know. :)

Also, what makes you think it's not for copying to another VI? If so, there wouldn't be an Owner parameter that does that. (Though come to think of it, it could be more for putting things in structures and stuff like that.)

All I'd like to do though is make a subVI that can be placed in an Xnode GenerateCode VI, which will duplicate the contents of a template VI and hook up some terminals. That way I can program the Xnode's generated code just like I would if I was writing a regular subVI. It's a shame Generic VIs are so problematic.

Edited by flarn2006
Link to comment
I usually create a new subvi on the diagram using a path to the template. SubVIs then have a method to place their contents. I am on my phone so this is from memory.

That's actually a good idea, and I'm surprised I hadn't thought of it. I'll give it a try and post if anything goes wrong (which wouldn't be a surprise since I'm working with Xnodes.)

Edited by flarn2006
Link to comment
That's actually a good idea, and I'm surprised I hadn't thought of it. I'll give it a try and post if anything goes wrong (which wouldn't be a surprise since I'm working with Xnodes.)

 

Worked great! Though I wish it was easier to get adaptive terminals to work.

Link to comment

D'oh! Sorry for the triple post, but I remember now that that's why I wanted to place the contents of the VI rather than embedding it as a subVI. (I knew there was a reason.) That way the adaptive terminals would work correctly, and I could program my code template VI as I would if I was writing a generic VI, but it wouldn't be as dangerous. Anyone know how to do this?

 

And yes, I am aware this thread has gone off topic somewhat.

Link to comment
D'oh! Sorry for the triple post, but I remember now that that's why I wanted to place the contents of the VI rather than embedding it as a subVI. (I knew there was a reason.) That way the adaptive terminals would work correctly, and I could program my code template VI as I would if I was writing a generic VI, but it wouldn't be as dangerous. Anyone know how to do this?

 

And yes, I am aware this thread has gone off topic somewhat.

 

The way I did this in the past is enumerating the entire contents of the diagram recursively, place everything into a selection, copy it to the clipboard, then pasting it from there into the new VI. Quite involved, and very easy to forget something, so if you do not need this to work with ancient LabVIEW versions, I would look for the Inline method, Darin mentions. Sorry I wouldn't know where it is as I haven't used that so far, but I assume it would be only in recent versions.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.