问题
I am having trouble locating an example for creating a windows named pipe in matlab.
Any suggestions on how to program or where to look?
回答1:
Using .NET's System.IO.Pipes is probably the easiest way out of the box, easier than writing a MEX file to call the Win32 API. Matlab lets you call .NET directly from M-code, and the objects are managed so resource cleanup will be easier. .NET 3.5 and newer support named pipes.
The resulting M-code would look something like this. (Sorry; I don't have Matlab at the moment so can't test it.)
NET.addAssembly('System.Core'); %# might be superfluous
pipeStream = System.IO.Pipes.NamedPipeServerStream('testpipe', System.IO.Pipes.PipeDirection.Out);
Nowadays, I think .NET is the easiest way to access native Windows features that Matlab doesn't directly expose. So for something like this, the first thing to try is looking for examples of doing it in C#. If it can be done in C# using .NET standard library features, you can often translate it pretty directly to M-code. E.g. I found this one by Googling for "create named pipe .net" and getting this example. Loren discusses this technique here.
来源:https://stackoverflow.com/questions/12649778/named-pipes-matlab