Only one serial component per experiment?

If this template helps then use it. If not then just delete and start from scratch.

OS Win10
PsychoPy 2022.2.4

What are you trying to achieve?:
Using multiple serial components in a single experiment (single routine even) to create multiple event markers at different times within a trial.

What did you try to make it work?:
Adding multiple serial components and setting them accordingly.

What specifically went wrong when you tried that?:

    raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM5': PermissionError(13, 'Access is denied.', None, 5)
################# Experiment ended with exit code 1 [pid:7512] #################

From the access denied error above, it appears that each serial component is trying to access the same COM port but separately, so the second one crashes and causes the error. Is this a known issue with the serial component? Or have I just done something entirely wrong? (Hopefully the latter.)

Also… Setting Parity to None as I would when using a Code component for serial communication also crashes the experiment and I can only get it working when setting Parity to Off. Is this expected?

The :serial: Serial component just creates a serial.Serial object, which means you can only link one to a device at a time. Could you share the experiment you’re trying to do this with?

We could potentially add some code to Builder such that the serial.Serial object is only created once even with multiple components, and the other components become essentially just different names for the same object. To do this (and test that it works!) it would be helpful to have a real-world example of an experiment using multiple :serial: Serial components.

Many thanks for the explanation of how the Serial component works.

I’ll happily provide a .psyexp example when I’m back in the lab, but for now, the main usage would be to have multiple components within a routine, each sending different triggers/bytes at different defined times e.g., event 1 or 2 at the start of the routine to define condition, another event to define when a stimulus starts/ends (e.g., jittered 100ms after start of routine), and, in this case, another to trigger a TMS system at a specific post-stimulus time (2,3,4 or 5 seconds after stimulus starts).