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

Data conversion+

2016-12-29
2017-01-04
  • Kallamamran - 2016-12-29

    Hello,

    I'm a n00b to Codesys programming, so sorry in advance if my question is a bit stupid
    This is probably not a dedicated V3-question, but since I'm working in V3.5 SP8 Patch 1 I guess I should post my question here anyway?!

    I have searched the forum and on the internets without finding the correct information to let me continue with my program.
    I'm reading a number (1-50) from a tag and now I want to take the binary version of that number and output it to 8 outputs (%QX1.0 to 1.7).
    One of the problems is I don't know how to get the boolean values of each bit in the byte to transfer to the output module?

    Any ideas?

     
  • Lo5tNet - 2016-12-29

    It sounds like what you are looking for is on your outputs you would access the tag variable then add .<bitindex> after that variable.</bitindex>

    QX1.0 := Tag.0;
    ......
    QX1.7 := Tag.7;

    Look under help "Programming Reference > Operands > Variables > Addressing bits in variables" to get maybe a better understanding.

     
  • camferti - 2016-12-31

    Kallamamran hat geschrieben:
    Hello,
    I'm a n00b to Codesys programming, so sorry in advance if my question is a bit stupid
    This is probably not a dedicated V3-question, but since I'm working in V3.5 SP8 Patch 1 I guess I should post my question here anyway?!
    I have searched the forum and on the internets without finding the correct information to let me continue with my program.
    I'm reading a number (1-50) from a tag and now I want to take the binary version of that number and output it to 8 outputs (%QX1.0 to 1.7).
    One of the problems is I don't know how to get the boolean values of each bit in the byte to transfer to the output module?
    Any ideas?

    You can also declare individual variables for da bit

    var1 at %ix1.1 :bool;
    In this way you refer to individually bit
    good luck

     
  • Joan M - 2016-12-31

    Never a question is stupid.

    You can do what is suggested before:

    • variable.bit (in certain numeric variable types).
    • Declare a variable for each position (given we are speaking of inputs/outputs that you can address).
    • Create a pointer to an array of bools with the same bit length for that variable and point it to the variable itself.
      ** This last option can be improved if you put that inside a function, you declare the array without limits and pass the address and sizeof of the variable to be examined.

    Hope this helps!

    Happy new year...

     
  • Joan M - 2017-01-04

    I've found another way to do this: you can add the library Util and it's EXTRACT function which allows you to use a variable to specify the position you want from a DWORD, WORD...

    Good luck!

     

Log in to post a comment.