AdvancedHMI Software
General Category => Support Questions => Topic started by: Cowboy1 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:
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
-
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.
-
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?
-
Insert an Exit Sub above the first line within the sub. That will be the easiest to do.
-
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
-
In your code somewhere are you doing a Modbusxxxx.Read("xxxx")?
-
Archie,
I use that in several places.
-
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
-
Archie,
When I run this code all the data populates and the message box pops up 3 times:
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?
-
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.
-
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?
-
Have you tried using a DataSubscriber instead of a timer? The DataSubscribers are very good with handling continuously updated data.
-
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
-
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 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:
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
-
Private Sub DataSubscriber3_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber3.DataReturned
Me.currentValue = e.values(0)
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
-
Archie,
Thanks for your help with this it works perfectly a lot smoother than the timer I stepped up the poll rate just to see response until I get actually running in the next couple of weeks. I posted the complete code for anybody that might use it for reference in the future.
Private lastValue As Single
Private currentValue As Single
Private vesselFillRate As Single
Private Sub DataSubscriber3_DataReturned(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber3.DataReturned
Me.currentValue = e.values(0)
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