Problem with writing to PLC
Hi Archie,
I've got a problem with the Ethernet driver that I don't with the DF1Com driver.
I've developed a touchscreen application that is running on Windows XP home, which controls and logs data for a metal loom machine (makes wire mesh).
The program requires the user to log in with their employee code and job number. This then allows them to operate the machine.
If the machine is idle for more than 60 seconds, the machine will switch to locked state, indicated by a pilot light, which then requires the operator to enter a stop reason via a form. Once entered the machine will go into "Machine Ready" state and begin the count up to 60 seconds.
When a lay strike is detected, the timer is reset and the counters increase by one.
In the PLC program (controlled by an ML1100), I am using N7:1 through to N7:10, which the plc uses as the data log integers so I can extract using the data log extract program.
See below for the layout of the screen with the two associated forms:
My original program using the DF1com driver functioned perfectly, but now I have just installed four more of these screens but to be talking to the PLC via the ethernet driver. In my original program, I stole some code out of your ABDF1 program to allow me to write to the PLC using code behind a button.
During testing of the program with the ethernet driver, whenever the login form or the stop reason form is enacted, the program freezes. I have managed to narrow the problem code down to this section below.
When I disable this code the forms have no problem at all (they just can't write to the plc) so I just can't help thinking why the write code that worked for the DF1Com driver does not work for the ethernet driver.
Below is the code for the DF1Com and the Ethernet I used. Very little difference except I changed the driver reference:
Code:
Private Sub Login_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login_Button.Click
If txtOperator.Text = "" Then
MsgBox("Please enter an operator ID!", MsgBoxStyle.Critical, "Error!")
ElseIf txtJobNumber.Text = "" Then
MsgBox("Your Job Number is incorrect!", MsgBoxStyle.Critical, "Error!")
ElseIf txtJobNumber.Text >= 32000 Then
MsgBox("Your Job Number is incorrect!", MsgBoxStyle.Critical, "Error!")
End If
'**************************
'* Write a single element
'**************************
Try
'* Perform the write
'* If its a string then write as string, otherwise write as single value
If txtOperatorAddress.Text.IndexOf("ST") >= 0 Or txtOperatorAddress.Text.IndexOf("st") >= 0 Or txtOperatorAddress.Text.IndexOf("St") >= 0 Or txtOperatorAddress.Text.IndexOf("sT") >= 0 Then
EthernetIPforSLCMicro1.WriteData("N7:2", txtOperator.Text)
Else
EthernetIPforSLCMicro1.WriteData("N7:2", CSng(txtOperator.Text))
End If
ResultError.Text = "Successful Write"
Catch ex As Exception
'* show any errors in status bar
ResultError.Text = ex.Message
End Try
'**************************
'* Write a single element
'**************************
Try
'* Perform the write
'* If its a string then write as string, otherwise write as single value
If txtJobNumberAddress.Text.IndexOf("ST") >= 0 Or txtJobNumberAddress.Text.IndexOf("st") >= 0 Or txtJobNumberAddress.Text.IndexOf("St") >= 0 Or txtJobNumberAddress.Text.IndexOf("sT") >= 0 Then
EthernetIPforSLCMicro1.WriteData("N7:3", txtJobNumber.Text)
Else
EthernetIPforSLCMicro1.WriteData("N7:3", CSng(txtJobNumber.Text))
End If
ResultError.Text = "Successful Write"
Catch ex As Exception
'* show any errors in status bar
ResultError.Text = ex.Message
End Try
MainForm.Label2.Text = EthernetIPforSLCMicro1.ReadAny("N7:2")
MainForm.Label4.Text = EthernetIPforSLCMicro1.ReadAny("N7:3")
txtOperator.Text = ""
txtJobNumber.Text = ""
End Sub
Code:
Private Sub Login_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login_Button.Click
If txtOperator.Text = "" Then
MsgBox("Please enter an operator ID!", MsgBoxStyle.Critical, "Error!")
ElseIf txtJobNumber.Text = "" Then
MsgBox("Your Job Number is incorrect!", MsgBoxStyle.Critical, "Error!")
ElseIf txtJobNumber.Text >= 32000 Then
MsgBox("Your Job Number is incorrect!", MsgBoxStyle.Critical, "Error!")
End If
'**************************
'* Write a single element
'**************************
Try
'* Perform the write
'* If its a string then write as string, otherwise write as single value
If txtOperatorAddress.Text.IndexOf("ST") >= 0 Or txtOperatorAddress.Text.IndexOf("st") >= 0 Or txtOperatorAddress.Text.IndexOf("St") >= 0 Or txtOperatorAddress.Text.IndexOf("sT") >= 0 Then
DF1Comm1.WriteData("N7:2", txtOperator.Text)
Else
DF1Comm1.WriteData("N7:2", CSng(txtOperator.Text))
End If
ResultError.Text = "Successful Write"
Catch ex As Exception
'* show any errors in status bar
ResultError.Text = ex.Message
End Try
'**************************
'* Write a single element
'**************************
Try
'* Perform the write
'* If its a string then write as string, otherwise write as single value
If txtJobNumberAddress.Text.IndexOf("ST") >= 0 Or txtJobNumberAddress.Text.IndexOf("st") >= 0 Or txtJobNumberAddress.Text.IndexOf("St") >= 0 Or txtJobNumberAddress.Text.IndexOf("sT") >= 0 Then
DF1Comm1.WriteData("N7:3", txtJobNumber.Text)
Else
DF1Comm1.WriteData("N7:3", CSng(txtJobNumber.Text))
End If
ResultError.Text = "Successful Write"
Catch ex As Exception
'* show any errors in status bar
ResultError.Text = ex.Message
End Try
MainForm.Label2.Text = DF1Comm1.ReadAny("N7:2")
MainForm.Label4.Text = DF1Comm1.ReadAny("N7:3")
txtOperator.Text = ""
txtJobNumber.Text = ""
End Sub
Similar code is behind the click event of the "OK" button on the Stop Reason Form. Both forms freeze the HMI, both forms work fine when the code is disabled.
What gets me is that the forms freeze before you hit the button, not when you hit the login button.
Lastly, the buttons I have used are normal buttons from VS, not the basic button that comes with AdvancedHMI. Could this be the problem? It shouldn't be because it worked with the DF1Com driver.
I'm hoping you can help me resolve what the problem is, to me it seems logical but it's not working right. There may be a glaring error in the code that I just can't see!
Thanks in advance that you or anyone else put into helping on this!