跳到主要内容

版本信息

提供原生库版本与 SDK 版本查询。可用于运行时兼容性校验和故障排查日志。

版本查询函数

get_dll_version()

def get_dll_version(dll) -> Optional[dict]

获取原生库版本信息。

返回值:

  • Optional[dict] — 版本信息字典 {'major', 'minor', 'build', 'version'},失败返回 None

get_api_version()

def get_api_version() -> str

获取 Python SDK API 版本字符串 (从包内 VERSION 文件读取)。当前版本为 2.5.x

get_build_number()

def get_build_number(dll) -> int

获取构建号,失败返回 -1

get_build_date()

def get_build_date(dll) -> str

获取构建日期,失败返回空字符串。

get_serial_number()

def get_serial_number(dll) -> str

获取设备序列号,失败返回空字符串。

主站属性

dll_version

@property
def dll_version(self) -> Optional[dict]

通过主站实例直接获取版本信息。

返回值:

  • Optional[dict]{'major', 'minor', 'patch', 'build', 'build_date'}

示例:

info = master.dll_version
if info:
print(f"版本: {info['major']}.{info['minor']}.{info['patch']}.{info['build']}")

完整示例

from darra_ethercat import EtherCATMaster, get_api_version

with EtherCATMaster() as master:
info = master.dll_version
print(f"SDK 版本: {get_api_version()}")
if info:
print(f"原生库版本: {info['major']}.{info['minor']}.{info['patch']}.{info['build']}")