Skip to content

Commit

Permalink
address some pylint concerns
Browse files Browse the repository at this point in the history
  • Loading branch information
drunsinn committed Oct 7, 2023
1 parent 65d8709 commit 79fddda
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 23 deletions.
20 changes: 10 additions & 10 deletions pyLSV2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,6 @@ def read_plc_memory(self, first_element: int, mem_type: lc.MemoryType, number_of
)
return []
else:

max_elements_per_transfer = math.floor(255 / mem_byte_count) - 1 # subtract 1 for safety
num_groups = math.ceil(number_of_elements / max_elements_per_transfer)
logging.debug(
Expand All @@ -1303,7 +1302,6 @@ def read_plc_memory(self, first_element: int, mem_type: lc.MemoryType, number_of
first_element_in_group = first_element

for i in range(num_groups):

# determine number of elements for this group
if remaining_elements > max_elements_per_transfer:
elements_in_group = max_elements_per_transfer
Expand Down Expand Up @@ -1660,9 +1658,11 @@ def read_data_path(self, path: str) -> Union[bool, int, float, str, None]:

self._logger.info("successfully read data path: %s and got value '%s'", path, data_value)
return data_value
elif self.last_error.e_code == lc.LSV2StatusCode.T_ER_WRONG_PARA:

if self.last_error.e_code == lc.LSV2StatusCode.T_ER_WRONG_PARA:
self._logger.warning("the argument '%s' is not supported by this control", path)
return None

self._logger.warning("an error occurred while querying data path '%s'. Error code was %d", path, self.last_error.e_code)
return None

Expand Down Expand Up @@ -1748,13 +1748,13 @@ def read_scope_signals(self) -> List[ld.ScopeSignal]:
"""
if not self.versions.is_itnc():
self._logger.warning("only works for iTNC530")
return list()
return []

if not self.login(lc.Login.SCOPE):
self._logger.warning("clould not log in as user for scope function")
return list()
return []

channel_list = list()
channel_list = []

content = self._llcom.telegram(lc.CMD.R_OC)
if self._llcom.last_response in lc.RSP.S_OC:
Expand Down Expand Up @@ -1788,11 +1788,11 @@ def real_time_readings(self, signal_list: List[ld.ScopeSignal], duration: int, i
"""
if not self.versions.is_itnc():
self._logger.warning("only works for iTNC530")
return list()
return []

if not self.login(lc.Login.SCOPE):
self._logger.warning("clould not log in as user for scope function")
return list()
return []

self._logger.debug(
"start recoding %d readings with interval of %d µs",
Expand Down Expand Up @@ -1831,7 +1831,7 @@ def real_time_readings(self, signal_list: List[ld.ScopeSignal], duration: int, i
payload.extend(struct.pack("!L", interval))

start = time.time() # start timer
recorded_data = list()
recorded_data = []
content = self._send_recive(lc.CMD.R_OD, payload, lc.RSP.S_OD)

if not isinstance(content, (bytearray,)) or len(content) <= 0:
Expand All @@ -1851,6 +1851,6 @@ def real_time_readings(self, signal_list: List[ld.ScopeSignal], duration: int, i
break
end = time.time()
timer = end - start
recorded_data = list()
recorded_data = []

self._logger.debug("finished reading scope data")
4 changes: 2 additions & 2 deletions pyLSV2/dat_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,7 +1158,7 @@ def __init__(self, channel: int, signal: int, offset: int, factor: float, unit:
self._unit = unit

# self._header = bytearray()
self.data = list()
self.data = []

@property
def channel(self) -> int:
Expand Down Expand Up @@ -1199,7 +1199,7 @@ class ScopeReading:
def __init__(self, sequence_number: int):
self._seqence_nr = sequence_number
# self._full_data = bytearray()
self._signal_data = list()
self._signal_data = []

def seqence_nr(self) -> int:
"""sequence number of consecuetive readings"""
Expand Down
4 changes: 1 addition & 3 deletions pyLSV2/low_level_com.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def __init__(self, port: str, speed: int, timeout: float = 15.0):
self._last_lsv2_response = RSP.NONE
self._last_error = LSV2Error()
raise NotImplementedError()
import serial
# import serial

@property
def last_response(self) -> RSP:
Expand Down Expand Up @@ -287,14 +287,12 @@ def connect(self):
Establish connection to control
"""
raise NotImplementedError()
pass

def disconnect(self):
"""
Close connection
"""
raise NotImplementedError()
pass

def telegram(
self,
Expand Down
15 changes: 8 additions & 7 deletions pyLSV2/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,19 @@ def decode_system_information(data_set: bytearray) -> Union[bool, int]:

if data_type == 1:
return struct.unpack("!xxx?", data_set[4:])[0]
elif data_type == 2:

if data_type == 2:
return struct.unpack("!L", data_set[4:])[0]
else:
raise LSV2DataException("unexpected value for data type of system information")

raise LSV2DataException("unexpected value for data type of system information")
# always returns b"\x00\x00\x00\x02\x00\x00\x0b\xb8" for recording 1, 2 and 3
# -> is independent of channel, axes, interval or samples
# maybe the last four bytes are the actual interval? 0x00 00 0b b8 = 3000
# documentation hints
if data_set != bytearray(b"\x00\x00\x00\x02\x00\x00\x0b\xb8"):
print(" # unexpected return pattern for R_CI!")
raise Exception("unknown data for S_CI result")
return data_set
# if data_set != bytearray(b"\x00\x00\x00\x02\x00\x00\x0b\xb8"):
# print(" # unexpected return pattern for R_CI!")
# raise Exception("unknown data for S_CI result")
# return data_set


def decode_file_system_info(data_set: bytearray, control_type: ControlType = ControlType.UNKNOWN) -> ld.FileEntry:
Expand Down
1 change: 0 additions & 1 deletion tests/test_plc_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ def test_comapare_values(address: str, timeout: float):
lsv2.connect()

if lsv2.versions.is_itnc():

for mem_address in [0, 1, 2, 4, 8, 12, 68, 69, 151, 300, 368]:
v1 = lsv2.read_plc_memory(mem_address, pyLSV2.MemoryType.DWORD, 1)[0]
v2 = lsv2.read_data_path("/PLC/memory/D/%d" % (mem_address * 4))
Expand Down

0 comments on commit 79fddda

Please sign in to comment.