Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "debugpy",
"request": "launch",
// "program": "src/__main__.py",
"module": "examples.dyscom.example_dyscom_pyplot",
"module": "examples.low_level.example_low_level",
"justMyCode": false,
// "args": ["COM3"],
"console": "integratedTerminal"
Expand Down
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,35 @@ Python 3.11 or higher
## Description
- Located in folder `examples`
- Run examples with `python -m examples.<layer>.<example>`
- From root directory of this repository
- Example: `python -m examples.dyscom.example_dyscom_fastplotlib`
- All examples try to find the serial port that a science mode device is connected to automatically
- If that fails, provide serial port name as parameter, e.g. `python -m examples.<layer>.<example> COM3`
- Good starting point for an simple stimulation is example `example_mid_level`
- Examples have own dependencies, see [Dependencies for examples](#dependencies-for-examples)
- General layer
- `example_general.py`
- Demonstrates how to use general layer to initialize device and get serial number and firmware version
- `python -m examples.general.example_general`
- Demonstrates how to use general layer to initialize device, get serial number and firmware version
- Does not call any stimulation functions
- Mid level layer
- `example_mid_level_simple`
- `python -m examples.mid_level.example_mid_level_simple`
- Demonstrates how to use mid level layer, where a stimulation pattern is send to the stimulator and the device automatically executes the pattern by itself for 15s
- `example_mid_level.py`
- `python -m examples.mid_level.example_mid_level`
- Demonstrates how to use mid level layer, where a stimulation pattern is send to the stimulator and the device automatically executes the pattern by itself until user ends stimulation by keyboard
- Low level layer
- `example_low_level.py`
- `python -m examples.low_level.example_low_level`
- Demonstrates how to use low level layer, where host has to trigger stimulation manually, in this case by pressing a key
- `example_low_level_plot.py`
- `python -m examples.low_level.example_low_level_plot`
- Demonstrates how to use low level layer to stimulate, measure current and plot it in a graph using PyPlot
- Dyscom layer
- `example_dyscom_get`
- `python -m examples.dyscom.example_dyscom_get`
- Demonstrate how to use different get commands from dyscom layer
- `example_dyscom_fastplotlib`
- Demonstrate how to use dyscom layer to measure EMG and BI and plotting values using fastplotlib
- `example_dyscom_pyplot`
- Demonstrate how to use dyscom layer to measure BI and plotting values using PyPlot
- `example_dyscom_write_csv`
- Demonstrate how to use dyscom layer to measure BI and EMG and writing measurement data to a .csv-file
- `python -m examples.dyscom.example_dyscom_fastplotlib`
- Demonstrate how to use dyscom layer to measure data and plotting values using fastplotlib
- `python -m examples.dyscom.example_dyscom_pyplot`
- Demonstrate how to use dyscom layer to measure data and plotting values using PyPlot
- `python -m examples.dyscom.example_dyscom_write_csv`
- Demonstrate how to use dyscom layer to measure data and writing measurement data to a .csv-file

## Dependencies for examples
- Install all dependencies
Expand Down Expand Up @@ -110,4 +113,8 @@ Python 3.11 or higher
- Enhanced example low level plot to show all channels

## 0.0.14
- Improved examples under Linux/MacOS
- Improved examples under Linux/MacOS

## 0.0.15
- Clarified readme
- Changed current for ChannelPoint from int to float
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "science_mode_4"
version = "0.0.14"
version = "0.0.15"
authors = [
{ name="Marc Hofmann", email="marc-hofmann@gmx.de" },
]
Expand Down
16 changes: 8 additions & 8 deletions src/science_mode_4/protocol/channel_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ class ChannelPoint():
"""Class for channel point"""


def __init__(self, duration_micro_seconds: int, current_milli_ampere: int):
def __init__(self, duration_micro_seconds: int, current_milli_ampere: float):
self._duration_in_micro_seconds = duration_micro_seconds
self._current_in_milli_ampere = current_milli_ampere


@property
def duration_in_micro_seconds(self) -> int:
"""Getter for duration"""
return self._duration_in_micro_seconds
def current_in_milli_ampere(self) -> float:
"""Getter for current"""
return self._current_in_milli_ampere


@property
def current_in_milli_ampere(self) -> int:
def duration_in_micro_seconds(self) -> int:
"""Getter for duration"""
return self._current_in_milli_ampere
return self._duration_in_micro_seconds


def get_data(self) -> bytes:
"""Convert information to bytes"""
if (self._current_in_milli_ampere < -150) or (self._current_in_milli_ampere > 150):
if (self._current_in_milli_ampere < -150.0) or (self._current_in_milli_ampere > 150.0):
raise ValueError(f"Channel point current must be between -150..150 {self._current_in_milli_ampere}")
if (self._duration_in_micro_seconds < 0) or (self._duration_in_micro_seconds > 4095):
raise ValueError(f"Channel point duration must be between 0..4095 {self._duration_in_micro_seconds}")

c = 2 * self._current_in_milli_ampere + 300
c = round(2.0 * self._current_in_milli_ampere + 300.0)

bb = ByteBuilder()
bb.set_bit_to_position(0, 0, 10)
Expand Down