FTView SE read PLC tag (RSLinx) in VBA

erghurt

Member
Join Date
Aug 2017
Location
Alton
Posts
14
Hi there,

I have been looking in the forums for this and I saw a couple of examples but I still don't understand very well how to create a VBA script that will allow me to read a value of a PLC tag browsed from the RSlinx Enterprise file (Offline Tag File)

For the PLC I am using Studio 5000 V30.00
for the SCADA I am using FactoryTalk View Studio SE V9.00

What I am trying to do is:
1)Read variables from the PLC
2)Create a file (*.txt)
3)Write to that file the value of the variables


So far what I have is:

Dim File_System As Object
Dim File As Object
Dim Started as boolean
Dim File_Name As string 'this needs to change with date, any advice?
Dim Finished as boolean
Dim PLC_local_tag as integer

Started = ?????
Finished = ?????

PLC_local_tag = ?????? ' how do I read the value of a PLC tag?

If Started = 1 Then

Set File_System = CreateObject("Scripting.FileSystemObject")
Set File = File_System.CreateTextFile("C:\Users\Admin\Desktop\data\ " & File_Name & ".txt", True)

Else
End If

If Finished = 1 Then

File.WriteBlankLines ("2")
File.writeline ("==========")
File.writeline ("Number")
File.writeline ("*PLC TAG HERE*")
File.writeline ("==========")

Else
End if



Any help is appreciated, thanks!

PS. I don't know much about VBA.
 
Last edited:
Hi gclshortt,

So out all of the threads you kindly sent me, only one of them is about reading a tag from a PLC

http://www.plctalk.net/qanda/showthread.php?t=70868

ok, and from what I am understanding (correct me if I'm wrong here) what I have to do is the following


'create a tag as tag group
Dim something As TagGroup


If something Is Nothing Then
Set something= Application.CreateTagGroup(Me.AreaName,500)
something.Add "{[PLC_Offline_Tag_file]PLC_Tag}"

Dim VBA_Tag As Tag

Set VBA_Tag = something.Item("{[PLC_Offline_Tag_file]PLC_Tag}")

End Function


If that is alright, that brings a second question,

after the script has run the first time, I am guessing that the value of the tag group won't be nothing, is it something that I have to clear to run the script again? or can I use a different If function for the code?
 
Last edited:
From what I remember you do not need to clear the group tag to run the script again.

Easiest way is to set it up based on the information you already have and play with it.
That should help you to understand what is going on.
 
Hello,

I'm getting an error in this line of code when I try to run it

Set VBA_Tag = something.Item({[PLCCC]d})

Saying the following: VBA Code has been halted. Reason: Run-time error - Tag {[PLCCC]d} was not found in the collection

Any advice?


full code is:




Private Sub NumericDisplay1_Change()
Dim something As TagGroup
Dim File_System As Object
Dim File As Object

If something Is Nothing
Then Set something = Application.CreateTagGroup(Me.AreaName, 500)
something.Add {{[PLCCC]d}}


Dim VBA_Tag As Tag
Set VBA_Tag = something.Item({[PLCCC]d})
End If

Set File_System = CreateObject(Scripting.FileSystemObject)
Set File = File_System.CreateTextFile(;C:\Users\admin\Desktop\New folder\test.txt, True)

On Error GoTo ErrorHandler
If Not IsError(NumericDisplay1.Value) Then
If NumericDisplay1.Value = 1 Then
File.WriteBlankLines (2)
File.writeline (==========)
File.writeline (VBA_Tag)
End If


End If
Exit Sub
ErrorHandler: LogDiagnosticsMessage Err.Description, ftDiagSeverityError
End Sub
 
Last edited:

Similar Topics

Dear colleagues, I am reaching out for assistance with an issue I am having. I have a code that can successfully insert data from FactoryTalk...
Replies
6
Views
1,001
Hi , in my application i was supposed to read the recipe name in a string & have to display it all other screens of scada & to perform operation...
Replies
0
Views
2,891
Hi, I managed to read all the tags and value from AB control logix but I had problem to read HMI tag and value from FTView SE, can anyone share...
Replies
2
Views
3,189
Hi, I'm working with Factory Talk Studio and VBA coding. So far, I have two questions. If someone could help me I would be really glad. First, I...
Replies
6
Views
17,286
Hi All, we've recently upgraded from FTView SE v10 to v12. Since the upgrade we've been having a problem where the HMI is slow to update tags in...
Replies
0
Views
41
Back
Top Bottom