Reading tags

How to Read values from Text file and assign them back to plc tags??? :prayer:

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

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,…
idle.txt (92 Bytes)

Alright, here is a sample script: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)

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

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.

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.
script output.txt (3.18 KB)

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

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”)[/code]

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…

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?

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.