How to send an array of data from Matlab 7 to an Active X (C#) object?

1 次查看(过去 30 天)
Hi!
It is possible to send an array of data from Matlab (7.10.0 R2012a) to an Active X object (coded in C#)? I have tried more than a dozen different approaches but with no luck. I have concluded the following by compiling code in C# and analyze the interface in Matlab:
C# Interface Matlab type
params byte[] -> SafeArray(char)
params char[] -> SafeArray(int16)
params int[] -> SafeArray(int32)
byte* -> char
char* -> int16
int* -> int32
Typically my method looks like this in C#:
void WriteDeviceBytes_matlab(byte wordAddress, int byteCount, params byte[] data);
In Matlab I use variants of this to call my C# method:
net = actxserver('RFFEDriver.RFFEDriverClass'); % Load the ActiveX
net.WriteDeviceBytes_matlab(char(4),4, {5 3 5 7}) % Using {}
I have tried six different types of data types in C# for the third parameter, the data array, and for each I have tried five inputs from matlab hoping to find a working combination.
With the list type “[]” I get error message: ??? Error: The parameter is incorrect. And with the pointer type I get the error message ??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
A full description of my experiments follows:
I have compiled the C# code with the following commands
C:\windows\Microsoft.NET\Framework\v4.0.30319\csc /t:library RFFEDriver.cs FTD2XX_NET.cs
C:\windows\Microsoft.NET\Framework\v4.0.30319\regasm RFFEDriver.dll /tlb /codebase
------- Test with byte[] ----------
C#
void WriteDeviceBytes_matlab(byte wordAddress, int byteCount, params byte[] data);
Matlab
>> net = actxserver('RFFEDriver.RFFEDriverClass'); % Load the ActiveX
>> methods 'COM.RFFEDriver_RFFEDriverClass' -full
Methods for class COM.RFFEDriver_RFFEDriverClass:
...
WriteDeviceBytes_matlab(handle, char, int32, SafeArray(char))
...
>> net.WriteDeviceBytes_matlab(char(4),4, {5 3 5 7}) % Using {}
??? Error: Type mismatch, argument 3
>> net.WriteDeviceBytes_matlab(char(4),4, {int16(5) char(3) char(5) char(7)})
??? Error: Type mismatch, argument 3
>> net.WriteDeviceBytes_matlab(char(4),4, [5 3 5 7]) % Using []
??? Error: Type mismatch, argument 3
>> net.WriteDeviceBytes_matlab(char(4),4, [int16(5) char(3) char(5) char(7)])
??? Error: Type mismatch, argument 3
>> Data_p = libpointer('uint8Ptr', [1 2 3 4]); % uint8
>> net.WriteDeviceBytes_matlab(char(4),4, Data_p)
??? Error: Type mismatch, argument 3
>> Data_p = libpointer('int8Ptr', [1 2 3 4]); % int8
>> net.WriteDeviceBytes_matlab(char(4),4, Data_p)
??? Error: The parameter is incorrect.
------- Test with char[] ----------
void WriteDeviceBytes_matlab(byte wordAddress, int byteCount, params char[] data);
>> net = actxserver('RFFEDriver.RFFEDriverClass'); % Load the ActiveX
>> methods 'COM.RFFEDriver_RFFEDriverClass' -full
Methods for class COM.RFFEDriver_RFFEDriverClass:
...
WriteDeviceBytes_matlab(handle, char, int32, SafeArray(int16))
...
>> net.WriteDeviceBytes_matlab(char(4),4, {5 3 5 7}) % Using {}
??? Error: Type mismatch, argument 3
>> net.WriteDeviceBytes_matlab(char(4),4, {int16(5) int16(3) int16(5) int16(7)})
??? Error: Type mismatch, argument 3
>> net.WriteDeviceBytes_matlab(char(4),4, [5 3 5 7]) % Using []
??? Error: Type mismatch, argument 3
>> net.WriteDeviceBytes_matlab(char(4),4, [int16(5) int16(3) int16(5) int16(7)])
??? Error: Type mismatch, argument 3
>> Data_p = libpointer('int16Ptr', [1 2 3 4]);
>> Data_p.value
ans = 1 2 3 4
>> net.WriteDeviceBytes_matlab(char(4),4, Data_p)
??? Error: The parameter is incorrect.
------- Test with int[] ----------
void WriteDeviceBytes_matlab(byte wordAddress, int byteCount, params int[] data);
>> net = actxserver('RFFEDriver.RFFEDriverClass'); % Load the ActiveX
>> methods 'COM.RFFEDriver_RFFEDriverClass' -full
Methods for class COM.RFFEDriver_RFFEDriverClass:
...
WriteDeviceBytes_matlab(handle, char, int32, SafeArray(int32))
...
>> net.WriteDeviceBytes_matlab(char(4),4, {5 3 5 7}) % Using {}
??? Error: Type mismatch, argument 3
>> net.WriteDeviceBytes_matlab(char(4),4, {int16(5) int16(3) int16(5) int16(7)})
??? Error: Type mismatch, argument 3
>> net.WriteDeviceBytes_matlab(char(4),4, [5 3 5 7]) % Using []
??? Error: Type mismatch, argument 3
>> net.WriteDeviceBytes_matlab(char(4),4, [int16(5) int16(3) int16(5) int16(7)])
??? Error: Type mismatch, argument 3
>> Data_p = libpointer('int16Ptr', [1 2 3 4]);
>> Data_p.value
ans = 1 2 3 4
>> net.WriteDeviceBytes_matlab(char(4),4, Data_p)
??? Error: The parameter is incorrect.
-------------------------------------------
Now pointers are used and the keyword “unsafe” is added when compiling and to method declarations
C:\windows\Microsoft.NET\Framework\v4.0.30319\csc /t:library RFFEDriver.cs FTD2XX_NET.cs /unsafe
C:\windows\Microsoft.NET\Framework\v4.0.30319\regasm RFFEDriver.dll /tlb /codebase
------- Test with byte* ----------
unsafe void WriteDeviceBytes_matlab(byte wordAddress, int byteCount, byte* data);
>> net = actxserver('RFFEDriver.RFFEDriverClass'); % Load the ActiveX
>> methods 'COM.RFFEDriver_RFFEDriverClass' -full
Methods for class COM.RFFEDriver_RFFEDriverClass:
...
char WriteDeviceBytes_matlab(handle, char, int32, char)
...
>> net.WriteDeviceBytes_matlab(char(4),4, {5 3 5 7}) % Using {}
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
>> net.WriteDeviceBytes_matlab(char(4),4, {int8(5) int8(3) int8(5) int8(7)})
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
>> net.WriteDeviceBytes_matlab(char(4),4, [5 3 5 7]) % Using []
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
>> net.WriteDeviceBytes_matlab(char(4),4, [int8(5) int8(3) int8(5) int8(7)])
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
>> Data_p = libpointer('int8Ptr', [1 2 3 4]);
>> Data_p.value
ans = 1 2 3 4
>> net.WriteDeviceBytes_matlab(char(4),4, Data_p)
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
------- Test with int* ----------
unsafe void WriteDeviceBytes_matlab(byte wordAddress, int byteCount, int* data);
>> net = actxserver('RFFEDriver.RFFEDriverClass'); % Load the ActiveX
>> methods 'COM.RFFEDriver_RFFEDriverClass' -full
Methods for class COM.RFFEDriver_RFFEDriverClass:
...
int32 WriteDeviceBytes_matlab(handle, char, int32, int32)
...
>> net.WriteDeviceBytes_matlab(char(4),4, {5 3 5 7}) % Using {}
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
>> net.WriteDeviceBytes_matlab(char(4),4, {int32(5) int32(3) int32(5) int32(7)})
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
>> net.WriteDeviceBytes_matlab(char(4),4, [5 3 5 7]) % Using []
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
>> net.WriteDeviceBytes_matlab(char(4),4, [int32(5) int32(3) int32(5) int32(7)])
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.
>> Data_p = libpointer('int32Ptr', [1 2 3 4]);
>> Data_p.value
ans = 1 2 3 4
>> net.WriteDeviceBytes_matlab(char(4),4, Data_p)
??? No method 'WriteDeviceBytes_matlab' with matching signature found for class 'COM.RFFEDriver_RFFEDriverClass'.

回答(1 个)

Steven
Steven 2015-1-28
编辑:Steven 2015-1-28
Are you calling a .net object or an activex control?
Make sure your activex control is registered .dll and that it shows up elsewhere (call it from vb or something)
  1 个评论
Steven
Steven 2015-1-28
Oh, also make sure your version of matlab supports this: ver 7 is so long ago it may not have the functionality

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by