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 - lunenburger

Pages: [1]
1
Open Discussion / Re: Driver Siemens with Snap7
« on: May 20, 2021, 07:01:24 AM »
Thank you Godfra and Tatin for the help with this driver..... it is greatly appreciated.

I have been using the ControlLogix driver, and I have been creating the code:

Code: [Select]
Dim BottomMotorSpeed As Integer = EthernetIPforCLXCom1.Read("BottomMotorSpeed")


Is there a comparable function in the Siemens driver to the EthernetIPforCLXCom1.Read?

Or do I have to do something like the following:

Code: [Select]
Dim recipesteps As Integer

        If e.PlcAddress = "MW10" Then
            recipesteps = e.Values(0)
        End If

Thank you again for the help....

2
Open Discussion / Re: Driver Siemens with Snap7
« on: May 11, 2021, 09:33:49 AM »
Actually, I never did figure out how to set snap7.dll copy always.....

If someone could let me know where to set to copy always that would be great...

thank you

3
Open Discussion / Re: Driver Siemens with Snap7
« on: May 11, 2021, 08:48:29 AM »
Hi Godra,
I have it working now.... disregard previous reply

and thanks again for the help!

4
Open Discussion / Re: Driver Siemens with Snap7
« on: May 11, 2021, 07:58:34 AM »
Thank you Godra for the reply.

I am pretty new to .net....
When adding the snap7.dll file to the project, do I do it at the top of the Solution Explorer where it shows My Project with the wrench symbol.
Also, do I add it as a reference or existing item.

And how do I set snap7.dll file to copy always?

Thank you

5
Open Discussion / Re: Driver Siemens with Snap7
« on: May 10, 2021, 03:38:36 PM »
I have followed the instructions, but I am getting the error:

System.DllNotFoundException
  HResult=0x80131524
  Message=Unable to load DLL 'snap7.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
  Source=Snap7.net
  StackTrace:
   at Snap7.S7Client.Cli_Create()
   at Snap7.S7Client..ctor()
   at AdvancedHMIDrivers.SiemensCom.CreateDLLInstance() in C:\Users\christopher.curry\Downloads\AdvancedHMIv399xR1\AdvancedHMIDrivers\SiemensCom.vb:line 110
   at AdvancedHMIDrivers.SiemensCom.PollUpdateTimer_Tick(Object sender, EventArgs e) in C:\Users\christopher.curry\Downloads\AdvancedHMIv399xR1\AdvancedHMIDrivers\SiemensCom.vb:line 638
   at System.Timers.Timer.MyTimerCallback(Object state)

6
That worked beautifully....
Thank you!!
Here is a copy of my new code:

Imports MySql.Data.MySqlClient

Public Class MainForm
    Dim MysqlConn As MySqlConnection
    Dim COMMAND As MySqlCommand

    '*******************************************************************************
    '* Stop polling when the form is not visible in order to reduce communications
    '* Copy this section of code to every new form created
    '*******************************************************************************
    Private NotFirstShow As Boolean

    Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        '* Do not start comms on first show in case it was set to disable in design mode
        If NotFirstShow Then
            AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
        Else
            NotFirstShow = True
        End If
    End Sub

    '***************************************************************
    '* .NET does not close hidden forms, so do it here
    '* to make sure forms are disposed and drivers close
    '***************************************************************
    Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        Dim index As Integer
        While index < My.Application.OpenForms.Count
            If My.Application.OpenForms(index) IsNot Me Then
                My.Application.OpenForms(index).Close()
            End If
            index += 1
        End While
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        MysqlConn = New MySqlConnection
        MysqlConn.ConnectionString = "server=localhost;userid=root;password=Splash123;database=icsdata"

        Try
            mysqlconn.Open()
            MessageBox.Show("Connected")
            mysqlconn.Close()

        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            mysqlconn.Dispose()

        End Try

    End Sub

    Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        Dim mytimestamp As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
        Dim eventcode As Integer

        MysqlConn = New MySqlConnection
        MysqlConn.ConnectionString = "server=localhost;userid=root;password=Splash123;database=icsdata"
        Dim reader As MySqlDataReader

        If e.PlcAddress = "CODICE_EVENTO" Then
            eventcode = e.Values(0)
        End If

        Dim eventcodevalue As Decimal = eventcode

        If eventcodevalue = 10 Then
            Dim jobnumber As String = EthernetIPforCLXCom1.Read("cesti_barcode[0].Lotto")
            Dim report As Decimal = EthernetIPforCLXCom1.Read("N022[40]")
            Dim basket As Decimal = EthernetIPforCLXCom1.Read("N022[40]")
            Dim programname As String = EthernetIPforCLXCom1.Read("Programma[17]")
            Dim programnumber As String = EthernetIPforCLXCom1.Read("N022[0]")
            Dim perator As String = EthernetIPforCLXCom1.Read("cesti_barcode[0].Utente")
            Dim barcode As String = EthernetIPforCLXCom1.Read("cesti_barcode[0].Barcode")
            Dim temperature As Decimal = EthernetIPforCLXCom1.Read("N015[220]")
            Dim total As Decimal = EthernetIPforCLXCom1.Read("N014[61]")
            Dim time1 As Integer = EthernetIPforCLXCom1.Read("N046[1]")
            Dim time2 As Integer = EthernetIPforCLXCom1.Read("N046[21]")
            Dim drip As Integer = EthernetIPforCLXCom1.Read("N046[1]")
            Dim ph As Decimal = EthernetIPforCLXCom1.Read("Ph_V1_2")

            Try
                MysqlConn.Open()
                Dim query As String
                query = "insert into icsdata.run_header (Date,JobNumber,Report,Basket,ProgramName,ProgramNumber,Operator,Barcode,EventCode,Description,Temperature,TotalTime,Time1,Time2,Drip,pH) values ('" & mytimestamp & "','" & jobnumber & "','" & report & "','" & basket & "','" & programname & "','" & programnumber & "','" & perator & "','" & barcode & "','" & eventcode & "','" & "Start Cleaning Tank 1" & "','" & temperature & "','" & total & "','" & time1 & "','" & time2 & "','" & drip & "','" & ph & "')"
                COMMAND = New MySqlCommand(query, MysqlConn)
                reader = COMMAND.ExecuteReader

                MessageBox.Show("Data Saved")

                MysqlConn.Close()

            Catch ex As MySqlException
                MessageBox.Show(ex.Message)
            Finally
                MysqlConn.Dispose()

            End Try
        End If
    End Sub


    Private Sub EthernetIPforCLXCom1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom1.DataReceived

    End Sub

    Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub
