Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: CmdMessenger + PyCmdMessenger on teensy

  1. #1
    Junior Member
    Join Date
    Oct 2017
    Posts
    15

    CmdMessenger + PyCmdMessenger on teensy

    Hi,

    I'm trying to run the CmdMessenger and PyCmdMessenger combo example from https://github.com/harmsm/PyCmdMesse...aster/examples on my Teensy 3.6.

    This is on Ubuntu.

    I get the following error on the Python side:

    Code:
    $ python3 python-basic.py 
    Connecting to arduino on /dev/ttyACM0... done.
    ('my_name_is', ['Bob'], 1511212793.2456436)
    Traceback (most recent call last):
      File "python-basic.py", line 31, in <module>
        msg = c.receive()
      File "/usr/local/lib/python3.5/dist-packages/PyCmdMessenger/PyCmdMessenger.py", line 284, in receive
        received.append(self._recv_methods[arg_format_list[i]](f))
      File "/usr/local/lib/python3.5/dist-packages/PyCmdMessenger/PyCmdMessenger.py", line 551, in _recv_int
        return struct.unpack(self.board.int_type,value)[0]
    struct.error: unpack requires a bytes object of length 2
    Any suggestions?

  2. #2
    Junior Member
    Join Date
    Aug 2015
    Posts
    11
    I have the same issue, using a teensy 3.5 and windows. Did you resolve it? The only thing I caught was that the baud rates were mismatched at first, but I still get the error after making them the same.

  3. #3
    Junior Member
    Join Date
    Oct 2017
    Posts
    15
    Quote Originally Posted by Erik View Post
    I have the same issue, using a teensy 3.5 and windows. Did you resolve it? The only thing I caught was that the baud rates were mismatched at first, but I still get the error after making them the same.

    I didn't resolve it and just abandoned the project. Sorry.

  4. #4
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,701
    I am not a python person, but was wondering what version of python you were running? Sounds like it was developed for 3.x version of python, but also gives you a link to go to if you are tying to run on 2.7. I noticed on my windows machine if I try to run python, it says version 2.7.3

    I remember some other recent thread where someone was having issues when they were trying to convert a program between two different versions of python.

  5. #5
    Junior Member
    Join Date
    Aug 2015
    Posts
    11
    I overcame the (first part) of the problem by realizing I had the wrong sketch on the teensy. In the \PyCmdMessenger\test\pingpong_arduino, the main.cpp is actually the sketch to upload. It threw me off since it was a .ino extension. Now all the types of size 4 bytes are passing. I am still having trouble with kDouble, which should be 8 bytes for both my python system and teensy micro. Struct.unpack() is looking for 4 byte buffer for some reason.

    KurtE- no that is not the problem, I'm on the latest python.

  6. #6
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,701
    Sorry... But I thought it was worth mentioning...

    As for 4 bytes vs 8 bytes... Maybe configuration issue?

    In the file: https://github.com/harmsm/PyCmdMesse...ger/arduino.py
    Code:
        def __init__(self,
                     device,
                     baud_rate=9600,
                     timeout=1.0,
                     settle_time=2.0,
                     enable_dtr=False,
                     int_bytes=2,
                     long_bytes=4,
                     float_bytes=4,
                     double_bytes=4):
    Which says double_bytes=4... Not sure if there is configuration stuff on both sides...

  7. #7
    Junior Member
    Join Date
    Aug 2015
    Posts
    11
    Right- I did see that configuration and I have the types reflecting the bytes from here:
    https://forum.pjrc.com/threads/36658...ypes-bit-depth
    So I use
    Code:
     double_bytes = 8
    , and
    Code:
    struct.calcsize('d')
    = 8 on my machine.
    Also,
    Code:
    struct.calcsize('@d')
    and
    Code:
    struct.calcsize('=d')
    are both 8 on my machine.
    I need to enter a debug session I think and examine what pycommandmessenger is receiving and why it is expecting 4 bytes, not 8.

  8. #8
    Junior Member
    Join Date
    Oct 2015
    Posts
    3
    Did anyone get this working? I'm trying to use CmdMessenger now with a Teensy3.2 and PyCmdMessenger. I'm pulling my hair out.
    The library seems to be exactly what I need. Send messages in both directions with arguments and callback functions. The only problem is that I can't even get the turn-on-LED example to work. If anyone has working Arduino and Python code I'd really appreciate seeing it.
    Thanks,
    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •