Author Topic: DataSubscriber2  (Read 6204 times)

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
DataSubscriber2
« on: August 05, 2015, 11:30:01 PM »
Could someone help me with DataSubscriber2 or another block that would work for this? On one form I have 12 addresses I want to monitor and if any of the 12 go true I want the appropriate message displayed.
Example:

If ModbusRTU address 40000 = "True" then
Msg "Start countdown timer dough-in temperature reached"vbExclimation + vbokonly
When I click ok it set ModbusRTU address 420000 true
End if

If ModbusRTU address 40001 = "true" then
Msg "Start countdown timer Acid Rest temperature reached"vbExclimation + vbokonly
When I click ok it set ModbusRTU address 420001 true
End if


And so on.
I'm still learning the functions of this program and not sure exactly how to make this work or the correct code. If there is a better way to accomplish this please let me know. I would also like add a audible alarm if possible to these messages, just to get my attention I'm not in front of the screen.

Any help would be greatly appreciated

Thanks,

David

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: DataSubscriber2
« Reply #1 on: August 06, 2015, 11:20:17 AM »
The 4xxxx series of addresses are signed integers, so you would have to check for not being 0.

- Add a DataSubscriber2 to your form.
- Go to PLCAddressValueItems and click the button with the 3 dots to open the dialog
- In that dialog window click the Add Button
- Set PLCAddressValue to the first address (e.g. 40001)
- Repeat for each address
- Double-Click the DataSubscriber you added to the form
- Add this code and repeat the If-Then block for each address you added in the items above:

        If e.PlcAddress = "40001" Then
            If e.Values(0) <> 0 Then
                System.Windows.Forms.MessageBox.Show("My first address of 40001 is not 0")
            End If
        End If

        If e.PlcAddress = "40002" Then
            If e.Values(0) <> 0 Then
                System.Windows.Forms.MessageBox.Show("The address of 40002 is not 0")
            End If
        End If
« Last Edit: August 07, 2015, 07:18:02 AM by Archie »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: DataSubscriber2
« Reply #2 on: August 06, 2015, 10:19:49 PM »
I guess it's a typo, what Archie meant was to "Double click the DataSubscriber you added to the form" and enter all the code in the sub.

Additional piece of code could be similar to this:

Code: [Select]
        If e.PlcAddress = "40001" Then
            If e.Values(0) <> 0 Then
                System.Windows.Forms.MessageBox.Show("My first address of 40001 is not 0", "Address 40001", MessageBoxButtons.OK)
                If MessageBoxButtons.OK Then Me.ModbusRTUCom1.Write("420000", "1")
            End If
        End If
« Last Edit: August 06, 2015, 10:29:57 PM by Godra »

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: DataSubscriber2
« Reply #3 on: August 06, 2015, 10:55:09 PM »
The 4xxxx series of addresses are signed integers, so you would have to check for not being 0.

- Add a DataSubscriber2 to your form.
- Go to PLCAddressValueItems and click the button with the 3 dots to open the dialog
- In that dialog window click the Add Button
- Set PLCAddressValue to the first address (e.g. 40001)
- Repeat for each address
- Double the DataSubscriber you added to the form
- Add this code and repeat the If-Then block for each address you added in the items above:

        If e.PlcAddress = "40001" Then
            If e.Values(0) <> 0 Then
                System.Windows.Forms.MessageBox.Show("My first address of 40001 is not 0")
            End If
        End If

        If e.PlcAddress = "40002" Then
            If e.Values(0) <> 0 Then
                System.Windows.Forms.MessageBox.Show("The address of 40002 is not 0")
            End If
        End If


Archie,

Thanks for your help it worked great. I had to use: MsgBox(" My message",vbExclimation + vbOkOnly) to get message box for some reason when I hit build VS had issues with "show" I will post code tomorrow after I try the portion of code Godra posted below for the OK button to write to a address. I will use this to start countdown timers when temperature set points are reached. I'm sure this could be automated but I still want some level of control.
Thanks for your help

 
« Last Edit: August 06, 2015, 10:58:45 PM by Cowboy1 »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: DataSubscriber2
« Reply #4 on: August 06, 2015, 11:23:55 PM »
MessageBox and MsgBox are different.

"Show" can only appear after the MessageBox and responses seem to be different as well:

- For MessageBox you can try the code I posted <-- Edit:  Better check the next post
- For MsgBox it should be like this: If MsgBoxResult.Ok then Me.ModbusRTU.Write("420000", "1)
« Last Edit: August 07, 2015, 12:24:24 AM by Godra »

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: DataSubscriber2
« Reply #5 on: August 06, 2015, 11:35:42 PM »
Just checked on the internet and it seems that for MessageBox you might need to do things a bit differently.

Here is an example:

http://www.dreamincode.net/forums/topic/178239-message-box-result/

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: DataSubscriber2
« Reply #6 on: August 06, 2015, 11:42:17 PM »
MessageBox and MsgBox are different.

"Show" can only appear after the MessageBox and responses seem to be different as well:

- For MessageBox you can try the code I posted
- For MsgBox it should be like this: If MsgBoxResult.Ok then Me.ModbusRTU.Write("420000", "1)


Godra,

Thanks for the information. I will try this out tomorrow. For learning purpose what are the differences in the 2 message boxes? Is message box show capable of customized message box with exclamation and stuff like that? I have done a little VBA in excel this is the first VB.NET.

Thanks

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: DataSubscriber2
« Reply #7 on: August 07, 2015, 12:20:20 AM »
If you do find time then read these 2 links:

https://msdn.microsoft.com/en-us/library/139z2azd(v=vs.90).aspx  <-- MsgBox Function

https://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox(v=vs.110).aspx  <-- MessageBox Class

The MsgBox appears to be Function that you can call directly and include parameters.
The MessageBox is a class and you have to call its method "Show". Different parameters can be used with this method (which shows in the link).

For either one you have to follow the syntax as the Visual Studio presents it to you while typing but could omit "Optional" ones. The syntax can be offered in different formats, which I think are called overloads. Check the attached picture which shows examples for both message boxes.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: DataSubscriber2
« Reply #8 on: August 07, 2015, 07:38:31 AM »
The main reason I encourage the use of MessageBox over MsgBox is for better chances of cross platform compatibility. When running AdvancedHMI on another, system such as Linux or iOS, you will need to use Mono. MsgBox is supported by the Microsoft.VisualBasic namespace and MessageBox is a class in the System.Windows.Forms namespace. Although Mono does support the Microsoft.VisualBasic classes, I find that it is not as well refined and some systems require a little extra effort to get it to install.

By avoiding the use of things that require the use of Microsoft.VisualBasic will ensure a better chance for cross platform use and it will also convert cleaner to C# if you ever migrate from VB to C#.

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: DataSubscriber2
« Reply #9 on: August 07, 2015, 08:33:52 AM »
The main reason I encourage the use of MessageBox over MsgBox is for better chances of cross platform compatibility. When running AdvancedHMI on another, system such as Linux or iOS, you will need to use Mono. MsgBox is supported by the Microsoft.VisualBasic namespace and MessageBox is a class in the System.Windows.Forms namespace. Although Mono does support the Microsoft.VisualBasic classes, I find that it is not as well refined and some systems require a little extra effort to get it to install.

By avoiding the use of things that require the use of Microsoft.VisualBasic will ensure a better chance for cross platform use and it will also convert cleaner to C# if you ever migrate from VB to C#.

Ok I understand, well a bit anyway : )

1.) So is Message box customizable like the caption and the Icon in the box? 
It is no big deal if not I just like the appearance, it has nothing to do with functionality.

2.) Can I attach a alarm to the MessageBox like a trainhorn.wav?

3.) Are there any good tutorials or write-ups on MessageBox .Show and features, that would be great!

Thanks for everybody's help with this project I may be completed with the programming this weekend.
At least as far as I can go until scaling and water batching.
Hopefully I will be done wiring the panels by the end of the month. I will post some pictures after it is up and running.

4.)Oh 1 last question what do you recommend to use for adjusting PID Integral and Differential gain on the fly?
I would like to use something small I need it to set my boil properly. The other 11 PIDs will run in auto mode.

Thanks,

David

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: DataSubscriber2
« Reply #10 on: August 07, 2015, 08:50:37 AM »
Scroll to the bot up of this page for examples of MessageBox:

http://www.thevbprogrammer.com/VBNET_08/08-00A-Msgbox.htm

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: DataSubscriber2
« Reply #11 on: August 07, 2015, 08:56:39 AM »
If you do find time then read these 2 links:

https://msdn.microsoft.com/en-us/library/139z2azd(v=vs.90).aspx  <-- MsgBox Function

https://msdn.microsoft.com/en-us/library/system.windows.forms.messagebox(v=vs.110).aspx  <-- MessageBox Class

The MsgBox appears to be Function that you can call directly and include parameters.
The MessageBox is a class and you have to call its method "Show". Different parameters can be used with this method (which shows in the link).

For either one you have to follow the syntax as the Visual Studio presents it to you while typing but could omit "Optional" ones. The syntax can be offered in different formats, which I think are called overloads. Check the attached picture which shows examples for both message boxes.

Godra,


