6
« on: January 11, 2019, 03:30:54 PM »
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