AdvancedHMI Software
General Category => Support Questions => Topic started by: sds5150 on March 16, 2016, 09:53:05 PM
-
I'm new to Advanced HMI as of this week. Very nice.
I have been trying to write a string from a textbox to a SLC500 over ethernet to set up simple user access levels controlled by the PLC.
I started doing some research on the forum. I found a lot of comments about issues in the past versions.
Are there still issues with the new 3.99 version?
Any sample code available?
Thanks
-
Probably the simplest test you can do is use a BasicLabel and set its PLCAddressKeypad and PLCAddressValue properties to the same address.
Once you run the program it should show the current string value of that address in the PLC.
When you click on the label then you can type a new string and write it to a PLC (if everything works fine then the label should show that new string).
-
A basic label does just as you mentioned, it writes to the PLC string location.
Unfortunately, the basiclabel value property seems to determine what shows as text on the label.
I was able to use the following code when the form loads, and get the value from the PLC to display, but it only updates when the form loads.
I guess I am not sure how to get the displayed text continuously update to match the PLC
Dim password As String
password = EthernetIPforSLCMicroCom1.Read("st9:1")
BasicLabel1.Text = password
-
Godra,
I managed to get it working using a time. That was easy.
The only small issue I have is setting the autosize of the box to false.
When I do so, run the application, and click on the label, it minimizes the window to the toolbar at the bottom of my screen.
Not sure why this occurs, seem like a bug-perhaps in the software.
Thank you for your help.
-
If you put ST9:1 in BOTH the PLCAddressKeypad and PLCAddressValue property, the BasicLabel will show the value and also let you change it.
-
sds5150,
I am a bit confused with the word "password" that you are using.
Can you explain what are you trying to achieve?
-
From your 1st post, it appears that you want this label to continuously show the word "Password" and when clicked have a user enter the password which will then be compared to the value stored in the PLC and either grant or deny access depending on whether the password entered was correct.
If this is the case then instead of using BasicLabel just add standard Label to the form and set its properties like this:
AutoSize = False
BackColor = Red
Text = Log In
Then you might add this code to the MainForm (maybe modify it as well):
Private WithEvents passwordForm As New Form
Private WithEvents passwordTextbox As New TextBox
Private flagPassword As Boolean
Private i As Integer
Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.passwordForm.Name = "Password"
Me.passwordForm.Text = "Enter Password"
Me.passwordForm.Size = New Size(220, 53)
Me.passwordForm.StartPosition = Windows.Forms.FormStartPosition.CenterScreen
Me.passwordTextbox.Dock = DockStyle.Fill
Me.passwordTextbox.PasswordChar = "*"
Me.passwordForm.Controls.Add(passwordTextbox)
End Sub
Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
If Me.flagPassword = False Then
Me.passwordForm.ShowDialog()
Me.flagPassword = True
Else
Me.passwordForm.Hide()
Me.flagPassword = False
If Me.Label2.Text = "Log Out" Then
'
'Add code here that will prevent user to access the interface or whatever else you need done
'
End If
End If
End Sub
Private Sub passwordTextbox_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles passwordTextbox.KeyDown
If e.KeyCode = Keys.Enter AndAlso Me.passwordTextbox.Text <> EthernetIPforSLCMicroCom1.Read("st9:1") Then
MessageBox.Show("Incorrect Password!")
Me.passwordTextbox.Text = ""
Me.flagPassword = False
i += 1
'Allow 3 attempts to enter password. If all 3 attempts have incorrect password then disable the label.
If i = 3 Then
Me.Label2.Enabled = False
Me.passwordForm.Hide()
i = 0
End If
Exit Sub
End If
If e.KeyCode = Keys.Enter AndAlso Me.passwordTextbox.Text = EthernetIPforSLCMicroCom1.Read("st9:1") Then
i = 0
MessageBox.Show("Password OK!")
Me.Label2.BackColor = Color.Green
Me.Label2.Text = "Log Out"
Me.passwordForm.Hide()
Me.flagPassword = False
Me.passwordTextbox.Text = ""
'
'Add code here that will allow user to access the interface or whatever else you need done
'
End If
End Sub
You would need to add code where it says.
-
Godra,
When I started attempting to figure this out, I was using a label.
I was attempting to create a storage location for the VB string that needed to be sent to the PLC string location.
So, I declared "password" as a string location....at least I thought that was what I was doing.
I have it working very well now.
I will review the code that was offered also.