CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum
Deutsche Version English version russian version 
It is currently Fri May 26, 2017 9:53 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Fri Feb 10, 2017 9:12 am 
Offline

Joined: Thu Feb 09, 2017 4:15 pm
Posts: 5
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


Top
   
PostPosted: Mon Feb 13, 2017 11:47 am 
Offline

Joined: Thu Feb 09, 2017 4:15 pm
Posts: 5
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


Top
   
PostPosted: Tue Feb 14, 2017 11:02 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 192
Hi Daniele.

danielesdei wrote:
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:
Code:
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 wrote:
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 wrote:
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(...) and unplug(...) to add and remove the module.

BR
Martin


You do not have the required permissions to view the files attached to this post.

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Tue Feb 14, 2017 11:36 am 
Offline

Joined: Thu Feb 09, 2017 4:15 pm
Posts: 5
M.Keller wrote:
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 wrote:
Here some example code for adding a device:
Code:
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 wrote:
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 wrote:
The IScriptModule* interfaces have nothing to do with devices. They are from the CODESYS Application Composer.

Ok, thank you.

M.Keller wrote:
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(...) and unplug(...) to add and remove the module.

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

Sincerely,
Daniele


Top
   
PostPosted: Tue Feb 14, 2017 1:10 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 192
Hi Daniele.

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

danielesdei wrote:
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

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Tue Feb 14, 2017 2:39 pm 
Offline

Joined: Thu Feb 09, 2017 4:15 pm
Posts: 5
M.Keller wrote:
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 DeviceID to the add() 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


Top
   
PostPosted: Thu Feb 16, 2017 10:08 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 192
Hi Daniele.

danielesdei wrote:
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 wrote:
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 DeviceID to the add() 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

_________________
Check out the CODESYS store: http://store.codesys.com/

CODESYS® a trademark of 3S-Smart Software Solutions GmbH
Inspiring Automation Solutions


Top
   
PostPosted: Thu Feb 16, 2017 10:41 am 
Offline

Joined: Thu Feb 09, 2017 4:15 pm
Posts: 5
M.Keller wrote:
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 wrote:
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


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

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