How to know the admissible devices in the master/slave hierarchy

2017-02-10
2017-02-16
  • danielesdei - 2017-02-10

    Hello everyone,

    I've just subscribed in the forum to get help in a script that I'm writing, I have two questions for you, I hope you could help me.

    1. I want to add/insert a device in the project but the method needs the DeviceID as parameter, what I know it's just the Order Number. I've seen something helpful in the file devicecache.xml but, is there an embedded method to get the association between Order Number and DeviceID?

    2. I want to add/insert a bus slave, how can I know the right bus master that I have to add to the controller? Or alternatively, can I have a list of slaves that I can add to a master in the project? In other words, is there something that help me to know the admissible devices in the master/slave hierarchy?

    Thank you very much!

    Best Regards,
    Daniele

     
  • danielesdei - 2017-02-13

    About the second question, I've found in the help the IScriptModuleRepository Interface that seems helpful but I didn't understand who implements it. Can somebody explain me how to use that interface and its methods with a simple example?

    Thanks in advance.

    Best Regards,
    Daniele

     
  • mkeller - 2017-02-14

    Hi Daniele.

    danielesdei hat geschrieben:
    1. I want to add/insert a device in the project but the method needs the DeviceID as parameter, what I know it's just the Order Number. I've seen something helpful in the file devicecache.xml but, is there an embedded method to get the association between Order Number and DeviceID?

    Open the device repository (Menu Tools->Device Repository), select a device and click on the Details button. In the dialog you can find the necessary information to add/update a device. See the marked parts in the attached screenshot.

    Here some example code for adding a device:

    proj = projects.primary
    \# Add PLC to an empty project using a DeviceId instance
    devId = device_repository.create_device_identification(4096, '0000 0001', '3.5.9.0')
    proj.add('Device', devId)
    found = proj.find('Device', False)
    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]
    ethernet.add('ModBus_Master', 88, '0000 0003', '3.5.9.0')
    master = ethernet.find('ModBus_Master', False)[0]
    master.add('ModBus_Slave', 89, '0000 0005', '3.5.7.0')
    slave = master.find('ModBus_Slave', False)[0]
    

    danielesdei hat geschrieben:
    2. I want to add/insert a bus slave, how can I know the right bus master that I have to add to the controller? Or alternatively, can I have a list of slaves that I can add to a master in the project? In other words, is there something that help me to know the admissible devices in the master/slave hierarchy?

    Open the context menu of the parent device and click on "Add device". The dialog lists only the devices which can be added below the selected device. If you select an other device the list is updated.

    danielesdei hat geschrieben:
    About the second question, I've found in the help the IScriptModuleRepository Interface that seems helpful but I didn't understand who implements it. Can somebody explain me how to use that interface and its methods with a simple example?

    The IScriptModule* interfaces have nothing to do with devices. They are from the CODESYS Application Composer. Modules are part of a device and some devices have "slots" where their modules can be plugged in. The slot objects have a method and to add and remove the module.

    BR
    Martin

    IMG: CDS_DevDesc_Details.PNG

     
  • danielesdei - 2017-02-14

    M.Keller hat geschrieben:
    Open the device repository (Menu Tools->Device Repository), select a device and click on the Details button. In the dialog you can find the necessary information to add/update a device. See the marked parts in the attached screenshot.

    This is the UI solution, I would like a scripting solution if exists.

    M.Keller hat geschrieben:
    Here some example code for adding a device:

    proj = projects.primary
    \# Add PLC to an empty project using a DeviceId instance
    devId = device_repository.create_device_identification(4096, '0000 0001', '3.5.9.0')
    proj.add('Device', devId)
    found = proj.find('Device', False)
    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]
    ethernet.add('ModBus_Master', 88, '0000 0003', '3.5.9.0')
    master = ethernet.find('ModBus_Master', False)[0]
    master.add('ModBus_Slave', 89, '0000 0005', '3.5.7.0')
    slave = master.find('ModBus_Slave', False)[0]
    

    You are still using DeviceID and it doesn't help me very much.

    M.Keller hat geschrieben:
    Open the context menu of the parent device and click on "Add device". The dialog lists only the devices which can be added below the selected device. If you select an other device the list is updated.

    Yes, I know, this UI behavior is exactly what I would like to reproduce by scripting.

    M.Keller hat geschrieben:
    The IScriptModule* interfaces have nothing to do with devices. They are from the CODESYS Application Composer.

    Ok, thank you.

    M.Keller hat geschrieben:
    Modules are part of a device and some devices have "slots" where their modules can be plugged in. The slot objects have a method and to add and remove the module.

    Once again, how to know the modules which can be added to a specific device?

    Sincerely,
    Daniele

     
  • mkeller - 2017-02-14

    Hi Daniele.

    What do you want to accomplish? What is your Use Case?

    danielesdei hat geschrieben:
    You are still using DeviceID and it doesn't help me very much.

    You can access the device repository through Scripting and search for a device. If you only have the order number, you can iterate through all devices and check for it.

    BR
    Martin

     
  • danielesdei - 2017-02-14

    M.Keller hat geschrieben:
    What do you want to accomplish? What is your Use Case?

    Hi Martin,
    I have an order number of a device that I want to add to the controller in the project. First of all I need to pass the to the function but I don't know it. The second problem I have encountered regards the hierarchy between devices, for example if my device is a bus slave I need to add the compatible master first.

    About the Device Repository, I can't use it because I'm working on SoMachine v4.31, the Schneider Electric software, actually based on Codesys v3.5.5 . Do you think it can help me? In few months a new version of SoMachine will release and maybe it will implement the device repository.

    Best Regards,
    Daniele

     
  • mkeller - 2017-02-16

    Hi Daniele.

    danielesdei hat geschrieben:
    About the Device Repository, I can't use it because I'm working on SoMachine v4.31, the Schneider Electric software, actually based on Codesys v3.5.5 . Do you think it can help me? In few months a new version of SoMachine will release and maybe it will implement the device repository.

    With CODESYS SP9 we introduced a Scripting API for the device repository but it does not provide the information you need for your use case.

    danielesdei hat geschrieben:
    I have an order number of a device that I want to add to the controller in the project. First of all I need to pass the to the function but I don't know it. The second problem I have encountered regards the hierarchy between devices, for example if my device is a bus slave I need to add the compatible master first.

    You have to parse the device cache and build your own data structure which contains the device and its connectors and interfaces. In the list of devices you can search the order number if it was specified in the device description. Through the connectors and interfaces you can find one or more possible parent devices. You may have to add some code to decide which parent device is the most suitable or the only one you want to use.

    BR
    Martin

     
  • danielesdei - 2017-02-16

    M.Keller hat geschrieben:
    With CODESYS SP9 we introduced a Scripting API for the device repository but it does not provide the information you need for your use case.

    Mmmh... ok

    M.Keller hat geschrieben:
    You have to parse the device cache and build your own data structure which contains the device and its connectors and interfaces. In the list of devices you can search the order number if it was specified in the device description. Through the connectors and interfaces you can find one or more possible parent devices. You may have to add some code to decide which parent device is the most suitable or the only one you want to use.

    Thank you Martin, I'll go in that way.

    Daniele

     

Log in to post a comment.