module:micropython:esp32checkthreading
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
module:micropython:esp32checkthreading [2021/12/08 13:02] – omdevelop | module:micropython:esp32checkthreading [2022/09/13 11:58] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 16: | Line 16: | ||
===== Benutzung ===== | ===== Benutzung ===== | ||
- | Beispiel für die Einbindung der MicroPython-Library **Math.py** : | + | Beispiel für die Einbindung der MicroPython-Library **Thread.py** : |
<code python> | <code python> | ||
# | # | ||
- | def Add(a, b): | + | import _thread |
- | return a + b | + | |
- | # | + | |
- | def Sub(a, b): | + | |
- | return a - b | + | |
# | # | ||
+ | class CThread(): | ||
+ | # | ||
+ | def __init__(self, | ||
+ | self.ID = threadid | ||
+ | self.OnExecute = onexecute | ||
+ | self.IsBusy = False | ||
+ | return | ||
+ | # | ||
+ | def Start(self): | ||
+ | self.IsBusy = True | ||
+ | _thread.start_new_thread(self.OnExecute, | ||
+ | return | ||
+ | # | ||
+ | def Abort(self): | ||
+ | self.IsBusy = False | ||
+ | return | ||
+ | # | ||
</ | </ | ||
- | Wichtig: Die Library muss im FileSystem des MicroControllers vorhanden sein! | + | Wichtig: Die Library |
- | Aufrufendes Programm **Esp32CheckMath.py** : | + | Aufrufendes Programm **Esp32CheckThreading.py** : |
<code python> | <code python> | ||
# | # | ||
- | import | + | import |
+ | # | ||
+ | import Thread | ||
+ | # | ||
+ | # | ||
+ | def CBOnExecute(thread): | ||
+ | print(' | ||
+ | I = 0 | ||
+ | while (thread.IsBusy): | ||
+ | I += 1 | ||
+ | print(" | ||
+ | time.sleep(1) | ||
+ | print(' | ||
+ | # | ||
+ | # | ||
+ | if (' | ||
+ | print(' | ||
+ | T = Thread.CThread(' | ||
+ | T.Start() | ||
+ | time.sleep(5) | ||
+ | T.Abort() | ||
+ | time.sleep(5) | ||
+ | print(' | ||
# | # | ||
- | print(' | ||
- | print(' | ||
</ | </ | ||
Run-Ausgabe im Terminal: | Run-Ausgabe im Terminal: | ||
< | < | ||
- | >>> | + | >>> |
- | >>> | + | >>> |
- | 3 + 5 = 8 | + | >>> |
- | 3 - 5 = -2 | + | CBOnExecute[T1]: |
+ | CBOnExecute[T1]: | ||
+ | CBOnExecute[T1]: | ||
+ | CBOnExecute[T1]: | ||
+ | CBOnExecute[T1]: | ||
+ | CBOnExecute[T1]: | ||
+ | CBOnExecute[T1]: | ||
+ | *** Esp32CheckThreading: | ||
♦♦> | ♦♦> | ||
MicroPython v1.17 on 2021-09-02; ESP32 module with ESP32 | MicroPython v1.17 on 2021-09-02; ESP32 module with ESP32 | ||
Line 52: | Line 92: | ||
===== Version ===== | ===== Version ===== | ||
- | {{: | + | {{: |
- | {{: | + | |
- | + | ||
- | ===== ===== | + | |
- | + | ||
- | + | ||
- | + | ||
- | + | ||
----- | ----- |
module/micropython/esp32checkthreading.1638964960.txt.gz · Last modified: 2021/12/08 14:02 (external edit)