mirror of
https://github.com/odriverobotics/ODrive.git
synced 2026-08-20 22:14:34 +08:00
Fixed disconnect/reconnect on windows. If an ODrive disappears (reboot, unplug, etc), the python server script gets killed and restarted
This commit is contained in:
@@ -154,6 +154,8 @@ def postVal(odrives, keyList, value, argType):
|
||||
RO.set_value(value == "true")
|
||||
else:
|
||||
pass # dont support that type yet
|
||||
except fibre.protocol.ChannelBrokenException:
|
||||
handle_disconnect()
|
||||
except:
|
||||
print("exception in postVal")
|
||||
|
||||
@@ -167,6 +169,8 @@ def getVal(odrives, keyList):
|
||||
return dictFromRO(RO)
|
||||
else:
|
||||
return RO.get_value()
|
||||
except fibre.protocol.ChannelBrokenException:
|
||||
handle_disconnect()
|
||||
except:
|
||||
print("exception in getVal")
|
||||
return 0
|
||||
@@ -189,6 +193,8 @@ def callFunc(odrives, keyList):
|
||||
RO = RO._remote_attributes[key]
|
||||
if isinstance(RO, fibre.remote_object.RemoteFunction):
|
||||
RO.__call__()
|
||||
except fibre.protocol.ChannelBrokenException:
|
||||
handle_disconnect()
|
||||
except:
|
||||
print("fcn call failed")
|
||||
|
||||
|
||||
@@ -46,8 +46,6 @@
|
||||
style="display: none"
|
||||
/>
|
||||
</button>
|
||||
<button @click="killServer">kill server</button>
|
||||
<button @click="startServer">start server</button>
|
||||
</div>
|
||||
|
||||
<!-- PAGE CONTENT -->
|
||||
@@ -261,13 +259,6 @@ export default {
|
||||
data: {},
|
||||
});
|
||||
},
|
||||
killServer() {
|
||||
window.ipcRenderer.send('kill-server');
|
||||
},
|
||||
startServer() {
|
||||
window.ipcRenderer.send('start-server');
|
||||
this.$store.dispatch("setServerAddress", "http://127.0.0.1:5000");
|
||||
}
|
||||
},
|
||||
created() {
|
||||
// on app creation, set the address to the default
|
||||
|
||||
+20
-8
@@ -11,7 +11,10 @@ const path = require('path');
|
||||
|
||||
// Keep a global reference of the window object, if you don't, the window will
|
||||
// be closed automatically when the JavaScript object is garbage collected.
|
||||
let win
|
||||
let win;
|
||||
|
||||
// var for python server
|
||||
let server;
|
||||
|
||||
// Scheme must be registered before the app is ready
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
@@ -119,21 +122,28 @@ app.on('ready', async () => {
|
||||
effectiveCommand.push(arg);
|
||||
}
|
||||
}
|
||||
var python;
|
||||
// launch python server on event from renderer process (gui) and pipe stdout/stderr to it
|
||||
ipcMain.on('start-server', () => {
|
||||
python = spawn(getPyCmd(), effectiveCommand);
|
||||
python.stdout.on('data',function(data) {
|
||||
server = spawn(getPyCmd(), effectiveCommand);
|
||||
server.stdout.on('data',function(data) {
|
||||
console.log(data.toString('utf8'));
|
||||
win.webContents.send('server-stdout', String(data.toString('utf8')));
|
||||
try {
|
||||
win.webContents.send('server-stdout', String(data.toString('utf8')));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
python.stderr.on('data',function(data) {
|
||||
server.stderr.on('data',function(data) {
|
||||
console.log(data.toString('utf8'));
|
||||
win.webContents.send('server-stderr', String(data.toString('utf8')));
|
||||
try {
|
||||
win.webContents.send('server-stderr', String(data.toString('utf8')));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
})
|
||||
ipcMain.on('kill-server', () => {
|
||||
python.kill('SIGINT');
|
||||
server.kill('SIGINT');
|
||||
})
|
||||
})
|
||||
|
||||
@@ -142,11 +152,13 @@ if (isDevelopment) {
|
||||
if (process.platform === 'win32') {
|
||||
process.on('message', (data) => {
|
||||
if (data === 'graceful-exit') {
|
||||
server.kill('SIGINT');
|
||||
app.quit()
|
||||
}
|
||||
})
|
||||
} else {
|
||||
process.on('SIGTERM', () => {
|
||||
server.kill('SIGINT');
|
||||
app.quit()
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user