CODESYS - the IEC 61131-3 automation software

Welcome to the official CODESYS Forum by 3S-Smart Software Solutions GmbH | A member of the CODESYS Group
Deutsche Version English version russian version 
It is currently Thu Jul 18, 2019 4:21 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 26 posts ]  Go to page 1 2 Next
Author Message
PostPosted: Thu Jan 15, 2015 7:01 pm 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
Hello,

I would like from a Python script.
I want to add the plug-device of the EH-IOCA (Hitachi).
there is someone who knows how to add plug-device via the Python script.

Rahied


Top
   
PostPosted: Mon Jan 19, 2015 9:19 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 244
Hello Rahied.

The following steps are required:
    - Get the slot object, e.g. projectObject.find(...)
    - Plug the device into slot with slotObject.plug(...)

For details about the parameters see the documentation of the ScriptEngine, which you can find in the sub directory "OnlineHelp" of the CODESYS directory.

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: Mon Jan 19, 2015 11:45 am 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
Thanks for your adversely word .

Only I 'm not from there at all . I send my script there. Maybe there is someone who got a example . Or can tell me what to do .

thanks You


:roll: :roll: :roll: :roll: :roll:


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


Top
   
PostPosted: Mon Jan 19, 2015 12:04 pm 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
M.Keller wrote:
Hello Rahied.

The following steps are required:
    - Get the slot object, e.g. projectObject.find(...)
    - Plug the device into slot with slotObject.plug(...)

For details about the parameters see the documentation of the ScriptEngine, which you can find in the sub directory "OnlineHelp" of the CODESYS directory.

BR
Martin


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


Top
   
PostPosted: Mon Jan 19, 2015 1:32 pm 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
Rahied wrote:
Thanks for your adversely word .

Only I 'm not from there at all . I send my script there. Maybe there is someone who got a example . Or can tell me what to do .

thanks You


:roll: :roll: :roll: :roll: :roll:


Hello Rahied.

The following steps are required:
- Get the slot object, e.g. projectObject.find(...)
- Plug the device into slot with slotObject.plug(...)

For details about the parameters see the documentation of the ScriptEngine, which you can find in the sub directory "OnlineHelp" of the CODESYS directory.

BR
Martin


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


Top
   
PostPosted: Mon Jan 19, 2015 1:58 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 244
Hi Rahied.

Please check the ID and the version of the device you want to plug! "51D_00000001_16 Digital Input_16 Digital Input" and "0" could be wrong.

Also check the indentation of the "plug" line in your script because it was wrong when I opened it on my computer.

I added a simple script as an example for you. It plugs all slots with the name "<Empty>". The specified device required a module ID.

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: Mon Jan 19, 2015 3:13 pm 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
M.Keller wrote:
Hi Rahied.

Please check the ID and the version of the device you want to plug! "51D_00000001_16 Digital Input_16 Digital Input" and "0" could be wrong.

Also check the indentation of the "plug" line in your script because it was wrong when I opened it on my computer.

I added a simple script as an example for you. It plugs all slots with the name "<Empty>". The specified device required a module ID.

BR
Martin


Tanks M.Keller,

But the next error shows.


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


Top
   
PostPosted: Mon Jan 19, 2015 3:15 pm 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
M.Keller wrote:
Hi Rahied.

Please check the ID and the version of the device you want to plug! "51D_00000001_16 Digital Input_16 Digital Input" and "0" could be wrong.

Also check the indentation of the "plug" line in your script because it was wrong when I opened it on my computer.

I added a simple script as an example for you. It plugs all slots with the name "<Empty>". The specified device required a module ID.

BR
Martin



I have a printscreen form the hitachi id code


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


Top
   
PostPosted: Mon Jan 19, 2015 3:52 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 244
Hi Rahied.

The ID and version are correct.

Since I'm not sure what you want to do, I modified your last script for two different scenarios:
    - Plug all slots with the same device
    - Plug only the first one

Please remove the code of the unused scenario.

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 Jan 20, 2015 8:55 am 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
M.Keller wrote:
Hi Rahied.

The ID and version are correct.

Since I'm not sure what you want to do, I modified your last script for two different scenarios:
    - Plug all slots with the same device
    - Plug only the first one

Please remove the code of the unused scenario.

BR
Martin


Thanks for your help.
But it's not working.
The next error is when a run the script.

I hoop then you can help me :P :P :P :P :P


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


Top
   
PostPosted: Tue Jan 20, 2015 9:11 am 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 244
Hello

Sorry, I forgot that find() returns a list. Please replace the code with the following:
Code:
objects = master.find('EH_IOCA', True) # Recursive search
assert(objects and len(objects) == 1, "no object or more than one object with the name EH_IOCA")
subnodes = objects[0].get_children() # Get all children


Is there more than one slave below the master? if yes than you have to find a way to find the correct slave.

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 Jan 20, 2015 10:51 am 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
M.Keller wrote:
Hello

Sorry, I forgot that find() returns a list. Please replace the code with the following:
Code:
objects = master.find('EH_IOCA', True) # Recursive search
assert(objects and len(objects) == 1, "no object or more than one object with the name EH_IOCA")
subnodes = objects[0].get_children() # Get all children


Is there more than one slave below the master? if yes than you have to find a way to find the correct slave.

BR
Martin


Hello a have put my script en Error code for u.
It's stil not working :twisted: :twisted: :twisted: :twisted:


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


Top
   
PostPosted: Tue Jan 20, 2015 11:36 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
It seems you did mix tabs and spaces in the attached script. The error message actually tells you the location of the problem in the source file.

Python generally interprets tabs according common standards with 8 characters, while your editor seems to use 4 characters of tab with.

Generally, the python community strongly suggests to not mix tabs and spaces in source files:
PEP 8 -- Style Guide for Python Code

You should use an editor which can display tabs and spaces, so you can see the problem. Here is how it looks in my editor using 4 characters tab with:
Attachment:
tabs_vs_spaces.png


And here's how the Python interpreter "sees" it using 8 characters tab with:
Attachment:
tabs_vs_spaces-2.png


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 Jan 20, 2015 12:20 pm 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
M.Schaber wrote:
It seems you did mix tabs and spaces in the attached script. The error message actually tells you the location of the problem in the source file.

Python generally interprets tabs according common standards with 8 characters, while your editor seems to use 4 characters of tab with.

Generally, the python community strongly suggests to not mix tabs and spaces in source files:
PEP 8 -- Style Guide for Python Code

You should use an editor which can display tabs and spaces, so you can see the problem. Here is how it looks in my editor using 4 characters tab with:
Attachment:
tabs_vs_spaces.png


And here's how the Python interpreter "sees" it using 8 characters tab with:
Attachment:
tabs_vs_spaces-2.png


Top
   
PostPosted: Tue Jan 20, 2015 12:21 pm 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
M.Schaber wrote:
It seems you did mix tabs and spaces in the attached script. The error message actually tells you the location of the problem in the source file.

Python generally interprets tabs according common standards with 8 characters, while your editor seems to use 4 characters of tab with.

Generally, the python community strongly suggests to not mix tabs and spaces in source files:
PEP 8 -- Style Guide for Python Code

You should use an editor which can display tabs and spaces, so you can see the problem. Here is how it looks in my editor using 4 characters tab with:
Attachment:
tabs_vs_spaces.png


And here's how the Python interpreter "sees" it using 8 characters tab with:
Attachment:
tabs_vs_spaces-2.png


Hello here is my script.

print "Current project."
proj = projects.primary

PROJECT = r"C:\CoDeSys-Projects\Script-Test.project"

# clean up any open project:
if projects.primary:
projects.primary.close()
print("--- CleanUp finished. ---")

# create a new project
proj = projects.create(PROJECT)
print("--- Project created. ---")

# add PLC
proj.add("CODESYS Control RTE V3",4096,"0000 0002","3.5.5.40")
print("--- PLC Device Insert. ---")

# Create the IO

for dev in proj.get_children():
if dev.is_device:
f = open("C:\Users\RO\Desktop\Import.txt", "r")
for line in f:
tok = line.split(' ')
if "(Master)" in tok[1]:
dev.add(tok[0], DeviceID(64, "0000 0001", "3.5.5.0"))
subnodes = dev.get_children()
master = subnodes[len(subnodes) - 1]
elif "(Slave)" in tok[1]:
master.add(tok[0], DeviceID(65, "51D_0201001000000001", "3.5.4.0"))
elif "(IO)" in tok[1]:
objects = master.find('EH_IOCA', True) # Recursive search
assert(objects and len(objects) == 1, "no object or more than one object with the name EH_IOCA") # Stil have the Error
subnodes = objects[0].get_children(True) # Get all children

# Scenario 1: Plug all
# i = 1
# for node in subnodes:
# name = "%s %d" % (tok[0], i) # Create name with index
# node.plug(name, 68, "51D_00000001_16 Digital Input_16 Digital Input","0")
# i += 1

# Scenario 2: Plug only the first one
if len(subnodes) > 0:
subnodes[0].plug(tok[0], 68, "51D_00000001_16 Digital Input_16 Digital Input","0")


# Save project
proj.save()

# Script finished
print("--- Script finished. ---")


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 26 posts ]  Go to page 1 2 Next

All times are UTC+01:00


Who is online

Users browsing this forum: No registered users and 2 guests


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