python - type error occurred using buffer memoryview -


i wanted program gets data serial port start , stop bit * , #. data received in *1234567# form. says 'type' object not subscriptable. i'm new python don't know next, can me solve problem?

import serial  ser = serial.serial(     port='com5',\     baudrate=9600,\     parity=serial.parity_none,\     stopbits=serial.stopbits_one,\     bytesize=serial.eightbits,\         timeout=0)  max_buf_size = 16 bits = 0  v = memoryview    print("connected to: " + ser.portstr)    while(1):     memoryview in ser.read():         if v[0] == 42:              if v[-1] == 35:                  print(v[1:-1].tobytes())          else:             memoryview = 0 ser.close() 

connected to: com5 traceback (most recent call last):   file "c:\python33\saves\receive using buff.py", line 24, in <module>     if v[0] == 42: typeerror: 'type' object not subscriptable >>>  

what doing wildly over-complicated. have no idea why using memoryview @ all. this:

import serial  ser = serial.serial(     port='com5',     baudrate=9600,     parity=serial.parity_none,     stopbits=serial.stopbits_one,     bytesize=serial.eightbits,     timeout=0)  print("connected to: " + ser.portstr) data in ser.read():     if data[0] == 42 , data[-1] == 35:            print(data[1:-1].decode()) ser.close() 

this unlikely work want, it's simplification of code. how actually handle depends on how data looks more in detail.


Comments

Popular posts from this blog

Eclipse formatter for java ending braces -

ruby - Nesting modules inside of a Rails eninge gem -

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -