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', '220.127.116.11')
found = proj.find('Device', False)
device = found
# Add Ethernet device using the type, ID and version instead of a DeviceID
device.add('Ethernet', 110, '0000 0002', '18.104.22.168')
ethernet = device.find('Ethernet', False)
ethernet.add('ModBus_Master', 88, '0000 0003', '22.214.171.124')
master = ethernet.find('ModBus_Master', False)
master.add('ModBus_Slave', 89, '0000 0005', '126.96.36.199')
slave = master.find('ModBus_Slave', False)
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.
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 plug(...)
to add and remove the module.
Check out the CODESYS store: http://store.codesys.com/CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions