STRING conversions to DWORD

bertcom
6 days ago
2 days ago
  • bertcom - 6 days ago

    Good afternoon.

    I want to communicate with a Domino Industrial Printer using its Codenet protocol.
    The printer wants a series of Hexadecimal characters with no spaces or '00' characters.
    Because of that i chose the option to make the prefix and subfix for my code in a string.
    I have variable data in another string.

    With a complete program of a lot of CONCAT functions i eventually get the format of code that the printer accepts ( tested it with the hercules tool).

    Hercules String : 1B4F513030311B7532626C61636B04

    The problem is : Codesys adds automatically 'code' to the code to show it is a string.

    Codesys string : '1B4F513030311B7532626C61636B04'

    The printer does not understand this. My idea is to convert the string datatype to an LWORD.

    I have no idea how to do this. I random types in STRING_TO_DWORD, as return i get 0. That didn't worked. Also on internet the explenations around string converting in codesys are very limited.

    If there in anyone who can explain me how to do it, i would appreciate it a lot !

    Thank you!

     

    Last edit: bertcom 6 days ago
  • bertcom - 4 days ago

    @trusty-suire,

    The problem is not encoding. The problem is that codesys ands ' ' to the string. And the printer can't handle these character.

     
  • bertcom - 4 days ago

    @trusty-suire,

    The problem is not encoding. The problem is that codesys ands ' ' to the string. And the printer can't handle these character.

     
  • rmaas - 4 days ago

    Hi,

    The '' characters in Codesys are there only to indicate it is a STRING type.
    They are not actually added to the string, maybe you are adding them unintentionally in the concat function?

    You can send your data from Codesys to Hercules to verify...

    Another option is to send the data as an array of bytes instead of a string, with every byte representing 1 ASCII character. https://www.ascii-code.com/
    This way you are 100% sure Codesys is not adding any unwanted characters.

     
  • bertcom - 3 days ago

    Hi rmaas,

    Do you have any explenation how to send it to Hercules?

    Thank you!

     
  • TimvH

    TimvH - 2 days ago

    I guess that the printer expects to receive an array of byte values. So where it is described that it expects to receive:
    Hercules String : 1B4F513030311B7532626C61636B04
    it actually expects to receive an array of bytes with the values 1B,4F,51,30,30, etc.
    So what you can do is create an array of bytes and assign the byte value to each item in the array:

    VAR
        abyToSend : ARRAY[0..99] OF BYTE;
    END_VAR
    
    abyToSend[0] := 16#1B; // ASCII Escape character, hexadecimal representation uses 16# as prefix
    abyToSend[1] := 16#4F; // ASCII 'O'
    abyToSend[2] := 16#51; // ASCII 'Q'
    abyToSend[3] := 16#30; // ASCII '0'
    // you can do the rest yourself
    // maybe could be created a lot smarter, but gives you an indication how to handle this.
    

    Then with the serial communication (or TCP/IP?) you can send a message with the reference to the array (abyToSend) and the number of bytes to send (15 bytes for the string you gave as example).

     

    Related

    Talk.ru: 1
    Talk.ru: 2
    Talk.ru: 3


Log in to post a comment.