| Author |
Message |
|
Aliya
Trooper
Joined: Wed Mar 21, 2012 10:05 pm Posts: 11
|
 Reading tags
How to Read values from Text file and assign them back to plc tags?????????? 
_________________ A F S
|
| Thu Mar 29, 2012 1:48 am |
|
 |
|
Travis.Cox
Moderator
Joined: Sun Apr 02, 2006 2:46 pm Posts: 1975 Location: Sacramento, CA
|
 Re: Reading tags
When do you want to read from the text file and write them to tags? When somebody presses a button? On a timer? Do you have an example of the text file so we can post an example? You have to use scripting in order to perform that task. The main idea is that you read the text file in, parse it, and write it to tags. Here is a small example: Code: contents = system.file.readFileAsString("C:\\Path\\To\\File.txt) values = contents.split(";") system.tag.writeToTag("Path/To/Tag1", values[0]) system.tag.writeToTag("Path/To/Tag2", values[1]) ... Of course yours will vary depending on the text file. The above example assumes the values in the text file are separated by a semi-colon.
_________________ Travis Cox
Inductive Automation
Technical Support Rep.
|
| Thu Mar 29, 2012 7:15 am |
|
 |
|
Aliya
Trooper
Joined: Wed Mar 21, 2012 10:05 pm Posts: 11
|
 Re: Reading tags
instead of using system.tag.writeToTag function for each tag path separately i want to use system.tag.writeToTags function coz i wanna read 300 tags from a text file. and here is the text file attached,...........
Attachments:
idle.txt [92 Bytes]
Downloaded 51 times
_________________ A F S
|
| Fri Mar 30, 2012 2:22 am |
|
 |
|
Travis.Cox
Moderator
Joined: Sun Apr 02, 2006 2:46 pm Posts: 1975 Location: Sacramento, CA
|
 Re: Reading tags
Alright, here is a sample script: Code: contents = system.file.readFileAsString("C:\\Path\\To\\idle.txt") values = contents.split(",") if len(values) == 43: tags = ["Path/To/Tag1", "Path/To/Tag2", ....., "Path/To/Tag43"] system.tag.writeToTags(tags, values)
_________________ Travis Cox
Inductive Automation
Technical Support Rep.
|
| Fri Mar 30, 2012 9:23 am |
|
 |
|
tailfire
General
Joined: Thu Jan 26, 2012 5:18 pm Posts: 187
|
 Re: Reading tags
Is there a way to do this (with credentials) from a website. Honeywell has a website for some data I want to get at, but you have to login with credentials. Once logged in you have the options to download csv,txt, or xml. I also have to 'choose account' from a drop down that is not defaulted to my account. Which would be easier to parse and is it possible to login with credentials via scripting and make the necessary account choices just to finally arrive at the file download? I do have the credentials, and Ignition 7.5. Also have a MSSQL database where I can write the tags to.
Also, on the same page where the downloads are, exists a display of the values. I am thinking once logged in where the data is being displayed I could just parse it from there.. This may be the best option since wsdl type service is not available at this time Help appreciated.. more precisely examples of logging in with credentials through scripting, appreciated
|
| Tue Aug 07, 2012 6:34 pm |
|
 |
|
Travis.Cox
Moderator
Joined: Sun Apr 02, 2006 2:46 pm Posts: 1975 Location: Sacramento, CA
|
 Re: Reading tags
You might be able to do this using system.net.httpPost. You can post the same information that the form needs such as the username and password. Some website protect against this so it could be a challenge.
_________________ Travis Cox
Inductive Automation
Technical Support Rep.
|
| Wed Aug 08, 2012 7:37 am |
|
 |
|
tailfire
General
Joined: Thu Jan 26, 2012 5:18 pm Posts: 187
|
 Re: Reading tags
This may be the case. I have posted sample. I pass postData parameter string, and get this over and over. The 'hidden' viewstate and eventvalidation may be some of the challenges. Looks to be something like a hash code but this is unfamiliar territory for me. I may just have to wait for xml or wsdl that i can properly interact with.
Attachments:
File comment: I attached txt output rather then putting in body of post
script output.txt [3.18 KiB]
Downloaded 32 times
|
| Wed Aug 08, 2012 9:10 am |
|
 |
|
tailfire
General
Joined: Thu Jan 26, 2012 5:18 pm Posts: 187
|
 Re: Reading tags
Its hard for me to imagine that Ignition cannot do this. Recent script: from urllib import urlopen auth = HTTPBasicAuthHandler() auth.add_password("https://www.mercuryinstrumentsmlb.com/dc2009web/Logon.aspx","XXXXXX","XXXXXX") #create opener with auth attached opener = build_opener(auth) #open url u = opener.open("https://www.mercuryinstrumentsmlb.com/dc2009web/default.aspx") print page
Throws an exception that HTTPBasicAuthHandler is not defined. Any information on this? i have also just did: import urllib without 'open' and still the same exception.
Help appreciated
|
| Wed Aug 08, 2012 10:39 am |
|
 |
|
James.Lorenz
Moderator
Joined: Mon Jun 04, 2012 8:53 am Posts: 405
|
 Re: Reading tags
Try using urllib2, and putting urllib2 in front of the method calls. The add_password call needed an extra parameter as well. Code: from urllib2 import urlopen
auth = urllib2.HTTPBasicAuthHandler() auth.add_password(None,"https://www.mercuryinstrumentsmlb.com/dc2009web/Logon.aspx","X","X") #create opener with auth attached opener = urllib2.build_opener(auth) #open url opener.open("https://www.mercuryinstrumentsmlb.com/dc2009web/default.aspx")
_________________ James Lorenz QA/Build Engineer Inductive Automation
|
| Wed Aug 08, 2012 11:32 am |
|
 |
|
tailfire
General
Joined: Thu Jan 26, 2012 5:18 pm Posts: 187
|
 Re: Reading tags
import urllib2 from urllib2 import urlopen auth = urllib2.HTTPBasicAuthHandler() auth.add_password(None,"https://www.mercuryinstrumentsmlb.com/dc2009web/Logon.aspx","******","*********") #create opener with auth attached opener = urllib2.build_opener(auth) #open url opener.open("https://www.mercuryinstrumentsmlb.com/dc2009web/Logon.aspx") u = urlopen("https://www.mercuryinstrumentsmlb.com/dc2009web/DailyReadingTableReportEX.aspx") print u
returns this output: <addinfourl at 3 whose fp = <socket._fileobject object at 0x4>> Not sure what this is telling me but it seems positive. I will research it some more. Getting closer....I think. I may give you guys a call tomorrow depending on how things go.
edit........not a good sign after all. changed print u to: print u.read() and it does not show that I have actually logged in....
|
| Wed Aug 08, 2012 5:01 pm |
|
 |
|
Greg.Simpson
Moderator
Joined: Fri Mar 16, 2012 1:00 pm Posts: 549 Location: Sacramento, CA
|
 Re: Reading tags
I know you called in earlier, I don't know what the resolution was for this. Dave had mentioned that you spoke to him about it.
Were you able to find a resolution?
_________________ Greg Simpson Inductive Automation Technical Support Rep
|
| Fri Aug 10, 2012 1:21 pm |
|
 |
|
tailfire
General
Joined: Thu Jan 26, 2012 5:18 pm Posts: 187
|
 Re: Reading tags
Short answer - there was not a true resolution. I do believe that through scripting this could be accomplished. There were several more complexities that would have needed to be handled to make it happen. The provider also does not intend for the data to be accessed this way nor would they support it. They would however, automate an email delivery of the xml, txt, or csv. I don't really like that method since I cannot persuade my I.T to create an email account just for Ignition. I will have to use my own account to have the file sent to. I did find a snippit of vb that I can use to setup in my outlook account that will move the file to a network directory.Once its there it can likely be parsed and deleted. Soooo to keep it short there was not a true solution but rather a workaround. If any other Ignition users are doing something similar, experiences and examples are welcomed.
|
| Sat Aug 11, 2012 7:36 pm |
|
 |
|