Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate exceptions correctly from setSLMImage() #87

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions pymmcore/pymmcore_swig.i
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,14 @@ import_array();
%rename(setSLMImage) setSLMImage_pywrap;
%apply (char *STRING, int LENGTH) { (char *pixels, int receivedLength) };
%extend CMMCore {
PyObject *setSLMImage_pywrap(const char* slmLabel, char *pixels, int receivedLength)
void setSLMImage_pywrap(const char* slmLabel, char *pixels, int receivedLength) throw (CMMError)
{
// TODO This size check is done here (instead of in MMCore) because the
// CMMCore::setSLMImage() interface is deficient: it does not include a
// length parameter. It will be better to change the CMMCore functions to
// require a length and move this check there.

long expectedLength = self->getSLMWidth(slmLabel) * self->getSLMHeight(slmLabel);
//printf("expected: %d -- received: %d\n",expectedLength,receivedLength);

if (receivedLength == expectedLength)
{
Expand All @@ -200,10 +204,8 @@ PyObject *setSLMImage_pywrap(const char* slmLabel, char *pixels, int receivedLen
}
else
{
PyErr_SetString(PyExc_TypeError, "Image dimensions are wrong for this SLM.");
return (PyObject *) NULL;
throw CMMError("Image dimensions are wrong for this SLM");
}
return PyInt_FromLong(0);
}
}
%ignore setSLMImage;
Expand Down
Loading