<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/</id><updated>2020-02-27T14:55:25.898000Z</updated><subtitle>Recent posts to add plug-device via the Python script</subtitle><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25&amp;page=1#4cf9" rel="alternate"/><published>2020-02-27T14:55:25.898000Z</published><updated>2020-02-27T14:55:25.898000Z</updated><author><name>zhou</name><uri>https://forge.codesys.com/u/zhou/</uri></author><id>https://forge.codesys.comce01ec2419bd63afeba548cf11c6af64968e05fd</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Rahied hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Hello here is my script.&lt;br/&gt;
print "Current project."&lt;br/&gt;
proj = projects.primary&lt;br/&gt;
PROJECT = r"C:\CoDeSys-Projects\Script-Test.project"&lt;br/&gt;
# clean up any open project: &lt;br/&gt;
if projects.primary:&lt;br/&gt;
   projects.primary.close()&lt;br/&gt;
print("--- CleanUp finished. ---")&lt;br/&gt;
# create a new project&lt;br/&gt;
proj = projects.create(PROJECT)&lt;br/&gt;
print("--- Project created. ---")&lt;br/&gt;
# add PLC&lt;br/&gt;
proj.add("CODESYS Control RTE V3",4096,"0000 0002","3.5.5.40")&lt;br/&gt;
print("--- PLC Device Insert. ---")&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;# Create the IO&lt;/p&gt;
&lt;p&gt;for dev in proj.get_children():&lt;br/&gt;
   if dev.is_device:&lt;br/&gt;
      f = open("C:\Users\RO\Desktop\Import.txt", "r")&lt;br/&gt;
      for line in f:&lt;br/&gt;
         tok = line.split(' ')&lt;br/&gt;
         if "(Master)" in tok&lt;span&gt;[1]&lt;/span&gt;:&lt;br/&gt;
        dev.add(tok&lt;span&gt;[0]&lt;/span&gt;, DeviceID(64, "0000 0001", "3.5.5.0"))&lt;br/&gt;
        subnodes = dev.get_children()&lt;br/&gt;
        master = subnodes&lt;span&gt;[len(subnodes) - 1]&lt;/span&gt;&lt;br/&gt;
         elif "(Slave)" in tok&lt;span&gt;[1]&lt;/span&gt;:&lt;br/&gt;
        master.add(tok&lt;span&gt;[0]&lt;/span&gt;, DeviceID(65, "51D_0201001000000001", "3.5.4.0"))&lt;br/&gt;
         elif "(IO)" in tok&lt;span&gt;[1]&lt;/span&gt;:&lt;br/&gt;
            objects = master.find('EH_IOCA', True) # Recursive search&lt;br/&gt;
            assert(objects and len(objects) == 1, "no object or more than one object with the name EH_IOCA") &lt;br/&gt;
            subnodes = objects&lt;span&gt;[0]&lt;/span&gt;.get_children(True) # Get all children&lt;br/&gt;
        # Scenario 1: Plug all&lt;br/&gt;
        # i = 1&lt;br/&gt;
        # for node in subnodes:&lt;br/&gt;
               # name = "%s %d" % (tok&lt;span&gt;[0]&lt;/span&gt;, i) # Create name with index&lt;br/&gt;
               # node.plug(name, 68, "51D_00000001_16 Digital Input_16 Digital Input","0")&lt;br/&gt;
           # i += 1&lt;br/&gt;
        # Scenario 2: Plug only the first one&lt;br/&gt;
        if len(subnodes) &amp;gt; 0:&lt;br/&gt;
               subnodes&lt;span&gt;[0]&lt;/span&gt;.plug(tok&lt;span&gt;[0]&lt;/span&gt;, 68, "51D_00000001_16 Digital Input_16 Digital Input","0") &lt;br/&gt;
