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 Tue Feb 19, 2019 9:28 am

All times are UTC+01:00




Post new topic  Reply to topic  [ 26 posts ]  Go to page Previous 1 2
Author Message
PostPosted: Tue Jan 20, 2015 12:23 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


attachment my scritpt


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


Top
   
PostPosted: Tue Jan 20, 2015 12:24 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


Stil the same probleem


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


Top
   
PostPosted: Tue Jan 20, 2015 1:28 pm 
Offline
Frequent User
Frequent User

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

What error do you get when you execute your script? Is it the text of the assertion or something else?

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 1:44 pm 
Offline

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

What error do you get when you execute your script? Is it the text of the assertion or something else?

BR
Martin


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


Top
   
PostPosted: Tue Jan 20, 2015 1:45 pm 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
Rahied wrote:
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


Stil the same probleem


here post mijn script en error


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


Top
   
PostPosted: Tue Jan 20, 2015 2:14 pm 
Offline
Frequent User
Frequent User

Joined: Tue Nov 13, 2012 9:20 am
Posts: 233
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


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 2:39 pm 
Offline

Joined: Mon Dec 08, 2014 2:28 pm
Posts: 23
M.Keller wrote:
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


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


Top
   
PostPosted: Tue Jan 20, 2015 8:24 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Tue Jun 06, 2006 9:03 am
Posts: 408
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.


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


Top
   
PostPosted: Fri Sep 04, 2015 8:06 am 
Offline

Joined: Fri Jul 10, 2015 10:52 am
Posts: 35
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.


Top
   
PostPosted: Tue Sep 08, 2015 12:46 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
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.)

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

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


Top
   
PostPosted: Fri Feb 08, 2019 1:57 pm 
Offline

Joined: Wed Dec 10, 2014 2:20 pm
Posts: 8
Rahied wrote:
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:
tabs_vs_spaces.png

And here's how the Python interpreter "sees" it using 8 characters tab with:
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. ---")


hello Rahied:
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.

thanks alot


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

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