OpenVibe as OSC server

Come here to discuss about OpenViBE in general!
Post Reply
joseph
Posts: 20
Joined: Wed Jun 12, 2013 1:33 pm

OpenVibe as OSC server

Post by joseph »

Hello,

I can successfully send OSC data from a Python 3 scripting box using the python-osc library.

Now I'd like to receive some OSC data in a scenario (several OpenVibe instances would receive synchronized stimulations from a single stimuli source).
Everything I tried so far with python-osc (using ThreadingOSCUDPServer and AsyncIOOSCUDPServer) gets OpenVibe to freeze, and there is apparently no OSC Server box in OpenVibe (which would be amazing and solve my problem immediately).

Could anyone give me a hint ?
I'm not very experienced with python, but I fear that using asyncio might not be recommended inside the Python 3 scripting box ...
I'd really love to use OSC because it fits well with the other software components involved in the project, but if anybody has an alternative solution to my problem I'd love to hear it too.
As I'm using an OpenBCI, I guess there might be a way to forward data from OpenBCI_GUI merged with the markers in LSL to OpenVibe, but this feels very convoluted ...

Thanks for any pointers !

Cheers,
Joseph

joseph
Posts: 20
Joined: Wed Jun 12, 2013 1:33 pm

Re: OpenVibe as OSC server

Post by joseph »

Just noticed the VRPN boxes.
I never used VRPN but I'll investigate if it can solve my issue.
Meanwhile, if anybody managed to get an OSC server running in OpenVibe I'm all ears :)

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: OpenVibe as OSC server

Post by Thibaut »

Hi,
You can have a generic oscillator with driver which send random sinus combinason signals on N channels.
If you wan't a specific sinusoidal signal, you have the box time signal and next simple dsp box wich transform your input with a function (as sin).
Thibaut

joseph
Posts: 20
Joined: Wed Jun 12, 2013 1:33 pm

Re: OpenVibe as OSC server

Post by joseph »

Hi Thibaut,

Thanks for answering.
I realize the sentence "several OpenVibe instances would receive synchronized stimulations from a single stimuli source" can be misleading.
What I mean is to have several OpenBCI headsets, each one connected to its own dedicated computer running OpenVibe, and get all those computers to receive some label messages broadcast on the local network by a "master" computer, so that they can record them as stimulations together with each specific eeg signal.
And by OSC I mean Open Sound Control protocol.
Sorry if that was not clear.

joseph
Posts: 20
Joined: Wed Jun 12, 2013 1:33 pm

Re: OpenVibe as OSC server

Post by joseph »

Ok, I finally got it to work using pyOSC3 instead of python-osc.
Here is the code for the Python 3 scripting box (this tutorial got me started) :

Code: Select all

from pyOSC3 import OSCServer

ip = "0.0.0.0"
port = 8000

class MyOVBox(OVBox):
	def __init__(self):
		OVBox.__init__(self)
	
	def onStimulation(self, path, tags, args, data):
		d = '""
		for item in args:
			d += str(item)
		print("received osc stimulation : " + path + " " + d)
	
	def initialize(self):
		self.server = OSCServer((ip, port))
		# this is required to avoid self.server.handle_request() calls to block during process execution
		self.server.socket.setblocking(0)
		self.server.addMsgHandler("/ov/stimulation", self.onStimulation)
		
	def process(self):
		# if we don't call self.server.socket.setblocking(0) in initialize, 
		# the default behaviour of self.server.handle_request() is to block
		# until a new message is received, if no message was received
		# timeout after 1 second, letting another call to process happen,
		# and then block again for 1 second, and so on ...
		self.server.handle_request()
		
	def uninitialize(self):
		self.server.close()
		
box = MyOVBox()
So far everything looks good, I'll report eventual issues with this technique here.
Maybe python-osc could be setup to work in a similar way but I got what I needed, so for now I'll stick to pyOSC3
Now I just have to generate OpenVibe stimulations from the OSC input messages.
This should be straightforward enough from the examples.

I hope this might help someone.

Cheers,
Joseph

Thibaut
Posts: 264
Joined: Wed Oct 31, 2018 9:14 am

Re: OpenVibe as OSC server

Post by Thibaut »

Ho, I never used OSC protocol. Actually in OpenViBE we favor the LSL protocol. It's good if you have solved your problem.
Thibaut

joseph
Posts: 20
Joined: Wed Jun 12, 2013 1:33 pm

Re: OpenVibe as OSC server

Post by joseph »

Yes, I see that LSL is the standard here.
I guess it's because it's a lossless protocol ... I'd need to dive deeper into LSL specs but unfortunately I can't afford the time right now.
Most OSC implementations use UDP as the transport layer, although OSC is just a data formatting specification.
In my case it's OK because I just send some sparse stimulations on a local network.

I'm really looking forward to use LSL.
For the moment I only tried to send data from OpenBCI_GUI to OpenVibe using LSL, but it felt quite unstable ...
I'll give it another try at some point, though

Thanks for answering, cheers

Post Reply