st-ten-1/src/test/hikrobot_sc/test_hikrobot_sc.py

129 lines
4.5 KiB
Python
Raw Normal View History

import ctypes
import os
2025-01-21 18:16:21 +00:00
import threading
import time
2025-01-17 15:23:24 +00:00
from ctypes import *
from src.components.hikrobot_dll import *
# Define the necessary structures and constants from MvVisionSensorDefine.h
2025-01-17 15:23:24 +00:00
def print_device_info(device_info_list):
num_devices=device_info_list.nDeviceNum
for i in range(num_devices):
device_info = device_info_list.pDeviceInfo[i].contents
nIp1 = ((device_info.nCurrentIp & 0xff000000) >> 24)
nIp2 = ((device_info.nCurrentIp & 0x00ff0000) >> 16)
nIp3 = ((device_info.nCurrentIp & 0x0000ff00) >> 8)
nIp4 = (device_info.nCurrentIp & 0x000000ff)
print(f"[{i}]Gige: {device_info.chUserDefinedName.decode()}"
f"({nIp1}.{nIp2}.{nIp3}.{nIp4})")
def main():
2025-01-17 15:23:24 +00:00
global MV_VS_OK
print("SC2016 TEST")
device_info_list = MV_VS_DEVICE_INFO_LIST()
nRet = mv_lib.MV_VS_EnumDevices(ctypes.byref(device_info_list))
if nRet != MV_VS_OK:
print(f"Enum devices failed! nRet [{nRet:#x}]")
return -2
else:
print("Enum devices OK")
if device_info_list.nDeviceNum > 0:
print_device_info(device_info_list)
else:
print("Find No Devices!")
return -2
2025-01-17 15:23:24 +00:00
if device_info_list.nDeviceNum == 2:
print("Starting dual camera test!")
# Define MV_VS_OK (replace with the actual value)
MV_VS_OK = 0
2025-01-22 18:01:57 +00:00
MV_VS_DEVICE_INFO_1 = device_info_list.pDeviceInfo[0]
MV_VS_DEVICE_INFO_2 = device_info_list.pDeviceInfo[1]
2025-01-17 15:23:24 +00:00
pHandle1 = c_void_p()
pHandle2 = c_void_p()
nRet1 = mv_lib.MV_VS_CreateHandle(byref(pHandle1), MV_VS_DEVICE_INFO_1)
2025-01-22 15:25:39 +00:00
nRet2=0
2025-01-22 18:01:57 +00:00
nRet2 = mv_lib.MV_VS_CreateHandle(byref(pHandle2), MV_VS_DEVICE_INFO_2)
2025-01-17 15:23:24 +00:00
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
print(f"Create Handle failed! [{nRet1:#x} {nRet2:#x}]")
return
2025-01-22 15:25:39 +00:00
time.sleep(0.1)
2025-01-17 15:23:24 +00:00
nRet1 = mv_lib.MV_VS_Login(pHandle1, b"Admin", b"Abc1234")
2025-01-22 15:25:39 +00:00
time.sleep(0.1)
2025-01-22 18:01:57 +00:00
nRet2 = mv_lib.MV_VS_Login(pHandle2, b"Admin", b"Abc1234")
2025-01-17 15:23:24 +00:00
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
2025-01-22 15:25:39 +00:00
print(f"Login failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]")
2025-01-17 15:23:24 +00:00
return
else:
print("Login OK")
nRet1 = mv_lib.MV_VS_SetBoolValue(pHandle1, b"CommandImageMode", 0)
2025-01-22 18:01:57 +00:00
nRet2 = mv_lib.MV_VS_SetBoolValue(pHandle2, b"CommandImageMode", 0)
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
2025-01-22 15:25:39 +00:00
print(f"CommandImageMode failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]")
return
else:
print("CommandImageMode OK")
2025-01-21 18:16:21 +00:00
nRet1 = mv_lib.MV_VS_SetEnumValue(pHandle1, b"AcquisitionMode", 0)
2025-01-22 18:01:57 +00:00
nRet2 = mv_lib.MV_VS_SetEnumValue(pHandle2, b"AcquisitionMode", 0)
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
2025-01-22 15:25:39 +00:00
print(f"AcquisitionMode failed! [{nRet1&0xFFFFFFFF:#x} {nRet2&0xFFFFFFFF:#x}]")
return
else:
print("AcquisitionMode OK")
2025-01-22 18:01:57 +00:00
# Start the camera test
nRet1 = mv_lib.MV_VS_StartRun(pHandle1)
nRet2 = mv_lib.MV_VS_StartRun(pHandle2)
2025-01-21 18:16:21 +00:00
stMemory = PROCESS_MEMORY_COUNTERS()
ctypes.windll.psapi.GetProcessMemoryInfo(
ctypes.windll.kernel32.GetCurrentProcess(), ctypes.byref(stMemory), ctypes.sizeof(stMemory)
)
# Get the current time
current_time = time.localtime()
# Print the information
print(
f"Start test Get/Release result data, begin time [{current_time.tm_hour + 8:02d}:{current_time.tm_min:02d}:{current_time.tm_sec:02d}], "
f"current memory [{stMemory.WorkingSetSize / 1024} KB]"
)
# Create the thread
2025-01-22 18:01:57 +00:00
thread = threading.Thread(target=MV_VS_GetFrame, args=(pHandle1, "dx"))
thread2 = threading.Thread(target=MV_VS_GetFrame, args=(pHandle2, "sx"))
2025-01-21 18:16:21 +00:00
# Start the thread
thread.start()
2025-01-22 18:01:57 +00:00
thread2.start()
2025-01-22 15:25:39 +00:00
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
print(f"Start run failed! [{nRet1 & 0xFFFFFFFF:#x} {nRet2 & 0xFFFFFFFF:#x}]")
2025-01-21 18:16:21 +00:00
while True:
print("main loop cycle")
2025-01-22 15:25:39 +00:00
#Trigger acquisition & test execution
2025-01-22 18:01:57 +00:00
nRet1 = mv_lib.MV_VS_SetCommandValue(pHandle1, b"AcquisitionStart")
nRet2 = mv_lib.MV_VS_SetCommandValue(pHandle2, b"AcquisitionStart")
2025-01-21 18:16:21 +00:00
if nRet1 != MV_VS_OK or nRet2 != MV_VS_OK:
2025-01-22 15:25:39 +00:00
print(f"AcquisitionStart failed! [{nRet1 & 0xFFFFFFFF:#x} {nRet2 & 0xFFFFFFFF:#x}]")
2025-01-21 18:16:21 +00:00
else:
2025-01-22 15:25:39 +00:00
print("AcquisitionStart OK")
2025-01-21 18:16:21 +00:00
time.sleep(1)
return 0
2025-01-22 15:25:39 +00:00
if __name__ == "__main__":
main()