+1

Text to integer

Marcel 2 years ago in IQANdesign updated by lbartik 4 months ago 13

Is it possible to convert text to integer? I would like to exchange the serial numbers (Module Diagnostic) of the hardware through the CAN bus. I believe the serial numbers are max 4 bytes in integer(hex) number. If I want to send them as text, I need longer CAN messages (>8 bytes). It will also be easier for the external system (no Parker system) that is supposed to read these values . I use a MD4 and MC41.

+1

If you're using IQAN 5, you can use the JTOUT (J1939 Text Out) channel.  In IQAN 6, there are TPOUT (text parameter out) channels that you can used which add some flexibility.

Thanks for your reply. I know about the TPOUT (I use iQan6), but how to convert the TPOUT to an integer value?

The TPOUT channel will convert the string to ASCII values.  The receiving device would need to convert the ASCII values back to the text.

Ok, but then I need 10 bytes instead of 4 bytes if I can convert it to an integer value. That makes it difficult on the receiving device. Is there no way to convert the text value to an integer value?

Is it the Serial of the IQAN module you want to send over CAN? I think they comes as Real value when using Module Diagnostics. And if you want that number as integer its a matter of rounding it.

The value type of S/N Module diagnostic channel is text. (the MDGN channel has different value type depending on what value you read with it)

Thank you for your replies!

Ok, so there is no way to convert the text value to an integer value? (Or get the serial number as number (integer/real))?

The least effort in the IQAN project is to make use of the J1939 COMPID. When another device sends a request for PGN 65259, the response from the IQAN module will include SN. 

But essentially that is the same as the method Ed suggested, the IQAN module will send a text string in a multi-packet message. 

To convert the text to an integer, you'd need some string handling function. There have been a number of requests for this, see this post here

Ok, thank you Gustav. It's clear now. I have to wait until there is a solution in iQan Design. I voted for your post, so maybe this helps :-).

Gustav, can a "Frame out" be looped back to a "Frame In" on the same Master via the CAN-Bus? Just thinking, If sending as Text and looping it back to Integer parameters the Text will be converted to ASCII values and from there is just a matter doing some math.

I think this classifies as a "Hack" not a proper solution.

Interesting idea for a hack Jonas.. It won't work on the same bus though. To read a frame out sent on one bus, you need to use a second CAN controller (another bus in the system layout) and wire the two together. 

+1

I implemented a 40 character freeform text message on an MD4 which is sent over CAN.  


ALB Ascii tests.idsx

Does anybody see an easier way to do this?


The ascii conversion to integer is very simple to calculate and store in a single array.  Showing the text on the screen while it is being typed is brutally difficult.


The best method I found uses a state machine per character then concatenate them all with a text formatting channel.  There are several factors which combine to make this convoluted and difficult.

  • arrays support real values only
  • array qcode cannot manipulate any text channel types.
  • arrays cannot be used as inputs to other functions, 
  • array data cannot be shown on the screen except as a bar graph
  • There is no way to programmatically step through array indices in a loop to do anything meaningful with text
  • There is no way to programmatically manipulate text other than simple concatenation via text formatting channels
  • Text formatting channels do not support any associated logic, they cannot be erased, they cannot be conditional, etc
  • Self-referencing is not allowed for text formatting channels: i.e. tfc1 := tfc1 + tfc2
  • lookup tables cannot make use of array inputs or text outputs
  • state machine conditions and new states cannot be added or edited quickly in a single text editor, instead we have one editor per state per state machine to click through.  My 42 character keyboard and 40 character text string yields 1680 different states to generate, debug, and curate.  Adding one new character to the keyboard is a massive undertaking.  
  • IQANdesign doesn't support find/replace within state machine qcode
  • IQANdesign source code cannot be edited in plain text with any 3rd party tools
  • A simple switch-case qcode syntax would make state machine implementation a lot cleaner