Skip to content

Commit

Permalink
Enable direct SD card readout
Browse files Browse the repository at this point in the history
  • Loading branch information
t-sasatani committed Aug 13, 2023
1 parent 713c434 commit bc9370a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 184,848 deletions.
35 changes: 21 additions & 14 deletions miniscope_io/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ class SDCard:
def __init__(
self,
drive: Union[str, Path],
layout: SDLayout

layout: SDLayout,
directpath: bool = False
):

self.drive = Path(drive).resolve()
if directpath == False:
self.drive = Path(drive).resolve()
else:
self.drive = drive
# Logs the error appropriately.
self.layout = layout

# Private attributes used when the file reading context is entered
Expand Down Expand Up @@ -68,17 +72,20 @@ def __init__(
@property
def config(self) -> SDConfig:
if self._config is None:
with open(self.drive, 'rb') as sd:
sd.seek(self.layout.sectors.config_pos, 0)
configSectorData = np.frombuffer(sd.read(self.layout.sectors.size), dtype=np.uint32)

self._config = SDConfig(
**{
k: configSectorData[v]
for k, v in self.layout.config.dict().items()
if v is not None
}
)
try:
with open(self.drive, 'rb') as sd:
sd.seek(self.layout.sectors.config_pos, 0)
configSectorData = np.frombuffer(sd.read(self.layout.sectors.size), dtype=np.uint32)

self._config = SDConfig(
**{
k: configSectorData[v]
for k, v in self.layout.config.dict().items()
if v is not None
}
)
except Exception as error:
print("An exception occurred:", error)

return self._config

Expand Down
Loading

0 comments on commit bc9370a

Please sign in to comment.