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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
M.Keller hat geschrieben:
Hello Rahied.
The following steps are required:
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
Rahied hat geschrieben:
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
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.
M.Keller hat geschrieben:
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</empty>
Tanks M.Keller,
But the next error shows.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
M.Keller hat geschrieben:
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</empty>
I have a printscreen form the hitachi id code
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
M.Keller hat geschrieben:
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:
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry, I forgot that find() returns a list. Please replace the code with the following:
objects=master.find('EH_IOCA',True)#Recursivesearchassert(objectsandlen(objects)==1,"no object or more than one object with the name EH_IOCA")subnodes=objects[0].get_children()#Getallchildren
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
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
M.Keller hat geschrieben:
Hello
Sorry, I forgot that find() returns a list. Please replace the code with the following:
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
M.Schaber hat geschrieben:
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:
And here's how the Python interpreter "sees" it using 8 characters tab with:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
M.Schaber hat geschrieben:
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:
And here's how the Python interpreter "sees" it using 8 characters tab with:
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
# Scenario1: Plugall
# i=1
# fornodeinsubnodes:
# name="%s %d"%(tok[0], i) # Createnamewithindex
# node.plug(name, 68, "51D_00000001_16 Digital Input_16 Digital Input","0")
# i+=1
# Scenario2: Plugonlythefirstoneiflen(subnodes)>0:
subnodes[0].plug(tok[0], 68, "51D_00000001_16 Digital Input_16 Digital Input","0")
M.Schaber hat geschrieben:
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:
And here's how the Python interpreter "sees" it using 8 characters tab with:
M.Schaber hat geschrieben:
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:
And here's how the Python interpreter "sees" it using 8 characters tab with:
M.Keller hat geschrieben:
Hi.
The indentation of your script is still wrong. The indentation is important in python. Look at the screenshots.
I modified your script to have the correct indentation and attached it. Please use a proper editor from now on.
BR
Martin
Its stil not working
Thanks voor you time
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The Device is an EH_IOCA (with underscore).
The name of the plugged devices cannot have a space. You should use e.g. "%s_%d" as device name to make them unique.
Your import file (.txt) should have no empty lines at the end.
Attached an example import file and script for plugging the modules in the Hitachi EH-IOCA EtherCAT slave.
Maybe not perfect or complete, but for me this works.
By plugging the device via a script a generated name is given to its structures and accessable variables (e.g. "%QX7.7", similarly when one has only plugs the device) but in GUI, I have the chance to map those addresses to variables.
Is there a way to configure the plugged device configuration and I/O mapping ("xxx Configuration" and "xxx I/O Mapping" tabs)?
I have some ADC/DIO/DAC "pins" configured and would like to map their variables and structures to one of the PRGs stored variables.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2015-09-08
Originally created by: M.Schaber
Hi, etamgul,
A scripting interface for the I/O Mapping is currently scheduled for the upcoming V3.5 SP8 release by the end of the year. (See CDS-37756).
(Please note that the schedule may still change when other, more important issues arise.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
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
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
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
Create CodeSys Project.py [1.31 KiB]
Create CodeSys Project.py [1.31 KiB]
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
Create CodeSys Project.py [1.31 KiB]
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.</empty>
BR
Martin
plug_device.py [329 Bytes]
Tanks M.Keller,
But the next error shows.
I have a printscreen form the hitachi id code
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
Create CodeSys Project_modified.py [1.67 KiB]
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
Hello
Sorry, I forgot that find() returns a list. Please replace the code with the following:
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
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
Create CodeSys Project_modified (3).py [1.76 KiB]
Originally created by: M.Schaber
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:
And here's how the Python interpreter "sees" it using 8 characters tab with:
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
# Save project
proj.save()
# Script finished
print("--- Script finished. ---")
Related
Talk.ru: 1
attachment my scritpt
Create CodeSys Project_modified (4).py [1.68 KiB]
Stil the same probleem
Create CodeSys Project_modified (4).py [1.68 KiB]
Create CodeSys Project_modified (4).py [1.68 KiB]
Hi.
What error do you get when you execute your script? Is it the text of the assertion or something else?
BR
Martin
here post mijn script en error
Create CodeSys Project_modified.py [1.71 KiB]
Hi.
The indentation of your script is still wrong. The indentation is important in python. Look at the screenshots.
I modified your script to have the correct indentation and attached it. Please use a proper editor from now on.
BR
Martin
Create CodeSys Project_7.py [1.85 KiB]
Its stil not working
Thanks voor you time
Hi Rahied,
The Device is an EH_IOCA (with underscore).
The name of the plugged devices cannot have a space. You should use e.g. "%s_%d" as device name to make them unique.
Your import file (.txt) should have no empty lines at the end.
Attached an example import file and script for plugging the modules in the Hitachi EH-IOCA EtherCAT slave.
Maybe not perfect or complete, but for me this works.
Import.txt [62 Bytes]
Create CodeSys Project_8.py [4 KiB]
By plugging the device via a script a generated name is given to its structures and accessable variables (e.g. "%QX7.7", similarly when one has only plugs the device) but in GUI, I have the chance to map those addresses to variables.
Is there a way to configure the plugged device configuration and I/O mapping ("xxx Configuration" and "xxx I/O Mapping" tabs)?
I have some ADC/DIO/DAC "pins" configured and would like to map their variables and structures to one of the PRGs stored variables.
Originally created by: M.Schaber
Hi, etamgul,
A scripting interface for the I/O Mapping is currently scheduled for the upcoming V3.5 SP8 release by the end of the year. (See CDS-37756).
(Please note that the schedule may still change when other, more important issues arise.)