Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - seth350

Pages: 1 2 3 [4]
46
Support Questions / Re: Logging to database VB Question
« on: March 24, 2017, 05:27:21 PM »
Dataset: phdataDataSet
Table: Cityph

Hmmm...

I will try that too. It is working using the .Insert command as of now. Just need to figure out why the decimal is not getting to the db.
Perhaps your method will resolve that.


47
Support Questions / Re: Logging to database VB Question
« on: March 24, 2017, 02:22:12 PM »
Got it working Archie. I appreciate the tip!

Much cleaner code and less hassle.

Using the tableadapter .Insert command and passing in the values I want to INSERT is pretty cool. I was going to try using the Query designer to build a query but VS did not like my parameters being undefined.

Code: [Select]
INSERT INTO CityPh (Entry, Cityph)
VALUES (Entry=?, CitypH=?)

Code: [Select]
    Public Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged

        Dim phvalue As Single

        If e.PlcAddress = "Process.Waste_Water_Facility.City.Pit.Ph.Reading" Then
            phvalue = e.Values(0)
            testdisp1.Value = phvalue

        End If



        If phvalue > 0 Then 'Log only if value is healthy.

            CitypHTableAdapter1.Insert(Now.Date, phvalue)

        End If


    End Sub

48
Support Questions / Re: Logging to database VB Question
« on: March 24, 2017, 12:58:52 PM »
Thank you Archie, that is a lot less hassle!

Let me give this a try and see where I end up. I will report back if I get lost.

49
Support Questions / Logging to database VB Question
« on: March 24, 2017, 12:16:54 PM »
Hello folks,

Been cutting my teeth with VB and I am just about down to my gums lol

I have a seemingly simple app using AHMI to connect to a CLGX plc and log a variable to an Access db. Once I have this working, I will expand to more variables.
 
Anyways, I have probably coded down a rabbit hole...
My problem is that it seems the code is not opening the connection to the database, or maybe I don't need to handle the connection in the way I am doing it?

Previously when I tried to run a different set of code, it would connect, log only a few variables, and then I would get an exception stating that the connection to the db was already open. I figured, "Ok, Someway or another the code to open the connection is being ran more than once, so I need to control when to open the connection based on the state of the connection."

And this is what I ended up with... 


Code: [Select]
Public Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged

        Dim phvalue As Single

        If e.PlcAddress = "Process.Waste_Water_Facility.City.Pit.Ph.Reading" Then
            phvalue = e.Values(0)
            testdisp1.Value = phvalue

        End If

        If phvalue > 0 Then 'Log only if value is healthy.

            Dim sqlcmd As String
            Dim objCmd As New OleDb.OleDbCommand
            Dim conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Documents\phdata.accdb")
            Dim connstate As Int16
            Dim dblogstate As Int16 = 1


            If ConnectionState.Closed Then 'Set connstate to 1 if DB Connection is Closed
                connstate = 1

            ElseIf ConnectionState.Connecting Then 'Set connstate to 2 if DB Connection is Connecting
                connstate = 2

            ElseIf ConnectionState.Open Then 'Set connstate to 3 if DB Connection is Connected
                connstate = 3

            End If

            Select Case dblogstate
                Case 1 'Open connection if one does not exist.

                    If connstate = 3 Then
                        dblogstate = 3 'Already connected to db, start logging.

                    ElseIf connstate = 1 Then
                        dblogstate = 2

                    End If

                    dbstatlabel.ForeColor = Color.Gray
                    dbstatlabel.Text = "Not Connected To Database"

                Case 2 'Connect to database

                    Try
                        conn.Open()
                        dbstatlabel.ForeColor = Color.Blue
                        dbstatlabel.Text = "Connecting to Database..."

                    Catch ex As Exce
                        MsgBox(ex.Message)
                        dbstatlabel.ForeColor = Color.Red
                        dbstatlabel.Text = "Database Error!"

                    End Try

                    If connstate = 3 Then 'Connected to database, start logging.
                        dblogstate = 3

                    ElseIf connstate = 2 Then 'Trying to connect to database.
                        dblogstate = 2 'Keep trying to connect.
                        dbstatlabel.ForeColor = Color.Blue
                        dbstatlabel.Text = "Trying to connect to Database..."

                    End If

                Case 3 'Connected to database
                    dbstatlabel.ForeColor = Color.Green
                    dbstatlabel.Text = "Connected to Database"

                    Try
                        sqlcmd = "INSERT INTO CitypH (Cityph) VALUES ('" & phvalue & "')"
                        objCmd = New OleDb.OleDbCommand(sqlcmd, conn) 'Set the command
                        objCmd.ExecuteNonQuery() 'Execute the SQL command

                    Catch ex As Exception
                        MsgBox(ex.Message)
                        dbstatlabel.ForeColor = Color.Red
                        dbstatlabel.Text = "Database Error!"

                    End Try

                Case Else
                    dbstatlabel.ForeColor = Color.Red
                    dbstatlabel.Text = "Program Error!"

            End Select
        End If

    End Sub

50
Open Discussion / Re: SCADA Network Question
« on: October 31, 2016, 06:49:54 AM »
That is what I suspected Archie. The plc network was setup years ago and kind of haphazardly in my opinion.
I will plan on installing our own separate SCADA network and also see what I can do to tame the Ethernet/ip.
I suppose installing a gateway at each machine that filters multicast traffic would help?

51
Open Discussion / SCADA Network Question
« on: October 30, 2016, 09:27:51 PM »
Hello everyone,
First I would like to say thank you Archie for a wonderful HMI!

I am going to be using AdvHMI for our new and first SCADA system.
I myself have never done one but from what I have seen, it is a plant HMI. All plant information in one place so to speak.
My question is how do other people typically setup their plant network? For example, we have a mixed network of two subnets. One is corporate controlled and is the DHCP server for all associate computers. The corporate range is 10.40.X.X. The other is a local network of which all the machines are connected. It's range is 192.168.16.X. There are around 30 machines, each with multiple Ethernet/ip devices. These two networks are connected somewhere that allows traffic to/from either network. Would it be wise to setup another subnet for communication to the SCADA PC? My worry is data collisions using the machine network. How have you guys done it?


Pages: 1 2 3 [4]