2025-01-16 18:01:07 +00:00
|
|
|
import ctypes
|
|
|
|
|
import os
|
2025-01-17 15:23:24 +00:00
|
|
|
from ctypes import *
|
2025-01-16 18:01:07 +00:00
|
|
|
# Load the MvVisionSensorControl library
|
2025-01-17 15:23:24 +00:00
|
|
|
mv_lib = ctypes.windll.LoadLibrary("src/test/hikrobot_sc/bin/MvVisionSensorControl.dll")
|
|
|
|
|
|
|
|
|
|
from src.components.hikrobot_sc import *
|
2025-01-16 18:01:07 +00:00
|
|
|
|
|
|
|
|
# Define the necessary structures and constants from MvVisionSensorDefine.h
|
|
|
|
|
class MV_VS_DEVICE_INFO(ctypes.Structure):
|
|
|
|
|
_fields_ = [
|
|
|
|
|
("nMajorVer", ctypes.c_ushort), # GigE protocol Major Version
|
|
|
|
|
("nMinorVer", ctypes.c_ushort), # GigE protocol Minor Version
|
|
|
|
|
("nMacAddrHigh", ctypes.c_uint), # High MAC Address
|
|
|
|
|
("nMacAddrLow", ctypes.c_uint), # Low MAC Address
|
|
|
|
|
("nIpCfgOption", ctypes.c_uint), # Supported IP Configuration Options
|
|
|
|
|
("nIpCfgCurrent", ctypes.c_uint), # IP Configuration
|
|
|
|
|
("nCurrentIp", ctypes.c_uint), # Current IP
|
|
|
|
|
("nCurrentSubNetMask", ctypes.c_uint), # Current Subnet Mask
|
|
|
|
|
("nDefultGateWay", ctypes.c_uint), # Current Gateway
|
|
|
|
|
("chManufacturerName", ctypes.c_char * 32), # Manufacturer Name
|
|
|
|
|
("chModelName", ctypes.c_char * 32), # Model Name
|
|
|
|
|
("chDeviceVersion", ctypes.c_char * 32), # Device Version
|
|
|
|
|
("chManufacturerSpecificInfo", ctypes.c_char * 48), # Manufacturer Specific Info
|
|
|
|
|
("chSerialNumber", ctypes.c_char * 16), # Serial Number
|
|
|
|
|
("chUserDefinedName", ctypes.c_char * 16), # User Defined Name
|
|
|
|
|
("nNetExport", ctypes.c_uint), # IP address of connected network port
|
|
|
|
|
("nReserved", ctypes.c_uint * 8), # Reserved
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MV_VS_DEVICE_INFO_LIST(ctypes.Structure):
|
|
|
|
|
_fields_ = [
|
|
|
|
|
("nDeviceNum", ctypes.c_uint), # Online Device Number
|
|
|
|
|
("pDeviceInfo", ctypes.POINTER(MV_VS_DEVICE_INFO) * MV_MAX_DEVICE_NUM), # Device info array
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Define function signatures
|
2025-01-17 15:23:24 +00:00
|
|
|
mv_lib.MV_VS_EnumDevices.argtypes = [POINTER(MV_VS_DEVICE_INFO_LIST)]
|
|
|
|
|
mv_lib.MV_VS_EnumDevices.restype = c_int
|
|
|
|
|
|
|
|
|
|
mv_lib.MV_VS_CreateHandle.argtypes = [POINTER(c_void_p), c_void_p] # Assuming pHandle is a void* and pstDeviceInfo is a struct
|
|
|
|
|
mv_lib.MV_VS_CreateHandle.restype = c_int
|
|
|
|
|
|
|
|
|
|
mv_lib.MV_VS_Login.argtypes = [c_void_p, c_char_p, c_char_p]
|
|
|
|
|
mv_lib.MV_VS_Login.restype = c_int
|
|
|
|
|
|
2025-01-16 18:01:07 +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
|
|
|
|
|
|
2025-01-16 18:01:07 +00:00
|
|
|
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
|
|
|
|
|
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 = 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
|
|
|
|
|
nRet1 = mv_lib.MV_VS_Login(pHandle1, 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:#x} {nRet2:#x}]")
|
|
|
|
|
return
|
|
|
|
|
else:
|
|
|
|
|
print("Login OK")
|
|
|
|
|
|
2025-01-16 18:01:07 +00:00
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|