Author Topic: Form stops running  (Read 3546 times)

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Form stops running
« on: August 25, 2015, 12:11:47 PM »
I created a button on my batch set-up screen that sends text from text boxes and masked text boxes to other forms in my project. For some reason when I click the button 10 seconds later the program errors with PLC connection issue. The project runs fine unless I select this button. Any ideas why this would happen? I know this is in another post but I think I'm suppose to create a new post since it is a different topic and also my late night explanation wasn't that great
Code Below:
Code: [Select]
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        PreCleanScreen.TextBox3.Text = TextBox1.Text
        MainForm.TextBox3.Text = TextBox1.Text
        MashScreen.TextBox3.Text = TextBox1.Text
        SpargeScreen.TextBox3.Text = TextBox1.Text
        BoilScreen.TextBox3.Text = TextBox1.Text
        ChillScreen.TextBox3.Text = TextBox1.Text
        FinishClean.TextBox3.Text = TextBox1.Text
        PreCleanScreen.TextBox1.Text = TextBox2.Text & " Gallons"
        MainForm.TextBox1.Text = TextBox2.Text & " Gallons"
        MashScreen.TextBox1.Text = TextBox2.Text & " Gallons"
        SpargeScreen.TextBox1.Text = TextBox2.Text & " Gallons"
        BoilScreen.TextBox1.Text = TextBox2.Text & " Gallons"
        ChillScreen.TextBox1.Text = TextBox2.Text & " Gallons"
        FinishClean.TextBox1.Text = TextBox2.Text & " Gallons"
        PreCleanScreen.TextBox2.Text = DateTimePicker1.Text
        BoilScreen.Label41.Text = TextBox49.Text
        BoilScreen.Label51.Text = MaskedTextBox1.Text
        BoilScreen.Label61.Text = TextBox50.Text

    End

Any Help would be appreciated.

Thanks,

David

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form stops running
« Reply #1 on: August 25, 2015, 12:43:59 PM »
There is nothing that you are doing in your click event handler that should cause any problems. Can you comment all of the code out in that event and see if it still does it. If it stops, then begin uncommenting each line one at a time to see if you can narrow it down to one particular line.

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Form stops running
« Reply #2 on: August 25, 2015, 01:35:01 PM »
There is nothing that you are doing in your click event handler that should cause any problems. Can you comment all of the code out in that event and see if it still does it. If it stops, then begin uncommenting each line one at a time to see if you can narrow it down to one particular line.

Archie,


How do I exclude the code? Do I delete it and paste it back in or is there a way to exclude it?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form stops running
« Reply #3 on: August 25, 2015, 02:04:32 PM »
Insert an Exit Sub above the first line within the sub. That will be the easiest to do.

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Form stops running
« Reply #4 on: August 25, 2015, 05:30:14 PM »
Archie,


I found the line where the error occurs, I'm just not sure what to do:
If I put Exit Sub before: ChillScreen.TextBox3.Text = TextBox1.Text it works if I do it after I get this error:

Update: If I go to each screen and open them up and let all the devices load then I can run the code without error? Is there anything I can do to workaround this or have done something wrong?

Thanks,

David
« Last Edit: August 25, 2015, 06:35:53 PM by Cowboy1 »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form stops running
« Reply #5 on: August 25, 2015, 06:38:39 PM »
In your code somewhere are you doing a Modbusxxxx.Read("xxxx")?

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Form stops running
« Reply #6 on: August 25, 2015, 10:55:07 PM »
Archie,

I use that in several places.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form stops running
« Reply #7 on: August 26, 2015, 04:38:42 AM »
Be sure to wrap your reads in a try catch:

Try
  Modbusxxx.Read("xxx")
Catch ex as exception
  '* Do something here if the read fails
End Try

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Form stops running
« Reply #8 on: August 26, 2015, 06:04:43 PM »
Archie,



When I run this code all the data populates and the message box pops up 3 times:

