Coder Social home page Coder Social logo

Comments (6)

sgchowar avatar sgchowar commented on July 26, 2024

I have managed to get something to work, but it seems to only read/write the arrays as arrays of dint/int etc, not as seperate bools. Does this therefore not support writing to an array of bools.

from pycomm.

sgchowar avatar sgchowar commented on July 26, 2024

Basically i have been able to write and read from the array of bools, but i cannot do it to individual bools in the array, instead the most amount of parts i can split the 128 bit array is into 4 parts, therefore viewing it as a 4 DINT array. Increasing the element count in the functions to 8 or 128 as i really want, doesn't return any output or error.

Is this a limitation with the library or something i am missing?

from pycomm.

rkrupnek avatar rkrupnek commented on July 26, 2024

Here is how I am reading from a (64 element) boolean array using my little test program:

print(bin(c.read_tag('B')[0])[2:64])

It prints the result like this:
111100001111

If you just straight-up read the content of the boolean array, you get:
(3855, 'DWORD')

The limitation is most likely due to a combination of the way Rockwell handles boolean arrays (as integers / blocks of bits) in the processor and perhaps the way Python handles this data. It could probably be worked around. I'll try to give it some thought.

from pycomm.

ruscito avatar ruscito commented on July 26, 2024

I have run a test and look like the _parse_fragment function read an "unknown status" from the PLC. I will need to look at the log files to understand what's happening. Will keep you posted

from pycomm.

sgchowar avatar sgchowar commented on July 26, 2024

Thanks it would be great if you could get it working.

rkrupnek, I used your method to read from an element in my array, but you cannot use this to write to a single element.

from pycomm.

ruscito avatar ruscito commented on July 26, 2024

Ok so this is more of a Rockwell representation. In other words Rockwell see the array of bool as DWORD type for both performance and space reasons (I read this somewhere in the documentation). If you try to define an array of BOOL of dimension 3 Rockwell will automatically create an array of dimension 32 BOOLS, or if you try to define an array of dimension 33 Rockwell (RSLogix I should say) will automatically create an array of 64.

The only way at the moment is to use the read and write array function as DWORD size for example:
I defined in my plc an array of 32 Boolean; now if I need set the first 3 bool to 1 i will have to write 15 in the whole DWORD .

    w_array = []
    w_array.append(15)
    c.write_array("AGO_BOOL_TEST", w_array, "DWORD")

If i need to read the array I will need to pass the size in term of DWORD , so if I need to read the first 4 bit i will have to use size of 1 because this 4 bits resize in the first DWORD

    r_array = c.read_array("AGO_BOOL_TEST", 1)

This will read the entire word.

This is not the best solution because you will need to do some coding to extrapolate the bit needed. To be honest this code could be easily write inside both "read_array" and "write_array" and I will try to do it but later because now I'm in the middle of a startup.

Hopefully this help a bit
Ago

from pycomm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.