ASCII to Number Conversion
ASCII to Number Conversion
I have CAN data that is sending numerical data in ASCII format. I wish to display the value using an analog meter in the instrument panel. Is there a way to convert the data from ASCII to an Unsigned data type so that it can be used with an analog meter?
- PEAK-Support
- Sales & Support
- Posts: 1646
- Joined: Fri 10. Sep 2010, 19:34
Re: ASCII to Number Conversion
When you receive via CAN Databytes a "String", you need to convert this by a VB Macro
"ASCII" - every single Byte is one Number - HEX 0x30 to HEX 0x39 ('0' to '9')
If you receive in a Data Byte the Value 0x31, you simply need to sub the Offset of the ASCII Table (0x30) and you have the "real" Number of this Byte. ("1")
If you know on which place the values are stored, you simply coul multiplicate the next numbers with 10, 100, 1000 etc. and build a sum
If you use a internal Signal, your script could use this to store the value, and you could use the internal signal as Input for your user panel instrument.
You also could define a String Signal in the Symbol Editor and use the "SignalName.StringValue" to read the complete String at once.
Then you need to convert the string, for example "1234" to a Int Type and also use a internal Signal to store and use the Value.
"ASCII" - every single Byte is one Number - HEX 0x30 to HEX 0x39 ('0' to '9')
If you receive in a Data Byte the Value 0x31, you simply need to sub the Offset of the ASCII Table (0x30) and you have the "real" Number of this Byte. ("1")
If you know on which place the values are stored, you simply coul multiplicate the next numbers with 10, 100, 1000 etc. and build a sum
If you use a internal Signal, your script could use this to store the value, and you could use the internal signal as Input for your user panel instrument.
You also could define a String Signal in the Symbol Editor and use the "SignalName.StringValue" to read the complete String at once.
Then you need to convert the string, for example "1234" to a Int Type and also use a internal Signal to store and use the Value.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------