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

Split system vars into chunks #142

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions control.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ async def main():
"""Show example on controlling a Cybro PLC."""
nad = 10000
prefix = f"c{nad}."
async with Cybro("192.168.10.62", 4000, nad) as cybro:
device = await cybro.update()
async with Cybro("192.168.10.48", 4000, nad) as cybro:
device = await cybro.update(device_type=1)
print("server_version -> " + device.server_info.server_version)
print("ip_port -> " + device.plc_info.ip_port)
print("timestamp -> " + device.plc_info.timestamp)
Expand Down
20 changes: 13 additions & 7 deletions src/cybro/cybro.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,19 @@ async def update(
if device_type == 1:
_vars = _add_hiq_tags(_vars, _controller)

if not (data := await self.request(data=_vars)):
raise CybroEmptyResponseError(
f"Cybro scgi server at {self.host}:{self.port} returned an empty API"
" response on full update"
)

self._device = Device(data, plc_nad=self.nad)
_sys_vars = _get_chunk(_vars, VAR_CHUNK_SIZE)
for _vars in _sys_vars:
if not (data1 := await self.request(data=_vars)):
raise CybroEmptyResponseError(
f"Cybro scgi server at {self.host}:{self.port} returned an empty API"
" response on full update"
)
# Update device info in chunks,
# but the first block must include all sys variables
if self._device is None:
self._device = Device(data1, plc_nad=self.nad)
else:
self._device.update_from_dict(data1)

if len(self._device.user_vars) > 0:
_user_vars = _get_chunk(self._device.user_vars, VAR_CHUNK_SIZE)
Expand Down