print('Importing SiSo Wrapper')
import SiSoPyInterface as s
raise ImportError('SiSo module not loaded successfully')
print('Runtime Version', s.Fg_getSWVersion())
# IMPORT additional modules
# for "s.getArrayFrom", to handle grabbed image as NumPy array
print('Importing NumPy', end='')
print('Version', np.__version__)
# returns count of available boards
(err, buffer, buflen) = s.Fg_getSystemInformation(None, s.INFO_NR_OF_BOARDS, s.PROP_ID_VALUE, 0)
# Lets the user select one of the available applets, and returns the selected applet
def selectAppletDialog(boardIndex):
iter, err = s.Fg_getAppletIterator(boardIndex, s.FG_AIS_FILESYSTEM, s.FG_AF_IS_LOADABLE)
print("No Applets found!")
print('Found', err, 'Applet(s)')
item = s.Fg_getAppletIteratorItem(iter, i)
appletPath = s.Fg_getAppletStringProperty(item, s.FG_AP_STRING_APPLET_PATH)
appletName = s.Fg_getAppletStringProperty(item, s.FG_AP_STRING_APPLET_NAME)
sys.stdout.write(str(i) + ": " + appletName + "(" + appletPath + ")\n");
inStr = "=====================================\n\nPlease choose an Applet [0-" + str(maxAppletIndex) + "]: "
while (not userInput.isdigit()) or (int(userInput) > maxAppletIndex):
inStr = "Invalid selection, retry[0-" + str(maxAppletIndex) + "]: "
item = s.Fg_getAppletIteratorItem(iter, int(userInput))
appletName = s.Fg_getAppletStringProperty(item, s.FG_AP_STRING_APPLET_NAME)
s.Fg_freeAppletIterator(iter)
# Additional Class definition
def __init__(self, fg, port, mem, displayid):
self.displayid = displayid
# Callback function definition
def apcCallback(imgNr, userData):
s.DrawBuffer(userData.displayid, s.Fg_getImagePtrEx(userData.fg, imgNr, userData.port, userData.mem), imgNr, "")
# Board and applet selection
#boardId = selectBoardDialog()
# definition of resolution
useCameraSimulator = False
# number of buffers for acquisition
totalBufferSize = width * height * samplePerPixel * bytePerSample * nbBuffers
# number of image to acquire
applet = selectAppletDialog(boardId)
#applet = "Test_Applet_CZ.hap"
print('Initializing Board ..', end='')
fg = s.Fg_InitEx(applet, boardId, 1);
fg = s.Fg_InitEx(applet, boardId, 0);
err = s.Fg_getLastErrorNumber(fg)
mes = s.Fg_getErrorDescription(err)
print("Error", err, ":", mes)
memHandle = s.Fg_AllocMemEx(fg, totalBufferSize, nbBuffers)
err = s.Fg_setParameterWithInt(fg, s.FG_WIDTH, width, camPort)
print("Fg_setParameter(FG_WIDTH) failed: ", s.Fg_getLastErrorDescription(fg))
s.Fg_FreeMemEx(fg, memHandle)
err = s.Fg_setParameterWithInt(fg, s.FG_HEIGHT, height, camPort)
print("Fg_setParameter(FG_HEIGHT) failed: ", s.Fg_getLastErrorDescription(fg))
s.Fg_FreeMemEx(fg, memHandle)
err = s.Fg_setParameterWithInt(fg, s.FG_BITALIGNMENT, s.FG_LEFT_ALIGNED, camPort)
print("Fg_setParameter(FG_BITALIGNMENT) failed: ", s.Fg_getLastErrorDescription(fg))
#s.Fg_FreeMemEx(fg, memHandle)
(err, oWidth) = s.Fg_getParameterWithInt(fg, s.FG_WIDTH, camPort)
(err, oHeight) = s.Fg_getParameterWithInt(fg, s.FG_HEIGHT, camPort)
print('Height =', oHeight)
(err, oString) = s.Fg_getParameterWithString(fg, s.FG_HAP_FILE, camPort)
print('Hap File =', oString)
sgc_init_flag = 0 # fixed according to documentation
(err, sgc_handle) = s.Sgc_initBoard(fg,sgc_init_flag)
print(s.Fg_getErrorDescription(err))
discoveryTimeoutms = 5000
(sgc_ports)= s.Sgc_scanPorts(sgc_handle, portMask, discoveryTimeoutms, speed)
print("sgc_ports",sgc_ports)
cameracount = s.Sgc_getCameraCount(sgc_handle)
print("cameracount", cameracount)
(err, camhandle) = s.Sgc_getCamera(sgc_handle, 0)
print("errcamhandle,",err)
print(s.Fg_getErrorDescription(err))
(err) = s.Sgc_connectCamera(camhandle)
print("errcamconnect,",err)
print(s.Fg_getErrorDescription(err))
# load parameter file if needed:
(err) = s.Sgc_LoadCameraParameters(camhandle,'Camera_1280x800_visible.genicam.parameters.txt',0)
print(s.Fg_getErrorDescription(err))
err = s.Sgc_startAcquisition(camhandle, 1)
print(s.Fg_getErrorDescription(err))
s.Fg_setParameterWithInt(fg, s.FG_GEN_ENABLE, s.FG_GENERATOR, camPort)
# s.Fg_setParameterWithInt(fg, s.FG_GEN_ROLL, 1, camPort)
s.Fg_setParameterWithInt(fg, s.FG_GEN_ENABLE, s.FG_CAMPORT, camPort)
# create a display window
dispId0 = s.CreateDisplay(8 * bytePerSample * samplePerPixel, width, height)
s.SetBufferWidth(dispId0, width, height)
# Register acquisition call back
#Define FgApcControl instance to handle the callback
apcCtrl = s.FgApcControl(5, s.FG_APC_DEFAULTS)
data = MyApcData(fg, camPort, memHandle, dispId0)
s.setApcCallbackFunction(apcCtrl, apcCallback, data)
#Register the FgApcControl instance to the Fg_Struct instance
err = s.Fg_registerApcHandler(fg, camPort, apcCtrl, s.FG_APC_CONTROL_BASIC)
print("registering APC handler failed:", s.Fg_getErrorDescription(err))
s.Fg_FreeMemEx(fg, memHandle)
print("Acquisition started")
err = s.Fg_AcquireEx(fg, camPort, nrOfPicturesToGrab, s.ACQ_STANDARD, memHandle)
print('Fg_AcquireEx() failed:', s.Fg_getLastErrorDescription(fg))
s.Fg_FreeMemEx(fg, memHandle)
s.Sgc_stopAcquisition(camhandle, 1)
s.Sgc_disconnectCamera(camhandle)
print("Acquisition stopped")
s.Fg_registerApcHandler(fg, camPort, None, s.FG_APC_CONTROL_BASIC);
s.Fg_stopAcquire(fg, camPort)
s.Fg_FreeMemEx(fg, memHandle)