转换设备

概述

转换项目内的设备可能十分复杂。此 API 简化了转换过程,并有助于避免错误。

使用 DeviceID 对象

转换 API 使用 DeviceID 对象,此对象通过特定版本来标识设备或设备模块。DeviceID 是按如下方式创建的:

<设备类型> <设备型号> <设备版本> <模块名称>

元素

示例

描述

设备类型

4096

标识控制器

设备型号

1003 00821003 009D

分别用于 LMCx00CLMCx01C

设备版本

1.50.0.4

控制器的固件版本

模块名称

LXM52

目标设备模块

转换 API 将 DeviceID 作为对象实例或作为单个参数接受。这样就可以使用包含上表中提及的所有元素的 DeviceID 或将每个元素作为单个参数传递。

下面的示例说明了如何通过固件版本 1.50.0.4 来创建 LMCx00C 控制器的 DeviceID

Lmcx00c = DeviceID(4096, "1003 0082", "1.50.0.4")

测试是否可以转换设备

通过下面的脚本,可以验证是否可在转换设备前转换到给定版本。

from __future__ import print_function
 
def main():
    # Set the project as primary project
    proj = projects.primary
    controller = proj.find('LMC_PacDrive', True)[0]
    drives = controller.find('DRV_Lexium62', True)
 
    if len(drives) == 0:
        print("Expected drive object not found")
        return
 
    drive = drives[0]
 
    # test if controller can be converted using DeviceID
    x01c = DeviceID(4096, "1003 009D", "1.53.5.4")
    if controller.can_convert(x01c):
        print("Conversion to LMCx01C possible")
 
    # test if drive can be converted using Parameters and module id
    if drive.can_convert(4096, "1003 0082", "1.53.5.4", "LXM52"):
        print("Conversion to LXM52 possible")
 
 
if not projects.primary:
    print("No project open.")
else:
    main()

获取选择转换目标

API 提供了一个调用,此调用将检索特定设备的可能转换目标。它将返回每个目标的 DeviceID

from __future__ import print_function
 
#help function to print the delivered device ids
def deviceid_to_string(devId):
    mystr = "ID: {0.id} Type: {0.type} Version: {0.version}".format(devId)
 
    if hasattr(devId, 'module_id') and devId.module_id is not None:
        mystr += " ModuleID: {0.module_id}".format(devId)
        return mystr
 
 
def main():
    
    # Set the project as primary project
    proj = projects.primary
 
    controller = proj.find('LMC_PacDrive', True)[0]
    alternativeControllers = controller.get_alternative_devices()
 
    print("ALTERNATIVE DEVICES FOR LMC")
    for id in alternativeControllers:
        print(deviceid_to_string(id))
 
    drive = proj.find('DRV_Lexium62', True)[0]
    alternativeDrives = drive.get_alternative_devices()
 
    print("ALTERNATIVE DEVICES FOR DRIVE")
    for id in alternativeDrives:
        print(deviceid_to_string(id))
 
    print("Test complete. Please check the script output window")
 
 
 
if not projects.primary:
    print("No project open.")
else:
    main()

转换设备

转换设备的过程是向前的,因为唯一需要的操作是调用转换方法。

from __future__ import print_function
 
def main():
    proj = projects.primary
    controller = proj.find('LMC_PacDrive', True)[0]
    drive = proj.find('DRV_Lexium62', True)[0]
 
    # converting the controller
    controller.convert(4096, "1003 009D", "1.53.5.4")
    # converting the drive
    drive.convert(DeviceID(4096, "1003 0082", "1.53.5.4"), "LXM52")
 
 
if not projects.primary:
    print("No project open.")
else:
    main()