Author Topic: Creating a label to show real time data  (Read 1598 times)

FuzyDragon

  • Newbie
  • *
  • Posts: 19
    • View Profile
Creating a label to show real time data
« on: November 10, 2015, 09:56:21 AM »
I am currently working on a screen that will show data being captured in real time (or as close to that as I can get). What I have so far is a List box that contains all of the Addresses and a function that changes a Label based on which address is chosen. I also have a timer running to update the read every second. I am using the EthernetIPforMicro800Com driver set to the IP of the test PLC. The generic label text works fine but I can't get the variable holding the real time data to show.  Though I'm not entirely sure where the issue is, I believe I'm running into an issue with my code reading my PLC Addresses. I will paste what I have below. Thank you in advance for any help or advice.

Public Class ThermocoupleScreen
    Public ThermoData(140) As String
    Public Sub ThermocoupleScreen_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim StringToAdd As String
        For count As Integer = 1 To 120
            StringToAdd = "DAQThermocouples[" + count.ToString + "]"
            ListBox1.Items.Add(StringToAdd)
        Next
        For x As Integer = 1 To 120
            EthernetIPforMicro800Com1.BeginRead("DB.CURRENT.dataPoints[" & x.ToString & "]", 1)
        Next
    End Sub


    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Timer1.Interval = 1000
        Label2.Text = "Ticking"
        For y As Integer = 1 To 120
            EthernetIPforMicro800Com1.Read("DB.CURRENT.dataPoints[" & y.ToString & "]", 1)
        Next

    End Sub


    Private Sub EthernetIPforMicro800Com1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforMicro800Com1.DataReceived
        If e.PlcAddress = "DB.CURRENT.dataPoints[1]" Then
            ThermoData(0) = e.Values(0)
        End If
        If e.PlcAddress = "DB.CURRENT.dataPoints[2]" Then
            ThermoData(1) = e.Values(0)
        End If
        If e.PlcAddress = "DB.CURRENT.dataPoints[3]" Then
            ThermoData(2) = e.Values(0)
        End If
    End Sub


    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
        For z As Integer = 0 To 119
            Label1.Text = ListBox1.SelectedItem.ToString + " is " + ThermoData(z) + " Deg. C"
        Next

    End Sub
End Class