How to trigger a VBA script in RSView

I would say the short answer is yes. Others will have to elaborate. Can you give more details as to what you are trying to do?
 
RSView 32? or RSView SE? big difference.
In SE you need to have a window always open (and updateing), Put a display tag on the window (can be hidden outside the viewable area), expose it to VBA, and let the on change event fire your vba routine. Keep the timer triggerring it in the PLC.

For View32, you can run it in the application VBA, again, as an event.
Don't trust the actual VBA Timers in Windows.
 
Hi Guys,

Its RSView SE I'm using. I havent had much exposure to VB so Im a little lost on this one.

Bascially what i want to do is follows:

I have an ActiveX imported into my application and on an event I read data from an instrument via the RS232 Port of industrial PC.

I have sucessfully connected to the instrument using methods on a button click event.

What I now need to do is every ten seconds read from instrument and write these values to the PLC.
Where can i put this event?

Dim TempPressure as Single
TempPressure=pdCommX.GetPressure

'What I now need to do is every 10s write this value to a HMI Tag Pressure in Tag DataBase or PLC Tag [SPX]ADCP.Pressure

Any suggestions?
 
Hi,

Try the following I did something similar to force a periodic refresh of Rockwell ActiveX object without an operator clicking any buttons.

Add a String Display object to the graphic and set it up to read 'System\Time'

Once you've added this to the graphic right click and select property panel. On the property panel set the following Properties
'Name' property to strTime
'Visibile' to False and
'ExposeToVBA' to True.

Close the property panel.
Select the string Display again , then right click and select VBA.
This should open the VB Editor with a routine called 'strTime_DataChange'.

This routine will fire once every second. To stop firing your code too frequently use following

Dim intSecond as integer

intSecond = Second(Now)

intSecond = intSecond Mod 10

If intSecond = 1 then

Dim TempPressure as Single
TempPressure=pdCommX.GetPressure

End if

Hope this helps

Regards
Finbarr
 
Vba

Hi Finbar,

Thanks for your help but the problem I'm having is setting a PLC tag.

pressure=PDComm.GetPressure

How do I now assign the value in pressure to a "real tag" HMI tag/ PLC tag rather than a VBA variable?

FKelly said:
Hi,

Try the following I did something similar to force a periodic refresh of Rockwell ActiveX object without an operator clicking any buttons.

Add a String Display object to the graphic and set it up to read 'System\Time'

Once you've added this to the graphic right click and select property panel. On the property panel set the following Properties
'Name' property to strTime
'Visibile' to False and
'ExposeToVBA' to True.

Close the property panel.
Select the string Display again , then right click and select VBA.
This should open the VB Editor with a routine called 'strTime_DataChange'.

This routine will fire once every second. To stop firing your code too frequently use following

Dim intSecond as integer

intSecond = Second(Now)

intSecond = intSecond Mod 10

If intSecond = 1 then

Dim TempPressure as Single
TempPressure=pdCommX.GetPressure

End if

Hope this helps

Regards
Finbarr
 
First, in the always open / updating window, make global tags for:
Dim HMIGlobalGroup As TagGroup
Dim HMIGlobalTag As Tag
Dim TagsInError As StringList
Dim Results As Boolean


Now initialize the Global Group:
(animation_start is a good place for this initialization)

Set HMIGlobalGroup = Application.CreateTagGroup(Me.AreaName, 50)

Once created, you can add tags to it:

HMIGlobalGroup.Add("[My_Data_Server]My_First_Tag")
HMIGlobalGroup.Add("[My_PLC]My_Timer.ACC")


--------------------------
Once some tags are added, (provided HMIGlobalGroup is globally scoped) you can access the tags in it from any VBA function for that display...

To set a tag to a value is a multi-step process...

Set the Global tag to the item from the group:

'Set Tag to item:
HMIGlobalTag = HMIGlobalGroup.Item("[My_Data_Server]My_First_Tag")
'Set the new value for the tag:
HMIGlobalTag.PendingWriteValue = 25.3
'Commit the write
Results = HMIGlobalGroup.WritePendingValues(TagsInError)

----- Advantage that way, is you can actually set multiple tags to be written at once, then commit them all.

To read values from tags in the group, use the value property:

Set HMIGlobalTag = HMIGlobalGroup.Item("[My_PLC]My_Timer.ACC")
Dim Current_ACC as INT
Current_ACC = HMIGlobalTag.Value


Bit of a PITA, but it works.
 
Last edited:
Where do I create my global tags?

When I run this script I get an error on

Set HMIGlobalGroup = Application.CreateTagGroup(Me.AreaName,50)

Run time error '-2147217661

Unable to set update Rate. Value is invalid


rdrast said:
First, in the always open / updating window, make global tags for:
Dim HMIGlobalGroup As TagGroup
Dim HMIGlobalTag As Tag
Dim TagsInError As StringList
Dim Results As Boolean


Now initialize the Global Group:
(animation_start is a good place for this initialization)

Set HMIGlobalGroup = Application.CreateTagGroup(Me.AreaName, 50)

Once created, you can add tags to it:

HMIGlobalGroup.Add("[My_Data_Server]My_First_Tag")
HMIGlobalGroup.Add("[My_PLC]My_Timer.ACC")


--------------------------
Once some tags are added, (provided HMIGlobalGroup is globally scoped) you can access the tags in it from any VBA function for that display...

To set a tag to a value is a multi-step process...

Set the Global tag to the item from the group:

'Set Tag to item:
HMIGlobalTag = HMIGlobalGroup.Item("[My_Data_Server]My_First_Tag")
'Set the new value for the tag:
HMIGlobalTag.PendingWriteValue = 25.3
'Commit the write
Results = HMIGlobalGroup.WritePendingValues(TagsInError)

----- Advantage that way, is you can actually set multiple tags to be written at once, then commit them all.

To read values from tags in the group, use the value property:

Set HMIGlobalTag = HMIGlobalGroup.Item("[My_PLC]My_Timer.ACC")
Dim Current_ACC as INT
Current_ACC = HMIGlobalTag.Value


Bit of a PITA, but it works.
 
Code location..

This depends on whether you need to update the tag every 10 seconds or
every 10 seconds when a particular graphic is open.

If it is the first case then declare the global variables in a graphic which will be open all the time such as a toolbar.
(Note: You may get issues if this code runs when nobody is logged in as they won't have security to write to tag)

Otherwise declare them within the relevant picture

Error..

The error may be caused by your update rate - the update rate is in milliseconds - try 500
 
Last edited:
Ok I have declared the variables in the General declarations section. Now when I trigger the event I get the error "Run Time Error '91' Object variable or with Block variable not set.
 
Cant seem to find a global area to declare variables. I have pasted the code to a button click event and i still recived the same error

Private Sub Button6_Released()
Dim HMIGlobalGroup As TagGroup

Dim HMIGlobalTag As Tag
Dim TagsInError As StringList
Dim Results As Boolean
Set HMIGlobalGroup = Application.CreateTagGroup(Me.AreaName, 1000)
HMIGlobalGroup.Add ("[IPCMS]ADCP[0].Pressure")
Set HMIGlobalTag = HMIGlobalGroup.Item("[IPCMS]ADCP[0].Pressure")
HMIGlobalTag.PendingWriteValue = 25.3

Results = HMIGlobalGroup.WritePendingValues(TagsInError)
End Sub
 
Hi Guys,

Still having problems writing to a HMI tag using VBA. I am now recieving the error:

Failed to write to tag. Error. Unable to perform the tag operation. Error code: -2147467259, Reason [FactoryTalk]: COM Operation Failed

My code is as follows:

In Declaration area:

Dim WithEvents oGroup As TagGroup

Sub SetUpTagGroup()
'Routine to create a tag group and assign tags to monitor

On Error Resume Next
Err.Clear
If oGroup Is Nothing Then
Set oGroup = Application.CreateTagGroup(Me.AreaName, 500)
If Err.Number Then
LogDiagnosticsMessage "Error creating TagGroup. Error: " _
& Err.Description, ftDiagSeverityError

Exit Sub
End If
oGroup.Add "System\Second"
oGroup.Add "System\Minute"
oGroup.Add "ADCP\Pressure"
oGroup.Active = True
End If

End Sub

Private Sub Button5_Released()

On Error Resume Next
Dim oTag As Tag
If Not oGroup Is Nothing Then
Set oTag = oGroup.Item("ADCP\Pressure")
Err.Clear
oTag.Value = 10.1

'Test the error number for the result
Select Case Err.Number
Case 0:
'Write completed sucessfully...log a message
LogDiagnosticsMessage "Write to tag" & oTag.Name & "was sucessful."

Case tagErrorReadOnlyAccess:
MsgBox "Unable to write tag value. Client is read-only."

Case tagErrorWriteValue:
If oTag.LastErrorNumber = tagErrorInvalidSecurity Then
MsgBox "Unable to write tag value. The current user does not have security rights."
Else
MsgBox "Error writing tag value. Error: " & _
oTag.LastErrorString
End If

Case tagErrorOperationFailed:
MsgBox "Failed to write to tag. Error: " & Err.Description

End Select

End If
End Sub
 

Similar Topics

Hi all Not very accomplished at VBA scripting, but managed to hash up a simple log tags to CSV file in FTView32. Trying to do the same now in...
Replies
1
Views
2,489
Hi i would like to ask! Im using Omron CP1E PLC May i know how to use one input to trigger two outputs alternatively? Meaning press X0 on, Y0...
Replies
11
Views
398
Hi all, I use e won for my OPCUA to back up my PLC (B&R X20 system) data. Whenever e won does maintenance updates, I need to reboot the e won in...
Replies
2
Views
473
Hello ladies and gents I’ve hit a road block on a project, it’s AB for preface this is a converting line including Winder tailsealer and...
Replies
4
Views
769
Hi, I'm using CX Programmer and just seeing what the best way to trigger an output from the plc clock time would be. I need this to come on at 9am...
Replies
4
Views
1,742
Back
Top Bottom