SimpleCirc.py#

#############################################################
 # 
 # FILE:        SimpleCirc.py
 # DATE:        1/14/2022
 # COMPANY:     BitFlow, Inc.
 # DESCRIPTION: A simple example of capturing data 
 #              to a circular buffer from a single frame grabber 
 #              board.
 #
#############################################################

import platform

if(platform.system() == 'Windows'):
    import sys
    import msvcrt

    if (sys.version_info.major >= 3 and sys.version_info.minor >= 8):
        import os
        #Following lines specifying, the location of DLLs, are required for Python Versions 3.8 and greater
        os.add_dll_directory("C:\BitFlow SDK 6.5\Bin64")
        os.add_dll_directory("C:\Program Files\CameraLink\Serial")

import BFModule.BufferAcquisition as Buf
import BFModule.Display as Disp


import time
from datetime import datetime

# The main function
def main():
    
    numBuffers = 10

    print('Circular Acquisition Example')
    print('---------------------------------')

    #CirAq = Buf.clsCircularAcquisition(Buf.ErrorMode.ErIgnore)
    CirAq = Buf.clsCircularAcquisition()

    #Call Open board function by showing the Board select dialog
    
    CirAq.Open()
    #CirAq.Open(4, Buf.OpenOptions.Initialize)
    #CirAq.Open(0) # Use this to open board 0 without displaying the board select dialog

    #Allocate the requested number of buffers
    BufArray = CirAq.BufferSetup(numBuffers)

    #Setup acquisition using the default options
    CirAq.AqSetup(Buf.SetupOptions.DisableAqErrorSig)

    #Create and open Display surface using the above parameters
    dispSurf = Disp.clsDisp(CirAq)
    #Open the display surface
    dispSurf.Open()

    #Start Acquisition
    CirAq.AqControl(Buf.AcqCommands.Start, Buf.AcqControlOptions.Wait)
    print("Acquisition Started.")

    prev_time = 0
    curr_time = 0

    keepUpdating = True

    start_time = time.time()
    frameCnt = 0
    try:
        while keepUpdating:        
            try:
                if(CirAq.GetAcqStatus().Start == True):
                    curBuf = CirAq.WaitForFrame(1000)
                    frameCnt += 1
                    fps = frameCnt/(time.time()-start_time)
                    prev_time = curr_time
                    print(f"Framerate = {int(fps)}\t\t",end="\r")
                    if (dispSurf.isOpen):
                        dispSurf.Update(BufArray[curBuf.BufferNumber])
            except Exception as e:
                print(e)
                keepUpdating = False
                pass
    except KeyboardInterrupt:
        pass

    CirAq.AqControl(Buf.AcqCommands.Stop, Buf.AcqControlOptions.Wait)

    #Print capture stats
    capStatus = CirAq.GetCaptureStatus()
    print("Frames Captured = ", capStatus[0])
    print("Frames Missed = ", capStatus[1])
                        
    #Cleanup acquisition
    CirAq.AqCleanup()
    
    #Close the display surface and free the resources
    dispSurf.Close()
    
    #Free allocated resources
    CirAq.BufferCleanup()

    #Close the board
    CirAq.Close()

if __name__ == "__main__":
    main()