Author Topic: SLC500 String Write  (Read 2024 times)

sds5150

  • Newbie
  • *
  • Posts: 14
    • View Profile
SLC500 String Write
« 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

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SLC500 String Write
« Reply #1 on: March 16, 2016, 11:20:44 PM »
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).

sds5150

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SLC500 String Write
« Reply #2 on: March 17, 2016, 08:21:18 AM »
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

sds5150

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SLC500 String Write
« Reply #3 on: March 17, 2016, 08:53:31 AM »
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.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: SLC500 String Write
« Reply #4 on: March 17, 2016, 09:23:14 AM »
If you put ST9:1 in BOTH the PLCAddressKeypad and PLCAddressValue property, the BasicLabel will show the value and also let you change it.

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SLC500 String Write
« Reply #5 on: March 17, 2016, 10:25:37 AM »
sds5150,

I am a bit confused with the word "password" that you are using.

Can you explain what are you trying to achieve?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: SLC500 String Write
« Reply #6 on: March 17, 2016, 10:32:34 AM »
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):

Code: [Select]
    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.
« Last Edit: March 17, 2016, 11:41:21 AM by Godra »

sds5150

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: SLC500 String Write
« Reply #7 on: March 17, 2016, 01:16:33 PM »
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.