Skip to content

Commit 5ad6a97

Browse files
Merge pull request #11 from nextroundwinner/dyscom_bugfixes
Dyscom bugfixes
2 parents bff0d2f + e39ea7f commit 5ad6a97

49 files changed

Lines changed: 505 additions & 275 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-validation.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ jobs:
2222
build
2323
pylint
2424
-r src/science_mode_4/requirements.txt
25+
-r examples/requirements.txt
2526
--user
2627
- name: Build a binary wheel and a source tarball
2728
run: python3 -m build
28-
- name: Run linter
29-
run: pylint ./src/science_mode_4
29+
- name: Run linter lib
30+
run: pylint ./src
31+
- name: Run linter examples
32+
run: pylint ./examples

.pylintrc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[MAIN]
22
max-line-length=140
3-
max-attributes=11
3+
max-attributes=15
44

55
[DESIGN]
66
max-statements=100
@@ -9,4 +9,7 @@ max-statements=100
99
check-quote-consistency=yes
1010

1111
[MESSAGES CONTROL]
12-
disable=too-few-public-methods
12+
disable=too-few-public-methods
13+
14+
[SIMILARITIES]
15+
min-similarity-lines=50

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
"name": "Python Debugger: Current File",
99
"type": "debugpy",
1010
"request": "launch",
11-
"program": "__main__.py",
12-
// "module": "examples.dyscom.example_dyscom_write_csv",
11+
// "program": "src/__main__.py",
12+
"module": "examples.mid_level.example_mid_level",
1313
"justMyCode": false,
1414
// "args": ["COM3"],
1515
"console": "integratedTerminal"

HINTS.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This page describes implementation details.
77
- Starting point is using a _Device_ object matching attached hardware: _DeviceP24_ or _DeviceI24_
88
- If you have multiple devices, create multiple _Device_ instances
99
- With _capabilities_ it is possible to query for available layer
10-
- To create a _Device_ object a _Connection_ object is required, use _SerialConnection_ to connect to a serial port
10+
- To create a _Device_ object, a _Connection_ object is required, use _SerialConnection_ to connect to a serial port
1111
- _Connection_ must be opened and closed
1212
- Call _device.initialize()_ to get a defined state of the device (it stops any active stimulation/measurement)
1313
- _Device_ object has layers to access commands
@@ -18,8 +18,16 @@ This page describes implementation details.
1818
- Do not mix usage of layers because device has a single internal state, e.g. calling low level _init()_ and afterwards mid level _update()_ will not work
1919

2020
## Device communication
21+
- Each device has an instance of a _PacketBuffer_
22+
- Should be used to read packets from connection
23+
- Handles extraction of packets from byte stream
2124
- Most functions communicating with the device are async functions, because they wait for a matching acknowledge and return values from acknowledge
2225
- If no matching acknowledge or no acknowledge arrives in time, an exception is raised
26+
- The async functions connection buffer handling is always identical:
27+
- Clear buffer
28+
- Send command
29+
- Process incoming data until the expected acknowledge arrives
30+
- More data remains in connection buffer
2331
- Additionally functions with naming schema _send_xxx_ are normal functions not waiting for acknowledge
2432
- The acknowledge needs to handled manually by using _PacketBuffer_ object from device
2533
- _PacketBuffer_ reads data from connection and separates packets from data stream
@@ -28,7 +36,9 @@ This page describes implementation details.
2836
- Library creates a custom logger, see class _Logger_
2937
- By default some information is logged to console
3038
- Set log level to DEBUG to get more detailed information
31-
- For more performance, disable logger
39+
- `logger().setLevel(logging.DEBUG)`
40+
- For better performance, disable logger
41+
- `logger().disabled = True`
3242

3343
## General layer
3444
- Contains functions to get common information like device serial or firmware version
@@ -63,19 +73,26 @@ This page describes implementation details.
6373
- Device sends now _DlSendLiveData_ packets with measurement data
6474
- Call _stop()_ to end measurement
6575
- Call _power_module()_ to power off measurement module
66-
- Important: all storage related functions are untested
76+
- IMPORTANT: all storage related functions are untested
6777

6878
# Deviation from Instruction for Use
6979

7080
## Dyscom commands
7181

7282
### Common
73-
- Strings are 1 byte less long (null termination is not an extra byte) in acknowledge packets
7483
- Datetime parameters have a different order
7584

7685
### DL_init
7786
- Init state seems always be UNUSED
87+
- Strings are 1 byte longer than in other commands
7888
- Output data rate depends on init params filter property
89+
- Setting a filter overwrite other settings
90+
- ADS129x register channel 1-4 settings
91+
- ADS129x config register output data rate
92+
- Maybe more register values are changed
93+
94+
### DL_get for type file system status and list of measurement info
95+
- Return never meaningful values, probably not implemented on I24 side
7996

8097
### DL_get_ack for type file by name
8198
- Additional parameter mode (1 byte)
@@ -98,5 +115,6 @@ This page describes implementation details.
98115
- Block number, 4 byte, block number of DL_send_file
99116

100117
### DL_send_live_data
101-
- Parameters are big endian?
102-
- SignalType for each sample is always 0
118+
- SignalType for each sample is always 0
119+
- Contains always 5 samples, regardless of selected signal types in DL_init
120+
- Fifth sample value seems always be zero

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,8 @@ Python 3.11 or higher
9898
## 0.0.11
9999
- Implemented UsbConnection class
100100
- Alternative for SerialPortConnection, both share the same base class Connection
101-
- Added _PyUSB_ and _libusb-package_ as dependencies
101+
- Added _PyUSB_ and _libusb-package_ as dependencies
102+
103+
## 0.0.12
104+
- Dyscom init
105+
- Added channel settings register

__main__.py

Lines changed: 0 additions & 110 deletions
This file was deleted.

examples/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""Init file for utils"""
2+
3+
from .dyscom import *
4+
from .general import *
5+
from .low_level import *
6+
from .mid_level import *
7+
from .utils import *

examples/dyscom/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""Init file for utils"""
2+
3+
from .example_dyscom_fastplotlib import *
4+
from .example_dyscom_get import *
5+
from .example_dyscom_pyplot import *
6+
from .example_dyscom_write_csv import *

examples/dyscom/example_dyscom_fastplotlib.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ def main():
2424
"""Main function"""
2525

2626
# initialize plot helper the handle plot specific things
27-
plot_helper = FastPlotLibHelper({0: ["BI", "b"], 1: ["EMG1", "r"], 2: ["EMG2", "y"],\
28-
3: ["Breathing", "g"], 4: ["Temperature", "w"]}, 1000)
27+
plot_helper = FastPlotLibHelper({0: ["Channel 1", "b"], 1: ["Channel 2", "r"], 2: ["Channel 3", "y"],\
28+
3: ["Channel 4", "g"]}, 1000)
2929
# flag to indicate
3030
is_window_open: bool = True
3131

@@ -53,7 +53,7 @@ async def device_communication() -> int:
5353
# call init with lowest sample rate and enable signal types
5454
init_params = DyscomInitParams()
5555
init_params.signal_type = [DyscomSignalType.BI, DyscomSignalType.EMG_1,\
56-
DyscomSignalType.EMG_2, DyscomSignalType.BREATHING, DyscomSignalType.TEMPERATURE]
56+
DyscomSignalType.EMG_2, DyscomSignalType.BREATHING]
5757
init_params.register_map_ads129x.config_register_1.output_data_rate = Ads129xOutputDataRate.HR_MODE_500_SPS__LP_MODE_250_SPS
5858
init_params.register_map_ads129x.config_register_1.power_mode = Ads129xPowerMode.LOW_POWER
5959
await dyscom.init(init_params)
@@ -93,23 +93,15 @@ async def device_communication() -> int:
9393
print(f"SendLiveData status error {sld.samples}")
9494
break
9595

96-
# these samples match signal types from dl_init command
97-
plot_helper.append_value(0, sld.samples[0].value)
98-
plot_helper.append_value(1, sld.samples[1].value)
99-
plot_helper.append_value(2, sld.samples[2].value)
100-
plot_helper.append_value(3, sld.samples[3].value)
101-
plot_helper.append_value(4, sld.samples[4].value)
102-
103-
# signal type seems to be always 0, so we can't use it
104-
# for s in sld.samples:
105-
# ph.append_value(int(s.signal_type), s.value)
96+
for x in range(4):
97+
plot_helper.append_value(x, sld.samples[x].value)
10698

10799
plot_helper.update()
108100
else:
109101
# print(f"Live data acknowledges per iteration {live_data_counter}")
110102
break
111103

112-
await asyncio.sleep(0.01)
104+
await asyncio.sleep(0.001)
113105

114106
# stop measurement
115107
await dyscom.stop()

examples/dyscom/example_dyscom_get.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ async def main() -> int:
4646
file_system_status = await dyscom.get_file_system_status()
4747
print(file_system_status)
4848

49+
####
50+
calibration_filename = f"rehaingest_{device_id}.cal"
51+
# get calibration file info
52+
await dyscom.get_file_info(calibration_filename)
53+
# get calibration file -> does not work
54+
# there should be DL_Send_File commands afterwards
55+
await dyscom.get_file_by_name(calibration_filename)
56+
4957
# close serial port connection
5058
connection.close()
5159
return 0

0 commit comments

Comments
 (0)