-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
035c1b6
commit 6659fcb
Showing
7 changed files
with
56 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,11 @@ | |
__author__ = "Dennis van Gils" | ||
__authoremail__ = "[email protected]" | ||
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo" | ||
__date__ = "07-07-2020" | ||
__version__ = "3.1" | ||
__date__ = "16-07-2020" | ||
__version__ = "4.0" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
import time | ||
|
||
import numpy as np | ||
|
@@ -28,8 +27,6 @@ | |
from dvg_debug_functions import dprint, print_fancy_traceback as pft | ||
|
||
from dvg_devices.Arduino_protocol_serial import Arduino # I.e. the `device` | ||
|
||
# from dvg_devices.Arduino_qdev import Arduino_qdev # Alternative approach as subclassed QDeviceIO() | ||
from dvg_qdeviceio import QDeviceIO | ||
|
||
|
||
|
@@ -324,13 +321,10 @@ def notify_connection_lost(): | |
excl = " ! ! ! ! ! ! ! " | ||
window.qlbl_title.setText("%sLOST CONNECTION%s" % (excl, excl)) | ||
|
||
str_msg = ( | ||
"%s %s\n" "Lost connection to Arduino.\n" " '%s', '%s': %salive" | ||
) % ( | ||
str_msg = ("%s %s\n" "Lost connection to Arduino.\n" " '%s': %salive") % ( | ||
str_cur_date, | ||
str_cur_time, | ||
ard.name, | ||
ard.identity, | ||
"" if ard.is_alive else "not ", | ||
) | ||
print("\nCRITICAL ERROR @ %s" % str_msg) | ||
|
@@ -362,7 +356,7 @@ def DAQ_function(): | |
str_cur_time = cur_date_time.toString("HH:mm:ss") | ||
|
||
# Query the Arduino for its state | ||
[success, tmp_state] = ard.query_ascii_values("?", separator="\t") | ||
success, tmp_state = ard.query_ascii_values("?", delimiter="\t") | ||
if not (success): | ||
dprint( | ||
"'%s' reports IOError @ %s %s" | ||
|
@@ -372,7 +366,7 @@ def DAQ_function(): | |
|
||
# Parse readings into separate state variables | ||
try: | ||
[state.time, state.reading_1] = tmp_state | ||
state.time, state.reading_1 = tmp_state | ||
state.time /= 1000 | ||
except Exception as err: | ||
pft(err, 3) | ||
|
@@ -432,10 +426,10 @@ def DAQ_function(): | |
# Connect to Arduino | ||
# -------------------------------------------------------------------------- | ||
|
||
ard = Arduino(name="Ard", baudrate=115200) | ||
ard.auto_connect( | ||
Path("last_used_port.txt"), match_identity="Wave generator" | ||
) | ||
ard = Arduino(name="Ard", connect_to_specific_ID="Wave generator") | ||
|
||
ard.serial_settings["baudrate"] = 115200 | ||
ard.auto_connect("last_used_port.txt") | ||
|
||
if not (ard.is_alive): | ||
print("\nCheck connection and try resetting the Arduino.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,11 @@ | |
__author__ = "Dennis van Gils" | ||
__authoremail__ = "[email protected]" | ||
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo" | ||
__date__ = "02-07-2020" | ||
__version__ = "3.0" | ||
__date__ = "16-07-2020" | ||
__version__ = "4.0" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
import time | ||
|
||
import numpy as np | ||
|
@@ -354,13 +353,10 @@ def notify_connection_lost(): | |
excl = " ! ! ! ! ! ! ! ! " | ||
window.qlbl_title.setText("%sLOST CONNECTION%s" % (excl, excl)) | ||
|
||
str_msg = ( | ||
"%s %s\n" "Lost connection to Arduino.\n" " '%s', '%s': %salive" | ||
) % ( | ||
str_msg = ("%s %s\n" "Lost connection to Arduino.\n" " '%s': %salive") % ( | ||
str_cur_date, | ||
str_cur_time, | ||
ard.name, | ||
ard.identity, | ||
"" if ard.is_alive else "not ", | ||
) | ||
print("\nCRITICAL ERROR @ %s" % str_msg) | ||
|
@@ -392,7 +388,7 @@ def DAQ_function(): | |
str_cur_time = cur_date_time.toString("HH:mm:ss") | ||
|
||
# Query the Arduino for its state | ||
[success, tmp_state] = ard.query_ascii_values("?", separator="\t") | ||
success, tmp_state = ard.query_ascii_values("?", delimiter="\t") | ||
if not (success): | ||
dprint( | ||
"'%s' reports IOError @ %s %s" | ||
|
@@ -402,7 +398,7 @@ def DAQ_function(): | |
|
||
# Parse readings into separate state variables | ||
try: | ||
[state.time, state.reading_1] = tmp_state | ||
state.time, state.reading_1 = tmp_state | ||
state.time /= 1000 | ||
except Exception as err: | ||
pft(err, 3) | ||
|
@@ -462,10 +458,10 @@ def DAQ_function(): | |
# Connect to Arduino | ||
# -------------------------------------------------------------------------- | ||
|
||
ard = Arduino(name="Ard", baudrate=115200) | ||
ard.auto_connect( | ||
Path("last_used_port.txt"), match_identity="Wave generator" | ||
) | ||
ard = Arduino(name="Ard", connect_to_specific_ID="Wave generator") | ||
|
||
ard.serial_settings["baudrate"] = 115200 | ||
ard.auto_connect("last_used_port.txt") | ||
|
||
if not (ard.is_alive): | ||
print("\nCheck connection and try resetting the Arduino.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,12 +6,11 @@ | |
__author__ = "Dennis van Gils" | ||
__authoremail__ = "[email protected]" | ||
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo" | ||
__date__ = "02-07-2020" | ||
__version__ = "3.0" | ||
__date__ = "16-07-2020" | ||
__version__ = "4.0" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
import time | ||
|
||
import numpy as np | ||
|
@@ -134,7 +133,7 @@ def DAQ_function(): | |
str_cur_time = cur_date_time.toString("HH:mm:ss") | ||
|
||
# Query the Arduino for its state | ||
[success, tmp_state] = ard.query_ascii_values("?", separator="\t") | ||
success, tmp_state = ard.query_ascii_values("?", delimiter="\t") | ||
if not (success): | ||
dprint( | ||
"'%s' reports IOError @ %s %s" | ||
|
@@ -144,7 +143,7 @@ def DAQ_function(): | |
|
||
# Parse readings into separate state variables | ||
try: | ||
[state.time, state.reading_1] = tmp_state | ||
state.time, state.reading_1 = tmp_state | ||
state.time /= 1000 | ||
except Exception as err: | ||
pft(err, 3) | ||
|
@@ -185,10 +184,10 @@ def DAQ_function(): | |
# Connect to Arduino | ||
# -------------------------------------------------------------------------- | ||
|
||
ard = Arduino(name="Ard", baudrate=115200) | ||
ard.auto_connect( | ||
Path("last_used_port.txt"), match_identity="Wave generator" | ||
) | ||
ard = Arduino(name="Ard", connect_to_specific_ID="Wave generator") | ||
|
||
ard.serial_settings["baudrate"] = 115200 | ||
ard.auto_connect("last_used_port.txt") | ||
|
||
if not (ard.is_alive): | ||
print("\nCheck connection and try resetting the Arduino.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,12 +10,11 @@ | |
__author__ = "Dennis van Gils" | ||
__authoremail__ = "[email protected]" | ||
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo" | ||
__date__ = "02-07-2020" | ||
__version__ = "3.0" | ||
__date__ = "16-07-2020" | ||
__version__ = "4.0" | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
import time | ||
|
||
import numpy as np | ||
|
@@ -341,7 +340,7 @@ def DAQ_function(): | |
state.prev_tick = now | ||
|
||
# Query the Arduino for its state | ||
[success, tmp_state] = ard.query_ascii_values("?", separator="\t") | ||
success, tmp_state = ard.query_ascii_values("?", delimiter="\t") | ||
if not (success): | ||
dprint( | ||
"'%s' reports IOError @ %s %s" | ||
|
@@ -350,7 +349,7 @@ def DAQ_function(): | |
|
||
# Parse readings into separate state variables | ||
try: | ||
[state.time, state.reading_1] = tmp_state | ||
state.time, state.reading_1 = tmp_state | ||
state.time /= 1000 | ||
except Exception as err: | ||
pft(err, 3) | ||
|
@@ -406,10 +405,10 @@ def DAQ_function(): | |
# Connect to Arduino | ||
# -------------------------------------------------------------------------- | ||
|
||
ard = Arduino(name="Ard", baudrate=115200) | ||
ard.auto_connect( | ||
Path("last_used_port.txt"), match_identity="Wave generator" | ||
) | ||
ard = Arduino(name="Ard", connect_to_specific_ID="Wave generator") | ||
|
||
ard.serial_settings["baudrate"] = 115200 | ||
ard.auto_connect("last_used_port.txt") | ||
|
||
if not (ard.is_alive): | ||
print("\nCheck connection and try resetting the Arduino.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,11 +7,10 @@ | |
__author__ = "Dennis van Gils" | ||
__authoremail__ = "[email protected]" | ||
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo" | ||
__date__ = "02-07-2020" | ||
__version__ = "3.0" | ||
__date__ = "16-07-2020" | ||
__version__ = "4.0" | ||
|
||
import sys | ||
from pathlib import Path | ||
import time | ||
import signal # To catch CTRL+C and quit | ||
|
||
|
@@ -90,14 +89,14 @@ def update_terminal(): | |
|
||
def DAQ_function(): | ||
# Query the Arduino for its state | ||
[success, tmp_state] = ard.query_ascii_values("?", separator="\t") | ||
success, tmp_state = ard.query_ascii_values("?", delimiter="\t") | ||
if not (success): | ||
dprint("'%s' reports IOError" % ard.name) | ||
return False | ||
|
||
# Parse readings into separate state variables | ||
try: | ||
[state.time, state.reading_1] = tmp_state | ||
state.time, state.reading_1 = tmp_state | ||
state.time /= 1000 | ||
except Exception as err: | ||
pft(err, 3) | ||
|
@@ -127,10 +126,10 @@ def DAQ_function(): | |
if __name__ == "__main__": | ||
|
||
# Connect to Arduino | ||
ard = Arduino(name="Ard", baudrate=115200) | ||
ard.auto_connect( | ||
Path("last_used_port.txt"), match_identity="Wave generator" | ||
) | ||
ard = Arduino(name="Ard", connect_to_specific_ID="Wave generator") | ||
|
||
ard.serial_settings["baudrate"] = 115200 | ||
ard.auto_connect("last_used_port.txt") | ||
|
||
if not (ard.is_alive): | ||
print("\nCheck connection and try resetting the Arduino.") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,15 +4,16 @@ | |
- CLI output only | ||
- Mode: INTERNAL_TIMER as master to another SINGLE_SHOT_WAKE_UP | ||
- Trick with fake device 'Sync()' | ||
TODO: Investigate hang in about_to_quit() when lost_connection was tripped. | ||
""" | ||
__author__ = "Dennis van Gils" | ||
__authoremail__ = "[email protected]" | ||
__url__ = "https://github.com/Dennis-van-Gils/DvG_Arduino_PyQt_multithread_demo" | ||
__date__ = "02-07-2020" | ||
__version__ = "3.0" | ||
__date__ = "16-07-2020" | ||
__version__ = "4.0" | ||
|
||
import sys | ||
from pathlib import Path | ||
import time | ||
import signal # To catch CTRL+C and quit | ||
|
||
|
@@ -26,7 +27,7 @@ | |
DAQ_INTERVAL_MS = 10 # 10 [ms] | ||
|
||
# Show debug info in terminal? Warning: Slow! Do not leave on unintentionally. | ||
DEBUG = False | ||
DEBUG = True | ||
|
||
|
||
# ------------------------------------------------------------------------------ | ||
|
@@ -92,14 +93,14 @@ def update_terminal(): | |
|
||
def DAQ_function(): | ||
# Query the Arduino for its state | ||
[success, tmp_state] = ard.query_ascii_values("?", separator="\t") | ||
success, tmp_state = ard.query_ascii_values("?", delimiter="\t") | ||
if not (success): | ||
dprint("'%s' reports IOError" % ard.name) | ||
return False | ||
|
||
# Parse readings into separate state variables | ||
try: | ||
[state.time, state.reading_1] = tmp_state | ||
state.time, state.reading_1 = tmp_state | ||
state.time /= 1000 | ||
except Exception as err: | ||
pft(err, 3) | ||
|
@@ -129,10 +130,10 @@ def DAQ_function(): | |
if __name__ == "__main__": | ||
|
||
# Connect to Arduino | ||
ard = Arduino(name="Ard", baudrate=115200) | ||
ard.auto_connect( | ||
Path("last_used_port.txt"), match_identity="Wave generator" | ||
) | ||
ard = Arduino(name="Ard", connect_to_specific_ID="Wave generator") | ||
|
||
ard.serial_settings["baudrate"] = 115200 | ||
ard.auto_connect("last_used_port.txt") | ||
|
||
if not (ard.is_alive): | ||
print("\nCheck connection and try resetting the Arduino.") | ||
|
@@ -167,7 +168,7 @@ def tick(self): | |
# fmt: off | ||
qdev_sync = QDeviceIO(sync) | ||
qdev_sync.create_worker_DAQ( | ||
DAQ_trigger = DAQ_trigger.INTERNAL_TIMER, | ||
DAQ_trigger = DAQ_TRIGGER.INTERNAL_TIMER, | ||
DAQ_function = sync.tick, | ||
DAQ_interval_ms = DAQ_INTERVAL_MS, | ||
debug = DEBUG, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters