AdvancedHMI Software
General Category => Support Questions => Topic started 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?
-
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:
MyStringLabel.Text = ""
For i = 0 To e.Values.Count - 1
MyStringLabel.Text &= Convert.ToChar(e.Values(i))
Next
-
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
-
You are on the event handler for the Label. You want the event handler for the DataSubscriber. Double click the DataSubscriber2, not the Label
-
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
-
Did you include the first line of code:
MyStringLabel.Text = ""
-
Yes I included it.
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
-
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.
-
That worked, thank you so much!