Code: [Select]
Private lastValue As Single
    Private currentValue As Single
    Private vesselFillRate As Single
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Try
            Me.currentValue = Me.ModbusRTUCom1.Read("404116") '<---- This line will depend on your driver and tag for D19 register
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show("All data exported successfully", "Data Export Complete!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
        End Try
        vesselFillRate = (Me.currentValue - Me.lastValue) * 60
        Me.BasicLabel4.Value = vesselFillRate 'This you could change to CInt(vesselFillRate) to get round value
        Me.lastValue = Me.currentValue
    End Sub



Do you see any problem that could cause or just annoyance?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form stops running
« Reply #9 on: August 26, 2015, 07:03:21 PM »
What is the interval on your timer? For some reason you are not getting a response every time. Possibly sending requests faster than the device can process responses.

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Form stops running
« Reply #10 on: August 26, 2015, 07:16:38 PM »
Timer is set to 1000 I have changed it to 10000 and it has stopped. I will see how that works for getting a flow rate not sure if a 10 second read is to long of a interval?
« Last Edit: August 26, 2015, 07:31:47 PM by Cowboy1 »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form stops running
« Reply #11 on: August 26, 2015, 07:45:37 PM »
Have you tried using a DataSubscriber instead of a timer? The DataSubscribers are very good with handling continuously updated data.

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Form stops running
« Reply #12 on: August 26, 2015, 08:00:31 PM »
I used the timer to set a interval between readings to get a rate of flow. I want to measure the level of increase at a set interval from a analog level transmitter I think 10 seconds will work, my flow rate will be very slow like .35 quarts per minute to 1 quart per minute max. So I might not see any change on the transmitter in a 1 second measurement. Now that I think about I won't see any change I may have to go longer than the 10 I have it at now, this may have saved me when I go to testing and can't figure out why I have a zero flow reading. If you know of another more reliable way to get a flow rate I'm open to all suggestions this is my rookie project so I'm winging it.

Thanks,

David

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Form stops running
« Reply #13 on: August 26, 2015, 08:57:27 PM »
I never tried to do a flow calculation using the HMI. I always do things like that in the PLC where the timers are more deterministic than in Windows. Using a DataSubscriber will probably give you a more consistent update rate. Do this to control the update rate of the DataSubscriber:

- Copy and paste your driver instance
- On the driver instance copy, set the PollRateOverride to 10000
- Add a DataSubscriber and set the ComComponent to the 2nd driver instance
- Select the DataSubscriber and go to the Properties Windows
- You will see a Lightening bolt icon in the Properties Window, select that to show events
- Double Click in the area to the right of DataReturned so it takes you back to the code
- Insert your code

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Form stops running
« Reply #14 on: August 26, 2015, 10:21:04 PM »
I never tried to do a flow calculation using the HMI. I always do things like that in the PLC where the timers are more deterministic than in Windows. Using a DataSubscriber will probably give you a more consistent update rate. Do this to control the update rate of the DataSubscriber:

- Copy and paste your driver instance
- On the driver instance copy, set the PollRateOverride to 10000
- Add a DataSubscriber and set the ComComponent to the 2nd driver instance
- Select the DataSubscriber and go to the Properties Windows
- You will see a Lightening bolt icon in the Properties Window, select that to show events
- Double Click in the area to the right of DataReturned so it takes you back to the code
- Insert your code

I have completed the above instructions but don't seem to be getting a response. Here is the code I'm trying to use for flow rate I basically removed it from the timer tick and pasted it in datasubscriber3 the poll rate on datasubscriber3 is zero and 10000 on the ModbusRTUDriver2:

Code: [Select]
Private Sub DataSubscriber3_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber3.DataReturned
        Me.currentValue = Me.ModbusRTUCom1.Read("404116") '<---- This line will depend on your driver and tag for D19 register
        vesselFillRate = (Me.currentValue - Me.lastValue) * 6
        Me.BasicLabel4.Value = vesselFillRate 'This you could change to CInt(vesselFillRate) to get round value
        Me.lastValue = Me.currentValue
    End Sub


End Class

I really appreciate the time you are taking to help me, I'm pretty lost but coming to the end and it seems like the last bit of anything is the hardest.


Thanks,

David