- Add a Datasubcriber2 to the form
- In the Properties windows click the ellipsis (3 dots) next to PLCAddressValueItems
- A new window will pop up
- Click the Add button
- In the right pane, enter 00017 for PLCAddress
- Click the Add Button again
- In the right pane, enter 00018 for PLCAddress
- Click the Add Button again
- In the right pane, eneter 00019 for PLCAddress
- Repeat the above 2 steps until you enter 0028
- Double click the Data subscriber to get to the value changed event handler
- Enter this code:
If e.PlcAddress = "00017" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 0)
ElseIf e.PlcAddress = "00018" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 1)
ElseIf e.PlcAddress = "00019" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 2)
ElseIf e.PlcAddress = "00020" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 3)
ElseIf e.PlcAddress = "00021" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 4)
ElseIf e.PlcAddress = "00022" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 5)
ElseIf e.PlcAddress = "00023" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 6)
ElseIf e.PlcAddress = "00024" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 7)
ElseIf e.PlcAddress = "00025" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 8)
ElseIf e.PlcAddress = "00026" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 9)
ElseIf e.PlcAddress = "00027" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 10)
ElseIf e.PlcAddress = "00028" Then
AnalogValue = SetNewBitValue(AnalogValue, e.Values(0), 11)
End If
- Just above the event handler "Private Sub DataSubscriber21_DataChanged........" enter this line of code:
Private AnalogValue As Integer
Below the event handler just after "End Sub", enter this code:
Private Function SetNewBitValue(ByVal value As Integer, ByVal bitValue As Boolean, ByVal bitNumber As Integer) As Integer
Dim MaskValue As Integer = (1 << bitNumber)
If bitValue Then
Return (Value Or MaskValue)
Else
Return (Value And (65535 - MaskValue))
End If
End Function