Is it possible to display two realtime signals by use of VisPy scene canvas

160 views
Skip to first unread message

bilgitay

unread,
Aug 5, 2019, 6:21:51 PM8/5/19
to vispy

I am trying to acquire and display to signals in real time using Vispy. I acquire signals over different serial ports by pyserial.

I have modified the realtime_signals example (https://github.com/vispy/vispy/blob/master/examples/demo/gloo/realtime_signals.py) and have been able to display each signal individually. I also can display 3 or 5 plots of the same signal. But I could not manage to diplay both signals (each from a different serial port) in the same canvas or in two different canvases inserted into PyQt5 application. I have no experience on OpenGL and shaders.

Embedded code for serial port is pc.printf("$%d,%d,%d;", a,b,c);

Any help would be appreciated. Best regards.

vispyserial.py

David Hoese

unread,
Aug 6, 2019, 9:03:43 AM8/6/19
to vispy
When you try to use the two canvases? What exactly doesn't work about it?

I'm a little worried about the amount of globals you are using and that they seem to be used in multiple places. You also have your "Seriport" class which has one (unbound?) method. Why not make that it's own function? You use the global `datam` but then return it. I think it would be better if you created the serial connections in the Canvas `__init__` and set them as an attribute on the class. Then in your timer method read the serial connection.

Dave

-- Complex Details --

If these serial connections are communicating really fast you may have problems with not being able to read the data off of the serial port fast enough due to swapping between the two connections and vispy's drawing. It is unlikely for only two serial connections, but thought I would mention it. The long term but much more complex solution would be to have the serial connections in separate threads and have them either write to a numpy array that gets plotted and/or use Qt signals to notify the main GUI thread of new data.

David Hoese

unread,
Aug 6, 2019, 9:04:54 AM8/6/19
to vispy
Meant to say: When you try to use the two canvases in your code, what happens?

bilgitay

unread,
Aug 7, 2019, 6:21:10 PM8/7/19
to vispy
Dear David  Hoese,
Thank  you for your reply. At first both signals were displayed but mixed together in each canvas. I have tried to use different shaders for each canvas and change y variable in on_timer method as y1 for the second canvas, and now succeeded to display each signal in their own canvases. But the problem now, as you have correctly predicted, is loss of transmitted data. I will try threading or multiprocessing approaches (which I have no experience on). I will also try your suggestion to insert serial communication code within the canvas code.
VisPy is really a very powerful tool. But I think for use in real world applications, it must be efficiently combined with serial communication code. I wish there was a good tutorial or sample code on this issue.
Best Regards.

David Hoese

unread,
Aug 7, 2019, 10:10:51 PM8/7/19
to vispy
How fast is data coming in on these serial ports? I would start by removing your use of global variables as much as possible and see if things behave/perform a little better.

Programming GUI applications can get complicated fast, especially when it involves accepting data from outside asynchronous sources. The main hurdle is understanding that the GUI/drawing operations happen in one thread (also known as the main thread or the GUI thread). If your serial communications are executing in that same thread then they are making the Qt application and other serial device wait; so no new drawing events, no new serial communication for the other device. There may be Qt examples out there that use QThreads (good examples and bad ones) and could help you get started. There may be other vispy examples that do things like you want to do, but off the top of my head I can't think of any.

Dave
Reply all
Reply to author
Forward
0 new messages