Author Topic: Modbustcpcom1.read not working in VBA chart component?  (Read 2339 times)

doggo

  • Newbie
  • *
  • Posts: 23
    • View Profile
Modbustcpcom1.read not working in VBA chart component?
« on: February 26, 2015, 05:07:35 PM »
Archie,

Ive got another VBA chart display where there are 4 analog channels being read from an omega temperature device. All four channels update correctly in your Digitalpanelmeter component on the same form as the chart component, and update temperatures every 5 seconds. The panel meters work fine, so I know the Modbus ethernet addresses are correct.

But putting those same addresses in the Timer code below, the chart does not update. Any ideas? How can I check the variables valueZ1 to Z3 to see what is actually getting read from the omega?

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Dim valueZ1, valueZ2, valueZ3, valueZ4 As Single
        '* Z1-Z4 = the temperatures from the omega device
        Try
            valueZ1 = ModbusTCPCom1.Read("400005", 1)(0)
            valueZ2 = ModbusTCPCom1.Read("400006", 1)(0)
            valueZ3 = ModbusTCPCom1.Read("400261", 1)(0)
            valueZ4 = ModbusTCPCom1.Read("400262", 1)(0)
        Catch ex As Exception
            Exit Sub
        End Try

        '* Add the next point to the chart
        Chart1.Series(0).Points.Add(valueZ1)
        Chart1.Series(1).Points.Add(valueZ2)
        Chart1.Series(2).Points.Add(valueZ3)
        Chart1.Series(3).Points.Add(valueZ4)

        '* Do not let more than 500 point be on the chart
        If Chart1.Series(0).Points.Count > 500 Then
            Chart1.Series(0).Points.RemoveAt(0)
            Chart1.Series(1).Points.RemoveAt(0)
            Chart1.Series(2).Points.RemoveAt(0)
            Chart1.Series(3).Points.RemoveAt(0)
        End If
 End Sub

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbustcpcom1.read not working in VBA chart component?
« Reply #1 on: February 26, 2015, 05:23:04 PM »
Put a breakpoint at your Exit Sub to see if the exception is being thrown. Or insert before the Exit sub:

MsgBox ex.message

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbustcpcom1.read not working in VBA chart component?
« Reply #2 on: February 26, 2015, 05:33:35 PM »
Also is your Timer enabled?

doggo

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Modbustcpcom1.read not working in VBA chart component?
« Reply #3 on: February 26, 2015, 06:01:58 PM »
It is. The form runs and the digitalindicators update, I just cant get the chart to update.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Modbustcpcom1.read not working in VBA chart component?
« Reply #4 on: February 26, 2015, 06:06:50 PM »
I would put a breakpoint in that routine and step through the code with F10

doggo

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Modbustcpcom1.read not working in VBA chart component?
« Reply #5 on: February 26, 2015, 06:19:50 PM »
Stepping thru did it. I was able to see the Z1-4 values were actually being read as 10 times their actual value, to eliminate the need for decimal point. So all the values were out of range and the chart doesnt show them.  Dividing by 10 before dispalying on the chart fixed everything.

Thanks!