How to Write a Variable to a PLC

Modified on Tue, 10 Jan 2023 at 10:53 AM


Here is a solution for sending local or global variables from the controller to the PLC by using the DEFIO command to assign values to Fieldbus IO sets.


One way to send a global or local variable from your robot program to your PLC is by defining a variable string to use by using the DefIO command.  Review the command specifically here: 

What our example will show here is sending from the robot to the PLC.

  • DefIO Int2IO = byte, 820
    • This line is using the DEFIO command to define our custom IO named "Int2IO".  It is sized at 1 byte (8-bits), and starts at IO number 820.
  • I[2] = 22
    • This is simply giving the Global Integer variable, I[2], a value of 22
  • Int2IO = I[2]
    • This line is setting our custom IO, Int2IO, equal to the Global Variable I[2], thus equal to 22.
    • After this happens, you can see that the bits/IO's in our custom IO take on the bit pattern to equal 22, but in Binary
    • The trick to seeing this is to realize that the most significant bit is the highest IO, and the least significant bit is the lowest IO.  In this case the MSB is 827, and the LSB is 820.  So if you read it from the bottom up in the picture, it's 0001 0110, thus equalling 22 in binary.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article