Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Adding Devices with Py Scripts

esskaey
2016-07-14
2017-05-22
  • esskaey - 2016-07-14

    Hello,

    I am attempting to add devices(sercos master, drives, profinet I/O etc.) to my application object. I read in one of the posts about an API implementation for device repository to be available from v3.5 sp9. Can you please provide a code snippet with its usage??.

    The goal is to add devices to my application object( starting with an empty project) using scripts. Thanks in advance.

    (Edit): Where can I find the parameters DeviceType, DeviceID, Supported Firmware Version and ModuleID pertaining to the device?

    Best Regards,

    SK

     
  • mkeller - 2016-07-14

    Hi SK.

    codesys_sig_forum hat geschrieben:
    I am attempting to add devices(sercos master, drives, profinet I/O etc.) to my application object. I read in one of the posts about an API implementation for device repository to be available from v3.5 sp9. Can you please provide a code snippet with its usage??.

    At the moment we only support our own device description format but we plan to support the other formats through the converters.

    sysRepoSource = device_repository.sources['System Repository']
    devId = device_repository.import_device('<path_to_device_desc>', sysRepoSource)
    device_repository.remove_device(devId, sysRepoSource
    

    codesys_sig_forum hat geschrieben:
    The goal is to add devices to my application object( starting with an empty project) using scripts. Thanks in advance.

    \# Check if the necessary device description is installed
    devId = device_repository.create_device_identification(4096, '0000 0001', '3.5.9.0')
    devDesc = device_repository.get_device(devId)
    if devDesc is None:
    Β  Β raise Exception('No WinV3 PLC available in device repo')
    proj = projects.primary
    \# Add PLC to an empty project using a DeviceId instance
    proj.add('Device', devId)
    found = proj.find('Device', False)
    assert(found is not None and len(found) == 1, 'No object with the name Device found')
    assert(found[0].is_device, 'Found object is not a device')
    device = found[0]
    \# Add Ethernet device using the type, ID and version instead of a DeviceID
    device.add('Ethernet', 110, '0000 0002', '3.5.9.0')
    ethernet = device.find('Ethernet', False)[0]
    

    codesys_sig_forum hat geschrieben:
    (Edit): Where can I find the parameters DeviceType, DeviceID, Supported Firmware Version and ModuleID pertaining to the device?

    You can find the required parameters on the tab "Information" of the corresponding device editor.

    BR
    Martin

     
  • chenhe - 2017-05-22

    M.Keller hat geschrieben:
    At the moment we only support our own device description format but we plan to support the other formats through the converters.

    Hi M.Keller,

    May I know what those supported device description formats are?
    I have tried to run the line below, it reported error saying "Data at the root level is invalid. Line 1, position 1" I assume it is because eds is the invalid format?

    devId = device_repository.import_device("C:\\Users\\hch\\svn\\codesys_awc500_testapp\\Testapp_original\\devices\\DEIF_LoopBack_Device_v4.eds", sysRepoSource)
    
     
  • mkeller - 2017-05-22

    Hi chenhe.

    chenhe hat geschrieben:
    May I know what those supported device description formats are?
    I have tried to run the line below, it reported error saying "Data at the root level is invalid. Line 1, position 1" I assume it is because eds is the invalid format?

    With CODESYS V3.5 SP10 or newer we also support the import of foreign device descriptions. You can import the same formats as through the UI.

    You have to use the following method to import a foreign device description:

    allConvert = Guid('{C633F245-876F-45E8-AAB4-3FBD994C08B8}')
    sources = device_repository.sources
    repoSource = sources["TestRepo"]
    devId = device_repository.import_device(basepath + r'\some-device.eds', repoSource, allConvert)
    

    BR
    Martin

     

Log in to post a comment.