the following code give me the following error "access requires a literal or an integer symbolic constant"
  PROGRAMPLC_PRG    VAR    my_word    :DWORD;    scan_bit    :INT;    test      :BOOL;  END_VAR
  FORscan_bit:=0TO24BY1DO
 Â
    IF(my_word.my_word)THEN
      test :=TRUE;
    ELSE
      test :=FALSE;
    END_IF   Â
  END_FOR   Â
     Â
Is there a solution to do it?
Thank you for help
Luca
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
JAPIB hat geschrieben:
I'm sory, I don't understand this : "IF(my_word.my_word)..."
I think you wanted to write "IF(my_word. scan_bit)..."
To my knowledge you can't use a variable to acces a bit of a word (it is the same with SINT, INT, DINT, USINT, UDINT, BYTE, WORD, DWORD)
To acces to a bit of a word you can only use :
- a value, for example you can test (or write ) "my_word.2" or "my_word.5" ...
- a Global Constant
VAR_GLOBAL CONSTANT
Indice:INT:=2;
END_VAR
And you can test (or write ) "my_word.Indice"
Hi to all,
the following code give me the following error "access requires a literal or an integer symbolic constant"
Is there a solution to do it?
Thank you for help
Luca
I'm sory, I don't understand this : "IF(my_word.my_word)..."
I think you wanted to write "IF(my_word. scan_bit)..."
To my knowledge you can't use a variable to acces a bit of a word (it is the same with SINT, INT, DINT, USINT, UDINT, BYTE, WORD, DWORD)
To acces to a bit of a word you can only use :
- a value, for example you can test (or write ) "my_word.2" or "my_word.5" ...
VAR_GLOBAL CONSTANT
Indice:INT:=2;
END_VAR
And you can test (or write ) "my_word.Indice"
One solution to test each bit of a word may be to use SHL/SHR operators to shift and test each bit.
You can see CODESYS HELP : https://help.codesys.com/webapp/_cds_op ... n=3.5.15.0
BR
Originally created by: D. Kugler
https://help.codesys.com/webapp/extract ... n=3.5.11.0
That's what you are searching for?
This could provide a nice access :see this post
To acces to a bit of a word you can only use :
- a value, for example you can test (or write ) "my_word.2" or "my_word.5" ...
- a Global Constant
VAR_GLOBAL CONSTANT
Indice:INT:=2;
END_VAR
And you can test (or write ) "my_word.Indice"
One solution to test each bit of a word may be to use SHL/SHR operators to shift and test each bit.
You can see CODESYS HELP : https://help.codesys.com/webapp/_cds_op ... n=3.5.15.0
BR
Sorry for my error, yes You have right should be ```
IF(my_word. scan_bit)
```
Thank you for help
Absolulty Yes! Thank you very much!