AdvancedHMI Software
General Category => Support Questions => Topic started by: bkane on February 07, 2018, 05:14:30 PM
-
Hello,
I am trying to read a value from my CCW program that is a time. (T#1s) Is there a way to output this entire string using a basic label or another type of label? I've tried and gotten the output "e8030000". I understand this is a problem probably stemming from trying to read/write different data types but was hoping there was a way around it.
Thanks
-
See if this is of any help: http://advancedhmi.com/forum/index.php?PHPSESSID=4dcb8a15b2f98e5a2ed5a48ff5698f3c&topic=1973.0
-
I think this is definitely on the right track but unfortunately it did not work. But it may not work because maybe the data I am reading isn't a string? In CCW it's designated as a "time." For example, whenever I edit this time and set it to 1000 through the hmi I get an output of e803000 which definitely isn't 1000 in hex. Is there a way to read a time value from CCW? Since it seems it isn't a string.
Thanks
-
The driver is returning a hex encoded byte stream because it doesn't recognize the data type being reported by the PLC. You will need to parse the data and convert it to the type you want. The code would be similar to this:
Private Function ExtractINT(ByVal s As String) As integer
Dim bytes((s.Length / 2) - 1) As Byte
For i = 0 To (s.Length / 2) - 1
bytes(i) = Byte.Parse(s.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber)
Next
Dim Result As Integer = BitConverter.ToInt32(bytes)
Return Result
End Function
I typed that code from memory and did not test it, so it may not be 100% correct.
-
I had to include the index value in the ToInt32 function. In case someone ever has a similar issue this was the correct code. But Archie was 99% correct.
Private Function ExtractINT(ByVal s As String) As Integer
Dim bytes((s.Length / 2) - 1) As Byte
For i = 0 To (s.Length / 2) - 1
bytes(i) = Byte.Parse(s.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber)
Next
Dim Result As Integer = BitConverter.ToInt32(bytes, 0)
Return Result
End Function