sccn / lsl_archived

Multi-modal time-synched data transmission over local network
242 stars 134 forks source link

pylsl and PsychoPy - invalid: bad lexical cast: source type value could not be interpreted as target #169

Open stfnrpplngr opened 7 years ago

stfnrpplngr commented 7 years ago

Trying to establish an lsl-stream within @PsychoPy, I get the following error message as the corresponding stream name in LabRecorder:

(invalid: bad lexical cast: source type value could not be interpreted as target) ()

I used the following lines to create the OutletStream:

import pylsl
info_markers = pylsl.StreamInfo(name='MarkerStream', type='Markers', channel_format='string', source_id='MyPresPC')
outlet_markers = pylsl.StreamOutlet(info_markers)

Running the same code in an IPython console in Spyder, there is not problem and the right stream name ('MarkerStream') appears.

labrecorder_issue

My configurations: PsychoPy v1.84.2 Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32

Spyder 3.0.0 Python 2.7.12 |Anaconda 4.2.0 (32-bit)| (default, Jun 29 2016, 11:42:13) [MSC v.1500 32 bit (Intel)] IPython 4.2.0 -- An enhanced Interactive Python.

pylsl-1.10.5

GeorgeDoe commented 7 years ago

Hi,

I had the same problems with using pylsl within PsychoPy but not Spyder. Interestingly, I also did not have the problem with scripted PsychoPy paradigm using Coder. After a few experiments, I could solve the problem by manually moving the StreamInfo and StreamOutlet initialization before the following import:

from psychopy import gui

It looks like that whatever that import is doing interferes with some sort of type definition that LSL relies on. The 'bad lexical cast' error messages is actually generated by the boost library that LSL uses internally, which converts arguments specified as strings to their respective typed counterparts.

To provide some more help, here's how the respective builder generated and manually modified block in the py-file looks like in my case:

from __future__ import absolute_import, division
from psychopy import locale_setup

from pylsl import StreamInfo, StreamOutlet
info = StreamInfo(name='my_stream_name', type='Markers', channel_count=1,
                  channel_format='int32', source_id='uniqueid12345')
triggers = StreamOutlet(info)

from psychopy import gui, visual, core, data, event, logging, sound
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
                                STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os  # handy system and path functions
import sys  # to get file system encoding
tstenner commented 5 years ago

I've been using Psychopy with pylsl on Windows just fine. Could you check if the error still appears with the new pylsl version on pypi?