CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Sat Aug 18, 2018 4:17 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Sep 15, 2017 2:34 pm 
Offline

Joined: Tue Sep 12, 2017 11:46 am
Posts: 1
Hi,

I'm quite new to CODESYS and I have recently started working with the script plugin for some operations in the application composer. In my project right now I'm trying to add some references to existing module instances (with help of python script) to some slots on some other instance modules that are created in AC with associated reference slots.

The method I try to use is from the Script Engine Plugin API, IScriptModuleRepository.add_reference_instance(IScriptObject scriptObj, IScriptModuleSlotInstance scriptSlot,System.Int32 index).
I have a correct module instance (scriptOjb) which the reference should point to. I have also localized the correct slot (IScriptModuleSlotInstance) where the reference instance should be created. The last argument, the index which is "defining the position of the created reference instance under the slot." is what confuses me. I have a module instance that consists of two separate single reference slots and even though I try to add a reference to each one of them the index argument mess it up. Instead of determine the index under the slot it seems like it is determine the index of slots under a module instance. I have tried to give an example in form of a short code snippet (Not directly runnable since modules must be created).

A simplification of the code:
Code:
def findRefModule(slot):
   #returns the RefModuleInstance

slotList= [slot1, slot2] #these are the two separete single slots on the same module instance
slotIndex = 0 #For my knowledge it should be index 0 for both of the slots since they are alone under each slot.
for slot in slotList:
   modulerepository.add_reference_instance(findRefModule(slot), slot, slotIndex)

The thing is that if I run this type of code, the first RefModuleInstance is created as reference correctly in the first slot. But for the second slot, if the index is still 0, the second RefModuleInstance is located above the first slot by a creation of a new slot.
It is also possible to change the slotIndex to 1, by which the first RefModuleInstance is created as a reference in the second slot, just like an index for slots under a module.
If a reference to a RefModuleInstance is created in the first slot (slotIndex 0) then in order to add a reference to the second slot the index must now be changed to 2 and not 1. This makes it really difficult to write code that is working for arbitrary number of slots since the index is changing depending on already occupied slots or not.

Sorry for the long post but to summarize my question: Is it meant to be that way that the index is not for indexing the reference instance under the slot but rather the slot under a module? Or have I missed something obvious?

Thanks for any input,
Daniel


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 1 post ] 

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited