Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Contact Us
  • Home
  • Products
  • Automation Systems
  • Machine Automation Controllers

How to access data at the bit level in Sysmac

Written by Arlo D'Cruz

Updated at December 18th, 2023

Contact Us

If you still have questions or prefer to get help directly from an agent, please submit a request.
We’ll get back to you as soon as possible.

Please fill out the contact form below and we will reply as soon as possible.

  • Products
    Automation Systems Control Components Motion & Drives Quality control & Inspection Robotics Safety Sensing Services Software Switching Components
  • Amplify e-Store
    e-Store public
  • Public CSC
+ More

It is quite common that it is necessary to either read or write a single bit as part of a BYTE/WORD/DWORD/LWORD in Sysmac. In Sysmac it is not possible to directly enter the address of the bit you wish to access. Instead there are two main methods you may use to accomplish bit access. 

1. Union

A union allows you to create multiple members of a variable that share the same memory. You can take advantage of this to create a variable that is directly accessible at various data type levels including the bit level. We would recommend the union method for scalable solutions where you often need to read or write bits in a byte. 

For this example we will create a byte array where each byte is accessible at the bit level.

  1. Create the union. As we are accessing a byte the bit array must be of length 8.


  2. Create the variable. In this example we are creating the data as an array of length 10. You can also use this same method for standard non-indexed variables.


  3. Add the variable to your ladder code. In this example we are reading from byte 3, bit 4 and writing to byte 5, bit 2 of MyData.
Delete

2. Function Block

There are a few functions in Sysmac that allow you to interact with data at the bit level. We would suggest using the functions when you need to have a one off instance of accessing a byte at the bit level.

Functions of note:

  • TestABit - Outputs the value of the specified bit.
  • OutABit - Sets the specified bit to True or False.
  • SetABit - Sets the specified bit to True.
  • ResetABit - Sets the specified bit to False.
  • MoveBit - Copies a bit from one variable to another.

In this example we will cover TestAbit and OutABit with a byte array. 

  1. Create the byte array. You can also use this same method for standard non-indexed variables.


  2. Write the ladder code. In this example we are reading from byte 3, bit 4 and writing to byte 5, bit 2 of MyData.
Delete

 

byte access sysmac bits word dword lword

Was this article helpful?

Yes
No
Give feedback about this article

Related Articles

  • Where to find the _sNXUNIT_ID of my NX unit?
  • NX and NJ Basic Data Types and Ranges
  • Major or Minor Revision mismatch for EtherNet/IP Error 0116
  • CP and NJ FINS TCP Sample Code

Definition by Author

0
0
Expand