david@realiv

A COMException Error when invoke MATLAB in ACE Program

Discussion created by david@realiv on Aug 25, 2010

Hi,

 

I was going to invoke MATLAB functions in my ACE program, while I made a test acorrding to white paper in vCampus Library, the code is as below(exactly the same as in white paper, VB.NET):

Imports OSIsoft.PI.ACE

Public Class MATLAB_Test_Module
    Inherits PIACENetClassModule
    Private sinusoid As PIACEPoint
    Private cdt158 As PIACEPoint
    Private oMatLab As MLApp.MLApp
    '
    '      Tag Name/VB Variable Name Correspondence Table
    ' Tag Name                                VB Variable Name
    ' ------------------------------------------------------------
    ' cdt158                                  cdt158
    ' sinusoid                                sinusoid
    '
    Public Overrides Sub ACECalculations()
        Dim oOutPut As Object
        oMatLab.PutWorkspaceData("x", "base", cdt158.Value)
        oMatLab.Execute("y=AddOne(x)")
        oMatLab.GetWorkspaceData("y", "base", oOutPut)

        sinusoid.Value = oOutPut
    End Sub

    Protected Overrides Sub InitializePIACEPoints()
        cdt158 = GetPIACEPoint("cdt158")
        sinusoid = GetPIACEPoint("sinusoid")
    End Sub

    '
    ' User-written module dependent initialization code
    '
    Protected Overrides Sub ModuleDependentInitialization()
        oMatLab = New MLApp.MLApp()
    End Sub

    '
    ' User-written module dependent termination code
    '
    Protected Overrides Sub ModuleDependentTermination()
        oMatLab = Nothing
    End Sub
End Class

But when I tried to debug, it came to a COMException error on the Line I marked. It seems object oOutPut is used before being set value, while I was just following the code in white paper 

 

Here's my Error detail:

System.Runtime.InteropServices.COMException
  ErrorCode=-2147352567
  Message=""
  Source=""
  StackTrace:
       at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)    at MLApp.MLAppClass.GetWorkspaceData(String Name, String Workspace, Object& pdata)    at PIACE.MATLAB_Test.MATLAB_Test_Module.ACECalculations() in C:\Program Files\pipc\ACE\ClassLibraries\MATLAB_Test\MATLAB_Test_Module.vb:line 19    at PIACEClassLibraryHost.PIACEHost.PIACENetSchedule..ctor(String ServerName, String PIACEClassLibraryName, String ACEModuleName, String ACEContext)
  InnerException:
 

Could anyone give me some advise on how to revise the code to make it work? Thanks

Outcomes