Author Topic: How to display a series of sints from a AB plc as a message in advanced hmi.  (Read 1424 times)

moxleyh2

  • Newbie
  • *
  • Posts: 7
    • View Profile
I'm trying to output what my barcode reader sends to the PLC on the display of advanced HMI. Currently the plc recieved the barcode string as a series of sints with each sint being a letter or number in ascii. What tool should I add to my hmi program to display this barcode?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
You will need to write a couple lines of code to convert from an array to strings.

- Add a DataSubscriber2 to the form.
- Go to PLCAddressValueItems and add an item. Set the PLCAddress to the first element of your array (e.g. MyArray[0])
- Set Number of Elements
- Add a Label to the form from the All Windows Forms group in the ToolBox
- Change the Name of the Label to MyStringLabel
- Double Click the DataSubscriber2 to get back to the code
- Add this code:

Code: [Select]
        MyStringLabel.Text = ""
        For i = 0 To e.Values.Count - 1
            MyStringLabel.Text &= Convert.ToChar(e.Values(i))
        Next
« Last Edit: January 16, 2023, 01:17:27 PM by Archie »

moxleyh2

  • Newbie
  • *
  • Posts: 7
    • View Profile
Thanks for the response! I've tried the solution but the build keeps failing. It says that events is not a part of of Event.Args. Do I need to change these values in the code you sent me? Here is how I have the code at the end

Private Sub MyStringLabel_Click(sender As Object, e As EventArgs) Handles MyStringLabel.Click
        For i = 0 To e.Values.Count - 1
            MyStringLabel.Text &= Convert.ToChar(e.Values(i))
        Next
    End Sub
End Class

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
You are on the event handler for the Label. You want the event handler for the DataSubscriber. Double click the DataSubscriber2, not the Label

moxleyh2

  • Newbie
  • *
  • Posts: 7
    • View Profile
Now the program is throwing this error message at me.


  Message=String must be exactly one character long.
  Source=mscorlib
  StackTrace:
   at System.Convert.ToChar(String value, IFormatProvider provider)
   at System.Convert.ToChar(String value)
   
  This exception was originally thrown at this call stack:
    [External Code]
    MfgControl.AdvancedHMI.MainForm.DataSubscriber21_DataChanged(Object, MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs) in MainForm.vb
    AdvancedHMIControls.DataSubscriber2.DataChangedSync(Object) in DataSubscriber2.vb

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
Did you include the first line of code:

MyStringLabel.Text = ""

moxleyh2

  • Newbie
  • *
  • Posts: 7
    • View Profile
Yes I included it.

Code: [Select]
Private Sub DataSubscriber21_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber21.DataChanged
        MyStringLabel.Text = ""
        For i = 0 To e.Values.Count - 1
            MyStringLabel.Text &= Convert.ToChar(e.Values(i))
        Next
    End Sub

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
I missed a detail

            Label11.Text &= Convert.ToChar(CUInt(e.Values(i)))

Sorry about that. I type out the code without testing it, so I will sometimes miss a detail.

moxleyh2

  • Newbie
  • *
  • Posts: 7
    • View Profile
That worked, thank you so much!