LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.NET object ToString from Generic in LabVIEW

 

(currently using LV2018sp1)

 

I'm trying to figure out how to programmatically acquire the data that the probe in this scenario displays- more specifically the data (ToString: 29896) that this obj ref points to from a .NET call.

 

the code below in this image errors out due to the "to more specific class" due to type mismatch (I just tried using system string from ms core.  These are calls to a C# API that appears to be using a generic type for this call in the examples.

 

p27_0-1599765200659.png

 

a coworker linked me to this:

 

https://forums.ni.com/t5/LabVIEW/Convert-quot-Generic-quot-to-Labview-NET/td-p/3131750?profile.langu...

 

which doesn't paint a pretty picture for this task.  I just thought I'd post up since I don't know much about C# and am stuck here... 

 

0 Kudos
Message 1 of 7
(2,890 Views)

The ToString() method is a virtual method located on the .NET Object class. Child classes (everything else) can override this method to provide their own version. The probe is simply calling the ToString() method on the object on the wire. Since all classes inherit from Object, this method can be called on every .NET object. You can perform the same function as the probe by doing the same thing. In this case - get rid of the cast node and call the ToString method on the object FloatNode wire directly.

 

In case you are wondering, the default implementation of this method is to provide the fully qualified class name. But many classes override it to provide alternate functionality.

 

Since you haven't provided any source code, it is hard to tell what interface and contracts the class "FloatNode" provides - or whether it overrides the ToString() virtual method. Its possible that "FloatNode" overrides this method to provide the 'value' and return this as a string. Given the "INodeMap" in play in your example picture, I assume there are different types of nodes of which Float is one.

Message 2 of 7
(2,878 Views)

thanks for the reply!

 

A coworker showed me that the API I'm working with had the floatnode type available (used "Browse..." right clicking on .NET constant and navigating to the API) to create a constant that you could then use to cast the get_item to, and then drop a prop node with a value read.  

 

I had tried wiring the ref directly into the tostring and that just resulted in a broken wire which is the reason I tried the cast.

 

thanks again!

 

 

0 Kudos
Message 3 of 7
(2,826 Views)

If it is a indeed string, ".NET Object To Variant" should convert it to variant. Then use Variant To Data to convert it to string.

0 Kudos
Message 4 of 7
(2,815 Views)

p27_0-1599839929108.png

 

Thanks for the suggestion, I gave it a shot and:

 

"LabVIEW: (Hex 0x5B) The data type of the variant is not compatible with the data type wired to the type input."

 

I'm still trying to figure out how to manage the types coming out of this API, there doesnt seem to be a way to query the type beforehand so I'm not sure how I'm going to programmatically cast to the right one...

 

0 Kudos
Message 5 of 7
(2,813 Views)

@p27 wrote:

p27_0-1599839929108.png

 

Thanks for the suggestion, I gave it a shot and:

 

"LabVIEW: (Hex 0x5B) The data type of the variant is not compatible with the data type wired to the type input."

 

I'm still trying to figure out how to manage the types coming out of this API, there doesnt seem to be a way to query the type beforehand so I'm not sure how I'm going to programmatically cast to the right one...

 


So the To Variant succeeds? That's 90% of the battle.

 

Create a variant indicator, and right click to show the type. Or put a probe on the variant wire.

 

That would give some information...

0 Kudos
Message 6 of 7
(2,809 Views)

Instead of casting it to a .NET string, try casting it to a .NET System.Object class:

 

Kyle97330_0-1599845730576.png

Kyle97330_1-1599845799192.png

 

0 Kudos
Message 7 of 7
(2,799 Views)