forked from awendt/pyrelacs
trying to find changes that lead to the segfault
This commit is contained in:
parent
9f7d28ccf8
commit
9cd6aadb3b
@ -1,130 +0,0 @@
|
|||||||
import ctypes
|
|
||||||
import time
|
|
||||||
|
|
||||||
import uldaq
|
|
||||||
from IPython import embed
|
|
||||||
from pyrelacs.repros.repos import Repos
|
|
||||||
from pyrelacs.util.logging import config_logging
|
|
||||||
import numpy as np
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
|
|
||||||
log = config_logging()
|
|
||||||
|
|
||||||
|
|
||||||
class Attenuator(Repos):
|
|
||||||
def __init__(self) -> None:
|
|
||||||
super().__init__()
|
|
||||||
|
|
||||||
def check_attenuator(self):
|
|
||||||
"""
|
|
||||||
ident : attdev-1
|
|
||||||
strobepin : 6
|
|
||||||
datainpin : 5
|
|
||||||
dataoutpin: -1
|
|
||||||
cspin : 4
|
|
||||||
mutepin : 7
|
|
||||||
zcenpin : -1
|
|
||||||
"""
|
|
||||||
t = np.arange(0, DURATION, 1 / SAMPLERATE)
|
|
||||||
data = AMPLITUDE * np.sin(2 * np.pi * SINFREQ * t)
|
|
||||||
data_channels = np.concatenate((data, data))
|
|
||||||
|
|
||||||
db_values = [0, 0, -2, -5, -10, -20, -50]
|
|
||||||
for i, db_value in enumerate(db_values):
|
|
||||||
log.info(f"Attenuating the Channels, with {db_value}")
|
|
||||||
if i == 1:
|
|
||||||
log.info("Muting the Channels")
|
|
||||||
self.set_attenuation_level(
|
|
||||||
db_value, db_value, mute_channel1=True, mute_channel2=True
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.set_attenuation_level(db_value, db_value)
|
|
||||||
|
|
||||||
stim, ao_device = self.write_analog_dac(
|
|
||||||
data_channels,
|
|
||||||
[0, 1],
|
|
||||||
SAMPLERATE,
|
|
||||||
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
|
||||||
Range=uldaq.Range.BIP10VOLTS,
|
|
||||||
)
|
|
||||||
self.diggital_trigger()
|
|
||||||
|
|
||||||
try:
|
|
||||||
ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
|
||||||
except uldaq.ul_exception.ULException:
|
|
||||||
log.debug("Operation timed out")
|
|
||||||
self.write_bit(channel=0, bit=0)
|
|
||||||
self.disconnect_dac()
|
|
||||||
self.connect_dac()
|
|
||||||
self.set_analog_to_zero()
|
|
||||||
finally:
|
|
||||||
self.write_bit(channel=0, bit=0)
|
|
||||||
self.disconnect_dac()
|
|
||||||
self.connect_dac()
|
|
||||||
self.set_analog_to_zero()
|
|
||||||
|
|
||||||
log.info("Sleeping for 1 second, before next attenuation")
|
|
||||||
time.sleep(1)
|
|
||||||
self.deactivate_attenuator()
|
|
||||||
|
|
||||||
def set_attenuation_level(
|
|
||||||
self,
|
|
||||||
db_channel1: float = 5.0,
|
|
||||||
db_channel2: float = 5.0,
|
|
||||||
mute_channel1: bool = False,
|
|
||||||
mute_channel2: bool = False,
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
ident : attdev-1
|
|
||||||
strobepin : 6
|
|
||||||
datainpin : 5
|
|
||||||
dataoutpin: -1
|
|
||||||
cspin : 4
|
|
||||||
mutepin : 7
|
|
||||||
zcenpin : -1
|
|
||||||
"""
|
|
||||||
|
|
||||||
self.activate_attenuator()
|
|
||||||
hardware_possible_db = np.arange(-95.5, 32.0, 0.5)
|
|
||||||
byte_number = np.arange(1, 256)
|
|
||||||
byte_number_db1 = byte_number[hardware_possible_db == db_channel1][0]
|
|
||||||
binary_db1 = np.binary_repr(byte_number_db1, width=8)
|
|
||||||
byte_number_db2 = byte_number[hardware_possible_db == db_channel2][0]
|
|
||||||
binary_db2 = np.binary_repr(byte_number_db2, width=8)
|
|
||||||
if mute_channel1:
|
|
||||||
log.info("Muting channel one")
|
|
||||||
binary_db1 = "00000000"
|
|
||||||
if mute_channel2:
|
|
||||||
log.info("Muting channel one")
|
|
||||||
binary_db2 = "00000000"
|
|
||||||
|
|
||||||
channels_db = binary_db1 + binary_db2
|
|
||||||
self.write_bit(channel=4, bit=0)
|
|
||||||
for b in channels_db:
|
|
||||||
self.write_bit(channel=5, bit=int(b))
|
|
||||||
time.time_ns()
|
|
||||||
self.write_bit(channel=6, bit=1)
|
|
||||||
time.time_ns()
|
|
||||||
self.write_bit(channel=6, bit=0)
|
|
||||||
time.time_ns()
|
|
||||||
self.write_bit(channel=4, bit=1)
|
|
||||||
|
|
||||||
def activate_attenuator(self):
|
|
||||||
for ch, b in zip([4, 5, 6, 7], [1, 0, 0, 1]):
|
|
||||||
self.write_bit(channel=ch, bit=b)
|
|
||||||
|
|
||||||
def deactivate_attenuator(self):
|
|
||||||
# mute should be enabled for starting calibration
|
|
||||||
self.write_bit(channel=7, bit=0)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
SAMPLERATE = 40_000.0
|
|
||||||
DURATION = 5
|
|
||||||
AMPLITUDE = 1
|
|
||||||
SINFREQ = 1
|
|
||||||
|
|
||||||
att = Attenuator()
|
|
||||||
# att.set_attenuation_level(db_channel1=5, db_channel2=5)
|
|
||||||
|
|
||||||
att.check_attenuator()
|
|
@ -3,7 +3,7 @@ import time
|
|||||||
|
|
||||||
import uldaq
|
import uldaq
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
from pyrelacs.repros.repos import Repos
|
from pyrelacs.repros.repos import MccDac
|
||||||
from pyrelacs.util.logging import config_logging
|
from pyrelacs.util.logging import config_logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@ -11,7 +11,7 @@ import matplotlib.pyplot as plt
|
|||||||
log = config_logging()
|
log = config_logging()
|
||||||
|
|
||||||
|
|
||||||
class Calibration(Repos):
|
class Calibration(MccDac):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
@ -48,4 +48,4 @@ if __name__ == "__main__":
|
|||||||
SINFREQ = 100
|
SINFREQ = 100
|
||||||
daq_input = Calibration()
|
daq_input = Calibration()
|
||||||
# daq_input.run_calibration()
|
# daq_input.run_calibration()
|
||||||
daq_input.attenuator()
|
daq_input.check_attenuator()
|
||||||
|
@ -2,12 +2,12 @@ import uldaq
|
|||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
|
||||||
from pyrelacs.util.logging import config_logging
|
from pyrelacs.util.logging import config_logging
|
||||||
from .repos import Repos
|
from .repos import MccDac
|
||||||
|
|
||||||
log = config_logging()
|
log = config_logging()
|
||||||
|
|
||||||
|
|
||||||
class ReadData(Repos):
|
class ReadData(MccDac):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import ctypes
|
|||||||
|
|
||||||
import uldaq
|
import uldaq
|
||||||
from IPython import embed
|
from IPython import embed
|
||||||
from pyrelacs.repros.repos import Repos
|
from pyrelacs.repros.repos import MccDac
|
||||||
from pyrelacs.util.logging import config_logging
|
from pyrelacs.util.logging import config_logging
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@ -10,7 +10,7 @@ import matplotlib.pyplot as plt
|
|||||||
log = config_logging()
|
log = config_logging()
|
||||||
|
|
||||||
|
|
||||||
class Output_daq(Repos):
|
class Output_daq(MccDac):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
# devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
# devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||||
|
@ -11,7 +11,7 @@ from pyrelacs.util.logging import config_logging
|
|||||||
log = config_logging()
|
log = config_logging()
|
||||||
|
|
||||||
|
|
||||||
class Repos:
|
class MccDac:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
devices = uldaq.get_daq_device_inventory(uldaq.InterfaceType.USB)
|
||||||
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
log.debug(f"Found daq devices {len(devices)}, connecting to the first one")
|
||||||
@ -221,11 +221,110 @@ class Repos:
|
|||||||
self.daq_device.disconnect()
|
self.daq_device.disconnect()
|
||||||
self.daq_device.release()
|
self.daq_device.release()
|
||||||
|
|
||||||
def run_repo(self) -> None:
|
def check_attenuator(self):
|
||||||
pass
|
"""
|
||||||
|
ident : attdev-1
|
||||||
|
strobepin : 6
|
||||||
|
datainpin : 5
|
||||||
|
dataoutpin: -1
|
||||||
|
cspin : 4
|
||||||
|
mutepin : 7
|
||||||
|
zcenpin : -1
|
||||||
|
"""
|
||||||
|
|
||||||
|
SAMPLERATE = 40_000.0
|
||||||
|
DURATION = 5
|
||||||
|
AMPLITUDE = 1
|
||||||
|
SINFREQ = 1
|
||||||
|
t = np.arange(0, DURATION, 1 / SAMPLERATE)
|
||||||
|
data = AMPLITUDE * np.sin(2 * np.pi * SINFREQ * t)
|
||||||
|
data_channels = np.concatenate((data, data))
|
||||||
|
|
||||||
|
db_values = [0, 0, -2, -5, -10, -20, -50]
|
||||||
|
db_values = [0, -10, -20]
|
||||||
|
for i, db_value in enumerate(db_values):
|
||||||
|
log.info(f"Attenuating the Channels, with {db_value}")
|
||||||
|
if i == 1:
|
||||||
|
log.info("Muting the Channels")
|
||||||
|
self.set_attenuation_level(
|
||||||
|
db_value, db_value, mute_channel1=True, mute_channel2=True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.set_attenuation_level(db_value, db_value)
|
||||||
|
|
||||||
|
stim, ao_device = self.write_analog_dac(
|
||||||
|
data_channels,
|
||||||
|
[0, 1],
|
||||||
|
SAMPLERATE,
|
||||||
|
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
||||||
|
Range=uldaq.Range.BIP10VOLTS,
|
||||||
|
)
|
||||||
|
self.diggital_trigger()
|
||||||
|
|
||||||
|
try:
|
||||||
|
ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
||||||
|
except uldaq.ul_exception.ULException:
|
||||||
|
log.debug("Operation timed out")
|
||||||
|
self.write_bit(channel=0, bit=0)
|
||||||
|
self.disconnect_dac()
|
||||||
|
self.connect_dac()
|
||||||
|
self.set_analog_to_zero()
|
||||||
|
finally:
|
||||||
|
self.write_bit(channel=0, bit=0)
|
||||||
|
self.disconnect_dac()
|
||||||
|
self.connect_dac()
|
||||||
|
self.set_analog_to_zero()
|
||||||
|
|
||||||
|
log.info("Sleeping for 1 second, before next attenuation")
|
||||||
|
time.sleep(1)
|
||||||
|
self.deactivate_attenuator()
|
||||||
|
|
||||||
|
def set_attenuation_level(
|
||||||
|
self,
|
||||||
|
db_channel1: float = 5.0,
|
||||||
|
db_channel2: float = 5.0,
|
||||||
|
mute_channel1: bool = False,
|
||||||
|
mute_channel2: bool = False,
|
||||||
|
):
|
||||||
|
"""
|
||||||
|
ident : attdev-1
|
||||||
|
strobepin : 6
|
||||||
|
datainpin : 5
|
||||||
|
dataoutpin: -1
|
||||||
|
cspin : 4
|
||||||
|
mutepin : 7
|
||||||
|
zcenpin : -1
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.activate_attenuator()
|
||||||
|
hardware_possible_db = np.arange(-95.5, 32.0, 0.5)
|
||||||
|
byte_number = np.arange(1, 256)
|
||||||
|
byte_number_db1 = byte_number[hardware_possible_db == db_channel1][0]
|
||||||
|
binary_db1 = np.binary_repr(byte_number_db1, width=8)
|
||||||
|
byte_number_db2 = byte_number[hardware_possible_db == db_channel2][0]
|
||||||
|
binary_db2 = np.binary_repr(byte_number_db2, width=8)
|
||||||
|
if mute_channel1:
|
||||||
|
log.info("Muting channel one")
|
||||||
|
binary_db1 = "00000000"
|
||||||
|
if mute_channel2:
|
||||||
|
log.info("Muting channel one")
|
||||||
|
binary_db2 = "00000000"
|
||||||
|
|
||||||
|
channels_db = binary_db1 + binary_db2
|
||||||
|
self.write_bit(channel=4, bit=0)
|
||||||
|
for b in channels_db:
|
||||||
|
self.write_bit(channel=5, bit=int(b))
|
||||||
|
time.time_ns()
|
||||||
|
self.write_bit(channel=6, bit=1)
|
||||||
|
time.time_ns()
|
||||||
|
self.write_bit(channel=6, bit=0)
|
||||||
|
time.time_ns()
|
||||||
|
self.write_bit(channel=4, bit=1)
|
||||||
|
|
||||||
def stop_repo(self) -> None:
|
def activate_attenuator(self):
|
||||||
pass
|
for ch, b in zip([4, 5, 6, 7], [1, 0, 0, 1]):
|
||||||
|
self.write_bit(channel=ch, bit=b)
|
||||||
|
|
||||||
def reload_repo(self) -> None:
|
def deactivate_attenuator(self):
|
||||||
pass
|
# mute should be enabled for starting calibration
|
||||||
|
self.write_bit(channel=7, bit=0)
|
||||||
|
Loading…
Reference in New Issue
Block a user