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

Simple example for Notifier? #71

Closed hardbyte closed 8 years ago

hardbyte commented 8 years ago

Originally reported by: Mathias Giacomuzzi (Bitbucket: mgiaco, GitHub: mgiaco)


Hello,

I tried to read back a message. So I tried:

#!python

from __future__ import print_function
from time import sleep
import can

TIMEOUT = 30

def send_one():
    bus = can.interface.Bus(bitrate=250000)
    msg = can.Message(arbitration_id=0x2,
                      data=[1, 0, 0, 0, 0, 0, 0, 0],
                      extended_id=False)
    try:
        can.Notifier(bus, [can.Printer()])
        bus.send(msg)
        print("Message sent on {}".format(bus.channel_info))
    except can.CanError:
        print("Message NOT sent")

if __name__ == "__main__":
    send_one()
    sleep(5)

So I attached a sniffer and I get a message back but I get this error:

#!python

Exception in thread Thread-1:
Traceback (most recent call last):
  File "c:\python27\Lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "c:\python27\Lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "C:\Users\lwngim1\Envs\py27_pycan\lib\site-packages\python_can-1.5.0-py2.7.egg\can\notifier.py", line 35, in rx_thread
    callback(msg)
  File "C:\Users\lwngim1\Envs\py27_pycan\lib\site-packages\python_can-1.5.0-py2.7.egg\can\CAN.py", line 43, in __call__
    return self.on_message_received(msg)
  File "C:\Users\lwngim1\Envs\py27_pycan\lib\site-packages\python_can-1.5.0-py2.7.egg\can\CAN.py", line 90, in on_message_received
    print(msg)
  File "C:\Users\lwngim1\Envs\py27_pycan\lib\site-packages\python_can-1.5.0-py2.7.egg\can\message.py", line 73, in __str__
    if (self.data is not None) and (self.data.isalnum()):
AttributeError: 'c_ubyte_Array_8' object has no attribute 'isalnum'

Exception AttributeError: "'NoneType' object has no attribute 'write'" in <bound method Printer.__del__ of <can.CAN.Printer object at 0x0000000002963080>> ignored

Process finished with exit code 0

Is it possible that this is a python2.7 problem?

thx


hardbyte commented 8 years ago

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


This should be solved in the latest development version. Please test/reopen if this isn't the case.

hardbyte commented 8 years ago

Original comment by Mathias Giacomuzzi (Bitbucket: mgiaco, GitHub: mgiaco):


Hello,

Yes I use Pcan.

hardbyte commented 8 years ago

Original comment by Kevin Albert (Bitbucket: Kevinalb, GitHub: Kevinalb):


If you are using PCAn this may be linked to the Issue #66

I have the same issue with python 3.5