Cancel
Showing results for 
Search instead for 
Did you mean: 

Creating a new TxComponent with logic behavior

I'm trying to create a component with logic behavior, by first creating a local component c, then calling the CreateLogicBehaviour.

 

            TxLocalComponentCreationData lccd = new TxLocalComponentCreationData("TestComponent");
            TxComponent c = TxApplication.ActiveDocument.PhysicalRoot.CreateLocalComponent(lccd);
            TxPlcLogicBehaviorCreationData lbcd = new TxPlcLogicBehaviorCreationData("TestLogicBehaviour");
            c.CreateLogicBehavior(lbcd);

The last line fails with the exception TxCanNotCreateLogicBehaviorException which doesn't give many clues.

Has anyone any pointers on this?

 

-----------------------------------------------------------------------------------------------------------------------------------------------------

 

I've tried an alternative (and less optimal) approach of creating an empty logic block manually, saving it in the library, inserting it into another study, adding the required logic, then saving it (i.e. ending modelling scope) in a different location. This appears to work, but when I create two logic blocks in this way from the same library component and add a slightly different element to each one (e.g. "Entry1" to one and "Entry2" to the second), the second logic block contains both elements - furthermore on saving the study and re-opening, the storage path of the first logic block has changed to the same as the second, so the elements are the same for the 2 logic blocks, i.e. they are not independent.

 

In the code below, EmptyLB is the path string pointing to the manually-created empty logic block, and Dir is the directory (string) within the library for where the new versions are to be stored. I've tried setting and ending modelling scope in many different places to try to save with at a particukar time in a particular location.

 

            TxInsertComponentCreationData iccd1 = new TxInsertComponentCreationData("Comp1", EmptyLB);
            TxComponent c1 = (TxComponent)TxApplication.ActiveDocument.PhysicalRoot.InsertComponent(iccd1);
            c1.EndModeling(Dir + "LB1.cojt");
            c1.SetModelingScope();
            TxPlcLogicBehaviorEntryCreationData entryCreationData = new TxPlcLogicBehaviorEntryCreationData("Entry1");
            ITxPlcLogicBehaviorEntry entry = c1.LogicBehavior.CreateEntry(entryCreationData);
            c1.EndModeling(Dir + "LB1.cojt");

            TxInsertComponentCreationData iccd2 = new TxInsertComponentCreationData("Comp2", EmptyLB);
            TxComponent c2 = (TxComponent)TxApplication.ActiveDocument.PhysicalRoot.InsertComponent(iccd2);
            c2.EndModeling(Dir + "LB2.cojt");
            c2.SetModelingScope();
            TxPlcLogicBehaviorEntryCreationData entryCreationData2 = new TxPlcLogicBehaviorEntryCreationData("Entry2");
            ITxPlcLogicBehaviorEntry entry2 = c2.LogicBehavior.CreateEntry(entryCreationData2);
            c2.EndModeling(Dir + "LB2.cojt");

 

If anyone can suggest the "correct" way to create a new component with logic behaviour, that would be very useful.

8 REPLIES

Re: Creating a new TxComponent with logic behavior

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi Cypherspaceman,

 

Try to create the logic behavior after you insert the component.

 

TxPlcLogicBehaviorCreationData crData = new TxPlcLogicBehaviorCreationData("myLB");
TxPlcLogicBehavior myLB = c1.CreateLogicBehavior(crData);    
myLB.CreateEntry(new TxPlcLogicBehaviorEntryCreationData("Entry1"));        

 

Best Regards,

DianaG

 

Re: Creating a new TxComponent with logic behavior

Hi Diana,

 

Thanks for your code snippet - it works on a component that has been created manually, but my question was really about how to create a component automatically whose CreateLogicBehavior method does not fail (your example assumes the component already exists).

 

I've tried creating a component locally, and adding logic behavior to it either before or after saving it to the library (EndModelling), but the creation process fails.

