How can I read data from COM object (an activex server) in MATLAB?

1.2k Views Asked by At

I am trying to connect a simulator to the MATLAB. The simulator program exposes a COM object interface.

I have connected to the COM object by the following command and can perform most of it methods:

h=actxserver(ProgID)

But some of its methods need passing of a Variant* type as output.

Here is the signature of one of the methods indicated by "invoke" method:

ReadOutputImage=Variant(Pointer) ReadOutputImage(handle, int32, int32, `ImageDataTypeConstants, Variant(Pointer))`

I have called this method with several syntax's, but none of them work:

a=uint8([0])   %means unsigned integer array with 1 member

h.ReadOutputImage(0,1,2,a)  % 0 ,1 ,2 are contants pointing to the position, number of elements to read and size of elemnts while 2 shows Byte element (VT_UI2 COM type).

Other syntax's that I have tried and has no result are: using uint16, uint32, int8, int16, int32 for all of the followings:

logical types (like a=[false]), 
cell arrays (like a={uint8([0])} )
empty cell array {}
empty array []
empty sring ''

I have used libpointer as well:

a=libpointer;
also a=libpointer('uint8Ptr',0)
also a=libpointer('bool',false)
also a=libpointer('bool',[0])

The problem is that I am not sure about the following items:

  1. What is the similar type of " Variant(Pointer) " in MATLAB?
  2. What is the method of passing a variable as output to a COM method in MATLAB?
  3. Is it even possible to get a value from a COM object method result as a pointer in MATLAB?

To find how the data appears in other clients, I have imported the same dll file into Delphi and the signature of the type library for the above method is like this:

procedure ReadOutputImage(StartIndex: Integer; ElementsToRead: Integer; 
                          DataType: ImageDataTypeConstants; var pData: OleVariant);

Yes Siemens has provided a guide for this com server (prosim) and based on such documentation I have connected and performed most of its methods. But the methods which read I/o data are not working. In documentation the method signature is specified as follows: (in VB)

STDMETHOD(CS7Prosim::ReadOutputImage)(long startindex,long elementstoread, imagedatatypeconstants DtaType, VARIANT* pData)

What about your application, was it working? Did it contains variant pointers as the returning argument? Did you have simillar methods in that application?

Thank you

1

There are 1 best solutions below

0
On

I can help with #2 in your question. I just worked through this myself. Basically, any pass by reference to COM object you to access after it is modified, Matlab just spits back as an output.

[var1 a]=thisObject.DB.Execute(queryString,a)

See here "The syntax shown here shows a server function being called by the MATLAB client. The function's return value is shown as retval. The function's output arguments (out1, out2, ...) follow this:

[retval out1 out2 ...] = handle.functionname(in1, in2, ...);

MATLAB makes use of the pass by reference capabilities in COM to implement this feature. Note that pass by reference is a COM feature. It is not available in MATLAB at this time."