@@ -81,10 +81,11 @@ class BaseDevice(ReentrantOpen):
8181
8282 PREFIX = None
8383
84- def __init__ (self , name_or_file , read_write = True , io = IO ):
84+ def __init__ (self , name_or_file , read_write = True , io = IO , blocking = False ):
8585 super ().__init__ ()
8686 self .io = io
87- if isinstance (name_or_file , (str , pathlib .Path )):
87+ self .blocking = blocking
88+ if isinstance (name_or_file , str | pathlib .Path ):
8889 filename = pathlib .Path (name_or_file )
8990 self ._read_write = read_write
9091 self ._fobj = None
@@ -121,12 +122,12 @@ def open(self):
121122 """Open the device if not already open. Triggers _on_open after the underlying OS open has succeeded"""
122123 if not self ._fobj :
123124 self .log .info ("opening %s" , self .filename )
124- self ._fobj = self .io .open (self .filename , self ._read_write )
125+ self ._fobj = self .io .open (self .filename , self ._read_write , blocking = self . blocking )
125126 self ._on_open ()
126127 self .log .info ("opened %s" , self .filename )
127128
128129 def close (self ):
129- """Closes the device if not already closed. Triggers _on_close before the underlying OS open has succeeded"""
130+ """Closes the device if not already closed. Triggers _on_close before the underlying OS close has succeeded"""
130131 if not self .closed :
131132 self ._on_close ()
132133 self .log .info ("closing %s" , self .filename )
@@ -149,4 +150,12 @@ def is_blocking(self) -> bool:
149150 True if the underlying OS is opened in blocking mode.
150151 Raises error if device is not opened.
151152 """
152- return os .get_blocking (self .fileno ())
153+ return self .io .os .get_blocking (self .fileno ())
154+
155+ def set_blocking (self , yes_no : bool ) -> None :
156+ """
157+ Turns on/off blocking mode.
158+ Raises error if device is not opened.
159+ """
160+ self .io .os .set_blocking (self .fileno (), yes_no )
161+ self .blocking = yes_no
0 commit comments