def __del__(self):
     """
     Frees memory and grabber when closing.
     """
     s.Fg_FreeMemEx(self.device, self._free_run_buffer)
     if self._buffer_handle is not None:
         s.Fg_FreeMemEx(self.device, self._buffer_handle)
     s.clSerialClose(self._clser_ref[1])
     self.closeDevice()
 def _freeImageBuffer(self):
     """
     Frees allocated frame buffers and sets self.buffer_handle to None.
     """
     s.Fg_FreeMemEx(self.device, self._buffer_handle)
     self._buffer_handle = None
 def _freeLiveBuffer(self):
     """
     Frees allocated memory of self.free_run_buffer. Sets handle to None.
     """
     s.Fg_FreeMemEx(self.device, self._free_run_buffer)
     self._free_run_buffer = None
if err < 0:
    print("Error", err, ":", mes)
    sys.exit()
else:
    print("ok")

# allocating memory
memHandle = s.Fg_AllocMemEx(fg, totalBufferSize, nbBuffers)

# Set Applet Parameters
err = s.Fg_setParameterWithInt(fg, s.FG_WIDTH, width, camPort)
if (err < 0):
    print("Fg_setParameter(FG_WIDTH) failed: ",
          s.Fg_getLastErrorDescription(fg))
    s.Fg_FreeMemEx(fg, memHandle)
    s.Fg_FreeGrabber(fg)
    exit(err)

err = s.Fg_setParameterWithInt(fg, s.FG_HEIGHT, height, camPort)
if (err < 0):
    print("Fg_setParameter(FG_HEIGHT) failed: ",
          s.Fg_getLastErrorDescription(fg))
    s.Fg_FreeMemEx(fg, memHandle)
    s.Fg_FreeGrabber(fg)
    exit(err)

print(s.FG_BITALIGNMENT)
print(s.FG_LEFT_ALIGNED)
print(camPort)