|
10 | 10 | from can.interfaces.PCANBasic import * |
11 | 11 | from can.bus import BusABC |
12 | 12 | from can.message import Message |
| 13 | +from can import CanError |
13 | 14 | import time |
14 | 15 |
|
15 | 16 | boottimeEpoch = 0 |
@@ -173,28 +174,25 @@ def recv(self, timeout=None): |
173 | 174 |
|
174 | 175 | log.debug("Received a message") |
175 | 176 |
|
176 | | - arbitration_id = theMsg.ID |
177 | | - |
178 | 177 | bIsRTR = (theMsg.MSGTYPE & PCAN_MESSAGE_RTR.value) == PCAN_MESSAGE_RTR.value |
179 | 178 | bIsExt = (theMsg.MSGTYPE & PCAN_MESSAGE_EXTENDED.value) == PCAN_MESSAGE_EXTENDED.value |
180 | 179 |
|
181 | | - # Flags: EXT, RTR, ERR |
182 | | - #flags = (PYCAN_RTRFLG if bIsRTR else 0) | (PYCAN_STDFLG if not bIsExt else 0) |
183 | | - |
184 | 180 | if bIsExt: |
185 | 181 | #rx_msg.id_type = ID_TYPE_EXTENDED |
186 | 182 | log.debug("CAN: Extended") |
187 | 183 | else: |
188 | 184 | #rx_msg.id_type = ID_TYPE_STANDARD |
189 | 185 | log.debug("CAN: Standard") |
190 | 186 |
|
191 | | - rx_msg.arbitration_id = arbitration_id |
192 | | - rx_msg.id_type = bIsExt |
193 | | - rx_msg.is_remote_frame = bIsRTR |
194 | | - rx_msg.dlc = theMsg.LEN |
195 | | - #rx_msg.flags = flags |
196 | | - rx_msg.data = theMsg.DATA |
197 | | - rx_msg.timestamp = boottimeEpoch + ((itsTimeStamp.micros + (1000 * itsTimeStamp.millis)) / (1000.0 * 1000.0)) |
| 187 | + dlc = theMsg.LEN |
| 188 | + timestamp = boottimeEpoch + ((itsTimeStamp.micros + (1000 * itsTimeStamp.millis)) / (1000.0 * 1000.0)) |
| 189 | + |
| 190 | + rx_msg = Message(timestamp=timestamp, |
| 191 | + arbitration_id=theMsg.ID, |
| 192 | + extended_id=bIsExt, |
| 193 | + is_remote_frame=bIsRTR, |
| 194 | + dlc=dlc, |
| 195 | + data=theMsg.DATA[:dlc]) |
198 | 196 |
|
199 | 197 | return rx_msg |
200 | 198 |
|
@@ -224,13 +222,8 @@ def send(self, msg): |
224 | 222 | log.debug("Type: %s", type(msg.data)) |
225 | 223 |
|
226 | 224 | result = self.m_objPCANBasic.Write(self.m_PcanHandle, CANMsg) |
227 | | - |
228 | | - sent = result == PCAN_ERROR_OK |
229 | | - |
230 | | - if not sent: |
231 | | - logging.warning("Failed to send: " + self._get_formatted_error(result)) |
232 | | - |
233 | | - return sent |
| 225 | + if result != PCAN_ERROR_OK: |
| 226 | + raise CanError("Failed to send: " + self._get_formatted_error(result)) |
234 | 227 |
|
235 | 228 | def flash(self, flash): |
236 | 229 | """ |
|
0 commit comments