AdvancedHMI Software

General Category => Support Questions => Topic started by: moxleyh2 on January 16, 2023, 12:17:33 PM

Title: How to display a series of sints from a AB plc as a message in advanced hmi.
Post by: moxleyh2 on January 16, 2023, 12:17:33 PM
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?
Title: Re: How to display a series of sints from a AB plc as a message in advanced hmi.
Post by: Archie on January 16, 2023, 01:13:24 PM
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
Title: Re: How to display a series of sints from a AB plc as a message in advanced hmi.
Post by: moxleyh2 on January 16, 2023, 01:47:58 PM
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
Title: Re: How to display a series of sints from a AB plc as a message in advanced hmi.
Post by: Archie on January 16, 2023, 02:48:57 PM
You are on the event handler for the Label. You want the event handler for the DataSubscriber. Double click the DataSubscriber2, not the Label
Title: Re: How to display a series of sints from a AB plc as a message in advanced hmi.
Post by: moxleyh2 on January 16, 2023, 03:04:53 PM
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
Title: Re: How to display a series of sints from a AB plc as a message in advanced hmi.
Post by: Archie on January 16, 2023, 03:09:13 PM
Did you include the first line of code:

MyStringLabel.Text = ""
Title: Re: How to display a series of sints from a AB plc as a message in advanced hmi.
Post by: moxleyh2 on January 16, 2023, 03:25:18 PM
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
Title: Re: How to display a series of sints from a AB plc as a message in advanced hmi.
Post by: Archie on January 16, 2023, 03:48:30 PM
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.
Title: Re: How to display a series of sints from a AB plc as a message in advanced hmi.
Post by: moxleyh2 on January 16, 2023, 03:53:58 PM
That worked, thank you so much!