@@ -59,14 +59,14 @@ def __init__(self, channel, *args, **kwargs):
5959
6060 :param str channel:
6161 The can interface name. An example would be PCAN_USBBUS1
62-
62+
6363 Backend Configuration
6464 ---------------------
65-
65+
6666 :param int bitrate:
6767 Bitrate of channel in bit/s.
6868 Default is 500 Kbs
69-
69+
7070 """
7171 if channel is None or channel == '' :
7272 raise ArgumentError ("Must specify a PCAN channel" )
@@ -75,7 +75,7 @@ def __init__(self, channel, *args, **kwargs):
7575
7676 bitrate = kwargs .get ('bitrate' , 500000 )
7777 pcan_bitrate = pcan_bitrate_objs .get (bitrate , PCAN_BAUD_500K )
78-
78+
7979 hwtype = PCAN_TYPE_ISA
8080 ioport = 0x02A0
8181 interrupt = 11
@@ -86,8 +86,7 @@ def __init__(self, channel, *args, **kwargs):
8686 result = self .m_objPCANBasic .Initialize (self .m_PcanHandle , pcan_bitrate , hwtype , ioport , interrupt )
8787
8888 if result != PCAN_ERROR_OK :
89- # TODO throw a specific exception.
90- raise Exception (self ._get_formatted_error (result ))
89+ raise PcanError (self ._get_formatted_error (result ))
9190
9291 super (PcanBus , self ).__init__ (* args , ** kwargs )
9392
@@ -167,7 +166,7 @@ def recv(self, timeout=None):
167166 result = None
168167 time .sleep (0.001 )
169168 elif result [0 ] != PCAN_ERROR_OK :
170- raise Exception (self ._get_formatted_error (result [0 ]))
169+ raise PcanError (self ._get_formatted_error (result [0 ]))
171170
172171 theMsg = result [1 ]
173172 itsTimeStamp = result [2 ]
@@ -212,7 +211,7 @@ def send(self, msg):
212211
213212 # if a remote frame will be sent, data bytes are not important.
214213 if msg .is_remote_frame :
215- CANMsg .MSGTYPE = msgType | PCAN_MESSAGE_RTR
214+ CANMsg .MSGTYPE = msgType . value | PCAN_MESSAGE_RTR . value
216215 else :
217216 # copy data
218217 for i in range (CANMsg .LEN ):
@@ -223,7 +222,7 @@ def send(self, msg):
223222
224223 result = self .m_objPCANBasic .Write (self .m_PcanHandle , CANMsg )
225224 if result != PCAN_ERROR_OK :
226- raise CanError ("Failed to send: " + self ._get_formatted_error (result ))
225+ raise PcanError ("Failed to send: " + self ._get_formatted_error (result ))
227226
228227 def flash (self , flash ):
229228 """
@@ -234,3 +233,7 @@ def flash(self, flash):
234233
235234 def shutdown (self ):
236235 self .m_objPCANBasic .Uninitialize (self .m_PcanHandle )
236+
237+
238+ class PcanError (CanError ):
239+ pass
0 commit comments