Different asynchronous WriteFile behavior between MATLAB 2012a and MATLAB 2014b
Show older comments
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 Comments
JMP Phillips
on 29 Jun 2015
Guillaume
on 29 Jun 2015
It'll be more useful if you'd tell us what the error is rather than what it is not. That probably would go a long way to understanding what is different about the two setups.
JMP Phillips
on 30 Jun 2015
Edited: JMP Phillips
on 30 Jun 2015
Guillaume
on 30 Jun 2015
To me, its sounds that in the second case, the call completed successfully but synchronously.
There's an MSDN knowledge base article kb 156932 that explains potential reasons for why asynchronous calls can be completed synchronously.
Once again, I don't think it has anything to do with matlab, since matlab is not involved in WriteFile.
JMP Phillips
on 1 Jul 2015
Edited: JMP Phillips
on 1 Jul 2015
Guillaume
on 1 Jul 2015
No, matlab is not calling WriteFile, your mex file is. At this point, matlab is not involved anymore. So if there is a difference in behaviour, it's because the inputs are different, or the environment is different (OS, filesystem state), or the mex files are compiled differently.
JMP Phillips
on 19 Aug 2015
Walter Roberson
on 19 Aug 2015
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!".
Answers (0)
Categories
Find more on MATLAB Compiler in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!