1

I am using pySerial to get data from an Arduino (micro-controller).

The data are stored in a pickle file. It worked fine with Blender 2.49 (python 2.7).

Now, shifting to Blender 2.56 (python 3.2), I get the following error:

f=open('abc.dat','r')

with serial.Serial('COM31',9600) as port :
    for i in range(0, 10):
            x = port.read(size=1)
            print(int(x))
            y=pickle.load(f)
            f.close()
            f=open('abc.dat','w')
            y.append(i)                        
            pickle.dump(y,f)
            f.close()

port.close()

error:
Python script error from controller "Python Script#CONTR#1":
Traceback (most recent call last):
  File "256script1.py", line 18, in <module>
    f.close()
  File "C:\PROGRA~1\BLENDE~1\Blender\2.54\python\lib\pickle.py", line 1365, in l
oad
    encoding=encoding, errors=errors).load()
ValueError: read() from the underlying stream did notreturn bytes

Blender Game Engine Finished

Are there any operational changes in the use of pickle?

Greenonline
  • 1,330
  • 8
  • 23
  • 31
change
  • 3,400
  • 7
  • 32
  • 42
  • 1
    You are supposed to accept the best answer to your questions. Please accept some answers. It's really annoying to spend time to answer questions and then you get nothing for it. – Lennart Regebro Feb 27 '11 at 21:08
  • i m really sorry. but was unaware of such a thing.. hw m i supossed to do the same? – change Mar 01 '11 at 14:20
  • You select the checkbox besides the best answer. Please read the FAQ. http://stackoverflow.com/faq – Lennart Regebro Mar 04 '11 at 13:02

1 Answers1

1

You open the file in text mode, but for pickles it should be in binary mode. In Python 2 this doesn't matter (Except on Windows), but in Python 3 it does.

It should be

f=open('abc.dat','rb')
Lennart Regebro
  • 167,292
  • 41
  • 224
  • 251