Skip to content

Fix for pco camera crashing/capturing black frames/being stuck#1620

Open
Yujin-Bao wants to merge 5 commits into
python-microscopy:masterfrom
Yujin-Bao:pco_fix
Open

Fix for pco camera crashing/capturing black frames/being stuck#1620
Yujin-Bao wants to merge 5 commits into
python-microscopy:masterfrom
Yujin-Bao:pco_fix

Conversation

@Yujin-Bao
Copy link
Copy Markdown
Contributor

Addresses issue of pco edge 4.2 LT used on the OI-DIC microscope.

Is this a bugfix or an enhancement?
This is a bugfix.

Proposed changes:
Recycle buffer when encoutering timeouts or other errors. Flag errors in pco_sdk_cam.py for framewrangler.py to restart the camera. Add a logging to report which hardware is not ready, which is useful for debugging what causes the delay in the single-shot mode. There might be some redundancy in the type of errors might be encountered because I only have the timeout error in my logging based on my test, but I still keep the code as is to be safe.

Checklist:
The below is a list of things what will be considered when reviewing PRs. It is not prescriptive, and does not
imply that PRs which touch any of these will be rejected but gives a rough indication of where there is a potential
for hangups (i.e. factors which could turn a 5 min review into a half hour or longer and shunt it to the bottom
of the TODO list).

  • Does the PR avoid variable renaming in existing code, whitespace changes, and other forms of tidying? [There is a place for code tidying, but it makes reviewing
    much simpler if this is kept separate from functional changes. The auto-formatting performed by some editors is particulaly egregious and can lead to files with thousands
    of non-functional changes with a few functional changes scattered amoungst them]

If an enhancement (or non-trivial bugfix):

  • Has this been discussed in advance (feature request, PR proposal, email, or direct conversation)?
  • Does this change how users interact with the software? How will these changes be communicated?
  • Does this maintain backwards compatibility with old data?
  • Does this change the required dependencies?
  • Are there any other side effects of the change?

@property
def _timeout(self):
return int(max(2*100*self.GetCycleTime(), 100))
# set the time longer for all hardware check
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This timeout should be specific to the camera (other hardware and hardware checks are completely unimportant here). It's used in the tight loop which just serves the camera. Setting this too long is likely to be undesirable (makes it more likely that the camera buffer is not kept full).

# Bad buffer -> recycle it, don't deliver
logger.warning(f"PCO: error {status} during check of buffer {_curr_buf}. Recycling.")
self._consecutive_errors += 1
self._buffers_to_queue.put(_curr_buf)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might not want to re-queue bad buffers unless we are in continuous mode (if we want to match the current logic, i.e.:

For non-continuous modes:

  • A single buffer is queued in TriggerAq
  • We wait on this buffer, and return once full.

Re-queueing buffers that are bad risks letting the acquisition get out of sync with the triggers (the re-queued buffer might end up waiting on the next trigger)

@zacsimile
Copy link
Copy Markdown
Member

zacsimile commented Dec 22, 2025

FWIW, I recently used the pco. code as-is (prior to this PR) on an edge 4.2 LT and it worked perfectly. All of the timeouts/transfer issues we experienced ended up being due to the cable connecting the camera to the computer. We tried several off the shelf options that in theory matched the required spec with no success. We finally ordered a far too expensive cable directly from Excelitas and the camera buffering worked.

@Yujin-Bao
Copy link
Copy Markdown
Contributor Author

Thank you @zacsimile ! That's good to know swithing a cable solved the problem. Honestly I'm a bit surprised only their expensive cables work as I also tried troubleshooting some hardware before this PR but wasn't able to completely solve the issue. I updated the pco usb 3.0 driver and the pco firmware and inserted a PCIe board to provide a usb 3.0 controller only for the camera. This solved the crashing issue but there are still some timeouts and black frames. I therefore tried tweeking the software.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants