@@ -62,16 +62,16 @@ export class SerialMonitor implements vscode.Disposable {
6262
6363 this . serialMonitorApi = await getSerialMonitorApi ( Version . latest , extensionContext ) ;
6464
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 ( ) ;
6866 }
6967
7068 public get initialized ( ) : boolean {
7169 return ! ! this . extensionContext ;
7270 }
7371
7472 public async selectSerialPort ( ) : Promise < string | undefined > {
73+ this . checkForUndefinedSerialMonitorApi ( true ) ;
74+
7575 const ports = await this . serialMonitorApi . listAvailablePorts ( ) ;
7676 if ( ! ports . length ) {
7777 vscode . window . showInformationMessage ( "No serial port is available." ) ;
@@ -117,6 +117,8 @@ export class SerialMonitor implements vscode.Disposable {
117117 }
118118
119119 public async openSerialMonitor ( restore : boolean = false ) : Promise < void > {
120+ this . checkForUndefinedSerialMonitorApi ( true ) ;
121+
120122 if ( ! this . currentPort ) {
121123 const ans = await vscode . window . showInformationMessage ( "No serial port was selected, please select a serial port first" , "Select" , "Cancel" ) ;
122124 if ( ans === "Select" ) {
@@ -155,6 +157,8 @@ export class SerialMonitor implements vscode.Disposable {
155157 }
156158
157159 public async closeSerialMonitor ( port ?: string ) : Promise < boolean > {
160+ this . checkForUndefinedSerialMonitorApi ( true ) ;
161+
158162 const portToClose = port ?? this . currentPort ;
159163 let closed = false ;
160164 if ( portToClose ) {
@@ -169,6 +173,16 @@ export class SerialMonitor implements vscode.Disposable {
169173 this . serialMonitorApi . dispose ( ) ;
170174 }
171175
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+
172186 private updatePortListStatus ( port ?: string ) {
173187 const dc = DeviceContext . getInstance ( ) ;
174188 if ( port ) {
0 commit comments