From 2d92ab9555bb83e7db64189e744c33dd1f608fc7 Mon Sep 17 00:00:00 2001 From: gg Date: Wed, 22 Jan 2025 19:01:57 +0100 Subject: [PATCH] hikrobot dual smart camera test OK --- src/components/hikrobot_dll.py | 11 ++++++--- src/test/hikrobot_sc/test_hikrobot_sc.py | 29 ++++++++++++------------ 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/components/hikrobot_dll.py b/src/components/hikrobot_dll.py index 769bebd..f5add90 100644 --- a/src/components/hikrobot_dll.py +++ b/src/components/hikrobot_dll.py @@ -2,6 +2,7 @@ import ctypes import json import socket import struct +import time from ctypes import * import sys @@ -214,13 +215,16 @@ mv_lib.MV_VS_SetEnumValue.restype = c_int mv_lib.MV_VS_StartRun.argtypes = [c_void_p] # handle mv_lib.MV_VS_StartRun.restype = c_int +mv_lib.MV_VS_SetCommandValue.argtypes = [c_void_p, c_char_p] +mv_lib.MV_VS_SetCommandValue.restype = c_int -def MV_VS_GetFrame(handle): + +def MV_VS_GetFrame(handle, suffix): while True: stFrameData = MV_VS_DATA() - nRet = mv_lib.MV_VS_GetResultData(handle, byref(stFrameData), 1000) + nRet = mv_lib.MV_VS_GetResultData(handle, byref(stFrameData), 2000) if nRet == MV_VS_OK: # Print frame information print( @@ -309,7 +313,7 @@ def MV_VS_GetFrame(handle): m_stJpgParam.nBufInputLen = stFrameData.nImageLen jpegContents = ctypes.string_at(m_stJpgParam.pBufInput, m_stJpgParam.nBufInputLen) - with open("tmp/test.jpg", "wb") as f: + with open(f"tmp/test_{suffix}.jpg", "wb") as f: f.write(jpegContents) # Release frame buffer @@ -321,3 +325,4 @@ def MV_VS_GetFrame(handle): else: print(f"MV_VS_GetResultData fail! nRet [0x{nRet&0xFFFFFFFF:x}]") + time.sleep(500) diff --git a/src/test/hikrobot_sc/test_hikrobot_sc.py b/src/test/hikrobot_sc/test_hikrobot_sc.py index 6296c53..aeea6a5 100644 --- a/src/test/hikrobot_sc/test_hikrobot_sc.py +++ b/src/test/hikrobot_sc/test_hikrobot_sc.py @@ -44,13 +44,13 @@ def main(): print("Starting dual camera test!") # Define MV_VS_OK (replace with the actual value) MV_VS_OK = 0 - MV_VS_DEVICE_INFO_1 = device_info_list.pDeviceInfo[0]; - MV_VS_DEVICE_INFO_2 = device_info_list.pDeviceInfo[1]; + MV_VS_DEVICE_INFO_1 = device_info_list.pDeviceInfo[0] + MV_VS_DEVICE_INFO_2 = device_info_list.pDeviceInfo[1] pHandle1 = c_void_p() pHandle2 = c_void_p() nRet1 = mv_lib.MV_VS_CreateHandle(byref(pHandle1), MV_VS_DEVICE_INFO_1) nRet2=0 - #nRet2 = mv_lib.MV_VS_CreateHandle(byref(pHandle2), MV_VS_DEVICE_INFO_2) + nRet2 = mv_lib.MV_VS_CreateHandle(byref(pHandle2), MV_VS_DEVICE_INFO_2) if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK: print(f"Create Handle failed! [{nRet1:#x} {nRet2:#x}]") return @@ -58,7 +58,7 @@ def main(): time.sleep(0.1) nRet1 = mv_lib.MV_VS_Login(pHandle1, b"Admin", b"Abc1234") time.sleep(0.1) - #nRet2 = mv_lib.MV_VS_Login(pHandle2, b"Admin", b"Abc1234") + nRet2 = mv_lib.MV_VS_Login(pHandle2, b"Admin", b"Abc1234") if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK: print(f"Login failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]") return @@ -66,7 +66,7 @@ def main(): print("Login OK") nRet1 = mv_lib.MV_VS_SetBoolValue(pHandle1, b"CommandImageMode", 0) - #nRet2 = mv_lib.MV_VS_SetBoolValue(pHandle2, b"CommandImageMode", 0) + nRet2 = mv_lib.MV_VS_SetBoolValue(pHandle2, b"CommandImageMode", 0) if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK: print(f"CommandImageMode failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]") return @@ -74,13 +74,17 @@ def main(): print("CommandImageMode OK") nRet1 = mv_lib.MV_VS_SetEnumValue(pHandle1, b"AcquisitionMode", 0) - #nRet2 = mv_lib.MV_VS_SetEnumValue(pHandle2, b"AcquisitionMode", 0) + nRet2 = mv_lib.MV_VS_SetEnumValue(pHandle2, b"AcquisitionMode", 0) if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK: print(f"AcquisitionMode failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]") return else: print("AcquisitionMode OK") + # Start the camera test + nRet1 = mv_lib.MV_VS_StartRun(pHandle1) + nRet2 = mv_lib.MV_VS_StartRun(pHandle2) + stMemory = PROCESS_MEMORY_COUNTERS() ctypes.windll.psapi.GetProcessMemoryInfo( ctypes.windll.kernel32.GetCurrentProcess(), ctypes.byref(stMemory), ctypes.sizeof(stMemory) @@ -96,16 +100,13 @@ def main(): ) # Create the thread - thread = threading.Thread(target=MV_VS_GetFrame, args=(pHandle1,)) - thread2 = threading.Thread(target=MV_VS_GetFrame, args=(pHandle2,)) + thread = threading.Thread(target=MV_VS_GetFrame, args=(pHandle1, "dx")) + thread2 = threading.Thread(target=MV_VS_GetFrame, args=(pHandle2, "sx")) # Start the thread thread.start() - #thread2.start() + thread2.start() - #Start the camera test - nRet1 = mv_lib.MV_VS_StartRun(pHandle1) - #nRet2 = mv_lib.MV_VS_StartRun(pHandle2) if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK: print(f"Start run failed! [{nRet1 & 0xFFFFFFFF:#x} {nRet2 & 0xFFFFFFFF:#x}]") @@ -113,8 +114,8 @@ def main(): print("main loop cycle") #Trigger acquisition & test execution - nRet1 = mv_lib.MV_VS_SetCommandValue(pHandle1, "AcquisitionStart") - #nRet2 = mv_lib.MV_VS_SetCommandValue(pHandle2, "AcquisitionStart") + nRet1 = mv_lib.MV_VS_SetCommandValue(pHandle1, b"AcquisitionStart") + nRet2 = mv_lib.MV_VS_SetCommandValue(pHandle2, b"AcquisitionStart") if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK: print(f"AcquisitionStart failed! [{nRet1 & 0xFFFFFFFF:#x} {nRet2 & 0xFFFFFFFF:#x}]") else: