Forums
Clearing port - Printable Version

+- Forums (https://sanworks.io/forum)
+-- Forum: Bpod (https://sanworks.io/forum/forumdisplay.php?fid=1)
+--- Forum: Software (https://sanworks.io/forum/forumdisplay.php?fid=6)
+--- Thread: Clearing port (/showthread.php?tid=165)



Clearing port - rchitwood - 01-25-2018

Hello—

I am defining a port in a procedure:

R=RotaryEncoderModule('/dev/cu.usbmodem2812891');

When I exit and restart the protocol I am met with:

Error using ArCOMObject_Bpod (line 129)

Error: Unable to connect to port /dev/cu.usbmodem2812891. The port may be in use by another application.

The command clear R does not remedy the situation and my only option appears to be to restart Matlab.

Any suggestions?

Thank you,

Randy


RE: Clearing port - Josh - 01-25-2018

Hi Randy

When you create rotary encoder object R, one of the object's fields is SerialPort, a wrapper for a USB serial port leased to object R by your operating system. When you clear variable R from your workspace (or if R was created in a function, when the function ends), the R object's destructor method is called, relinquishing control of the port.

In your case, the fix is to run 

clear R

at the end of your protocol.

-Josh


RE: Clearing port - rchitwood - 02-05-2018

(01-25-2018, 07:43 PM)Josh Wrote: Hi Randy

When you create rotary encoder object R, one of the object's fields is SerialPort, a wrapper for a USB serial port leased to object R by your operating system. When you clear variable R from your workspace (or if R was created in a function, when the function ends), the R object's destructor method is called, relinquishing control of the port.

In your case, the fix is to run 

clear R

at the end of your protocol.

-Josh

Hi Josh—

Rookie mistake on my part.  The object 'R' was being defined as a global variable, so it was not being cleared when the function ended. 

Thanks for your help,

Randy