@@ -75,30 +75,29 @@ def file_handle( self, path, mode, reopen=False ):
75
75
76
76
return f
77
77
78
- def read (self , path , size = - 1 ):
78
+ def read (self , path ):
79
79
f = self .file_handle (path , 'r' )
80
80
81
81
try :
82
- value = f .read (size )
82
+ f .seek (0 )
83
+ value = f .readline ()
83
84
except IOError :
84
85
f = self .file_handle ( path , 'w+' , reopen = True )
85
- value = f .read ( size )
86
+ value = f .readline ( )
86
87
87
- if size < 0 :
88
- return value .strip ()
89
- else :
90
- return value
88
+ return value .strip ()
91
89
92
90
def write (self , path , value ):
93
91
f = self .file_handle ( path , 'w' )
94
92
95
93
try :
94
+ f .seek (0 )
96
95
f .write ( value )
97
- f .flush ()
98
96
except IOError :
99
97
f = self .file_handle ( path , 'w+' , reopen = True )
100
98
f .write ( value )
101
- f .flush ()
99
+
100
+ f .flush ()
102
101
103
102
104
103
#------------------------------------------------------------------------------
@@ -157,9 +156,9 @@ def _matches(self, attribute, pattern):
157
156
else :
158
157
return value .find (pattern ) >= 0
159
158
160
- def _get_attribute ( self , attribute , size = - 1 ):
159
+ def _get_attribute ( self , attribute ):
161
160
"""Device attribute getter"""
162
- return self ._attribute_cache .read (abspath (self ._path + '/' + attribute ), size )
161
+ return self ._attribute_cache .read (abspath (self ._path + '/' + attribute ))
163
162
164
163
def _set_attribute ( self , attribute , value ):
165
164
"""Device attribute setter"""
@@ -1291,7 +1290,9 @@ def bin_data(self, fmt=None):
1291
1290
"float" : 4
1292
1291
}.get (self .bin_data_format , 1 ) * self .num_values
1293
1292
1294
- raw = bytearray (self ._get_attribute ('bin_data' , self ._bin_data_size ))
1293
+ f = self ._attribute_cache .file_handle (abspath (self ._path + '/bin_data' ), 'rb' )
1294
+ f .seek (0 )
1295
+ raw = bytearray (f .read (self ._bin_data_size ))
1295
1296
1296
1297
if fmt is None : return raw
1297
1298
0 commit comments