@@ -61,13 +61,17 @@ export class SerialMonitor implements vscode.Disposable {
61
61
} ) ;
62
62
63
63
this . serialMonitorApi = await getSerialMonitorApi ( Version . latest , extensionContext ) ;
64
+
65
+ this . checkForUndefinedSerialMonitorApi ( ) ;
64
66
}
65
67
66
68
public get initialized ( ) : boolean {
67
69
return ! ! this . extensionContext ;
68
70
}
69
71
70
72
public async selectSerialPort ( ) : Promise < string | undefined > {
73
+ this . checkForUndefinedSerialMonitorApi ( true ) ;
74
+
71
75
const ports = await this . serialMonitorApi . listAvailablePorts ( ) ;
72
76
if ( ! ports . length ) {
73
77
vscode . window . showInformationMessage ( "No serial port is available." ) ;
@@ -113,6 +117,8 @@ export class SerialMonitor implements vscode.Disposable {
113
117
}
114
118
115
119
public async openSerialMonitor ( restore : boolean = false ) : Promise < void > {
120
+ this . checkForUndefinedSerialMonitorApi ( true ) ;
121
+
116
122
if ( ! this . currentPort ) {
117
123
const ans = await vscode . window . showInformationMessage ( "No serial port was selected, please select a serial port first" , "Select" , "Cancel" ) ;
118
124
if ( ans === "Select" ) {
@@ -151,6 +157,8 @@ export class SerialMonitor implements vscode.Disposable {
151
157
}
152
158
153
159
public async closeSerialMonitor ( port ?: string ) : Promise < boolean > {
160
+ this . checkForUndefinedSerialMonitorApi ( true ) ;
161
+
154
162
const portToClose = port ?? this . currentPort ;
155
163
let closed = false ;
156
164
if ( portToClose ) {
@@ -165,6 +173,17 @@ export class SerialMonitor implements vscode.Disposable {
165
173
this . serialMonitorApi . dispose ( ) ;
166
174
}
167
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
+ if ( showError ) {
180
+ Logger . notifyUserError ( "UndefinedSerialMonitorApi" , new Error ( errorString ) ) ;
181
+ } else {
182
+ Logger . traceError ( "UndefinedSerialMonitorApi" , new Error ( errorString ) ) ;
183
+ }
184
+ }
185
+ }
186
+
168
187
private updatePortListStatus ( port ?: string ) {
169
188
const dc = DeviceContext . getInstance ( ) ;
170
189
if ( port ) {
0 commit comments