Matlab internal problem when using .NET methods that have a REF parameter
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I am trying to use in matlab the functions provided by Yokogawa in their TMCTL library, for comunicating with physical equipment (a DL9140 oscilloscope, in my case).
I am having trouble when using the ReceiveBlockData function. This function resides in a .NET dll, and its C# desription is as follows:
Description: Receives the block data from the device (after receiving the byte size).
Syntax: [C#] int ReceiveBlockData( int id, ref sbyte buff, int blen, ref int rlen, ref int end)
int ReceiveBlockData( int id, ref byte buff, int blen, ref int rlen, ref int end)
int ReceiveBlockData( int id, ref short buff, int blen, ref int rlen, ref int end)
int ReceiveBlockData( int id, ref ushort buff, int blen, ref int rlen, ref int end)
int ReceiveBlockData( int id, ref int buff, int blen, ref int rlen, ref int end)
int ReceiveBlockData( int id, ref uint buff, int blen, ref int rlen, ref int end)
int ReceiveBlockData( int id, ref long buff, int blen, ref int rlen, ref int end)
int ReceiveBlockData( int id, ref ulong buff, int blen, ref int rlen, ref int end)
int ReceiveBlockData( int id, ref float buff, int blen, ref int rlen, ref int end)
int ReceiveBlockData( int id, ref double buff, int blen, ref int rlen, ref int end)
[VC++] int TmcReceiveBlockData( int id, char* buff, int blen, int* rlen, int* end );
[VBA] TmReceiveBlock( ByVal id As Long, buf() As Integer, ByVal blen As Long, ByRef rlen As Long, ByRef end As Long) As Long
TmReceiveBlockB( ByVal id As Long, buf() As Byte, ByVal blen As Long, ByRef rlen As Long, ByRef end As Long) As Long
Parameters:
[IN] id Device ID
[OUT] buff Receive data buffer
[IN] blen Receive size (in units of bytes)
[OUT] rlen Number of actually received bytes
[OUT] end Receive end flag
Value Description
0 Receiving (remaining data available)
1 Receive end
Return value:
0 Success
1 Error
Detail:
Use this command to receive the data section of block data (messages starting with #).
After preparing to receive data with “ReceiveBlockHeader,” receive the message from the device specified by the ID number.
If a terminator is detected and data up to that point is received. If it is not detected, data is received up to the number of bytes indicated with blen.
The equivalent functions seen by MATLAB, once the .NET assembly reference was added to my program are as follows:
[int32 scalar RetVal, double scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, double scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
[int32 scalar RetVal, uint64 scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, uint64 scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
[int32 scalar RetVal, int8 scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, int8 scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
[int32 scalar RetVal, uint8 scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, uint8 scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
[int32 scalar RetVal, int16 scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, int16 scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
[int32 scalar RetVal, uint16 scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, uint16 scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
[int32 scalar RetVal, int32 scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, int32 scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
[int32 scalar RetVal, uint32 scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, uint32 scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
[int32 scalar RetVal, int64 scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, int64 scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
[int32 scalar RetVal, single scalar buff, int32 scalar rlen, int32 scalar end] ReceiveBlockData(TmctlAPINet.TMCTL this, int32 scalar id, single scalar buff, int32 scalar blen, int32 scalar rlen, int32 scalar end)
I am calling the function as follows:
int32DataToBeReceivedLength = int32(98366);
int8ReceivedData = int8(0);
int32NoOfActuallyReceivedBytes = int32(0);
int32ReceiveEndFlag = int32(0);
[int32InstrumentAnswer, int8ReceivedData, int32NoOfActuallyReceivedBytes, int32ReceiveEndFlag] = TMCTLobject.ReceiveBlockData(int32DeviceID, int8ReceivedData, int32DataToBeReceivedLength+1, int32NoOfActuallyReceivedBytes, int32ReceiveEndFlag);
When MATLAB attempts to run the last line of code (namely the ReceiveBlockData call), the following error is generated:
The error report indicates "Unknown exception 0xe0434352 detected", but it is otherwise not very helpful.
My suspicion is related to the int8ReceivedData variable. The function is expected to retreive a large number of bytes and store it in an output buffer, which is a ref in C# and a char* in VC++. But how could a simple int8 MATLAB variable store so much data? Where would this data be placed in MATLAB? I am confused and I suppose that's what also confuses MATLAB.
Any ideas?
Best regards,
Cristian
0 件のコメント
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!