dzhu / myo-raw

MIT License
218 stars 115 forks source link

struct.error: unpack requires a bytes object of length 3 #32

Open hassanyousufx opened 6 years ago

hassanyousufx commented 6 years ago

I get a struct.error when I run myo-raw.py or myo.py.

hassan@finroc:~/myo-raw-master$ python myo.py 
using device: /dev/ttyACM0
scanning...
scan response: Packet(80, 06, 00, [C8 00 D4 D1 52 C7 46 DC 00 FF 1F 09 08 4D 79 6F 00 00 00 00 00 02 01 06 11 06 42 48 12 4A 7F 2C 48 47 B9 DE 04 A9 01 00 06 D5])
firmware version: 1.5.1970.2
device name: b'\x00\x03\x00\x00\x03Myo'
0
Traceback (most recent call last):
  File "myo.py", line 115, in <module>
    m.run()
  File "/home/hassan/myo-raw-master/myo_raw.py", line 195, in run
    self.bt.recv_packet(timeout)
  File "/home/hassan/myo-raw-master/myo_raw.py", line 80, in recv_packet
    self.handle_event(ret)
  File "/home/hassan/myo-raw-master/myo_raw.py", line 112, in handle_event
    h(p)
  File "/home/hassan/myo-raw-master/myo_raw.py", line 291, in handle_data
    typ, val, xdir = unpack('3B', pay)
  File "/home/hassan/myo-raw-master/common.py", line 7, in unpack
    return struct.unpack('<' + fmt, *args)
struct.error: unpack requires a bytes object of length 3

I am running this in Ubuntu 16.04.5 LTS. What could be the reason? I want to run Myo in Linux environment.

ssravali commented 5 years ago

I got the same error while running on a windows 8 OS with python 3.5!! What to do?

ghost commented 5 years ago

I got the same error while running on a windows 8 OS with python 3.5!! What to do?

Someone has updated this library to run on 3.5 and possibly higher. Myo Raw Python3

HIFIKIKI commented 5 years ago

Anyone can solve this problem?

MiraWelner commented 4 years ago

Use loxxy's solution! They made a pull request that was not merged, but it's a simple fix: Just switch elif attr == 0x23 typ, val, xdir = unpack('3B', pay)

to: elif attr == 0x23

6 Bytes instead of 3

            typ, val, xdir,_,_,_ = unpack('6B', pay)