Different asynchronous WriteFile behavior between MATLAB 2012a and MATLAB 2014b

조회 수: 3 (최근 30일)
I am doing asynchronous Serial I/O using a MEX function created using Microsoft Windows SDK 7.1 (C++) on 64bit Windows 7 machine, a .cpp function with the following lines:
Success = WriteFile(hCom, cbuf, BytesToWrite, NULL, &oW); // Overlapped
if(!Successful) {
DWORD Error = GetLastError();
if( Error == ERROR_IO_PENDING ){
I ran this code on MATLAB 2012, 2014 and 2015.
When I try to write, WriteFile (Success) always returns 0. But then, DWORD Error when running in MATLAB2012 returns:
ERROR_IO_PENDING
997 (0x3E5)
Overlapped I/O operation is in progress.
Which means the operation is a success.
But DWORD Error in MATLAB 2014 or 2015 returns fail as well.
I can't get WriteFile to work on MATLAB 2014 or 2015 (I tried both). Reading from the serial port is no problem ,just problem with WriteFile.
I am thinking it is some sort of issue with the Microsoft Windows SDK 7.1 (C++), and probably older versions of Matlab (2012 or earlier) might work.
  댓글 수: 9
JMP Phillips
JMP Phillips 2015년 8월 19일
That's not strictly true. MEX-files use MATLAB runtime libraries (see http://au.mathworks.com/help/matlab/matlab_external/version-compatibility.html).
In my case the only point of difference is the MATLAB version which is calling the mex file, everything else is identical including the mex file which I compiled on one version only. And it is not an issue of which MATLAB version I compiled it on, as I have already tested compiling and running on the same and different MATLAB versions. I believe it could be a MATLAB runtime library issue.
Walter Roberson
Walter Roberson 2015년 8월 19일
Given the API, it is an error for your code to require that the operation not happen synchronously. It may be unexpected, but it is permitted for the operating system to return synchronously for any reason it feels like, including the possibility that every 47th bit in the executable happens to match the sound file representation of "Anchors Away!".

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by