Convert Array Of DINT To STRING

ANU
2018-09-19
2023-12-03
  • ANU - 2018-09-19

    hello ,
    I am New In PLC programming And I Need Help.
    I have Array Of DINT Which I want to Convert Into STRING Or ARRAY Of STRING , How Can I Do it ?

    Thanks a Lot
    Anu

     
  • TURCKONE - 2018-09-19

    see its so simple

    no need to use any conversion

    codesys is best for this

    you just define dint variable at some physical address

    define string array on the same address thats it

    e.x Dintarray: array[0..30] of DINT AT %MDW100;
    Dintarray_STRING: array[0..30] of STRING AT %MDW100;

     
  • aliazzz

    aliazzz - 2018-09-19

    Instead you can use a more modern approach via a UNION for this kind of operations as it is meant for this.
    I'd suggest something like the following example;

    TYPE myUnion:
    UNION
    Β  Β  ardiMyArr : ARRAY [0..4] OF DINT; // 16 byte
    Β  Β  sMyString : STRING[16]; // 16 byte
    END_UNION
    END_TYPE
    

    See CODESYS help on UNION datatypes;
    https://help.codesys.com/webapp/_cds_datatype_union;product=codesys;version=3.5.12.0

     
    πŸ‘
    1
    • andras-mozes - 2020-11-16

      Hello!

      The size of ardiMyArr is not 5x4 = 20 bytes?

      Thanks in advance!

       
      πŸ‘
      1
  • Anonymous - 2018-09-20

    Originally created by: ph0010421

    Inside a FOR loop...
    StringArray[i] := DINT_TO_STRING(DintArray[i]);

     
  • Anonymous - 2018-09-21

    Originally created by: rickj

    If you want to convert the numeric value of each DINT array element then use ph0010421's method. If the DINT array contains ascii data then use Aliazzz's method.

     
  • Sangchin - 2023-12-03
     

    Last edit: Sangchin 2023-12-03

Log in to post a comment.