Way to find out which program is installed? #1604
Replies: 2 comments
-
It's a bit of a workaround, but may do the job: You might know that you can read data that you have stored yourself. But you can read beyond that, which gives you the compiled user program. Run the following on the REPL (
So it reads starting from the end of user storage, plus 17 to skip some header information for convenience. I chose 40 bytes to read, but just pick something higher if your program name is not visible in the output. On my hub I get:
So the script on the hub was
See the It's not entirely the same, but gives you a lot of flexibility. You could even use this technique on the small hubs with one button, if you make another way to do the selection. For example by cycling through several colors with the button, or based on sensor input, etc. |
Beta Was this translation helpful? Give feedback.
-
Which program was loaded onto one of my Technic hubs? Upcoming changes wil change the location more, I think. REPLUse the REPL to keep the loaded program unchanged! Paste the complete program including the empty lines (they end the while statements) startloc = 0
look_for_6 = b'\x00M\x06\x00'
look_for_6_1 = b'\x00M\x06\x01'
while hub.system.storage(startloc, read=4) not in [look_for_6, look_for_6_1]: startloc += 1
startloc += 1
print("startloc", startloc, "\n", hub.system.storage(startloc, read=60))
fn = bytearray(); i = 0; byte = hub.system.storage(startloc + 7 + i, read=1);
while byte != b'\x00': fn.extend(byte); i += 1; byte = hub.system.storage(startloc + 7 + i, read=1)
filename_str = str(fn, 'utf-8')
print("\nfilename:", filename_str) This procedure is full of assumptions, so no guarantee. Explanation:
If you run this program (so not in the REPL), just to test how it works, add these two lines on the top: from pybricks.hubs import ThisHub
hub = ThisHub() They are not needed in the REPL as they are already done. As example the result in the REPL:
mpy Header:
Hope you never need it. Fun puzzling this, Bert |
Beta Was this translation helpful? Give feedback.
-
I think I mentioned before, that it would be nice to be able to read a program back from a hub - but fully aware that it's not possible due to the translation from python to machine code..
BUT... would it be possible for pybricks to at identify the filename, or some program name that is currently stored on the hub?
I have quite a few hubs.. and sometimes they don't get used for a while, and it would be handy to be able to connect to it, and pybricks could tell me that the last program downloaded was "Motor_Control_Crane_v1.5.py" or something
Also - are you looking into supporting multiple programs on inventor/spike hubs? ala the way the official Lego software works?
thanks again for all the great work! :)
Beta Was this translation helpful? Give feedback.
All reactions