diff --git a/GUI/server/odrive_server.py b/GUI/server/odrive_server.py index 0ee37692..7501d7fa 100644 --- a/GUI/server/odrive_server.py +++ b/GUI/server/odrive_server.py @@ -58,8 +58,12 @@ def discovered_device(device): while globals()['inUse']: time.sleep(0.1) globals()['odrives'][odrive_name] = device + globals()['odrives_status'][odrive_name] = True print("Found " + str(serial_number)) print("odrive list: " + str([key for key in globals()['odrives'].keys()])) + # tell GUI the status of known ODrives (previously connected and then disconnected ODrives will be "False") + socketio.emit('odrives-status', json.dumps(globals()['odrives_status'])) + # triggers a getODrives socketio message socketio.emit('odrive-found') def start_discovery(): @@ -68,9 +72,12 @@ def start_discovery(): shutdown = fibre.Event() fibre.find_all("usb", None, discovered_device, shutdown, shutdown, log) -def handle_disconnect(): +def handle_disconnect(odrive_name): print("lost odrive") - #socketio.emit('odrive-disconnected') + globals()['odrives_status'][odrive_name] = False + # emit the whole list of odrive statuses + # in the GUI, mark and use status as ODrive state. + socketio.emit('odrives-status', json.dumps(globals()['odrives_status'])) @socketio.on('findODrives') def getODrives(message): @@ -115,8 +122,9 @@ def get_odrives(data): odriveDict = {} #for (index, odrv) in enumerate(globals()['odrives']): # odriveDict["odrive" + str(index)] = dictFromRO(odrv) - for key in globals()['odrives'].keys(): - odriveDict[key] = dictFromRO(globals()['odrives'][key]) + for key in globals()['odrives_status'].keys(): + if globals()['odrives_status'][key] == True: + odriveDict[key] = dictFromRO(globals()['odrives'][key]) globals()['inUse'] = False emit('odrives', json.dumps(odriveDict)) @@ -126,10 +134,11 @@ def get_property(message): # will be {"path": "odriveX.axisY.blah.blah"} while globals()['inUse']: time.sleep(0.1) - globals()['inUse'] = True - val = getVal(globals()['odrives'], message["path"].split('.')) - globals()['inUse'] = False - emit('ODriveProperty', json.dumps({"path": message["path"], "val": val})) + if globals()['odrives_status'][message["path"].split('.')[0]]: + globals()['inUse'] = True + val = getVal(globals()['odrives'], message["path"].split('.')) + globals()['inUse'] = False + emit('ODriveProperty', json.dumps({"path": message["path"], "val": val})) @socketio.on('setProperty') def set_property(message): @@ -194,7 +203,7 @@ def postVal(odrives, keyList, value, argType): else: pass # dont support that type yet except fibre.protocol.ChannelBrokenException: - handle_disconnect() + handle_disconnect(odrv) except: print("exception in postVal") @@ -210,7 +219,7 @@ def getVal(odrives, keyList): else: return RO.get_value() except fibre.protocol.ChannelBrokenException: - handle_disconnect() + handle_disconnect(odrv) except: print("exception in getVal") return 0 @@ -235,7 +244,7 @@ def callFunc(odrives, keyList): if isinstance(RO, fibre.remote_object.RemoteFunction): RO.__call__() except fibre.protocol.ChannelBrokenException: - handle_disconnect() + handle_disconnect(odrv) except: print("fcn call failed") @@ -252,7 +261,11 @@ if __name__ == "__main__": import odrive.utils # for dump_errors() import fibre + # global for holding references to all connected odrives globals()['odrives'] = {} + # global dict {'odriveX': True/False} where True/False reflects status of connection + # on handle_disconnect, set it to False. On connection, set it to True + globals()['odrives_status'] = {} globals()['discovered_devices'] = [] # spinlock globals()['inUse'] = False diff --git a/GUI/src/App.vue b/GUI/src/App.vue index 2c9f52e6..fd64070a 100644 --- a/GUI/src/App.vue +++ b/GUI/src/App.vue @@ -56,9 +56,6 @@ :axis="axis.name" :odrives="odrives" > - @@ -129,22 +126,6 @@ export default { currentDash: function () { return this.$store.state.currentDash; }, - ODriveConnected: function () { - // if server and odrive disconnected, disconnected - // if server connected and odrive disco, connecting - // if server and odrive connected, connected - let ret; - if (this.$store.state.serverConnected && this.$store.state.ODriveConnected) { - ret = "connected"; - } - else if (this.$store.state.serverConnected && !this.$store.state.ODriveConnected) { - ret = "connecting..."; - } - else { - ret = "disconnected"; - } - return ret; - }, samplingText: function () { let ret; if (this.$store.state.sampling) { diff --git a/GUI/src/components/Axis.vue b/GUI/src/components/Axis.vue index 2ee3503a..8d0806ba 100644 --- a/GUI/src/components/Axis.vue +++ b/GUI/src/components/Axis.vue @@ -2,7 +2,7 @@