From d75c9504945bc1cb7a46a670d54d0fcd814d32f1 Mon Sep 17 00:00:00 2001 From: MongoOnlyPawn Date: Wed, 16 Oct 2024 14:13:46 -0600 Subject: [PATCH 1/5] Add function to configure digital output of channels. --- src/pycbsdk/cbhw/device/nsp.py | 38 ++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/pycbsdk/cbhw/device/nsp.py b/src/pycbsdk/cbhw/device/nsp.py index 01fb6d0..1ac1ad6 100644 --- a/src/pycbsdk/cbhw/device/nsp.py +++ b/src/pycbsdk/cbhw/device/nsp.py @@ -335,6 +335,8 @@ def _register_basic_callbacks(self): self.register_config_callback(CBPacketType.CHANREPAOUT, self._handle_chaninfo) self.register_config_callback(CBPacketType.CHANREPSCALE, self._handle_chaninfo) self.register_config_callback(CBPacketType.CHANREPDINP, self._handle_chaninfo) + self.register_config_callback(CBPacketType.CHANREPDOUT, self._handle_chaninfo) + self.register_config_callback(CBPacketType.CHANREPLABEL, self._handle_chaninfo) self.register_config_callback(CBPacketType.CHANREPAINP, self._handle_chaninfo) self.register_config_callback(CBPacketType.GROUPREP, self._handle_groupinfo) @@ -420,6 +422,15 @@ def _handle_chaninfo(self, pkt): # TODO: NOTE: Need extra check if this is for serial or digital? self._config["channel_infos"][pkt.chan].dinpopts = pkt.dinpopts self._config["channel_infos"][pkt.chan].eopchar = pkt.eopchar + elif pkt.header.type == CBPacketType.CHANREPDOUT: + self._config["channel_infos"][pkt.chan].doutopts = pkt.doutopts + self._config["channel_infos"][pkt.chan].doutcaps = pkt.doutcaps + # TODO: .moninst, .monchan, .outvalue, more..., from union? + elif pkt.header.type == CBPacketType.CHANREPLABEL: + self._config["channel_infos"][pkt.chan].label = pkt.label + self._config["channel_infos"][pkt.chan].userflags = pkt.userflags + + else: # TODO: from CHANREPNTRODEGROUP, .spkgroup # TODO: from CHANREPSPKTHR, .spkthrlevel @@ -428,7 +439,6 @@ def _handle_chaninfo(self, pkt): # TODO: from CHANREPUNITOVERRIDES, .unitmapping # TODO: from CHANREPSPKHPS, .spkhoops, .unitmapping[n].bValid = pkt.spkhoops[n][0].valid # TODO: from CHANREPDINP, .dinpopts; NOTE: Need extra check if this is for serial or digital - # TODO: from CHANREPDOUT, .doutopts = pkt.doutopts & .doutcaps, .moninst, .monchan, .outvalue, more... # TODO: from CHANREPAOUT, ... complicated # TODO: from CHANREPSCALE, .scalin, .scalout pass @@ -665,7 +675,15 @@ def _configure_channel_label(self, chid: int, attr_value: str, timeout: float = # TODO: pkt.userflags # TODO: pkt.position event = self._config_events["chaninfo"] if timeout > 0 else None - self._send_packet(pkt=pkt, event=event, timeout=timeout) + if not self._send_packet(pkt=pkt, event=event, timeout=timeout): + self.get_config(timeout=2.0, force_refresh=True) + + if pkt.label != self._config["channel_infos"][chid].label: + raise RuntimeError("Packet response contents do not match expected values.") + else: + raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + + def _configure_channel_lnc(self, chid: int, attr_value: int, timeout: float = 0): pkt = copy.copy(self._config["channel_infos"][chid]) @@ -789,6 +807,22 @@ def _configure_channel_digital_input( raise RuntimeError("Packet response contents do not match expected values.") else: raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + + def _configure_channel_digital_output( + self, chid: int, attr_value: int, timeout: float = 0.0 + ): + pkt = copy.copy(self._config["channel_infos"][chid]) + pkt.doutopts = attr_value + pkt.header.type = CBPacketType.CHANSETDOUT + event = self._config_events["chaninfo"] if timeout > 0 else None + + if not self._send_packet(pkt=pkt, event=event, timeout=timeout): + self.get_config(timeout=2.0, force_refresh=True) + + if pkt.doutopts != self._config["channel_infos"][chid].doutopts: + raise RuntimeError("Packet response contents do not match expected values.") + else: + raise RuntimeError("Valid packet response NOT received, but packet contains expected values") def _configure_channel_smpfilter( self, chid: int, attr_value: int, timeout: float = 0.0 From c1392203f5b0251738a87ae0145863c02370e73c Mon Sep 17 00:00:00 2001 From: MongoOnlyPawn Date: Wed, 16 Oct 2024 14:45:25 -0600 Subject: [PATCH 2/5] Update to configure spike threshold level. Same as setting Threshold Level in Single Neural Channel. --- src/pycbsdk/cbhw/device/nsp.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/pycbsdk/cbhw/device/nsp.py b/src/pycbsdk/cbhw/device/nsp.py index 1ac1ad6..e9cc3c4 100644 --- a/src/pycbsdk/cbhw/device/nsp.py +++ b/src/pycbsdk/cbhw/device/nsp.py @@ -299,6 +299,7 @@ def __init__(self, params: Params, **kwargs): "global_lnc": self._set_lnc_global_config, "dc_offset": self._configure_channel_dcoffset, "spkfilter": self._configure_channel_spkfilter, + "spkthrlevel": self._configure_spk_threshold, } # Receives broadcast UDP (or unicast targeting the adapter at client_addr). @@ -339,6 +340,8 @@ def _register_basic_callbacks(self): self.register_config_callback(CBPacketType.CHANREPLABEL, self._handle_chaninfo) self.register_config_callback(CBPacketType.CHANREPAINP, self._handle_chaninfo) + self.register_config_callback(CBPacketType.CHANREPSPKTHR, self._handle_chaninfo) + self.register_config_callback(CBPacketType.GROUPREP, self._handle_groupinfo) self.register_config_callback(CBPacketType.PROCREP, self._handle_procinfo) self.register_config_callback(CBPacketType.NPLAYREP, self._handle_nplay) @@ -429,11 +432,13 @@ def _handle_chaninfo(self, pkt): elif pkt.header.type == CBPacketType.CHANREPLABEL: self._config["channel_infos"][pkt.chan].label = pkt.label self._config["channel_infos"][pkt.chan].userflags = pkt.userflags - + elif pkt.header.type == CBPacketType.CHANSETSPKTHR: + # TODO: from CHANREPSPKTHR, .spkthrlevel + self._config["channel_infos"][pkt.chan].spkthrlevel = pkt.spkthrlevel + else: # TODO: from CHANREPNTRODEGROUP, .spkgroup - # TODO: from CHANREPSPKTHR, .spkthrlevel # TODO: from CHANREPDISP, .smpdispmin, .smpdispmax, .spkdispmax, .lncdispmax # TODO: from CHANREPLABEL, .label, .userflags # TODO: from CHANREPUNITOVERRIDES, .unitmapping @@ -775,6 +780,22 @@ def _configure_channel_spkfilter( raise RuntimeError("Packet response contents do not match expected values.") else: raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + + def _configure_spk_threshold(self, chid: int, attr_value: int, timeout: float = 0.0): + pkt = copy.copy(self._config["channel_infos"][chid]) + pkt.spkthrlevel = attr_value + pkt.header.type = CBPacketType.CHANSETSPKTHR + + event = self._config_events["chaninfo"] if timeout > 0 else None + + if not self._send_packet(pkt=pkt, event=event, timeout=timeout): + self.get_config(timeout=2.0, force_refresh=True) + + if pkt.spkthrlevel != self._config["channel_infos"][chid].spkthrlevel: + raise RuntimeError("Packet response contents do not match expected values.") + else: + raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + def _configure_channel_analogout( self, chid: int, attr_value: int, timeout: float = 0.0 From 00060082d9a1cd014733930160b7ed16ef764753 Mon Sep 17 00:00:00 2001 From: Chadwick Boulay Date: Sat, 19 Oct 2024 20:00:57 -0400 Subject: [PATCH 3/5] Replace 2.0 with GET_CONFIG_TIMEOUT in calls to self.get_config(timeout=...) --- src/pycbsdk/cbhw/device/nsp.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/pycbsdk/cbhw/device/nsp.py b/src/pycbsdk/cbhw/device/nsp.py index e9cc3c4..73f40ba 100644 --- a/src/pycbsdk/cbhw/device/nsp.py +++ b/src/pycbsdk/cbhw/device/nsp.py @@ -73,6 +73,7 @@ cbNUM_SERIAL_CHANS = 1 cbNUM_DIGOUT_CHANS = 4 # endregion +GET_CONFIG_TIMEOUT = 2.0 # region Enums @@ -576,7 +577,7 @@ def _toggle_channel_ainp_flag( event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if (pkt.ainpopts != self._config["channel_infos"][chid].ainpopts): raise RuntimeError("Packet response contents do not match expected values.") @@ -608,7 +609,7 @@ def _configure_channel_smpgroup( event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if ( pkt.smpgroup != self._config["channel_infos"][chid].smpgroup @@ -681,7 +682,7 @@ def _configure_channel_label(self, chid: int, attr_value: str, timeout: float = # TODO: pkt.position event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.label != self._config["channel_infos"][chid].label: raise RuntimeError("Packet response contents do not match expected values.") @@ -700,7 +701,7 @@ def _configure_channel_lnc(self, chid: int, attr_value: int, timeout: float = 0) event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.ainpopts != self._config["channel_infos"][chid].ainpopts: raise RuntimeError("Packet response contents do not match expected values.") @@ -716,7 +717,7 @@ def _configure_channel_lnc_rate(self, chid: int, attr_value: int, timeout: float event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.lncrate != self._config["channel_infos"][chid].lncrate: raise RuntimeError("Packet response contents do not match expected values.") @@ -739,7 +740,7 @@ def _set_lnc_global_config( event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if ( (pkt.lncFreq != self._config["channel_infos"][chid].lncFreq) @@ -774,7 +775,7 @@ def _configure_channel_spkfilter( event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.spkfilter != self._config["channel_infos"][chid].spkfilter: raise RuntimeError("Packet response contents do not match expected values.") @@ -789,7 +790,7 @@ def _configure_spk_threshold(self, chid: int, attr_value: int, timeout: float = event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.spkthrlevel != self._config["channel_infos"][chid].spkthrlevel: raise RuntimeError("Packet response contents do not match expected values.") @@ -806,7 +807,7 @@ def _configure_channel_analogout( event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.aoutopts != self._config["channel_infos"][chid].aoutopts: raise RuntimeError("Packet response contents do not match expected values.") @@ -822,7 +823,7 @@ def _configure_channel_digital_input( event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.dinpopts != self._config["channel_infos"][chid].dinpopts: raise RuntimeError("Packet response contents do not match expected values.") @@ -838,7 +839,7 @@ def _configure_channel_digital_output( event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.doutopts != self._config["channel_infos"][chid].doutopts: raise RuntimeError("Packet response contents do not match expected values.") @@ -854,7 +855,7 @@ def _configure_channel_smpfilter( event = self._config_events["chaninfo"] if timeout > 0 else None if not self._send_packet(pkt=pkt, event=event, timeout=timeout): - self.get_config(timeout=2.0, force_refresh=True) + self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.smpfilter != self._config["channel_infos"][chid].smpfilter: raise RuntimeError("Packet response contents do not match expected values.") @@ -1161,7 +1162,7 @@ def _startup_sequence(self) -> CBError: # We don't do that here. logger.debug("Attempting to get_config") - _cfg = self.get_config(timeout=2.0) + _cfg = self.get_config(timeout=GET_CONFIG_TIMEOUT) if self._config["runlevel"] != CBRunLevel.RUNNING: # Central waits a full second between the reqconfigall and reset From a9529ffa4e72e17f7b099d14cde0ffc203b61b6e Mon Sep 17 00:00:00 2001 From: Chadwick Boulay Date: Sat, 19 Oct 2024 20:01:09 -0400 Subject: [PATCH 4/5] black formatting --- src/pycbsdk/cbhw/device/nsp.py | 143 ++++++++++++++++++++++----------- 1 file changed, 96 insertions(+), 47 deletions(-) diff --git a/src/pycbsdk/cbhw/device/nsp.py b/src/pycbsdk/cbhw/device/nsp.py index 73f40ba..f9aba49 100644 --- a/src/pycbsdk/cbhw/device/nsp.py +++ b/src/pycbsdk/cbhw/device/nsp.py @@ -134,6 +134,7 @@ class CBAnaInpOpts(IntEnum): refelec_rawstream = 0x00000040 refelec_offsetcorrect = 0x00000100 + class CBAOutOpts(IntEnum): AUDIO = 0x00000001 SCALE = 0x00000002 @@ -229,6 +230,7 @@ class CBAInpSpk(IntFlag): PCASORT = PCAMANSORT | PCAAUTOSORT # All PCA sorting algorithms ALLSORT = AUTOSORT | HOOPSORT | PCASORT # All sorting algorithms + class LNCRate: lnc_rates = { 0: 0, @@ -237,6 +239,7 @@ class LNCRate: 30: 30000, 60: 60000, } + @staticmethod def GetLNCRate(key) -> int: try: @@ -437,7 +440,6 @@ def _handle_chaninfo(self, pkt): # TODO: from CHANREPSPKTHR, .spkthrlevel self._config["channel_infos"][pkt.chan].spkthrlevel = pkt.spkthrlevel - else: # TODO: from CHANREPNTRODEGROUP, .spkgroup # TODO: from CHANREPDISP, .smpdispmin, .smpdispmax, .spkdispmax, .lncdispmax @@ -579,10 +581,14 @@ def _toggle_channel_ainp_flag( if not self._send_packet(pkt=pkt, event=event, timeout=timeout): self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) - if (pkt.ainpopts != self._config["channel_infos"][chid].ainpopts): - raise RuntimeError("Packet response contents do not match expected values.") + if pkt.ainpopts != self._config["channel_infos"][chid].ainpopts: + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) def _configure_channel_smpgroup( self, chid: int, attr_value: int, timeout: float = 0 @@ -611,14 +617,16 @@ def _configure_channel_smpgroup( if not self._send_packet(pkt=pkt, event=event, timeout=timeout): self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) - if ( - pkt.smpgroup != self._config["channel_infos"][chid].smpgroup - ) or ( - pkt.smpfilter != self._config["channel_infos"][chid].smpfilter - ): - raise RuntimeError("Packet response contents do not match expected values.") + if (pkt.smpgroup != self._config["channel_infos"][chid].smpgroup) or ( + pkt.smpfilter != self._config["channel_infos"][chid].smpfilter + ): + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) def _configure_channel_autothreshold( self, chid: int, attr_value: int, timeout: float = 0.0 @@ -677,7 +685,7 @@ def _configure_channel_hoops(self, chid: int, attr_value: dict, timeout: float = def _configure_channel_label(self, chid: int, attr_value: str, timeout: float = 0): pkt = copy.copy(self._config["channel_infos"][chid]) pkt.header.type = CBPacketType.CHANSETLABEL - pkt.label = bytes(create_string_buffer(attr_value.encode('utf-8'), 16)) + pkt.label = bytes(create_string_buffer(attr_value.encode("utf-8"), 16)) # TODO: pkt.userflags # TODO: pkt.position event = self._config_events["chaninfo"] if timeout > 0 else None @@ -685,11 +693,13 @@ def _configure_channel_label(self, chid: int, attr_value: str, timeout: float = self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.label != self._config["channel_infos"][chid].label: - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") - - + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) def _configure_channel_lnc(self, chid: int, attr_value: int, timeout: float = 0): pkt = copy.copy(self._config["channel_infos"][chid]) @@ -704,11 +714,17 @@ def _configure_channel_lnc(self, chid: int, attr_value: int, timeout: float = 0) self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.ainpopts != self._config["channel_infos"][chid].ainpopts: - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) - def _configure_channel_lnc_rate(self, chid: int, attr_value: int, timeout: float) -> None: + def _configure_channel_lnc_rate( + self, chid: int, attr_value: int, timeout: float + ) -> None: pkt = copy.copy(self._config["channel_infos"][chid]) pkt.lncrate = LNCRate.GetLNCRate(attr_value) @@ -720,9 +736,13 @@ def _configure_channel_lnc_rate(self, chid: int, attr_value: int, timeout: float self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.lncrate != self._config["channel_infos"][chid].lncrate: - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) def _set_lnc_global_config( self, chid: int, attr_value: int = 60, timeout: float = 0 @@ -744,17 +764,19 @@ def _set_lnc_global_config( if ( (pkt.lncFreq != self._config["channel_infos"][chid].lncFreq) - or ( - pkt.lncRefChan != self._config["channel_infos"][chid].lncRefChan - ) + or (pkt.lncRefChan != self._config["channel_infos"][chid].lncRefChan) or ( pkt.lncGlobalMode != self._config["channel_infos"][chid].lncGlobalMode ) ): - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) def _configure_channel_dcoffset( self, chid: int, attr_value: bool, timeout: float = 0.0 @@ -765,9 +787,9 @@ def _configure_channel_dcoffset( enable=not not attr_value, timeout=timeout, ) - + def _configure_channel_spkfilter( - self, chid: int, attr_value: int, timeout: float = 0.0 + self, chid: int, attr_value: int, timeout: float = 0.0 ): pkt = copy.copy(self._config["channel_infos"][chid]) pkt.spkfilter = attr_value @@ -778,11 +800,17 @@ def _configure_channel_spkfilter( self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.spkfilter != self._config["channel_infos"][chid].spkfilter: - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") - - def _configure_spk_threshold(self, chid: int, attr_value: int, timeout: float = 0.0): + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) + + def _configure_spk_threshold( + self, chid: int, attr_value: int, timeout: float = 0.0 + ): pkt = copy.copy(self._config["channel_infos"][chid]) pkt.spkthrlevel = attr_value pkt.header.type = CBPacketType.CHANSETSPKTHR @@ -793,13 +821,16 @@ def _configure_spk_threshold(self, chid: int, attr_value: int, timeout: float = self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.spkthrlevel != self._config["channel_infos"][chid].spkthrlevel: - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") - + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) def _configure_channel_analogout( - self, chid: int, attr_value: int, timeout: float = 0.0 + self, chid: int, attr_value: int, timeout: float = 0.0 ): pkt = copy.copy(self._config["channel_infos"][chid]) pkt.aoutopts = attr_value @@ -810,10 +841,14 @@ def _configure_channel_analogout( self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.aoutopts != self._config["channel_infos"][chid].aoutopts: - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") - + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) + def _configure_channel_digital_input( self, chid: int, attr_value: int, timeout: float = 0.0 ): @@ -826,10 +861,14 @@ def _configure_channel_digital_input( self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.dinpopts != self._config["channel_infos"][chid].dinpopts: - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") - + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) + def _configure_channel_digital_output( self, chid: int, attr_value: int, timeout: float = 0.0 ): @@ -842,9 +881,13 @@ def _configure_channel_digital_output( self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.doutopts != self._config["channel_infos"][chid].doutopts: - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) def _configure_channel_smpfilter( self, chid: int, attr_value: int, timeout: float = 0.0 @@ -858,9 +901,13 @@ def _configure_channel_smpfilter( self.get_config(timeout=GET_CONFIG_TIMEOUT, force_refresh=True) if pkt.smpfilter != self._config["channel_infos"][chid].smpfilter: - raise RuntimeError("Packet response contents do not match expected values.") + raise RuntimeError( + "Packet response contents do not match expected values." + ) else: - raise RuntimeError("Valid packet response NOT received, but packet contains expected values") + raise RuntimeError( + "Valid packet response NOT received, but packet contains expected values" + ) def _configure_channel_enable_spike( self, chid: int, attr_value: bool, timeout: float = 0 @@ -899,7 +946,9 @@ def configure_channel( # so let the user know, TODO: raise an exception? print(f"{attr_name} is not a recognized name.") - def configure_all_channels(self, chtype: CBChannelType, attr_name: str, attr_value, timeout: float): + def configure_all_channels( + self, chtype: CBChannelType, attr_name: str, attr_value, timeout: float + ): for chid, ch_info in self._config["channel_infos"].items(): if self._config["channel_types"][chid] == chtype: self.configure_channel(chid, attr_name, attr_value, timeout) From f2014ea893c2b17eeb9bc25ccc368d0c95f19996 Mon Sep 17 00:00:00 2001 From: Chadwick Boulay Date: Sat, 19 Oct 2024 20:06:14 -0400 Subject: [PATCH 5/5] Delete TODO statements that have been done. --- src/pycbsdk/cbhw/device/nsp.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/pycbsdk/cbhw/device/nsp.py b/src/pycbsdk/cbhw/device/nsp.py index f9aba49..0f45df9 100644 --- a/src/pycbsdk/cbhw/device/nsp.py +++ b/src/pycbsdk/cbhw/device/nsp.py @@ -418,6 +418,7 @@ def _handle_chaninfo(self, pkt): self._config["channel_infos"][pkt.chan].smpgroup = pkt.smpgroup elif pkt.header.type == CBPacketType.CHANREPSPKHPS: self._config["channel_infos"][pkt.chan].spkhoops = pkt.spkhoops + # TODO: .unitmapping[n].bValid = pkt.spkhoops[n][0].valid ?? elif pkt.header.type == CBPacketType.CHANREPAOUT: self._config["channel_infos"][pkt.chan].aoutopts = pkt.aoutopts # self._config["channel_infos"][pkt.chan].union.a.moninst = pkt.moninst @@ -443,12 +444,7 @@ def _handle_chaninfo(self, pkt): else: # TODO: from CHANREPNTRODEGROUP, .spkgroup # TODO: from CHANREPDISP, .smpdispmin, .smpdispmax, .spkdispmax, .lncdispmax - # TODO: from CHANREPLABEL, .label, .userflags # TODO: from CHANREPUNITOVERRIDES, .unitmapping - # TODO: from CHANREPSPKHPS, .spkhoops, .unitmapping[n].bValid = pkt.spkhoops[n][0].valid - # TODO: from CHANREPDINP, .dinpopts; NOTE: Need extra check if this is for serial or digital - # TODO: from CHANREPAOUT, ... complicated - # TODO: from CHANREPSCALE, .scalin, .scalout pass # print(f"handled chaninfo {pkt.chan} of type {hex(pkt.header.type)}") self._config_events["chaninfo"].set()