Comments (7)
@pizzalord22
This will give you the specific boolean you want from the byte.
myBool = (byte & (1 << bitPos-1)) != 0;
from gos7.
@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.
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.
@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.
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.
I have added the boolean support in the helper.
#17
from gos7.
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)
- SetStringAt() address error
- Add support of wstring in helper
- About Set/Get PLC time function HOT 2
- read addresses from wincc HOT 1
- Can I connect to Profinet using this library? HOT 2
- how to detect a timed-out connection, and avoid panic on `client.AGReadDB` HOT 1
- Problems with cross compiling for darwin (serial.go) HOT 3
- About write bit to DB address HOT 4
- Where to start? HOT 1
- How do I connect to s7-1200?There are no tracks and slots in s7-1200,errors:invalid pdu received or invalid buffer passed to send/receive '19' HOT 4
- When will support PPI? HOT 3
- BUG : gos7.SetWStringAt()
- Request support for some S7-200 HOT 2
- Best practice: Should change 'dbIndex' in 'DBX' format HOT 1
- When playing the example from the README, I get the following error: "binary.Write failed: binary.Write: invalid type int" and "ISO : Invalid Buffer passed to Send/Receive'19'" HOT 7
- How connect s7 smart200 plc HOT 5
- Query Bits in AGMultiRead
- Suggestion:support PLC Type Select HOT 1
- Suggestion: ADD new func "NewTCPClientHandlerWithConnectType" to change connectionType when allocates a new TCPClientHandler HOT 2
- panic when use PLCStop()
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gos7.