Hi. I have noticed that the return value of  mitkSerialCommunication::Send
is incosistent in Windows. That function returns 1 for Ok and 0 for an
error condition, but if the WriteFile fails (it it returns FALSE), Send
returns the GetLastError() value. In general GetLastError will return
values > 0 for error codes, possibly not a 1 (ERROR_INVALID_FUNCTION) for
the WriteFile call, but surely a 5 (ERROR_ACCESS_DENIED) when the serial
port is physically unplugged while sending data.

Then for example in mitkNDITrackingDevice (around line 249) you have:

long returnvalue = m_SerialCommunication->Send(message);
if (returnvalue == 0)
return SERIALSENDERROR;
else
return NDIOKAY;

So if the serial is disconnected we will not detect it.

A simple solution is to replace the return GetLastError(); in the Send
function by a return ERROR_VALUE;

Then we can add a GetLastError to mitkSerialCommunication to get the exact
error code (if there is one available). Please notice that this problem
will not occur if you are using Posix.

I can contribute a PR with this change if you think it is reasonable.

Thanks

Federico
_______________________________________________
mitk-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mitk-users

Reply via email to