0

I'm trying to implement the logic below:

if bcc = STX or bcc = CR, then bcc := +1 (increment of 1).

bcc is a byte and i'm trying to increment it by 1 if this condition above is true.

my code is:

IF message_byte[11] = 16#0D OR message_byte[11] = 16#02 THEN message_byte[11] := message_byte[11] + TO_BYTE(1); END_IF

where message_byte is an array of bytes and I want to access a specific one. However, it gives me an error when saying it can't be added.

any help is appreciated

opol
  • 1
  • 1
  • I think you might be missing something in your example code, Would the condition be `bcc = STX OR bcc = CR`? – dwpessoa Jun 15 '22 at 16:54
  • yes, thanks for pointing it out – opol Jun 15 '22 at 16:59
  • 1
    Is this the exact snippet of your program? Would it be possible to include the `message_byte` declaration? What is the exact error message and which line does it point to? – dwpessoa Jun 15 '22 at 18:03
  • Variable :Message_byte. Type: AXL_RSUNI_ARR_B_1_1023. This type is ( ARRAY[1..1023] OF BYTES) The error message: SEM1106 The data type of the left operand ('BYTE') is not 'ANY_NUM' – opol Jun 15 '22 at 18:14
  • Hmm... `ARRAY OF BYTES` is different from `ARRAY OF BYTE`, so you are trying to write a `BYTE` in a variable of type `BYTES`, so it is giving an error (Although the error message indicates `BYTE`, it may be a typo). As it seems to me, the definition of `BYTES` must depend on some library or internal structure of your PLC. – dwpessoa Jun 15 '22 at 18:34

1 Answers1

0

I believe the error is telling you that message_byte[11] (left operant of your addition) is not a type BYTE, so the compiler can’t figure out how to add a BYTE to it - as commented by dwpessoa. I also don’t know what a data type “BYTES” is - maybe that should just be BYTE.

When you get these types of errors, try breaking apart your task and just try the absolute basics - just try adding 1 to message_byte[11]. Then it will be easier to solve the error.

Scott
  • 116
  • 2