Coder Social home page Coder Social logo

Reading DINT about python-snap7 HOT 4 CLOSED

gijzelaerr avatar gijzelaerr commented on May 29, 2024
Reading DINT

from python-snap7.

Comments (4)

hkocaoglu avatar hkocaoglu commented on May 29, 2024

i found a solution. i edited the util.py and add the following function:

def get_dint(_bytearray, byte_index):
data = _bytearray[byte_index:byte_index + 4]
dint = struct.unpack('>i', struct.pack('4B', *data))[0]
return dint

from python-snap7.

spreeker avatar spreeker commented on May 29, 2024

Well make pull request and add a test to the test code and we can add your
code to the codebase!
On Jul 7, 2014 12:03 PM, "hkocaoglu" [email protected] wrote:

i found a solution. i edited the util.py and add the following function:

def get_dint(_bytearray, byte_index):
data = _bytearray[byte_index:byte_index + 4]
dint = struct.unpack('>i', struct.pack('4B', *data))[0]
return dint


Reply to this email directly or view it on GitHub.

from python-snap7.

gijzelaerr avatar gijzelaerr commented on May 29, 2024

Hi Hkocaoglu,

We maintain python-snap7 in our spare time, so we don't always have time to incorporate changes like these. It would save us time and effort if you follow our development contribution guideline and issue a pull request fixing this issue:

http://python-snap7.readthedocs.org/en/latest/development.html#github

Greetings,

  • Gijs

from python-snap7.

schlamar avatar schlamar commented on May 29, 2024

DWORD and DINT should result in the same integer value in Python, so this is clearly a byte ordering issue (in python-snap7). You should explicitly use big-endian (as you are already doing it in get/set_real).

@hkocaoglu r is just the ASCII representation for 114:

>>> [ord(c) for c in b'\x00\x15r\xcf']
[0, 21, 114, 207]

from python-snap7.

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.