USB packets - receive wrong data

Posted by regorianer on Ask Ubuntu See other posts from Ask Ubuntu or by regorianer
Published on 2012-03-19T08:01:18Z Indexed on 2012/03/19 10:19 UTC
Read the original article Hit count: 984

Filed under:

i have a little python script which shows me the packets of an enocean device and does some events depending on the packet type. unfortunately it doesn't work because i'm getting wrong packets.

Parts of the python script (used pySerial):

Blockquote

ser = serial.Serial('/dev/ttyUSB1',57600,bytesize = serial.EIGHTBITS,timeout = 1, parity = serial.PARITY_NONE , rtscts = 0)

print 'clearing buffer'

s = ser.read(10000)

print 'start read'

while 1:

s = ser.read(1)

for character in s:

sys.stdout.write(" %s" % character.encode('hex'))

print 'end'

ser.close()

output baudrate 57600: e0 e0 00 e0 00 e0 e0 e0 e0 e0 00 e0 e0 00 00 00 00 00 00 00 e0 e0 e0 00 00 00 00 e0 e0 e0 00 00 e0 e0 e0 e0 e0 00 e0 00 e0 e0 e0 e0 e0 00 e0 e0 00 00 00 00 00 00 e0 e0 e0 00 00 00 00 e0 e0 e0 00 00 e0 e0 e0

output baudrate 9600: a5 5a 0b 05 10 00 00 00 00 15 c4 56 20 6f a5 5a 0b 05 00 00 00 00 00 15 c4 56 20 5f

linux terminal baudrate 57600:

$stty -F /dev/ttyUSB1 57600

$stty < /dev/ttyUSB1 speed 57600 baud; line = 0; eof = ^A; min = 0; time = 0; -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

$while (true) do cat -A /dev/ttyUSB1 ; done >> myfile

$hexdump -C myfile

00000000 4d 2d 60 4d 2d 60 5e 40 4d 2d 60 5e 40 4d 2d 60 |M-M-^@M-^@M-|

00000010 4d 2d 60 4d 2d 60 4d 2d 60 4d 2d 60 5e 40 4d 2d |M-M-M-M-^@M-|

00000020 60 4d 2d 60 5e 40 5e 40 5e 40 5e 40 5e 40 5e 40 |M-^@^@^@^@^@^@|

00000030 5e 40 4d 2d 60 4d 2d 60 4d 2d 60 5e 40 5e 40 5e |^@M-M-M-`^@^@^|

00000040 40 5e 40 4d 2d 60 4d 2d 60 4d 2d 60 |@^@M-M-M-`| 0000004c

linux terminal baudrate 9600:

$hexdump -C myfile2 00000000 5e 40 5e 55 4d 2d 44 56 30 4d 2d 3f 5e 40 5e 40 |^@^UM-DV0M-?^@^@|

00000010 5e 55 4d 2d 44 56 20 5f |^UM-DV _|

00000018

the specification says:

  • 0x55 sync byte 1st

  • 0xNNNN data length bytes (2 bytes)

  • 0x07 opt length byte

  • 0x01 type byte

  • CRC, data, opt data und nochmal CRC

but I'm not getting this packet structure. The output of the python script differs from the one I get via the terminal. I also wrote the python part with C, but the output is the same as with python

As the USB receiver a BSC-BoR USB Receiver/Sender is used

The EnOcean device is a simple button

© Ask Ubuntu or respective owner

Related posts about usb