@@ -62,16 +62,16 @@ export class SerialMonitor implements vscode.Disposable {
62
62
63
63
this . serialMonitorApi = await getSerialMonitorApi ( Version . latest , extensionContext ) ;
64
64
65
- if ( this . serialMonitorApi === undefined ) {
66
- Logger . error ( "Serial Monitor API was not retrieved. You may not have the most recent version of the Serial Monitor extension installed." )
67
- }
65
+ this . checkForUndefinedSerialMonitorApi ( ) ;
68
66
}
69
67
70
68
public get initialized ( ) : boolean {
71
69
return ! ! this . extensionContext ;
72
70
}
73
71
74
72
public async selectSerialPort ( ) : Promise < string | undefined > {
73
+ this . checkForUndefinedSerialMonitorApi ( true ) ;
74
+
75
75
const ports = await this . serialMonitorApi . listAvailablePorts ( ) ;
76
76
if ( ! ports . length ) {
77
77
vscode . window . showInformationMessage ( "No serial port is available." ) ;
@@ -117,6 +117,8 @@ export class SerialMonitor implements vscode.Disposable {
117
117
}
118
118
119
119
public async openSerialMonitor ( restore : boolean = false ) : Promise < void > {
120
+ this . checkForUndefinedSerialMonitorApi ( true ) ;
121
+
120
122
if ( ! this . currentPort ) {
121
123
const ans = await vscode . window . showInformationMessage ( "No serial port was selected, please select a serial port first" , "Select" , "Cancel" ) ;
122
124
if ( ans === "Select" ) {
@@ -155,6 +157,8 @@ export class SerialMonitor implements vscode.Disposable {
155
157
}
156
158
157
159
public async closeSerialMonitor ( port ?: string ) : Promise < boolean > {
160
+ this . checkForUndefinedSerialMonitorApi ( true ) ;
161
+
158
162
const portToClose = port ?? this . currentPort ;
159
163
let closed = false ;
160
164
if ( portToClose ) {
@@ -169,6 +173,16 @@ export class SerialMonitor implements vscode.Disposable {
169
173
this . serialMonitorApi . dispose ( ) ;
170
174
}
171
175
176
+ private checkForUndefinedSerialMonitorApi ( showError : boolean = false ) : void {
177
+ const errorString = "Serial Monitor API was not retrieved. You may not have the most recent version of the Serial Monitor extension installed." ;
178
+ if ( this . serialMonitorApi === undefined ) {
179
+ Logger . error ( errorString )
180
+ if ( showError ) {
181
+ vscode . window . showErrorMessage ( errorString ) ;
182
+ }
183
+ }
184
+ }
185
+
172
186
private updatePortListStatus ( port ?: string ) {
173
187
const dc = DeviceContext . getInstance ( ) ;
174
188
if ( port ) {
0 commit comments