LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

.NET Refnum pointing to a labview array for an input to a .NET Invoke Method HOW DO I

Can anyone show me how to make a valid .NET Refnum to a Labview array that I can use an an input to a .NET Invoke Method that require a .NET Rufnum input that refences an array?
 
Thanks in advance
Tim C.
1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
0 Kudos
Message 1 of 7
(2,831 Views)
The .NET invoke node needs an array of what?
If it's e.g. a simple string array, the ordinary LV string array type will match. If on the other hand it's an array of a .NET defined type, you need to create the "nested" type with a .NET constructor node and build an array from it accordingly.
 
Understood?
 
Greetings,
Hans
0 Kudos
Message 2 of 7
(2,818 Views)
Hello
 
It turns out that the .NET DLL is expecting a pointer to an array.  I went in and looked at the code and the function is using the ByRef function to setup the field variable.  There are two ByRef variables.  Database and Field.  Database is expecting a string path to the database file
and a second string that designates the seperator.  The Field Variable appears to want a pointer to an array but I canoont get this to work.
 
I have looked at all the constructor and methods but no combination seems to work.  I keep getting a .NET exception error.
 
Thanks
Tim C.
1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
0 Kudos
Message 3 of 7
(2,811 Views)

The ByRef parameter option indicates that the called function may want to write data back into the specified parameters themselves.
Anyway, I still need some more information to help you further. Could you paste the code or at least the signature of the VB.NET function you're calling?

Greetings,
Hans

0 Kudos
Message 4 of 7
(2,805 Views)
Here is the funtion
 
 
 
 

    Public Function SimpleMovingAverage(ByRef Data As Database, ByRef Source As Field, ByVal Periods As Integer, Optional ByVal FieldAliasName As String = "") As RecordSet
        Dim Avg As Double
        Dim Period As Short
        Dim Record As Short
        Dim RecordCount As Short
        Dim Start As Short
        Dim Field1 As New Field()
        Dim Results As New RecordSet()
        On Error GoTo UnexpectedError
        If FieldAliasName = "" Then FieldAliasName = "SimpleMovingAverage"
        RecordCount = Data.getRecordCount
        Field1.initialize(RecordCount, FieldAliasName)
        Start = Periods + 1
        Data.setPosition(Start)
        'Loop through each record in Recordset
        For Record = Start To RecordCount
            Avg = 0
            'Loop backwards through each period
            For Period = 1 To Periods
                Avg = Avg + Source.getValue(Data.getPosition)
                Data.MovePrevious()
            Next Period
            'Jump forward to last position
            Data.setPosition(Data.getPosition + Periods)
            'Calculate moving average
            Avg = Avg / Periods
            Field1.setValue(Data.getPosition, Avg)
            Data.MoveNext()
            System.Windows.Forms.Application.DoEvents()
        Next Record
        Data.MoveFirst()
        Results.addField(Field1)
        SimpleMovingAverage = Results
        Exit Function
UnexpectedError:
        Err.Raise(1105, "MovingAverage.SimpleMovingAverage.UnexpectedError", "An unexpected error has occured")
        Exit Function
    End Function
1:30 Seconds ARRRGHHH!!!! I want my popcorn NOW! Isn't there anything faster than a microwave!
0 Kudos
Message 5 of 7
(2,805 Views)

...ahem, actually I don't see any array parameters in the code signature. But you were asking for handing over arrays?!?

Looks like some old VB ADO code has been transferred to VB.NET. The Database and Field parameters are not arrays but ADO classes or types defined somewhere else in your code, as far as I can see. They may be derived from other collection or array based classes, but I'd bet they're not.
The function you've posted simply does an evaluation of the data within a Database object using the Field object, both handed over as parameters, so their actual values must originate somewhere else in your calling LabVIEW code...

Sorry, but this takes some more investigation of the whole project to help you further.
Smiley Indifferent

Greetings,
Hans

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

I'm also not sure what version of LabVIEW you're running, but we did change the mapping some in 8.2 so that byref parameters of primatives (int, string, arrays) showed up correctly (i.e., you don't need to make them .NET references first).

However, if you ever do need to convert a LV primative into a .NET refnum, use To .NET Refnum.vi in <vi.lib>/platform/dotnet.llb

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