instamatic-dev / instamatic

Python program for automated electron diffraction data collection
https://instamatic.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
56 stars 25 forks source link

Timeout when using Merlin #75

Closed GearoidM closed 1 year ago

GearoidM commented 1 year ago

Hello,

I am getting the following error after running Instamatic on a Merlin detector for a short time ( < 5 minutes).

Exception in thread Thread-2: Traceback (most recent call last): File "c:\users\merlin\appdata\local\programs\python\python38\lib\threading.py", line 932, in _bootstrap_inner self.run() File "c:\users\merlin\appdata\local\programs\python\python38\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "c:\users\merlin\appdata\local\programs\python\python38\lib\site-packages\instamatic\camera\videostream.py", line 56, in run frame = self.cam.getImage(exposure=self.frametime, binsize=self.binsize) File "c:\users\merlin\appdata\local\programs\python\python38\lib\site-packages\instamatic\camera\camera_merlin.py", line 196, in getImage framedata = self.receive_data(nbytes=self._frame_length) File "c:\users\merlin\appdata\local\programs\python\python38\lib\site-packages\instamatic\camera\camera_merlin.py", line 86, in receive_data data.extend(self.s_data.recv(nbytes - len(data))) socket.timeout: timed out

stefsmeets commented 1 year ago

Thanks for report! When acquiring data using software trigger, I set Merlin to collect 10k frames:

https://github.com/instamatic-dev/instamatic/blob/5397b11c114cf5bc06b0bab45efbc03ba1fad250/instamatic/camera/camera_merlin.py#L141-L143

I think you may be hitting this number, after which Merlin will no longer send frames and the command needs to be refreshed. Changing the exposure time will reset the acquisition, and also the frame counter. Does this sound possible?

stefsmeets commented 1 year ago

I added a check that tracks the frame number and resets when the number of frames to acquire gets hit. I will test and merge it on Friday.

GearoidM commented 1 year ago

Yeah, that seems to be what is happening. The timeout occurred at around 8.35 minutes for a 0.05 s exposure time. So that's about 10000 frames. I then tested changing the exposure time and Instamatic did not timeout after this, implying the counter was reset by this action. I think your check should solve this issue, then. Thanks!

stefsmeets commented 1 year ago

I set the number to the maximum value of 42949672950. This means you can collect for over a year with continuous 1 ms exposures to hit the limit 😅