Cannot connect Photoresearch PR655 to PC using Psychopy, Communication Protocol Problem?

Dear All,

I’m coming close to the cause of the problem.

PR-655 is driven by the script ‘pr.py’ (in ‘hardware’ subfolder of psychopy scripts.).
In PsychoPy2, the class PR655 had a separate ‘sendMessage’ to have this part:

        for letter in message:
            # for PR655 have to send individual chars ! :-/
            self.com.write(letter)
            self.com.flush()

In PsychoPy3 (incl. 2021.2.3), this function is deleted, and sendMessage defined for PR650 is used.
As written in the comment, PR650 seem to require sending chars one by one.
I have copy-pasted sendMessage from PR650 into PR655 (pasted before startRemoteMode), and modified the lines for serial writing.

    def sendMessage(self, message, timeout=0.5, DEBUG=False):
        """Send a command to the photometer and wait an allotted
        timeout for a response (Timeout should be long for low
        light measurements)
        """
        if message[-1] != '\n':
            message += '\n'  # append a newline if necess

        # flush the read buffer first
        # read as many chars as are in the buffer
        self.com.read(self.com.inWaiting())

        # send the message
        if type(message) != bytes:
            for m in message:
                self.com.write(m.encode('utf-8'))
                self.com.flush()
            # self.com.write(message.encode('utf-8'))
        else:
            for b in message:
                self.com.write(b)
                self.flush()
        self.com.flush()
        # time.sleep(0.1)  # PR650 gets upset if hurried!

        # get feedback (within timeout limit)
        self.com.timeout = timeout
        logging.debug(message)  # send complete message
        if message in ('d5\n', 'D5\n'):
            # we need a spectrum which will have multiple lines
            reply = self.com.readlines()
            if PY3:
                reply = [thisLine.decode('utf-8') for thisLine in reply]
        else:
            reply = self.com.readline()
            if PY3:
                reply = reply.decode('utf-8')
        return reply

And now my photometer responds! This works both on my intel Mac and Win10 PC, though editing files on Win is tricky as I don’t really understand the privileges.

I hope someone in the team can fix it (maybe in a more appropriate way) in the future updates.

1 Like