End Class

7
Yes, I would like to move some PLC values into the database when a tag called CODICE_EVENTO (it means event code in Italian) equals 10.
But when I use more than one tag in datasubscriber, it sometimes fills zeros into the database where the PLC data should be.
I am not sure how to store the PLC variables into vb.net local variables, would it be an = function like this:

If e.PlcAddress = "CODICE_EVENTO" Then
            eventcode = e.Values(0)
        End If

        Dim eventcodevalue As Decimal = eventcode

Where eventcodevalue would be the local vb.net variable...

8
Hi there,
I am new to using vb.net and i am having trouble finding an example where a PLC tag value triggers an insert instruction to write to a mysql database.
What I am trying to do is write 6 PLC tag values to a mysql database when the compactlogix plc tag "CODICE_EVENTO" equals a value of 10.
I am using DataSubscriber21 to get my PLC data, if i want to write multiple PLC values into a database all at the same time and into the same row, do I need multiple DataSubscribers or can I do it with one?
When I am writing multiple PLC values to mysql, I am getting lots of zeros when there should be a PLC value. Is there a way to set the plc value in vb.net before inserting it into mysql.
Here is the code I have so far:

Imports MySql.Data.MySqlClient

Public Class MainForm
    Dim MysqlConn As MySqlConnection
    Dim COMMAND As MySqlCommand

    '*******************************************************************************
    '* Stop polling when the form is not visible in order to reduce communications
    '* Copy this section of code to every new form created
    '*******************************************************************************
    Private NotFirstShow As Boolean

    Private Sub Form_VisibleChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.VisibleChanged
        '* Do not start comms on first show in case it was set to disable in design mode
        If NotFirstShow Then
            AdvancedHMIDrivers.Utilities.StopComsOnHidden(components, Me)
        Else
            NotFirstShow = True
        End If
    End Sub

    '***************************************************************
    '* .NET does not close hidden forms, so do it here
    '* to make sure forms are disposed and drivers close
    '***************************************************************
    Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
        Dim index As Integer
        While index < My.Application.OpenForms.Count
            If My.Application.OpenForms(index) IsNot Me Then
                My.Application.OpenForms(index).Close()
            End If
            index += 1
        End While
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

        MysqlConn = New MySqlConnection
        MysqlConn.ConnectionString = "server=localhost;userid=root;password=Splash123;database=icsdata"

        Try
            mysqlconn.Open()
            MessageBox.Show("Connected")
            mysqlconn.Close()

        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            mysqlconn.Dispose()

        End Try

    End Sub

    Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        Dim mytimestamp As String = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
        Dim eventcode As Integer

        MysqlConn = New MySqlConnection
        MysqlConn.ConnectionString = "server=localhost;userid=root;password=Splash123;database=icsdata"
        Dim reader As MySqlDataReader

        If e.PlcAddress = "CODICE_EVENTO" Then
            eventcode = e.Values(0)
        End If

        If eventcode = 10 Then
        End If

        Try
            MysqlConn.Open()
            Dim query As String
            query = "insert into icsdata.run_header (Date,EventCode) values ('" & mytimestamp & "','" & eventcode & "')"
            COMMAND = New MySqlCommand(query, MysqlConn)
            reader = COMMAND.ExecuteReader

            MessageBox.Show("Data Saved")

            MysqlConn.Close()

        Catch ex As MySqlException
            MessageBox.Show(ex.Message)
        Finally
            MysqlConn.Dispose()

        End Try
    End Sub


    Private Sub EthernetIPforCLXCom1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles EthernetIPforCLXCom1.DataReceived

    End Sub


End Class



9
Support Questions / Re: Read/write in Mysql DB
« on: December 19, 2018, 10:39:06 AM »
Hi Condore,  Would you still have  a copy of the changes you made to Vitor's code? I am trying to write Controllogix PLC data to a MYSQL Database and it is not connecting.
Any help would be greatly appreciated....

Pages: [1]