intrepidcs / python_ics

Library for interfacing with Intrepid devices in Python
MIT License
61 stars 29 forks source link

Got redundant frame while sending CAN periodically #174

Closed silin0816 closed 3 months ago

silin0816 commented 6 months ago

The device i used is Neo VI and i call the api to send CAN as demo shown. But when i send CAN data periodcally (about 20 ms), it got a redundant frame on bus.
As the log below, the frame inside the blue box is the normal send frame, the red one is redundant. The second byte in red frame is 00 which is set before. now it appeared when i already set the byte to 0x20. The second-to-last bytes is counter, it should be continous, but the red frame is not continous like frames inside blue box. Therefore, it is not realtime.

img_v3_027o_07292763-6860-4a91-baf0-e098f85f48ag

the way i send frame is call the transmit_can function by timer (e.g. 20 ms).

    def transmit_can(self, Id, DataList, DataLen, Channel):
        msg = ics.SpyMessage()
        msg.ArbIDOrHeader = Id
        send_data = []
        for i in range(0, DataLen):
            try:
                send_data.append(DataList[i])
            except IndexError:
                send_data.append(0xCC)
        msg.Data = tuple(send_data)
        msg.NetworkID = neo_vi_NETIDS_REVERSE[Channel]
        # msg parameter here can also be a tuple of messages
        ics.transmit_messages(self.tx_device, msg)

Why there is a frame that might be sent previously? is it was saved in the cache and not be set before. Or is the way i used the api not correct? I am so appreciate if someone can give me some hints... thx

drebbe-intrepid commented 6 months ago

When a message is transmitted via ics.transmit_messages() it will queue up a ics.SpyMessage() on the receive side also. This is useful for detecting CAN errors with the status bit fields. From what I can tell the two blue boxes look correct to me. The messages in the red box look like a response from another CAN device, hard to tell without knowing the entire bus configuration and having all the source code.

These APIs are not real-time since we have to deal with everything at the operating system level and firmware level for processing. If you need that type of precision, I recommend writing a coremini script with Vehicle Spy 3.

Hopefully this answers the questions you have.

drebbe-intrepid commented 3 months ago

@silin0816 I'm going to close this out as complete, please feel free to re-open if needed.