How do I reconnect USB serial that gets lost programatically.
MatLab R2024b using AppDesigner on Windows 10 Enterprise
My GUI app connects to an Arduino which sometimes looses it’s connection or reboots itself.
I’m trying to detect when connection is lost and reconnect, but after getting an error message in the Command Window:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
My program (at least interacting with it in the CW is hung until I Ctrl-C.
I have set a dummy breakpoint so I can see variables from the Command Window (It doesn’t seem to know anything about my app until I break, but at least the program still runs after the break button is pushed)
So here’s what happens in CW with my comments added in bold and extra blank lines removed:
2513 pause(0.5); Pressed the Break Button
K>> app.PicoCom Look at my Serial Port connection
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
NumBytesAvailable: 0
etc… Now I reboot my Arduino and get:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
K>> app.PicoCom Try to look at serial port (or do ANYTHING)
[CW hangs until I hit Ctrl-C – WHY?
Operation terminated by user during MouseOdor61/RunOneTrial (line 1131)
In MouseOdor61/DoSession (line 1238)
etc
In matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 60)
newCallback = @(source, event)executeCallback(ams, …
^^^^^^^^^^^^^^^^^^^^^^^^
Interrupt while evaluating Button PrivateButtonPushedFcn.
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter
{0}.
Now I can try to see the handle again.
K>> app.PicoCom
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for
parameter {0}.
Not very helpful. At this point I can see:
K>> serialportlist()
ans =
1×2 string array
"COM1" "COM11"
To recover this seems to work:
K>> delete(app.PicoCom)
Let’s check
K>> app.PicoCom
ans =
handle to deleted Serialport
Reconnect
K>> app.PicoCom = serialport
[ shows every object in app! If I don’t add the ;]
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
Tag: ""
NumBytesAvailable: 0
OK, it’s back, all I need to add, it appears is the callback
K>> configureCallback(app.PicoCom,"terminator",@app.PicoInput)
I’ve tried putting things in my callback for input (like try … catch) but it never gets there.
It’s stuck in matlab.apps.AppBase not my code
I also added checks in the output routine to the Arduino, but it doesn’t seem to be helpful. That thread is stuck! I can press another button in the app the forces a reconnect but I want it to happen without user intervention.
How can I detect and trap the loss of COM in my program? (Obviously I want to stop the Pico from rebooting, but meanwhile my users need some decent work around).MatLab R2024b using AppDesigner on Windows 10 Enterprise
My GUI app connects to an Arduino which sometimes looses it’s connection or reboots itself.
I’m trying to detect when connection is lost and reconnect, but after getting an error message in the Command Window:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
My program (at least interacting with it in the CW is hung until I Ctrl-C.
I have set a dummy breakpoint so I can see variables from the Command Window (It doesn’t seem to know anything about my app until I break, but at least the program still runs after the break button is pushed)
So here’s what happens in CW with my comments added in bold and extra blank lines removed:
2513 pause(0.5); Pressed the Break Button
K>> app.PicoCom Look at my Serial Port connection
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
NumBytesAvailable: 0
etc… Now I reboot my Arduino and get:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
K>> app.PicoCom Try to look at serial port (or do ANYTHING)
[CW hangs until I hit Ctrl-C – WHY?
Operation terminated by user during MouseOdor61/RunOneTrial (line 1131)
In MouseOdor61/DoSession (line 1238)
etc
In matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 60)
newCallback = @(source, event)executeCallback(ams, …
^^^^^^^^^^^^^^^^^^^^^^^^
Interrupt while evaluating Button PrivateButtonPushedFcn.
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter
{0}.
Now I can try to see the handle again.
K>> app.PicoCom
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for
parameter {0}.
Not very helpful. At this point I can see:
K>> serialportlist()
ans =
1×2 string array
"COM1" "COM11"
To recover this seems to work:
K>> delete(app.PicoCom)
Let’s check
K>> app.PicoCom
ans =
handle to deleted Serialport
Reconnect
K>> app.PicoCom = serialport
[ shows every object in app! If I don’t add the ;]
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
Tag: ""
NumBytesAvailable: 0
OK, it’s back, all I need to add, it appears is the callback
K>> configureCallback(app.PicoCom,"terminator",@app.PicoInput)
I’ve tried putting things in my callback for input (like try … catch) but it never gets there.
It’s stuck in matlab.apps.AppBase not my code
I also added checks in the output routine to the Arduino, but it doesn’t seem to be helpful. That thread is stuck! I can press another button in the app the forces a reconnect but I want it to happen without user intervention.
How can I detect and trap the loss of COM in my program? (Obviously I want to stop the Pico from rebooting, but meanwhile my users need some decent work around). MatLab R2024b using AppDesigner on Windows 10 Enterprise
My GUI app connects to an Arduino which sometimes looses it’s connection or reboots itself.
I’m trying to detect when connection is lost and reconnect, but after getting an error message in the Command Window:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
My program (at least interacting with it in the CW is hung until I Ctrl-C.
I have set a dummy breakpoint so I can see variables from the Command Window (It doesn’t seem to know anything about my app until I break, but at least the program still runs after the break button is pushed)
So here’s what happens in CW with my comments added in bold and extra blank lines removed:
2513 pause(0.5); Pressed the Break Button
K>> app.PicoCom Look at my Serial Port connection
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
NumBytesAvailable: 0
etc… Now I reboot my Arduino and get:
Unable to detect connection to the serialport device. Ensure that the device is plugged in and create a new serialport object.
K>> app.PicoCom Try to look at serial port (or do ANYTHING)
[CW hangs until I hit Ctrl-C – WHY?
Operation terminated by user during MouseOdor61/RunOneTrial (line 1131)
In MouseOdor61/DoSession (line 1238)
etc
In matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 60)
newCallback = @(source, event)executeCallback(ams, …
^^^^^^^^^^^^^^^^^^^^^^^^
Interrupt while evaluating Button PrivateButtonPushedFcn.
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for parameter
{0}.
Now I can try to see the handle again.
K>> app.PicoCom
ans =
Serialport with properties:
In
‘testmeaslib:CustomDisplay:PropertyWarning’,
data type supplied is incorrect for
parameter {0}.
Not very helpful. At this point I can see:
K>> serialportlist()
ans =
1×2 string array
"COM1" "COM11"
To recover this seems to work:
K>> delete(app.PicoCom)
Let’s check
K>> app.PicoCom
ans =
handle to deleted Serialport
Reconnect
K>> app.PicoCom = serialport
[ shows every object in app! If I don’t add the ;]
K>> app.PicoCom
ans =
Serialport with properties:
Port: "COM11"
BaudRate: 57600
Tag: ""
NumBytesAvailable: 0
OK, it’s back, all I need to add, it appears is the callback
K>> configureCallback(app.PicoCom,"terminator",@app.PicoInput)
I’ve tried putting things in my callback for input (like try … catch) but it never gets there.
It’s stuck in matlab.apps.AppBase not my code
I also added checks in the output routine to the Arduino, but it doesn’t seem to be helpful. That thread is stuck! I can press another button in the app the forces a reconnect but I want it to happen without user intervention.
How can I detect and trap the loss of COM in my program? (Obviously I want to stop the Pico from rebooting, but meanwhile my users need some decent work around). reconnect usb MATLAB Answers — New Questions