Sorry not sure how I missed this post may have been put up while I was writing my last post. I think this answers questions 1 and 3. I like the ability to arrow down and select the type of message box you want, that is helpful when learning. Thanks for your time and answers to my questions. I will be trying the message box ok write to a Modbus address tonight and let you know how it turns out.

Thanks,

David

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: DataSubscriber2
« Reply #12 on: August 07, 2015, 09:05:09 AM »
Scroll to the bot up of this page for examples of MessageBox:

http://www.thevbprogrammer.com/VBNET_08/08-00A-Msgbox.htm

Thanks great information on MessageBox exactly what I need.

Cowboy1

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: DataSubscriber2
« Reply #13 on: August 16, 2015, 08:28:51 PM »
I finally got to work with the message box code and writing to PLC addresses and it works great. Here is the code I used. I know I still have to change my MsgBox To MessageBox show but I originally had some issues with the use of message box.

Code: [Select]
[/Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        If e.PlcAddress = "002575" Then
            If e.Values(0) = True Then
                TextBox4.Text = "! Open Manual Valve From HXTo The MLT !"
                TextBox4.BackColor = Color.Red
            End If
            If e.Values(0) = "True" Then
                MsgBox("Open Manual Valve From HX To MLT", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
            End If
        End If

        If e.PlcAddress = "003585" Then
            If e.Values(0) = True Then
                TextBox4.Text = "! Dough-In Complete !"
                TextBox4.BackColor = Color.Red
            End If
            If e.Values(0) = "True" Then
                MsgBox("Dough-In Complete, Reset Dough-In Alarm", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
            End If
            If MsgBoxResult.Ok Then
                Me.ModbusRTUCom1.Write("047522", "1")
            End If
        End If



        If e.PlcAddress = "003586" Then
            If e.Values(0) = True Then
                TextBox4.Text = "! Acid Rest Complete !"
                TextBox4.BackColor = Color.Red
            End If
            If e.Values(0) = "True" Then
                MsgBox("Acid Rest Complete, Reset Acid Rest Alarm", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
            End If
            If MsgBoxResult.Ok Then
                Me.ModbusRTUCom1.Write("047524", "1")
            End If
        End If


        If e.PlcAddress = "003587" Then
            If e.Values(0) = True Then
                TextBox4.Text = "! Protein Rest Complete !"
                TextBox4.BackColor = Color.Red
            End If
            If e.Values(0) = "True" Then
                MsgBox("Protein Rest Complete, Reset Protein Rest Alarm", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
            End If
            If MsgBoxResult.Ok Then
                Me.ModbusRTUCom1.Write("047526", "1")
            End If
        End If


        If e.PlcAddress = "003588" Then
            If e.Values(0) = True Then
                TextBox4.Text = "! Beta Rest Complete !"
                TextBox4.BackColor = Color.Red
            End If
            If e.Values(0) = "True" Then
                MsgBox("Beta Rest Complete, Reset Beta Rest Alarm", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
            End If
            If MsgBoxResult.Ok Then
                Me.ModbusRTUCom1.Write("047528", "1")
            End If
        End If

        Dim CC As DialogResult
        If e.PlcAddress = "003589" Then
            If e.Values(0) = True Then
                TextBox4.Text = "! Perform Iodine Test !"
                TextBox4.BackColor = Color.Red
            End If
            If e.Values(0) = "True" Then
                CC = System.Windows.Forms.MessageBox.Show("Perform Iodine Test On The Mash Is Conversion Complete?", "Conversion Complete?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                If CC = Windows.Forms.DialogResult.Yes Then
                    MsgBox("Saccharification Rest Complete, Reset Saccharification Rest Alarm", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
                    If MsgBoxResult.Ok Then
                        Me.ModbusRTUCom1.Write("047530", "1")
                    End If
                End If
                If CC = Windows.Forms.DialogResult.No Then
                    MsgBox("Add 10 Minutes to Saccharification Rest Timer", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
                    If MsgBoxResult.Ok Then
                        Me.ModbusRTUCom1.Write("047529", "0")
                        Me.ModbusRTUCom1.Write("045747", "1")
                        Me.ModbusRTUCom1.Write("003589", "0")
                        Me.ModbusRTUCom1.Write("047530", "0")
                    End If
                End If
            End If
        End If


        If e.PlcAddress = "003590" Then
            If e.Values(0) = True Then
                TextBox4.Text = "! Mash-Out Complete !"
                TextBox4.BackColor = Color.Red
            End If
            If e.Values(0) = "True" Then
                MsgBox("Mash-Out Complete, Reset Mash-Out Alarm", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly)
            End If
            If MsgBoxResult.Ok Then
                Me.ModbusRTUCom1.Write("047532", "1")
                Timer1.Stop()
            End If
        End If

    End Subcode]

Thanks for the help.