ASCII to Number Conversion

Professional Windows® software to communicate with CAN and CAN FD busses and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
Post Reply
SDOHFE
Posts: 4
Joined: Fri 16. Sep 2022, 22:42

ASCII to Number Conversion

Post by SDOHFE » Thu 22. Sep 2022, 05:30

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?

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: ASCII to Number Conversion

Post by PEAK-Support » Thu 22. Sep 2022, 10:40

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.
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Post Reply