hardbyte / python-can

The can package provides controller area network support for Python developers
https://python-can.readthedocs.io
GNU Lesser General Public License v3.0
1.29k stars 602 forks source link

j1939_logger dumping messages #57

Closed hardbyte closed 8 years ago

hardbyte commented 8 years ago

Originally reported by: Olivier Bertrand (Bitbucket: lamoule74, GitHub: Unknown)


Hi all,

Many frames aren't captured by the J1939_logger when executed.. see attached; I'm using candump and wireshark for to highlighting this: Link Text Btw, the speed I'm putting between the cansend seems to influence the reception like: the faster I'm sending frames, the better they are received...

The behaviour is quite different when I try this in my own program, the 3 first messages are dumped, then they're all seen by terminal...

#!python

#!/usr/bin/python3.4
# coding: utf8
import can
from can.protocols import j1939
from can.interfaces.interface import *
from can import Message
import sys,os,operator

# create bus
bus = j1939.Bus(channel='vcan0', bustype='socketcan_ctypes')

message = bus.recv() 

#for message in Bus('vcan0'):
print(message)

# close the bus
bus.shutdown()
sys.exit(0)

do you have any example available ?.. I know there is many TODO for J1939, but if you have any explanations...

Best.


hardbyte commented 8 years ago

Original comment by David 'Miller' Lowe (Bitbucket: milhead, GitHub: milhead):


My company makes gauges for motorcycles and other off road vehicles, Currently we don't have much automated test so I'm building a set of libraries that sit between your j1939 module and Robot Framework.

I can now send periodic messages from the test harness quite well but am struggling a bit with some of the protocol interchages like a DM14 memory transfer.. I'm quite new to J1939.

If you'd like I can shoot up some examples but they are premature for posting

Mil

hardbyte commented 8 years ago

Original comment by Olivier Bertrand (Bitbucket: lamoule74, GitHub: Unknown):


Hey guys, sorry for the late reply...

@milhead : Dunno this framework, by curiosity when you say gauges are you talking about measuring instrument? Have you made some conclusive tests since your last post ?

@M_Molt : yeah, I've tried the standard bus which works correctly. I've created my own J1939 class, my project must progress anyway..

@hardbyte : Btw, you should use the last Wireshark via automated build ( https://www.wireshark.org/download/automated/ ) I've reported some bugs on J1939 wireshark dissector.. Otherwise, this fixed bug should be efficient on the next Wireshark's release. Does kvaser receive's functions are dumping the first messages in the same way ?... Do you advice me to use Kvaser's canlib ?

hardbyte commented 8 years ago

Original comment by Brian Thorne (Bitbucket: hardbyte, GitHub: hardbyte):


The only interface that I've used the J1939 code with is Kvaser. Replicating your test Olivier using linux virtual socketcan I get the same results - the messages all appear in a raw can logger, but not the J1939 one. Wireshark isn't picking up the messages as J1939 for me though.

We need to see if this just effects the socketcan interface.

@milhead what interface are you using?

This test J1939 send might be useful too:

from __future__ import print_function

from time import sleep

import can
from can.protocols import j1939

def send_j1939():
    bus = j1939.Bus(channel='vcan0')

    node1 = j1939.Node(bus, j1939.NodeName(0), [0x01])
    node2 = j1939.Node(bus, j1939.NodeName(0), [0x42])

    bus.j1939_notifier.listeners.append(node1)
    bus.j1939_notifier.listeners.append(node2)

    pgn = j1939.PGN(reserved_flag=True,
                    pdu_specific=j1939.constants.DESTINATION_ADDRESS_GLOBAL)
    arbitration_id = j1939.ArbitrationID(pgn=pgn, source_address=0x01)
    msg = j1939.PDU(arbitration_id=arbitration_id,
                    data=[0x10, 0x20, 0x30])

    sleep(1)
    node1.start_address_claim()
    sleep(1)
    try:
        bus.send(msg)
        print("Message sent on {}".format(bus.channel_info))
    except can.CanError:
        print("Message NOT sent")

    sleep(1)
    bus.flush_tx_buffer()
    bus.shutdown()

if __name__ == "__main__":
    send_j1939()
hardbyte commented 8 years ago

Original comment by Mike Molt (Bitbucket: M_Molt, GitHub: Unknown):


Oliver have you tried the standard bus to get the messages? As I understand it J1939 is just mapped into the extended message frame of regular ole CAN.

hardbyte commented 8 years ago

Original comment by David 'Miller' Lowe (Bitbucket: milhead, GitHub: milhead):


I've been attempting to pick-up the j1939 protocol code to instrument j1939 testing with Robot Framework for our gauges

If I enable the python INFO or DEBUG logging is see the j1939 bus receiving many more messages but they don't percolate to be received and returned by the recv() method.

Currently I'm trying to issue DM13 commands, some examples would really be nice.

hardbyte commented 8 years ago

Original comment by Olivier Bertrand (Bitbucket: lamoule74, GitHub: Unknown):


Hello,

I need to know if this is a bug.. If yes I have to create my own code brick above python-can for the J1939's bus management. Else, I must understand how this is working and what necessary to do for receiving the messages at the first sending.

Thank you in advance guys. cheers

hardbyte commented 8 years ago

Original comment by Olivier Bertrand (Bitbucket: lamoule74, GitHub: Unknown):


Anyone ?

hardbyte commented 8 years ago

I'll close this here on github as this repository isn't going to include J1939.