Simple example for Notifier?

Issue #71 resolved
Mathias Giacomuzzi created an issue

Hello,

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

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:

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

Comments (3)

  1. Brian Thorne repo owner

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

  2. Log in to comment