Variable becomes undefined between two lines of code, kawasaki robot

We are using the kawasaki robot in our project, but it gives this weird error randomly in the code:

(E0104) String variable is not defined.
No = 1002
Program held.No = 1
Program = read_tcp_buffer Step = 18
PC program aborted.No = 1002

this is the piece of code that the error is taking about

As far as i can see the error is talking about the $tcp_buffer variable that is undefined, but as you can see i check if tcp_buffer exists and create it if is does not exist. I also tried tried to check if it exists in the wait function. But it still crashes at this point sometimes. It will run fine for a few times and then give the error. Does anyone have any ideas how to fix this?

I assigned Guus for this one. He might be able to help with this.

When you are asking for help, please supply the code as well, not just a screenshot!

The error tells you something is wrong in step=18.
The Kawasaki ignores lines where no executable code is present, in your screenshot I can see 4 lines without code. Therefore I expect your error to be at least on line 22.

In line 23 & 24 you are decoding the $tcp_buffer using the command $DECODE to transform a string variable. So this is the code where I expect you to possibly have errors.

Running the following lines of code in K-Roset (Kawasaki simulation) reproduces the same error you are talking about

>$buffer = "foobar"
>$temp = $DECODE($buffer,"|",0)
>print $buffer

>print $temp
foobar
>$temp = $DECODE($buffer,"|",1)
(E0102)Variable is not defined.

The following code does not reproduce the error.

>$buffer = "foo|bar"
>$temp = $DECODE($buffer,"|",0)
>print $buffer
|bar
>print $temp
foo
>$temp = $DECODE($buffer,"|",1)
>

So if the variable $buffer is filled with string information without pipes, your ‘if statement’ will pass, but the first $DECODE command will empty your string variable. This can cause an error in the next line.

Please let us know if this indeed is the problem you are having!

thank you for your quick response, you are correct that Kawasaki ignores lines with no code, but it does count lines with comments. Running this code

 .PROGRAM test1()
  $buffer = "foobar"
  $temp = $DECODE($buffer,"|",0)
  print $buffer
  print $temp
  
  
  
  
  $temp = $DECODE($buffer,"|",1)
.END

I get this error(wrong line number):

(E0102) Variable is not defined.
        
 Program = test1  Step = 5
Program aborted.No = 1

but running this code :

.PROGRAM test1()
  $buffer = "foobar"
  $temp = $DECODE($buffer,"|",0)
  print $buffer
  print $temp
  ;
  ;
  ;
  ;
  $temp = $DECODE($buffer,"|",1)
.END

i get this error with the correct line number:

(E0102) Variable is not defined.
        
 Program = test1  Step = 9
Program aborted.No = 1

so I am of the opinon that the problem is with the actual line 18 of our code. It could still be somerting related to the problem you pointed out and i will see if i can recreate and debug the issue on the simulator.

I have atached our .as file. It is a modified version of this library https://github.com/G-Paris/kawapai and has been working perfectly for our entire project until for today.

kawasai_export.as (79.5 KB)

edit:
here is also the modified version of the python file we use:
robot.py (15.2 KB)

That is a repository from Guus fyi :grinning:

Did you solve this issue?

nop.

They made a work-around -> use different code.

@tom What was the workaround you used so we can close this topic?