Passing a MATLAB object-handle through a .NET call

1 回表示 (過去 30 日間)
Gary
Gary 2019 年 7 月 15 日
I would like to pass a MATLAB object handle with an asynchronous .NET call, so that it can be passed back to the same MATLAB instance and resolved as an object reference.
The specific case is that I am using a Windows Named Pipe for interprocess communication between another application and MATLAB. To use the pipe asynchronously, I issue the following call from a MATLAB object 'pclient' of class 'PipeClient' (which I defined):
pclient.Stream.BeginRead(pclient.Buffer,0,pclient.BufferSize,@pipeClientReadCallback,STATE);
The last parameter STATE in this .NET call can be any object translatable into the call, and its purpose is that it is passed back to the ReadCallback function. I can send a number, or a pointer to a System.Byte[] array created in MATLAB, but ideally I would pass a reference to the pclient object.
If I could convert a MATLAB object handle into a number (and later convert it back again), this would allow me to code this cleanly. As it is now, I have a workaround in which the callback refers to a global object containing pClient, but this seems unaesthetic.

回答 (0 件)

カテゴリ

Help Center および File ExchangeGetting Started with Microsoft .NET についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by