Convert word to ascii

lorenzop
2022-02-23
2022-03-09
  • lorenzop - 2022-02-23

    Hi,
    i'm a bit newby, how can i convert a word to an ASCII?

     
  • krstech

    krstech - 2022-03-09

    1) Install Library UTIL
    2) Use Function(Word_As_String)
    iWord : WORD;
    oString : STRING;
    oString := WORD_AS_STRING(iWord,FALSE);

    See attachment for additional information.
    Hope this is helpful.

    -krstech

     
  • krstech

    krstech - 2022-03-09

    1) Install Library UTIL
    2) Use Function(Word_As_String)
    iWord : WORD;
    oString : STRING;
    oString := WORD_AS_STRING(iWord,FALSE);

    See attachment for additional information.
    Hope this is helpful.

    -krstech

     
    • lorenzop - 2022-03-09

      Thanks a lot, i have a question, I am given a word (example: hello) like Word, how do I convert it to a String? Because if I insert in the converter only one letter at a time in ASCII it converts it, otherwise not

       
  • krstech

    krstech - 2022-03-09

    Here's a snippet i've used for RS232 ASCII comm on one of my application.
    I'm hoping you can extract something useful from it for your requirements.

    It converts the input string "hello" to integer. Play around with it.

    I hope i understand your question.
    Also look into:
    WORD_TO_STRING();
    TO_STRING();

    -krstech.i

    code
    
    PROGRAM RS232_ReadRegisters
    VAR
    
        hexDataString   :   ARRAY[0..15] OF STRING[4];
        readRegister    :   ARRAY[0..15] OF WORD;
    
        i, x            : INT;
        counter : INT   := 8;
    
    END_VAR
    
    
    (* Extract Hex data from Read Response dataString, then convert the hexstring to integer *)
    
    FOR i := 0 TO gvl.PFC200.RS232.numReadReg - 1 BY 1 DO
    
        hexDataString[i] := MID(gvl.PFC200.RS232.dataString,4,counter);         // Extract Hex Data: MID(string,len,pos)
        readRegister[i]  := STRING_TO_WORD(CONCAT('16#',hexDataString[i]));     // Convert Hexstring Data to integer
        counter := counter + 4;
    
    //  gvl.OMRON.to_PFC[i] := readRegister[i];                                 // Point readRegisters for I/O Mapping 
    
        IF i >= gvl.PFC200.RS232.numReadReg - 1 THEN i:=0; counter:=8; EXIT; END_IF;
    END_FOR
    
    
    FOR x := gvl.PFC200.RS232.numReadReg TO 15 BY 1 DO
        hexDataString[x] := ''; 
    END_FOR
    
     

    Last edit: krstech 2022-03-09

Log in to post a comment.