Skip to content

Memory problem, and repeat capture bug #2

@benjpjones

Description

@benjpjones

Hello,

I am trying to use this software with a C9100-23B camera, and am having trouble with the basic example code. Running Python 3.8.8 on Windows.

I am able to take one set of images from the camera using the code below, which is heavily based on the example code provided:


def Snap(self,frames):
        from hamamatsu.dcam import dcam, Stream, copy_frame, ECCDMode

        returnvec=[]
        with dcam:
            camera = dcam[0]
            with camera:
                print(camera.info)
                print(camera['image_width'].value, camera['image_height'].value)

                # Simple acquisition example
                nb_frames = 5

                camera['ccd_mode']=ECCDMode.NORMALCCD
                camera['readout_speed'] = 1
                camera["exposure_time"] = 5
                
                with Stream(camera, nb_frames) as stream:
                        camera.start()

                        for i, frame_buffer in enumerate(stream):
                            frame = copy_frame(frame_buffer)
                            returnvec.append(copy.deepcopy(frame))
                            print(f"acquired frame #%d/%d: %s", i+1, nb_frames)
                        print("finished acquisition")

        return returnvec

However, if I run the function a second time; the camera takes the right number of images, but now uses its default settings for exposure time, EMCCD mode, rather than setting up the camera correctly with the ones provided in this function.

Trying to debug this problem I tried a few things, and one thing I noticed was that when I run the similar code block as a standalone python script from command line, it fails with a memory error at the end. The program and output are below. I wonder if cleanup of the objects at the the of the 'with' scope is not occurring properly and this is what is preventing the camera from being able to take more than one image set in a given program?

I am not sure what else to try to debug, but would be very grateful for any guidance.

#!/usr/bin/env python

from hamamatsu.dcam import dcam, Stream, copy_frame, ECCDMode
import numpy as np

returnvec=[]
with dcam:
    camera = dcam[0]
    with camera:
        print(camera.info)
        print(camera['image_width'].value, camera['image_height'].value)

        # Simple acquisition example
        camera['ccd_mode']=ECCDMode.NORMALCCD
        camera['readout_speed'] = 1
        camera["exposure_time"] = 5



        with Stream(camera, 1) as stream:
                camera.start()

                for i, frame_buffer in enumerate(stream):
                    frame = copy_frame(frame_buffer)
                    np.savetxt('out_snap.txt',frame)
                    print(f"acquired frame #%d/%d: %s", i+1)
                print("finished acquisition")


$ ./snap.py
{<EIDString.BUS: 67109121>: 'OHCI 1394', <EIDString.CAMERAID: 67109122>: 'S/N: 000342', <EIDString.VENDOR: 67109123>: 'Hamamatsu', <EIDString.MODEL: 67109124>: 'C9100-23B', <EIDString.CAMERAVERSION: 67109125>: '1.21.00.D', <EIDString.DRIVERVERSION: 67109126>: '9.28.14.5162', <EIDString.MODULEVERSION: 67109127>: '16.10.642.5162', <EIDString.DCAMAPIVERSION: 67109128>: '4.00'}
512 512
acquired frame #%d/%d: %s 1
finished acquisition
Exception ignored in: <function DCAM.del at 0x00000000035423A0>
Traceback (most recent call last):
File "C:\Users\jonesb\Anaconda3\lib\site-packages\hamamatsu\dcam.py", line 1797, in del
File "C:\Users\jonesb\Anaconda3\lib\site-packages\hamamatsu\dcam.py", line 1857, in close
OSError: exception: access violation reading 0xFFFFFFFFFFFFFFFF

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions