diff --git a/src/components/hikrobot_dll.py b/src/components/hikrobot_dll.py index c2ce528..69f8f03 100644 --- a/src/components/hikrobot_dll.py +++ b/src/components/hikrobot_dll.py @@ -1,4 +1,5 @@ import ctypes +import socket import struct from ctypes import * import sys @@ -144,6 +145,25 @@ class MV_VS_DEVICE_INFO_LIST(ctypes.Structure): ] +class PROCESS_MEMORY_COUNTERS(ctypes.Structure): + _fields_ = [ + ("cb", ctypes.c_ulong), + ("PageFaultCount", ctypes.c_ulong), + ("PeakWorkingSetSize", ctypes.c_size_t), + ("WorkingSetSize", ctypes.c_size_t), + ("QuotaPeakPagedPoolUsage", ctypes.c_size_t), + ("QuotaPagedPoolUsage", ctypes.c_size_t), + ("QuotaPeakNonPagedPoolUsage", ctypes.c_size_t), + ("QuotaNonPagedPoolUsage", ctypes.c_size_t), + ("PagefileUsage", ctypes.c_size_t), + ("PeakPagefileUsage", ctypes.c_size_t), + ] + + +# PPROCESS_MEMORY_COUNTERS is simply a pointer to the struct +PPROCESS_MEMORY_COUNTERS = ctypes.POINTER(PROCESS_MEMORY_COUNTERS) + + # Define function signatures mv_lib.MV_VS_GetResultData.argtypes = [c_void_p, POINTER(MV_VS_DATA), c_int] @@ -185,15 +205,27 @@ def MV_VS_GetFrame(handle): # Process chunk data currentDataTag = 0 while stFrameData.nChunkDataLen > currentDataTag: - chunkLength = \ - struct.unpack_from(" stFrameData.nChunkDataLen - 8 - currentDataTag: - # Handle exception + # Copy data from source to chunkLength and chunkID + ctypes.memmove(ctypes.byref(chunkLength), source_address_length, 4) + ctypes.memmove(ctypes.byref(chunkID), source_address_id, 4) + + # Convert network byte order to host byte order + chunkLength.value = socket.ntohl(chunkLength.value) + chunkID.value = socket.ntohl(chunkID.value) + + # Print the values + print(f"chunkLength [{chunkLength.value}], chunkID: [{chunkID.value}]") + + if chunkLength.value <= 0 or chunkLength.value > stFrameData.nChunkDataLen - 8 - currentDataTag: break if chunkID == CHUNK_RESULT_PORT: # Result data in JSON format @@ -203,24 +235,42 @@ def MV_VS_GetFrame(handle): print(f"chResultInfo [{chResultInfo.value.decode()}] end") elif chunkID == CHUNK_MASK_IMAGE_PORT: # Mask image data - maskModID = struct.unpack_from("