# Save project&lt;br/&gt;
proj.save()&lt;/p&gt;
&lt;p&gt;# Script finished&lt;br/&gt;
print("--- Script finished. ---")&lt;/p&gt;
&lt;p&gt;hello Rahied:&lt;br/&gt;
I've an another quesiton: how could you know there is a method "add" for proj? I used dir(proj) there was not "add" method listed.&lt;/p&gt;
&lt;p&gt;thanks alot&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25#63a5" rel="alternate"/><published>2020-02-27T14:55:24.054000Z</published><updated>2020-02-27T14:55:24.054000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.comc579d9590ddc167aef97472ca66415ee70121e4d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; M.Schaber&lt;/p&gt;
&lt;p&gt;Hi, etamgul,&lt;/p&gt;
&lt;p&gt;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 &lt;a class="" href="http://jira.3s-software.com/browse/CDS-37756" rel="nofollow"&gt;CDS-37756&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;(Please note that the schedule may still change when other, more important issues arise.)&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25#077f" rel="alternate"/><published>2020-02-27T14:55:23.382000Z</published><updated>2020-02-27T14:55:23.382000Z</updated><author><name>etamgul</name><uri>https://forge.codesys.com/u/etamgul/</uri></author><id>https://forge.codesys.com8b9f08b5bab2ce66e482131c5158e8578f975ad9</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;Is there a way to configure the plugged device configuration and I/O mapping ("xxx Configuration" and "xxx I/O Mapping" tabs)?&lt;/p&gt;
&lt;p&gt;I have some ADC/DIO/DAC "pins" configured and would like to map their variables and structures to one of the PRGs stored variables.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25#e03d" rel="alternate"/><published>2020-02-27T14:55:22.753000Z</published><updated>2020-02-27T14:55:22.753000Z</updated><author><name>timvh</name><uri>https://forge.codesys.com/u/timvh/</uri></author><id>https://forge.codesys.comc722d01e624e631672aa1c3c9bda0ddf0f448a1d</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Rahied,&lt;/p&gt;
&lt;p&gt;The Device is an EH_IOCA (with underscore).&lt;br/&gt;
The name of the plugged devices cannot have a space. You should use e.g. "%s_%d" as device name to make them unique.&lt;br/&gt;
Your import file (.txt) should have no empty lines at the end.&lt;/p&gt;
&lt;p&gt;Attached an example import file and script for plugging the modules in the Hitachi EH-IOCA EtherCAT slave.&lt;/p&gt;
&lt;p&gt;Maybe not perfect or complete, but for me this works.&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=940" rel="nofollow"&gt;Import.txt &lt;span&gt;&lt;span&gt;[62 Bytes]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=939" rel="nofollow"&gt;Create CodeSys Project_8.py &lt;span&gt;&lt;span&gt;[4 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25#6f99" rel="alternate"/><published>2020-02-27T14:55:21.009000Z</published><updated>2020-02-27T14:55:21.009000Z</updated><author><name>Rahied</name><uri>https://forge.codesys.com/u/rahied/</uri></author><id>https://forge.codesys.com6fbca3baf5ea91ae3cd6d3d1b62a0664685abf32</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;M.Keller hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Hi.&lt;br/&gt;
The indentation of your script is still wrong. The indentation is important in python. Look at the screenshots.&lt;br/&gt;
I modified your script to have the correct indentation and attached it. Please use a proper editor from now on.&lt;br/&gt;
BR&lt;br/&gt;
Martin&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Its stil not working&lt;br/&gt;
Thanks voor you time&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: Error.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=938"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25#1ec0" rel="alternate"/><published>2020-02-27T14:55:20.424000Z</published><updated>2020-02-27T14:55:20.424000Z</updated><author><name>mkeller</name><uri>https://forge.codesys.com/u/mkeller/</uri></author><id>https://forge.codesys.coma999ed55917a7ab4720742a1ea21010daf9ad3fd</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;The indentation of your script is still wrong. The indentation is important in python. Look at the screenshots.&lt;/p&gt;
&lt;p&gt;I modified your script to have the correct indentation and attached it. Please use a proper editor from now on.&lt;/p&gt;
&lt;p&gt;BR&lt;br/&gt;
Martin&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: correct indentation.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=937"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: wrong_indentation.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=936"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=935" rel="nofollow"&gt;Create CodeSys Project_7.py &lt;span&gt;&lt;span&gt;[1.85 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25#a29a" rel="alternate"/><published>2020-02-27T14:55:18.776000Z</published><updated>2020-02-27T14:55:18.776000Z</updated><author><name>Rahied</name><uri>https://forge.codesys.com/u/rahied/</uri></author><id>https://forge.codesys.com9f7887e13facd5a36fec2b9054506b7de17d6d95</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Rahied hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Stil the same probleem&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;here post mijn script en error&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: Error.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=933"/&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=934" rel="nofollow"&gt;Create CodeSys Project_modified.py &lt;span&gt;&lt;span&gt;[1.71 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25#d771" rel="alternate"/><published>2020-02-27T14:55:18.216000Z</published><updated>2020-02-27T14:55:18.216000Z</updated><author><name>Rahied</name><uri>https://forge.codesys.com/u/rahied/</uri></author><id>https://forge.codesys.comda80958ec917b74c3dc17a90522eb89abf8133a2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;M.Keller hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Hi.&lt;br/&gt;
What error do you get when you execute your script? Is it the text of the assertion or something else?&lt;br/&gt;
BR&lt;br/&gt;
Martin&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img alt="IMG: Error.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=932"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25#5f92" rel="alternate"/><published>2020-02-27T14:55:17.644000Z</published><updated>2020-02-27T14:55:17.644000Z</updated><author><name>mkeller</name><uri>https://forge.codesys.com/u/mkeller/</uri></author><id>https://forge.codesys.com20769cd0ab2dd3dc1294bc092372977fdc6368c8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;What error do you get when you execute your script? Is it the text of the assertion or something else?&lt;/p&gt;
&lt;p&gt;BR&lt;br/&gt;
Martin&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>add plug-device via the Python script</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/55a2bcd97e/?limit=25#4db6" rel="alternate"/><published>2020-02-27T14:55:16.028000Z</published><updated>2020-02-27T14:55:16.028000Z</updated><author><name>Rahied</name><uri>https://forge.codesys.com/u/rahied/</uri></author><id>https://forge.codesys.com5757f64396835fe2f58a53fad2256098bbe19206</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;M.Schaber hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
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.&lt;br/&gt;
Python generally interprets tabs according common standards with 8 characters, while your editor seems to use 4 characters of tab with.&lt;br/&gt;
Generally, the python community strongly suggests to not mix tabs and spaces in source files:&lt;br/&gt;
&lt;a class="" href="http://legacy.python.org/dev/peps/pep-0008/#tabs-or-spaces" rel="nofollow"&gt;PEP 8 -- Style Guide for Python Code&lt;/a&gt;&lt;br/&gt;
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:&lt;br/&gt;
And here's how the Python interpreter "sees" it using 8 characters tab with:&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Stil the same probleem&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=931" rel="nofollow"&gt;Create CodeSys Project_modified (4).py &lt;span&gt;&lt;span&gt;[1.68 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a class="" href="https://forum.codesys.com//download/file.php?id=930" rel="nofollow"&gt;Create CodeSys Project_modified (4).py &lt;span&gt;&lt;span&gt;[1.68 KiB]&lt;/span&gt;&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>