@@ -114,21 +114,22 @@ def upload(self, index: int, subindex: int) -> bytes:
114
114
When node responds with an error.
115
115
"""
116
116
with self .open (index , subindex , buffering = 0 ) as fp :
117
- size = fp .size
117
+ response_size = fp .size
118
118
data = fp .read ()
119
- if size is None :
120
- # Node did not specify how many bytes to use
121
- # Try to find out using Object Dictionary
122
- var = self .od .get_variable (index , subindex )
123
- if var is not None :
124
- # Found a matching variable in OD
125
- # If this is a data type (string, domain etc) the size is
126
- # unknown anyway so keep the data as is
127
- if var .data_type not in objectdictionary .DATA_TYPES :
128
- # Get the size in bytes for this variable
129
- size = len (var ) // 8
119
+
120
+ # If size is available through variable in OD, then use the smaller of the two sizes.
121
+ # Some devices send U32/I32 even if variable is smaller in OD
122
+ var = self .od .get_variable (index , subindex )
123
+ if var is not None :
124
+ # Found a matching variable in OD
125
+ # If this is a data type (string, domain etc) the size is
126
+ # unknown anyway so keep the data as is
127
+ if var .data_type not in objectdictionary .DATA_TYPES :
128
+ # Get the size in bytes for this variable
129
+ var_size = len (var ) // 8
130
+ if response_size is None or var_size < response_size :
130
131
# Truncate the data to specified size
131
- data = data [0 :size ]
132
+ data = data [0 :var_size ]
132
133
return data
133
134
134
135
def download (
0 commit comments