-
Notifications
You must be signed in to change notification settings - Fork 401
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plc4py): Modbus write support (#1745)
* feat(plc4py): get started on some modbus writing * feat(plc4py): clean up comparisons of PlcValues * feat(plc4py): Add some manual modbus tests * feat(plc4py): Modbus write stuff * feat(plc4py/modbus): Writing now works * feat(plc4py/modbus): Time to work on word swapping * feat(plc4py/modbus): Ignore tests when server isn't available * feat(plc4py/modbus): Support for word swapping * feat(plc4py/modbus): Support for word swapping * feat(plc4py): Fix support for parameters * feat(plc4py): start looking at error handling * feat(plc4py/umas): start fixing up umas * feat(plc4py): rename byte swap enum * feat(plc4py/modbus): Review new code
- Loading branch information
Showing
22 changed files
with
678 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
plc4py/plc4py/protocols/umas/readwrite/UmasPDUErrorResponse.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
|
||
from dataclasses import dataclass | ||
|
||
from plc4py.api.exceptions.exceptions import PlcRuntimeException | ||
from plc4py.api.exceptions.exceptions import SerializationException | ||
from plc4py.api.messages.PlcMessage import PlcMessage | ||
from plc4py.protocols.umas.readwrite.UmasPDUItem import UmasPDUItem | ||
from plc4py.spi.generation.ReadBuffer import ReadBuffer | ||
from plc4py.spi.generation.WriteBuffer import WriteBuffer | ||
from plc4py.utils.GenericTypes import ByteOrder | ||
from typing import Any | ||
from typing import ClassVar | ||
from typing import List | ||
import math | ||
|
||
|
||
@dataclass | ||
class UmasPDUErrorResponse(UmasPDUItem): | ||
block: List[int] | ||
# Arguments. | ||
byte_length: int | ||
# Accessors for discriminator values. | ||
umas_function_key: ClassVar[int] = 0xFD | ||
umas_request_function_key: ClassVar[int] = 0 | ||
|
||
def serialize_umas_pduitem_child(self, write_buffer: WriteBuffer): | ||
write_buffer.push_context("UmasPDUErrorResponse") | ||
|
||
# Array Field (block) | ||
write_buffer.write_simple_array( | ||
self.block, write_buffer.write_unsigned_byte, logical_name="block" | ||
) | ||
|
||
write_buffer.pop_context("UmasPDUErrorResponse") | ||
|
||
def length_in_bytes(self) -> int: | ||
return int(math.ceil(float(self.length_in_bits() / 8.0))) | ||
|
||
def length_in_bits(self) -> int: | ||
length_in_bits: int = super().length_in_bits() | ||
_value: UmasPDUErrorResponse = self | ||
|
||
# Array field | ||
if self.block is not None: | ||
length_in_bits += 8 * len(self.block) | ||
|
||
return length_in_bits | ||
|
||
@staticmethod | ||
def static_parse_builder( | ||
read_buffer: ReadBuffer, umas_request_function_key: int, byte_length: int | ||
): | ||
read_buffer.push_context("UmasPDUErrorResponse") | ||
|
||
if isinstance(umas_request_function_key, str): | ||
umas_request_function_key = int(umas_request_function_key) | ||
if isinstance(byte_length, str): | ||
byte_length = int(byte_length) | ||
|
||
block: List[Any] = read_buffer.read_array_field( | ||
logical_name="block", | ||
read_function=read_buffer.read_unsigned_byte, | ||
count=byte_length - int(2), | ||
byte_order=ByteOrder.LITTLE_ENDIAN, | ||
umas_request_function_key=umas_request_function_key, | ||
byte_length=byte_length, | ||
) | ||
|
||
read_buffer.pop_context("UmasPDUErrorResponse") | ||
# Create the instance | ||
return UmasPDUErrorResponseBuilder(block) | ||
|
||
def equals(self, o: object) -> bool: | ||
if self == o: | ||
return True | ||
|
||
if not isinstance(o, UmasPDUErrorResponse): | ||
return False | ||
|
||
that: UmasPDUErrorResponse = UmasPDUErrorResponse(o) | ||
return (self.block == that.block) and super().equals(that) and True | ||
|
||
def hash_code(self) -> int: | ||
return hash(self) | ||
|
||
def __str__(self) -> str: | ||
pass | ||
# write_buffer_box_based: WriteBufferBoxBased = WriteBufferBoxBased(True, True) | ||
# try: | ||
# write_buffer_box_based.writeSerializable(self) | ||
# except SerializationException as e: | ||
# raise PlcRuntimeException(e) | ||
|
||
# return "\n" + str(write_buffer_box_based.get_box()) + "\n" | ||
|
||
|
||
@dataclass | ||
class UmasPDUErrorResponseBuilder: | ||
block: List[int] | ||
|
||
def build(self, byte_length: int, pairing_key) -> UmasPDUErrorResponse: | ||
umas_pduerror_response: UmasPDUErrorResponse = UmasPDUErrorResponse( | ||
byte_length, pairing_key, self.block | ||
) | ||
return umas_pduerror_response |
Oops, something went wrong.