Difference between revisions of "DataSubscriber"

From AdvancedHMI
Jump to: navigation, search
(DataSubscriber)
m
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== DataSubscriber ==
 
== DataSubscriber ==
  
This component is used to monitor a value within the PLC without a visual control. It has to events to indicate when data has returned from the PLC and when the value has changed. Within these events you would add your own code to perform any action desired.
+
This component is used to monitor a value within the PLC without a visual control. It has two events to indicate when data has returned from the PLC and when the value has changed. Within these events you would add your own code to perform any action desired.
  
 
{| class="wikitable"
 
{| class="wikitable"
Line 12: Line 12:
 
|Enter the PLC address of the value you wish to monitor
 
|Enter the PLC address of the value you wish to monitor
 
|}
 
|}
 +
 +
== Walk Through ==
 +
1) Add a driver to the form and set the corresponding properties<br>
 +
2) Add a DataSubscriber to the form<br>
 +
3) Enter a valid PLC address in the PLCAddressValue property<br>
 +
4) Double click the DataSubscriber to get back to the DataChanged event handler<br>
 +
5) Enter this code:<br>
 +
<code>
 +
Me.Text = e.values(0)
 +
</code>
 +
 +
When the application runs, the value from the PLC will be put into the title bar of the window.
 +
 +
== More Examples ==
 +
Multiple DataSubscribers can use the same event handler code. When doing this you will need to use e.PLcAddress to know which address the value is associated with.
 +
 +
<code>
 +
If e.PLCAddress = "N7:0" then
 +
    Label1.Text = e.Values(0)
 +
ElseIf e.PLCAddress = "N7:1" then
 +
    Label2.Text = e.Values(0)
 +
End If
 +
</code>
 +
 +
== IMPORTANT ==
 +
When a driver error occurs, it will also be returned in the event handler. In this case, nothing will be in e.Values and could cause exceptions. To avoid this, use similar code to this:
 +
<code>
 +
If e.ErrorId = 0 Then
 +
  If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
 +
      If e.PLCAddress = "N7:0" then
 +
      Label1.Text = e.Values(0)
 +
    ElseIf e.PLCAddress = "N7:1" then
 +
      Label2.Text = e.Values(0)
 +
    End If
 +
  End If
 +
End If
 +
</code>

Latest revision as of 13:48, 29 March 2017

DataSubscriber

This component is used to monitor a value within the PLC without a visual control. It has two events to indicate when data has returned from the PLC and when the value has changed. Within these events you would add your own code to perform any action desired.

Properties
ComComponent Points to the driver instance for reading its values through
PLCAddressValue Enter the PLC address of the value you wish to monitor

Walk Through

1) Add a driver to the form and set the corresponding properties
2) Add a DataSubscriber to the form
3) Enter a valid PLC address in the PLCAddressValue property
4) Double click the DataSubscriber to get back to the DataChanged event handler
5) Enter this code:
Me.Text = e.values(0)

When the application runs, the value from the PLC will be put into the title bar of the window.

More Examples

Multiple DataSubscribers can use the same event handler code. When doing this you will need to use e.PLcAddress to know which address the value is associated with.

If e.PLCAddress = "N7:0" then
   Label1.Text = e.Values(0)
ElseIf e.PLCAddress = "N7:1" then
   Label2.Text = e.Values(0)
End If

IMPORTANT

When a driver error occurs, it will also be returned in the event handler. In this case, nothing will be in e.Values and could cause exceptions. To avoid this, use similar code to this:

If e.ErrorId = 0 Then
  If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
     If e.PLCAddress = "N7:0" then
      Label1.Text = e.Values(0)
    ElseIf e.PLCAddress = "N7:1" then
      Label2.Text = e.Values(0)
    End If
  End If
End If