I've tried opening an existing component from the library (created manually using Create Logic Block then saved to the library), but even after saving it as a new library component (again using EndModelling) the original component in the library is modified when I modify the new instance. For example - if I create a logic block manually, immediately end modelling and save it as "EmptyLogicBlock.cojt", then insert a new component from this using TxInsertComponentCreationData(...., "...EmptyLogicBlock.cojt"), then when I add an Entry to my new component, the same Entry is added to the library component called "EmptyLogicBlock.cojt".

 

What I'm after is how to create a suitable new component, or if this is not possible, how to create a copy of a library item so I can create instances of the modified item without changing instances of the original item. 

 

Ultimately I'd like to create a number of logic blocks automatically, and store them in the library.

 

Best Regards,

 

Andrew

Re: Creating a new TxComponent with logic behavior

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi,

 

Starting from V14.1 it will be possible to create new component (part or resource) with the .NET API (there will be new methods) for Process Simulate on eMServer and Process Simulate Standalone on top of eMServer.

Currently this is supported only for Process Simulate Standalone on top of eMServer and it requires several steps - see this link.

 

Best Regards,

DianaG

Re: Creating a new TxComponent with logic behavior

Hi Diana,

 

Fortunately I am using PS Standalone on eMServer, and the link gives a useful method of creating TxComponents.

 

However, I'm still getting TxCanNotCreateLogicBehaviorException when I try to create the Logic Behavior.

 

I tried changing the CreatePrototypeData from "PmToolPrototype" to "Container", to match the TuneData.XML for manually-created logic blocks, but there was no difference.

 

If there is anything else obvious that would help, I'd be interested, but otherwise I'll wait for 14.1.

 

Best Regards,

 

Andrew

Re: Creating a new TxComponent with logic behavior

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi  Cypherspaceman,

 

Can you send me your code (you can send it in a private message) with the TuneData.xml and creation of the logic block.

I will debug and check what is the issue.

 

Best Regards,

DianaG

Re: Creating a new TxComponent with logic behavior

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi Cypherspaceman,

 

The API is restricted so that logic behavior can be added only to devices, robots and conveyors. You can add kinematics to your component to make it a device and then add logic behavior.

            TxComponent comp1 = CreateComponent("TestComponent");
            comp1.SetModelingScope();

            //Create dummy kinematics
            TxKinematicLinkCreationData linkData1 = new TxKinematicLinkCreationData("link1");
            TxKinematicLink link1 = (comp1 as ITxKinematicsModellable).CreateLink(linkData1);

            TxKinematicLinkCreationData linkData2 = new TxKinematicLinkCreationData("link2");
            TxKinematicLink link2 = comp1.CreateLink(linkData2);

            TxJointCreationData jointData = new TxJointCreationData("j1", TxJoint.TxJointType.Prismatic, link1, link2);
            TxJoint j1 = comp1.CreateJoint(jointData);

            ITxDevice device = j1.Device;
            if(device != null)
            {
                TxPlcLogicBehaviorCreationData plbCreationData = new TxPlcLogicBehaviorCreationData("Sequence");
                TxPlcLogicBehavior plb = (device as ITxPlcLogicBehaviorCreation).CreateLogicBehavior(plbCreationData);
            }

 The object must be open for modeling to be able to create or edit its logic behavior.

 

Best Regards,

DianaG

Re: Creating a new TxComponent with logic behavior

Experimenter
Experimenter

Hi Diana

 

Please could you explain why this is, I dont fully understand why a device,robot and conveyor would only be allowed to be created as a logic block? Should this not also be allowed for a Txcomponent

 

 

Regards

Re: Creating a new TxComponent with logic behavior

Siemens Genius Siemens Genius
Siemens Genius

Hi,

 

Smart component is allowed only on a resource, since it provides also kinematics abilities (open to modeling + preselection+ see Add LB to Resource command )

Logic Block is created without any component, it is just for logic calculations (no preselection + see Create Logic Resource command)

 

Regards,

MosheH