Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c064673

Browse files
author
Alberto Iannaccone
authored
Close serial port connection before flashing firmware (#688)
1 parent cc5764e commit c064673

File tree

2 files changed

+34
-22
lines changed

2 files changed

+34
-22
lines changed

‎arduino-ide-extension/src/node/arduino-firmware-uploader-impl.ts‎

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from '../common/protocol/arduino-firmware-uploader';
55
import { injectable, inject, named } from 'inversify';
66
import { ExecutableService } from '../common/protocol';
7+
import { SerialService } from '../common/protocol/serial-service';
78
import { getExecPath, spawnCommand } from './exec-util';
89
import { ILogger } from '@theia/core/lib/common/logger';
910

@@ -18,6 +19,9 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
1819
@named('fwuploader')
1920
protected readonly logger: ILogger;
2021

22+
@inject(SerialService)
23+
protected readonly serialService: SerialService;
24+
2125
protected onError(error: any): void {
2226
this.logger.error(error);
2327
}
@@ -66,15 +70,26 @@ export class ArduinoFirmwareUploaderImpl implements ArduinoFirmwareUploader {
6670
}
6771

6872
async flash(firmware: FirmwareInfo, port: string): Promise<string> {
69-
return await this.runCommand([
70-
'firmware',
71-
'flash',
72-
'--fqbn',
73-
firmware.board_fqbn,
74-
'--address',
75-
port,
76-
'--module',
77-
`${firmware.module}@${firmware.firmware_version}`,
78-
]);
73+
let output;
74+
try {
75+
this.serialService.uploadInProgress = true;
76+
await this.serialService.disconnect();
77+
output = await this.runCommand([
78+
'firmware',
79+
'flash',
80+
'--fqbn',
81+
firmware.board_fqbn,
82+
'--address',
83+
port,
84+
'--module',
85+
`${firmware.module}@${firmware.firmware_version}`,
86+
]);
87+
} catch (e) {
88+
throw e;
89+
} finally {
90+
this.serialService.uploadInProgress = false;
91+
this.serialService.connectSerialIfRequired();
92+
return output;
93+
}
7994
}
8095
}

‎arduino-ide-extension/src/node/arduino-ide-backend-module.ts‎

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
203203

204204
// #endregion Theia customizations
205205

206-
// Monitor client provider per connected frontend.
206+
// Serial client provider per connected frontend.
207207
bind(ConnectionContainerModule).toConstantValue(
208208
ConnectionContainerModule.create(({ bind, bindBackendService }) => {
209209
bind(MonitorClientProvider).toSelf().inSingletonScope();
@@ -260,17 +260,14 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
260260
)
261261
.inSingletonScope();
262262

263-
bind(ArduinoFirmwareUploaderImpl).toSelf().inSingletonScope();
264-
bind(ArduinoFirmwareUploader).toService(ArduinoFirmwareUploaderImpl);
265-
bind(BackendApplicationContribution).toService(ArduinoFirmwareUploaderImpl);
266-
bind(ConnectionHandler)
267-
.toDynamicValue(
268-
(context) =>
269-
new JsonRpcConnectionHandler(ArduinoFirmwareUploaderPath, () =>
270-
context.container.get(ArduinoFirmwareUploader)
271-
)
272-
)
273-
.inSingletonScope();
263+
// Singleton per BE, each FE connection gets its proxy.
264+
bind(ConnectionContainerModule).toConstantValue(
265+
ConnectionContainerModule.create(({ bind, bindBackendService }) => {
266+
bind(ArduinoFirmwareUploaderImpl).toSelf().inSingletonScope();
267+
bind(ArduinoFirmwareUploader).toService(ArduinoFirmwareUploaderImpl);
268+
bindBackendService(ArduinoFirmwareUploaderPath, ArduinoFirmwareUploader);
269+
})
270+
);
274271

275272
// Logger for the Arduino daemon
276273
bind(ILogger)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /