0

My program sends almost 50 messages, all with different ID's, on a pcan can-bus. And then loops again continuously, starting with a new data for 1st ID.

I have been able to initialize and send the single ID message, but I'm not able to send any other ID on the bus. I am analyzing the bus signal using an oscilloscope, and therefore I can see what messages are on the bus.

This is a part of code, showing how I'm trying to send 2 consecutive messages on the bus, but it only sends the id=100 message and not the next ones. I'm only importing the python-can library, for this.

        for i in range(self.n_param):
            if self.headers[i] == 'StoreNo':  # ID 100 byte size = 3
                to_can_msg = []
                byte_size = 3
                hex_data = '0x{0:0{1}X}'.format(int(self.row_data[i], 10), byte_size * 2)
                to_can_msg = [int(hex_data[2:4], 16), int(hex_data[5:6], 16), int(hex_data[7:8], 16)]
                bus_send.send(Message(arbitration_id=100, data=to_can_msg))

            elif self.headers[i] == 'Date':  # ID 101 byte size = 4
                to_can_msg = []
                byte_size = 4
                date_play = int(self.row_data[i].replace("/", ""), 10)
                hex_data = '0x{0:0{1}X}'.format(date_play, byte_size * 2)
                to_can_msg = message_array(hex_data)
                bus_send.send(Message(arbitration_id=101, data=to_can_msg))

And I'm closing each loop with bus_send.reset() to clear any outstanding message in the queue and begin afresh in the next loop.

Much thanks!

Inc0gnito
  • 21
  • 6
  • Too little information to answer. You'll either need to provide a [mcve] or describe your trouble-shooting steps more in detail. The problem could be in the application code, or how you use the library, or in the hardware. For example, are there any other CAN nodes listening on the bus? – Lundin May 13 '19 at 07:54
  • I understand. I'm a beginner, so couldn't figure out then how much would be the right information to convey my problem. But after some more research, I figured this one out. So answering for myself below. – Inc0gnito May 14 '19 at 14:25
  • Which is what I hinted at with "are there any other CAN nodes listening on the bus?", since this happens to be the single-most common beginner problem when it comes to CAN :) – Lundin May 14 '19 at 14:36

1 Answers1

0

Turns out I missed an important detail in CAN communication,the ACK bit, which needs to be set to recessive by the receiver node. And since I'm only trying to read the CAN bus using one node,that node keeps on transmitting the first message forever in hope to receive the ACK bit. Loopback could've worked but appears like pcan doesn't support loopback functionality for linux. So would have to use a second CAN node to receive messages.

Inc0gnito
  • 21
  • 6