Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db[0]['x']=22.33 raises ValueError #486

Closed
thkfighter opened this issue Jan 31, 2024 · 2 comments
Closed

db[0]['x']=22.33 raises ValueError #486

thkfighter opened this issue Jan 31, 2024 · 2 comments
Milestone

Comments

@thkfighter
Copy link

import snap7

config = {
    "user_name": "admin",
    "password": "admin",
    "locator_host": "127.0.0.1",
    "locator_pose_port": 9011,
    "locator_json_rpc_port": 8080,
    "plc_host": "192.168.8.71",
    "plc_port": 102,
    "plc_rack": 0,
    "plc_slot": 1,
    "seed_count": 8,
    "db_number": 10000,
    "row_size": 26,
    "pose_size": 24,
    "layout": """
0       x               LREAL
8       y               LREAL
16      yaw             LREAL
24.0    enforceSeed     BOOL
24.1    uncertainSeed   BOOL
24.2    recordSeed      BOOL
24.3    setSeed         BOOL
""",
    "debug": 0,
}

client = snap7.client.Client()
client.connect(
    config["plc_host"], config["plc_rack"], config["plc_slot"], config["plc_port"]
)
all_data = client.db_read(
    config["db_number"], 0, config["row_size"] * config["seed_count"]
)
# all_data = client.upload(config["db_number"])
db = snap7.util.DB(
    db_number=config["db_number"],
    bytearray_=all_data,
    specification=config["layout"],
    row_size=config["row_size"],
    size=config["seed_count"],
)
db[0]['x']=22.33
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[8], line 1----> 1 db[0]['x']=22.33

File c:\workspace\locator_plc_bridge\venv\Lib\site-packages\snap7\util.py:1657, in DB_Row.__setitem__(self, key, value)
   1655 def __setitem__(self, key, value):
   1656     index, _type = self._specification[key]
-> 1657     self.set_value(index, _type, value)

File c:\workspace\locator_plc_bridge\venv\Lib\site-packages\snap7\util.py:1823, in DB_Row.set_value(self, byte_index, type_, value)
   1820 if type_ == 'TIME' and isinstance(value, str):
   1821     return set_time(bytearray_, byte_index, value)
-> 1823 raise ValueError

ValueError: 
@spreeker
Copy link
Collaborator

https://github.com/gijzelaerr/python-snap7/blob/master/snap7/util.py#L1806 You are right!! the LREAL type is missing here!

@spreeker
Copy link
Collaborator

spreeker commented Jan 31, 2024

#487 should be fixed. can pull this branch to test yourself.

@gijzelaerr gijzelaerr added this to the 1.4 milestone May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants