@@ -84,10 +84,8 @@ def __init__(
8484
8585 if not channel : # if None or empty
8686 raise TypeError ("Must specify a serial port." )
87-
8887 if "@" in channel :
8988 (channel , ttyBaudrate ) = channel .split ("@" )
90-
9189 self .serialPortOrig = serial .serial_for_url (
9290 channel , baudrate = ttyBaudrate , rtscts = rtscts
9391 )
@@ -98,13 +96,10 @@ def __init__(
9896
9997 if bitrate is not None and btr is not None :
10098 raise ValueError ("Bitrate and btr mutually exclusive." )
101-
10299 if bitrate is not None :
103100 self .set_bitrate (self , bitrate )
104-
105101 if btr is not None :
106102 self .set_bitrate_reg (self , btr )
107-
108103 self .open ()
109104
110105 super ().__init__ (
@@ -117,8 +112,7 @@ def set_bitrate(self, bitrate):
117112 self .write (self ._BITRATES [bitrate ])
118113 else :
119114 raise ValueError (
120- "Invalid bitrate, choose one of " +
121- (", " .join (self ._BITRATES )) + "."
115+ "Invalid bitrate, choose one of " + (", " .join (self ._BITRATES )) + "."
122116 )
123117 self .open ()
124118
@@ -136,19 +130,14 @@ def read(self, timeout):
136130 # first read what is already in receive buffer
137131 while self .serialPortOrig .in_waiting :
138132 self ._buffer += self .serialPortOrig .read ()
139-
140133 # if we still don't have a complete message, do a blocking read
141134 start = time .time ()
142135 time_left = timeout
143- while not (
144- ord (self ._OK ) in self ._buffer or
145- ord (self ._ERROR ) in self ._buffer
146- ):
136+ while not (ord (self ._OK ) in self ._buffer or ord (self ._ERROR ) in self ._buffer ):
147137 self .serialPortOrig .timeout = time_left
148138 byte = self .serialPortOrig .read ()
149139 if byte :
150140 self ._buffer += byte
151-
152141 # if timeout is None, try indefinitely
153142 if timeout is None :
154143 continue
@@ -160,15 +149,12 @@ def read(self, timeout):
160149 continue
161150 else :
162151 return None
163-
164152 # return first message
165153 for i in range (len (self ._buffer )):
166- if ( self ._buffer [i ] == ord (self ._OK ) or
167- self ._buffer [i ] == ord (self ._ERROR ) ):
168- string = self ._buffer [:i + 1 ].decode ()
169- del self ._buffer [:i + 1 ]
154+ if self ._buffer [i ] == ord (self ._OK ) or self ._buffer [i ] == ord (self ._ERROR ):
155+ string = self ._buffer [: i + 1 ].decode ()
156+ del self ._buffer [: i + 1 ]
170157 break
171-
172158 return string
173159
174160 def flush (self ):
@@ -217,7 +203,6 @@ def _recv_internal(self, timeout):
217203 dlc = int (string [9 ])
218204 extended = True
219205 remote = True
220-
221206 if canId is not None :
222207 msg = Message (
223208 arbitration_id = canId ,
@@ -233,7 +218,6 @@ def _recv_internal(self, timeout):
233218 def send (self , msg , timeout = None ):
234219 if timeout != self .serialPortOrig .write_timeout :
235220 self .serialPortOrig .write_timeout = timeout
236-
237221 if msg .is_remote_frame :
238222 if msg .is_extended_id :
239223 sendStr = "R%08X%d" % (msg .arbitration_id , msg .dlc )
@@ -244,7 +228,6 @@ def send(self, msg, timeout=None):
244228 sendStr = "T%08X%d" % (msg .arbitration_id , msg .dlc )
245229 else :
246230 sendStr = "t%03X%d" % (msg .arbitration_id , msg .dlc )
247-
248231 sendStr += "" .join (["%02X" % b for b in msg .data ])
249232 self .write (sendStr )
250233
@@ -274,7 +257,6 @@ def get_version(self, timeout):
274257 hw_version = int (string [1 :3 ])
275258 sw_version = int (string [3 :5 ])
276259 return hw_version , sw_version
277-
278260 # if timeout is None, try indefinitely
279261 if timeout is None :
280262 continue
@@ -301,7 +283,6 @@ def get_serial_number(self, timeout):
301283 elif string [0 ] == cmd and len (string ) == 6 :
302284 serial_number = string [1 :- 1 ]
303285 return serial_number
304-
305286 # if timeout is None, try indefinitely
306287 if timeout is None :
307288 continue
0 commit comments