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 Sat Aug 17, 2019 10:04 pm

All times are UTC+01:00




Post new topic  Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Reading excel files
PostPosted: Mon Nov 26, 2012 9:14 am 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Hello,

Do someone know how to install package from this site: http://www.python-excel.org/ to CoDeSys? I wan to use excel file to read some variables into the python script.


Top
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 9:46 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

I did not try this myself, but I guess it should just work to unpack the module directories to some common parent directory, and then add that directory to sys.path from within the python script. Alternatively, you could try to copy the directories to the ScriptLib subdirectory ouf your CODESYS installation.

HTH,
Markus Schaber

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

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


Top
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 10:00 am 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Hi,

I did copy the package directories to CoDeSys \ScriptLib directory, but there is still an error while trying to run the script. This is the example:
Code:
from xlrd import open_workbook

proj = projects.primary
app = proj.active_application
onlineapp = online.create_online_application(app)

temp = xlrd.open_workbook('test.xlsx')



And the error message is:
Cannot import name nested_scopes


Top
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 10:14 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hmm, strange...

nested_scopes is a "from __future__" special feature. It should work with IronPython, too.

I'll try to find some time to look into that issue, but for diagnostic purposes, could you try to check whether it works with plain IronPython?

Thanks,
Markus

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

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


Top
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 10:28 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi,

I just did see that your example code does the import the wrong way:

If you use "from xlrd import open_workbook", then you need to use "temp = open_workbook(...)" below.

And maybe you also need to install the errorhandler package as explained on http://pypi.python.org/pypi/xlutils.

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

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


Top
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 10:51 am 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Still, none of this works:(


Top
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 11:21 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Hi, Daniel,

I did solve the problem: It seems that the __future__.py we deliver with CODESYS is an outdated version, it is fixed in recent IronPython versions (2.7.3 has the fix).

If you copy the attached __future__.py CODESYS scriptlib/ directory, it should work. (It did work on my machine with V3.5 SP1 Patch 4).

The __future__.py file is from IronPython 2.7.3, and it is identical to the one from cPython (ActivePython 2.7.2.4). There's a Thread on the mailing list covering that subject.

I did open CDS-31786: ScriptEngine: nested scopes don't work, feel free to add yourself as an interested customer via your support contact.

HTH,
Markus


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
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 11:26 am 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
Thank You for reply.
Can You also check the attachment, because when I try to download it there's a message "file not found"?


Top
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 11:32 am 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
I can download it from the internal network, but not externally (with my smartphone). I'll contact our admins...

In the meantime, you can copy the __future__.py from IronPython 2.7.3 or a recent 2.7 cPython installation, or download it from the IronPython Github repository (use the "RAW" button on that page).

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

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


Top
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 12:44 pm 
Offline

Joined: Wed Jul 18, 2012 11:42 am
Posts: 15
It's like never ending errors:)
After Your tip and trying to execute I have another error message: 'LightException' object has no attribute 'etree'.
In IronPython this is working.


Top
   
 Post subject: Re: Reading excel files
PostPosted: Mon Nov 26, 2012 1:36 pm 
Offline
Frequent User
Frequent User
User avatar

Joined: Fri Mar 18, 2011 4:12 pm
Posts: 266
Just for the record: It seems that import of xsl files works, but xlsx does not. I currently don't know how to fix that problem, my guess is that it might work once we update the IronPython version delivered with CODESYS.

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

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


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

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