No attribute setBaudrate

Hello, I am brand new to psychopy and found it while trying to get a way to communicate with my PhotoResearch PR655 meter for use in my python project. I installed all the dependencies to get the program to run, but I’m unsuccessfully trying to connect to my meter. The documentation I followed is here:

http://www.psychopy.org/api/hardware/pr.html#psychopy.hardware.pr.PR655

With very little serial communication experience, it is unclear to me what to use as ‘port’ so I have tried both ‘/dev/tty.usbmodem31’ and ‘/dev/cu.usbmodem31’. When I run my script:

from psychopy.hardware.pr import PR655

port = r'/dev/tty.usbmodem31'
meter = PR655(port)

meter.getDeviceSN()

I get the following error:

Traceback (most recent call last):
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 1596, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/pydevd.py", line 974, in run
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/ccuellar/gdrive/softdev/proj/cal_tools/cal_tools/pr_connect.py", line 4, in <module>
    meter = PR655(port)
  File "/usr/local/lib/python2.7/site-packages/psychopy/hardware/pr.py", line 318, in __init__
    self.com.setBaudrate(115200)
AttributeError: 'Serial' object has no attribute 'setBaudrate'

I poked around the pr.py file and don’t see any methods for the PR655 class called setBaudrate, so I’m not sure how this is supposed to run. I will keep poking around and seeing if there is anything else, but I assume this is a problem on my end as I’m sure other people have made this meter work if the module exists for it. Any help would be greatly appreciated!

Hello,

Which version of PsychoPy are you running? Looking at the “pr.py” file of the latest version shows baudrate is being set using an attribute rather than a setter method. PySerial seems to have removed the “setBaudrate()” method for specifying baudrate. A solution would be to update your PsychoPy installation and try running your code again.

Name: PsychoPy
Version: 1.84.2

This should be the latest version, and I also have the latest PySerial module. I pip installed both modules today.

This is where it’s failing in pr.py:

        try:
            self.com = serial.Serial(self.portString)
        except Exception:
            msg = ("Couldn't connect to port %s. Is it being used by "
                   "another program?")
            self._error(msg % self.portString)
        # setup the params for PR650 comms
        if self.OK:
            self.com.setBaudrate(9600)

Now if I trace back into the serial init.py file I see it’s importing Serial from serialposix.py:

elif os.name == 'posix':
        from serial.serialposix import Serial, PosixPollSerial, VTIMESerial  # noqa

Now, in pr.py, the line

self.com.setBaudrate(9600)

is confusing because it appears to be calling a method of the Serial class, which does not exist. All I see in serialposix.py that suggests it would do something with the baudrate is a method called _reconfigure_port, but it doesn’t have a baudrate parameter, so I’m at a bit of a loss as to what pr.py should be calling.

Hello Cody,

The most current version of PsychoPy is 1.85 which should be available from the main site. Examine the following ‘pr.py’ file from the r1.85 branch to see where the differences are:

R1.85 hasn’t yet been uploaded to PIP I presume. An interm solution would be to clone the r1.85 repository and manually install PsychoPy using setuptools.

Excellent, thank you so much - makes much more sense. I just copied those three lines from the new code into my existing install and all appears to work as needed for now.

You could perhaps alternatively revert to the previous working pyserial:

pip install pyserial==2.7
2 Likes

I’ll try that too, so far I have a very limited use for either module, so since it’s working now, I’m sure they will publicly release a newer compatibly PsychoPy version before I ever need any other features. But thanks for the tip, I’ll do that if I run into any other issues.