Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

mapping array or string

sundog
2016-09-09
2017-05-30
  • sundog - 2016-09-09

    Newbie to all of this. Working with Microscan ID-40 using EtherNet/IP to CodeSys Control Win.

    The ID-40 is a barcode scanner and puts the ascii barcode string into 64 bytes in the T->O stream.

    The provided EDS file (connection) defines symbol_str64 at %IB20 as BYTE of length 512 bits. I cannot figure out how to map this to an array of bytes in ST or CodeSys Editors. Whatever I do populates only the first byte in the array, the remainder are left as zero bytes.

    If I create a generic connection of pure bytes, I can map (by hand) location 20 to array[1], location 21 to array[2],...

    At that point I can convert the array of bytes to a string in ST, and do a %s visualization of the string. Works great, but tedious.

    I poked around the forum a bit and found the 'AT' option, so I tried:

    but that did not do what I wished for. Still only the first byte is transferred.

    I saw some posts referring to ARRAY of BYTE definitions in assemblies, but I cannot figure out how to add such a Data Type to a generic input assembly.

    Is there a way to do this sort of mapping?

     

    Related

    Talk.ru: 1
    Talk.ru: 2

  • jere - 2016-09-09

    Edit: well it wasn't actually the same as you were talking about. I read your post hastily. But as of copying bytes, I'm wondering the same thing. I guess the only thing is to do a FOR that copies the bytes one by one.

    Funny that I have just figured a way to do this and logged in here to ask if there's any better way.

    My current solution is to define a pointer to an array of bytes and then ask for the address of the string and assign it to the pointer. Then you can access the content of the pointer to get to the array of bytes. Seems to work, but I suspect there might be something more to this and this might not be the safest way to do this.

    Anyway, declarations:
    text :STRING(20);
    pointer_to_text :POINTER TO ARRAY[1..20] OF BYTE;

    then:
    pointer_to_text := ADR(text);
    and then you can access
    byte_at_i := pointer_to_text^[i];

    Seems to work, but I'd like any comments or suggestions on how to do this better.

     
  • shooter - 2016-09-10

    get yourself the library of w www.oscat.de w , it handles with this type of copy.

    you can not structure input bytes/words, same for any type of hardware bytes, however you can point to a structure.

     
  • nothinrandom - 2017-05-28

    @sundog

    Are you able to figure out this issue? I'm running into the same issue as well with EthernNet/IP devices since you can't create a structure or arrays of data.

     
  • nothinrandom - 2017-05-30

    @sundog,

    In case you're still looking, another post had the answer ( l viewtopic.php?f=11&t=7861 l ). Change your code to:

    code AT %IB20 : ARRAY[1..64] OF BYTE;

     

Log in to post a comment.