Giter Club home page Giter Club logo

Comments (7)

petar-dambovaliev avatar petar-dambovaliev commented on August 25, 2024 1

@pizzalord22
This will give you the specific boolean you want from the byte.
myBool = (byte & (1 << bitPos-1)) != 0;

from gos7.

robinson avatar robinson commented on August 25, 2024

@RTmaster read boolean is similar with read any types of data:
buf := make([]byte, 255)
err := client.AGReadDB(address, start, size, buf)
if err != nil {
t.Fatal(err)
}
here you got the the buf, which is an array of byte, then just get the value from buf:
var s7 gos7.Helper
var result boolean
s7.GetValueAt(buf, 0, &result)
Now you got the result is a boolean.
Cheers, R

from gos7.

sandeep51989 avatar sandeep51989 commented on August 25, 2024

I see there to be a problem with this approach. If the boolean is given in a byte it works. How can we have get booleans at the bit position in a byte. For example if i want to get the boolean value at 180 the position at bit 6.

According to examples given.
s7.GetValueAt(buf, 180, &result)

All the function does is read the record at position byte 180 but how do we get the value at the bit position off the byte.

from gos7.

robinson avatar robinson commented on August 25, 2024

@sandeep51989: more specific: the buf is an array of bytes which stores the return values - maybe: bool, int8, int16...so on. The values arrange from the position 0. The helper: S7.GetValueAt will return an interface of value.

from gos7.

pizzalord22 avatar pizzalord22 commented on August 25, 2024

sorry for reviving this old thread but when i read a byte containing 8 bool bits it returns 1 byte in the buffer array instead of 1 byte for each bool value. so i can not get individual bool values

from gos7.

petar-dambovaliev avatar petar-dambovaliev commented on August 25, 2024

I have added the boolean support in the helper.
#17

from gos7.

sunblack110 avatar sunblack110 commented on August 25, 2024

It's good , but how about write a boolean to PLC, do we need to read it in a byte first, then change a bit in the byte, then we write to PLC , it's not a good idea.

from gos7.

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.