@@ -78,7 +78,7 @@ def set_word(bytearray_: bytearray, byte_index: int, _int: int) -> bytearray:
7878 """
7979 _int = int (_int )
8080 _bytes = struct .unpack ("2B" , struct .pack (">H" , _int ))
81- bytearray_ [byte_index : byte_index + 2 ] = _bytes
81+ bytearray_ [byte_index : byte_index + 2 ] = bytes ( _bytes )
8282 return bytearray_
8383
8484
@@ -104,7 +104,7 @@ def set_int(bytearray_: bytearray, byte_index: int, _int: int) -> bytearray:
104104 # make sure were dealing with an int
105105 _int = int (_int )
106106 _bytes = struct .unpack ("2B" , struct .pack (">h" , _int ))
107- bytearray_ [byte_index : byte_index + 2 ] = _bytes
107+ bytearray_ [byte_index : byte_index + 2 ] = bytes ( _bytes )
108108 return bytearray_
109109
110110
@@ -131,7 +131,7 @@ def set_uint(bytearray_: bytearray, byte_index: int, _int: int) -> bytearray:
131131 # make sure were dealing with an int
132132 _int = int (_int )
133133 _bytes = struct .unpack ("2B" , struct .pack (">H" , _int ))
134- bytearray_ [byte_index : byte_index + 2 ] = _bytes
134+ bytearray_ [byte_index : byte_index + 2 ] = bytes ( _bytes )
135135 return bytearray_
136136
137137
@@ -157,8 +157,7 @@ def set_real(bytearray_: bytearray, byte_index: int, real: Union[bool, str, floa
157157 """
158158 real_packed = struct .pack (">f" , float (real ))
159159 _bytes = struct .unpack ("4B" , real_packed )
160- for i , b in enumerate (_bytes ):
161- bytearray_ [byte_index + i ] = b
160+ bytearray_ [byte_index : byte_index + 4 ] = bytes (_bytes )
162161 return bytearray_
163162
164163
@@ -275,8 +274,7 @@ def set_dword(bytearray_: bytearray, byte_index: int, dword: int) -> None:
275274 """
276275 dword = int (dword )
277276 _bytes = struct .unpack ("4B" , struct .pack (">I" , dword ))
278- for i , b in enumerate (_bytes ):
279- bytearray_ [byte_index + i ] = b
277+ bytearray_ [byte_index : byte_index + 4 ] = bytes (_bytes )
280278
281279
282280def set_dint (bytearray_ : bytearray , byte_index : int , dint : int ) -> None :
@@ -300,8 +298,7 @@ def set_dint(bytearray_: bytearray, byte_index: int, dint: int) -> None:
300298 """
301299 dint = int (dint )
302300 _bytes = struct .unpack ("4B" , struct .pack (">i" , dint ))
303- for i , b in enumerate (_bytes ):
304- bytearray_ [byte_index + i ] = b
301+ bytearray_ [byte_index : byte_index + 4 ] = bytes (_bytes )
305302
306303
307304def set_udint (bytearray_ : bytearray , byte_index : int , udint : int ) -> None :
@@ -325,8 +322,7 @@ def set_udint(bytearray_: bytearray, byte_index: int, udint: int) -> None:
325322 """
326323 udint = int (udint )
327324 _bytes = struct .unpack ("4B" , struct .pack (">I" , udint ))
328- for i , b in enumerate (_bytes ):
329- bytearray_ [byte_index + i ] = b
325+ bytearray_ [byte_index : byte_index + 4 ] = bytes (_bytes )
330326
331327
332328def set_time (bytearray_ : bytearray , byte_index : int , time_string : str ) -> bytearray :
@@ -370,7 +366,7 @@ def set_time(bytearray_: bytearray, byte_index: int, time_string: str) -> bytear
370366 (int (days ) * sign * 3600 * 24 + (hours % 24 ) * 3600 + (minutes % 60 ) * 60 + seconds % 60 ) * 1000 + milli_seconds
371367 ) * sign
372368 bytes_array = time_int .to_bytes (4 , byteorder = "big" , signed = True )
373- bytearray_ [byte_index : byte_index + 4 ] = bytes_array
369+ bytearray_ [byte_index : byte_index + 4 ] = bytes ( bytes_array )
374370 return bytearray_
375371 else :
376372 raise ValueError ("time value out of range, please check the value interval" )
@@ -547,5 +543,5 @@ def set_date(bytearray_: bytearray, byte_index: int, date_: date) -> bytearray:
547543 raise ValueError ("date is higher than specification allows." )
548544 _days = (date_ - date (1990 , 1 , 1 )).days
549545 _bytes = struct .unpack ("2B" , struct .pack (">h" , _days ))
550- bytearray_ [byte_index : byte_index + 2 ] = _bytes
546+ bytearray_ [byte_index : byte_index + 2 ] = bytes ( _bytes )
551547 return bytearray_
0 commit comments