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

81 lines
3.1 KiB
Python
Raw Normal View History

import ctypes
import os
# Load the MvVisionSensorControl library
mv_lib = ctypes.windll.LoadLibrary("bin/MvVisionSensorControl.dll")
MV_MAX_DEVICE_NUM=256
# 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
]
MV_MAX_DEVICE_NUM = 256 # Maximum number of supported devices
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 MV_VS_OK from MvVSErrorDefine.h (assuming it's 0)
MV_VS_OK = 0
# Define function signatures
mv_lib.MV_VS_EnumDevices.argtypes = [ctypes.POINTER(MV_VS_DEVICE_INFO_LIST)]
mv_lib.MV_VS_EnumDevices.restype = ctypes.c_int
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():
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
return 0
if __name__ == "__main__":
main()