Quick Drop Enthusiasts

cancel
Showing results for 
Search instead for 
Did you mean: 

EasyConvert- QD Plugin

What it does

Takes selected wires and inserts a conversion for that wire. To do this, you have to intentionally create a broken wire, select it, then run the plugin.

The plugin will insert the relevant function and create any necessary constants (like typecast type).

If no conversion is found, a type cast is automatically used. You can also default to typecast by holding shift while running the plugin.

What it converts

  • Byte array to string
  • String to byte array
  • Number to boolean array
  • Boolean array to number
  • Boolean to numeric
  • String to Path
  • Path to String
  • Array of Strings to Path
  • Path to Array of Strings
  • Scan String to Enum
  • Format Enum to String
  • Coerce to Enum
  • Variant to Data
  • Timestamp to Double
  • Double to Timestamp
  • Reference to More Specific
  • Reference to More Generic
  • 1D array to Element
  • 2D array to Element
  • 2D array to 1D array
  • Element to 1D array
  • 1D array to 2D array
  • Element to Cluster (selects first element it finds)
  • Cluster to Element (selects first element it finds)
  • Typecast

Example

Before.png

Then wire it up

Wire.png

Then run the plugin

After.png

Version History

V 1.0- Release as document (from prototype: added conversion binary file instead of contant, fixed U8 enum conversions, error doesn't undo)

Josh
Software is never really finished, it's just an acceptable level of broken
Message 1 of 14
(8,146 Views)

Couple things.  When you have a wire and it returns an array of terminals, I believe index 0 is always a source and the last index is always a sink.  You can use the index to get the first, and a delete from array with nothing wired to the index or length to get the last.  Then you don't need your Find Wire Sink and Source VI.

As for simplifying the constant creation.  You could use the private method Create Constant, on the Block Diagram.  This function takes a variant data type and creates a constant at the location you specify.  You can read the Data Type of the sink terminal and use that, then you just need to move it and wire it.  No need for creating the constant, finding the wire, deleteing the wire, move it, then wiring it.  Maybe it doesn't save much space.  Also if you know your function is a Type Cast you can probably get away with using a constant for indexing the terminals to find the "type". 

Have you looked at the scripting functions in the hidden gems?  I think a few in there could be helpful too.

0 Kudos
Message 2 of 14
(5,254 Views)

Great. Thanks a lot. These will definitely simply the code. Even if the create constant doesn't save space, the current method feels Rube Goldberg to me and created odd behavior like that bumped wire seen above.

I may keep the terminal "type" search, because I'm adding "Variant to Data" insertion to this plugin and that VI happens to have the same "type" terminal.

For the hidden gems, are you talking about the Variant Data Type functions or the Scripting ones?

  • If the variants data types, I'm a little torn. Incredible gain in readability, but a loss in flexibility. I'll definitely look at it closely though.
  • If scripting, I'm a little lost as to which one you're referring to.
Josh
Software is never really finished, it's just an acceptable level of broken
0 Kudos
Message 3 of 14
(5,255 Views)

It's labeled under Hidden Gems >> VI Server and Scripting.

Looking at it I don't see all the awesome things I thought were there, but there are some good gems still.  I might have been thinking of the LAVA scripting tools.  But it probably isn't desirable to add additional external dependencies.

0 Kudos
Message 4 of 14
(5,255 Views)

List of things it can do so far (currently not uploaded)

Byte Array to String

String to Byte Array

Number to Boolean Array

Boolean Array to Number

Boolean To (0,1)

String to Path

Path to String

Array of Strings to Path

Path to Array of Strings

To Timestamp

Type Cast

I'm working on:

Variant to Data

Unsigned to Enum using the Coerce to Type

I guess this shouldn't be call "typecast". More like "Easy Convert" with the added "With great power comes great responsibility"

Josh
Software is never really finished, it's just an acceptable level of broken
0 Kudos
Message 5 of 14
(5,255 Views)

Sorry if I'm hitting this group too often.

I have a version (attached here) that is working and stable (as far as I've seen). I've also renamed it to EasyConvert.

Example.png

Working conversions

Byte Array to String

String to Byte Array

Number to Boolean Array

Boolean Array to Number

Boolean To (0,1)

String to Path

Path to String

Array of Strings to Path

Path to Array of Strings

To Timestamp

To Double (from timestamp)

Type Cast

Variant to Data

Coerce to Type (number to enum)

Ideas I'm considering:

Scanning string to enum (via scan from string)- A lot of hand-placed/connected objects... not thrilled to try

More generic or More specific references- Not sure how to identify if it needs to Up/Down the hierchy (to use specific or generic)

Josh
Software is never really finished, it's just an acceptable level of broken
Message 6 of 14
(5,255 Views)

New version. Fixes the following bugs

  • A LabVIEW scripting crash involving TypeDefs and the "Create from Data Type" method (here). If a typedef is presented, it goes back to the less-optimal way of "Create Constant", deleting the wire, and recreating
  • Enums now correctly identify
  • Variant to Data had a problem with insertion. It seems to like connecting the Error wire to the sink. I had to delete the output wire and recreate in the correct place.

I think I'm finished for now unless anyone comes up with new ideas/bugs/feedback.

Josh
Software is never really finished, it's just an acceptable level of broken
0 Kudos
Message 7 of 14
(5,255 Views)

Ok, I wasn't finished.

New things added:

  • More Generic and More Specific References (It identifies based on the wire being broken or not)
  • String to enum-  Scan from string
  • Enum to string- Format into string
  • Single object to 1D array- Build array (note: source and sink must have exact same data type)
Josh
Software is never really finished, it's just an acceptable level of broken
Message 8 of 14
(5,255 Views)

This is shaping up to have some pretty useful features.  It might read my mind and know the conversion I want but I can always undo quickly if it doesn't work right.  Haven't used it yet but enum and string, and build array is something I could see myself using.

What's your thought on clusters?  If I have a cluster wired to a string indicator, would automatically inserting the unbundle and selecting the first string be useful?

And if we go from scalar to array, could we go from array to scalar, or 2D to 1D using index?

0 Kudos
Message 9 of 14
(5,255 Views)

Done and done (jumped on this because that sounded really useful)

Added:

  • Clusters now collapse to icon
  • Unbundle element. This is base functionality. It will search the elements for a matching type and select the first.
  • Bundle element. Same as above, plus will create a constant of the cluster (otherwise selecting the name fails). This one isn't as optimal to most use cases.
  • 1D array to element- Index (must be of same type)

Also of note, "build array" and "Index" work for arrays of numerics, strings, enums, booleans, paths, waveforms, refnums, and variants.

Haven't done 2D->1D and 1D->2D yet.

Josh
Software is never really finished, it's just an acceptable level of broken
0 Kudos
Message 10 of 14
(5,255 Views)