Skip to content

AvaSpec SDK¤

Wrapper around the avaspec SDK from Avantes.

The wrapper was written using v9.7.0.0 of the SDK. The avaspec SDK may require a Visual C++ Redistributable Package to be installed (on Windows).

The main class is AvaSpec and the Enums and Structs are available once the avantes module is imported, for example,

from msl.equipment.resources import avantes

cfg = avantes.MeasConfigType()
cfg.m_IntegrationTime = 5  # in milliseconds
cfg.m_NrAverages = 1  # number of averages

AvaSpec (SDK) ¤

AvaSpec(equipment: Equipment)

              flowchart LR
              msl.equipment_resources.avantes.avaspec.AvaSpec[AvaSpec]
              msl.equipment.interfaces.sdk.SDK[SDK]
              msl.equipment.schema.Interface[Interface]

                              msl.equipment.interfaces.sdk.SDK --> msl.equipment_resources.avantes.avaspec.AvaSpec
                                msl.equipment.schema.Interface --> msl.equipment.interfaces.sdk.SDK
                



              click msl.equipment_resources.avantes.avaspec.AvaSpec href "" "msl.equipment_resources.avantes.avaspec.AvaSpec"
              click msl.equipment.interfaces.sdk.SDK href "" "msl.equipment.interfaces.sdk.SDK"
              click msl.equipment.schema.Interface href "" "msl.equipment.schema.Interface"
            

Wrapper around the avaspec SDK from Avantes.

Regular-expression patterns that are used to select this Resource when connect() is called.

manufacturer=r"Avantes"
model=r""

Parameters:

Name Type Description Default
equipment Equipment

An Equipment instance.

required

A Connection instance supports the following properties for the AvaSpec wrapper.

Connection Properties:

Name Type Description
port_id int

One of -1 (Ethernet+USB), 0 (USB) or 256 (Ethernet). Default: -1

activate bool

Whether to automatically activate the connection. Default: True

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
def __init__(self, equipment: Equipment) -> None:
    """Wrapper around the `avaspec` SDK from Avantes.

    Regular-expression patterns that are used to select this Resource when
    [connect()][msl.equipment.schema.Equipment.connect] is called.
    ```python
    manufacturer=r"Avantes"
    model=r""
    ```

    Args:
        equipment: An [Equipment][] instance.

    A [Connection][msl.equipment.schema.Connection] instance supports the following _properties_
    for the AvaSpec wrapper.

    Attributes: Connection Properties:
        port_id (int): One of `-1` (Ethernet+USB), `0` (USB) or `256` (Ethernet). _Default: `-1`_
        activate (bool): Whether to automatically activate the connection. _Default: `True`_
    """
    self._handle: int | None = None
    super().__init__(equipment, libtype="windll" if IS_WINDOWS else "cdll")

    functions: dict[
        str, tuple[type[c_int32 | c_bool], Callable[..., int | None], list[tuple[str, type[_CDataType]]]]
    ] = {
        "AVS_Init": (c_int32, self._err_check, [("a_Port", c_int16)]),
        "AVS_Done": (c_int32, self._err_check, []),
        "AVS_GetNrOfDevices": (c_int32, self._log_errcheck, []),
        "AVS_UpdateUSBDevices": (c_int32, self._log_errcheck, []),
        "AVS_UpdateETHDevices": (
            c_int32,
            self._err_check,
            [
                ("a_ListSize", c_uint32),
                ("a_pRequiredSize", POINTER(c_uint32)),
                ("a_pList", POINTER(BroadcastAnswerType)),
            ],
        ),
        "AVS_GetList": (
            c_int32,
            self._err_check,
            [
                ("a_ListSize", c_uint32),
                ("a_pRequiredSize", POINTER(c_uint32)),
                ("a_pList", POINTER(AvsIdentityType)),
            ],
        ),
        "AVS_Activate": (c_int32, self._err_check, [("a_pDeviceId", POINTER(AvsIdentityType))]),
        "AVS_ActivateConn": (c_int32, self._err_check, [("a_pDeviceId", POINTER(AvsIdentityType))]),
        "AVS_ActivateConnCb": (c_int32, self._err_check, [("a_pDeviceId", POINTER(AvsIdentityType))]),
        "AVS_Deactivate": (c_bool, self._check_bool, [("a_hDevice", c_int32)]),
        "AVS_GetHandleFromSerial": (c_int32, self._err_check, [("a_pSerial", c_char_p)]),
        "AVS_GetStatusBySerial": (
            c_int32,
            self._err_check,
            [("a_pSerial", c_char_p), ("a_status", POINTER(c_int32))],
        ),
        "AVS_Register": (c_bool, self._check_bool, [("a_Hwnd", c_void_p)]),
        "AVS_Measure": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_hWnd", c_void_p), ("a_Nmsr", c_int16)],
        ),
        "AVS_MeasureCallback": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("__Done", MeasureCallback), ("a_Nmsr", c_int16)],
        ),
        "AVS_PrepareMeasure": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_pMeasConfig", POINTER(MeasConfigType))],
        ),
        "AVS_StopMeasure": (c_int32, self._err_check, [("a_hDevice", c_int32)]),
        "AVS_PollScan": (c_int32, self._err_check, [("a_hDevice", c_int32)]),
        "AVS_GetScopeData": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_pTimeLabel", POINTER(c_uint32)), ("a_pSpectrum", POINTER(c_double))],
        ),
        "AVS_GetSaturatedPixels": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_pSaturated", POINTER(c_ubyte))],
        ),
        "AVS_GetLambda": (c_int32, self._err_check, [("a_hDevice", c_int32), ("a_pWaveLength", POINTER(c_double))]),
        "AVS_GetNumPixels": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_pNumPixels", POINTER(c_uint16))],
        ),
        "AVS_GetParameter": (
            c_int32,
            self._err_check,
            [
                ("a_hDevice", c_int32),
                ("a_Size", c_uint32),
                ("a_pRequiredSize", POINTER(c_uint32)),
                ("a_pDeviceParm", POINTER(DeviceConfigType)),
            ],
        ),
        "AVS_SetParameter": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_pDeviceParm", POINTER(DeviceConfigType))],
        ),
        "AVS_GetVersionInfo": (
            c_int32,
            self._err_check,
            [
                ("a_hDevice", c_int32),
                ("a_pFPGAVersion", c_char_p),
                ("a_pFirmwareVersion", c_char_p),
                ("a_pDLLVersion", c_char_p),
            ],
        ),
        "AVS_GetDLLVersion": (c_int32, self._err_check, [("a_pVersionString", c_char_p)]),
        "AVS_SetSyncMode": (c_int32, self._err_check, [("a_hDevice", c_int32), ("a_Enable", c_ubyte)]),
        "AVS_SetPrescanMode": (c_int32, self._err_check, [("a_hDevice", c_int32), ("a_Prescan", c_bool)]),
        "AVS_UseHighResAdc": (c_int32, self._err_check, [("a_hDevice", c_int32), ("a_Enable", c_bool)]),
        "AVS_GetAnalogIn": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_AnalogInId", c_ubyte), ("a_pAnalogIn", POINTER(c_float))],
        ),
        "AVS_GetDigIn": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_DigInId", c_ubyte), ("a_pDigIn", POINTER(c_ubyte))],
        ),
        "AVS_SetAnalogOut": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_PortId", c_ubyte), ("a_Value", c_float)],
        ),
        "AVS_SetDigOut": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_PortId", c_ubyte), ("a_Status", c_ubyte)],
        ),
        "AVS_SetPwmOut": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_PortId", c_ubyte), ("a_Freq", c_ulong), ("a_Duty", c_ubyte)],
        ),
        "AVS_GetDarkPixelData": (
            c_int32,
            self._check_bool,
            [("a_hDevice", c_int32), ("a_pDarkData", POINTER(c_double))],
        ),
        "AVS_GetComPortName": (
            c_int32,
            self._check_bool,
            [("a_pDeviceId", POINTER(AvsIdentityType)), ("a_pIp", c_char_p), ("a_size", POINTER(c_int32))],
        ),
        "AVS_GetComType": (
            c_int32,
            self._err_check,
            [("a_pDeviceId", POINTER(AvsIdentityType)), ("a_type", POINTER(c_int32))],
        ),
        "AVS_SetSensitivityMode": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_SensitivityMode", c_uint32)],
        ),
        "AVS_GetIpConfig": (
            c_int32,
            self._check_bool,
            [("a_hDevice", c_int32), ("a_Data", POINTER(EthernetSettingsType))],
        ),
        "AVS_SuppressStrayLight": (
            c_int32,
            self._err_check,
            [
                ("a_hDevice", c_int32),
                ("a_Multifactor", c_float),
                ("a_pSrcSpectrum", POINTER(c_double)),
                ("a_pDestSpectrum", POINTER(c_double)),
            ],
        ),
        "AVS_Heartbeat": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_pHbReq", POINTER(c_uint32)), ("a_pHbResp", POINTER(HeartbeatRespType))],
        ),
        "AVS_ResetDevice": (c_int32, self._err_check, [("a_hDevice", c_int32)]),
        "AVS_GetOemParameter": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_pOemData", POINTER(OemDataType))],
        ),
        "AVS_SetOemParameter": (
            c_int32,
            self._err_check,
            [("a_hDevice", c_int32), ("a_pOemData", POINTER(OemDataType))],
        ),
    }

    for key, value in functions.items():
        try:
            attr = getattr(self.sdk, key)
        except AttributeError as e:  # noqa: PERF203
            logger.debug("%s: %s", self.__class__.__name__, e)
        else:
            attr.restype, attr.errcheck = value[:2]
            attr.argtypes = [typ for _, typ in value[2]]

    assert equipment.connection  # noqa: S101
    props = equipment.connection.properties
    _ = self.init(props.get("port_id", -1))
    if props.get("activate", True):
        self.activate()

activate ¤

activate() -> None

Activates the spectrometer for communication.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
def activate(self) -> None:
    """Activates the spectrometer for communication."""
    out = AvaSpec.find(path=self.path)
    if not out:
        raise MSLConnectionError(self, "Cannot activate. No devices found.")

    for item in out:
        if item.SerialNumber.decode() == self.equipment.serial:
            self._handle = int(self.sdk.AVS_Activate(item))
            if self._handle == INVALID_AVS_HANDLE_VALUE:
                raise MSLConnectionError(self, "Invalid handle")
            _handles.append(self._handle)
            return

    msg = f"Did not find the Avantes serial number {self.equipment.serial!r} in the list of devices."
    raise MSLConnectionError(self, msg)

deactivate ¤

deactivate() -> None

Closes communication with the spectrometer.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
 997
 998
 999
1000
1001
1002
1003
def deactivate(self) -> None:
    """Closes communication with the spectrometer."""
    if self._handle in _handles:
        self.sdk.AVS_Deactivate(self._handle)
        _handles.remove(self._handle)
        self._handle = None
        super().disconnect()

disconnect ¤

disconnect() -> None

Calls deactivate.

Also calls done (if there are no additional connections open to other spectrometers).

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1005
1006
1007
1008
1009
1010
1011
1012
1013
def disconnect(self) -> None:  # pyright: ignore[reportImplicitOverride]
    """Calls [deactivate][msl.equipment_resources.avantes.avaspec.AvaSpec.deactivate].

    Also calls [done][msl.equipment_resources.avantes.avaspec.AvaSpec.done] (if there
    are no additional connections open to other spectrometers).
    """
    self.deactivate()
    if not _handles:
        self.done()

done ¤

done() -> None

Closes communication with all spectrometers and releases internal storage.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1015
1016
1017
1018
def done(self) -> None:
    """Closes communication with all spectrometers and releases internal storage."""
    if hasattr(self, "_sdk") and self._sdk is not None:
        self.sdk.AVS_Done()

find staticmethod ¤

find(
    path: str = "avaspecx64", port_id: int = -1, nmax: int = 16
) -> list[AvsIdentityType]

Returns device information for each spectrometer that is connected.

Parameters:

Name Type Description Default
path str

The path to the AvaSpec SDK.

'avaspecx64'
port_id int

ID of port to be used. One of:

  • -1: Use both Ethernet (AS7010) and USB ports
  • 0: Use USB port
  • 1..255: Not supported in v9.7 of the SDK
  • 256: Use Ethernet port (AS7010)
-1
nmax int

The maximum number of devices that can be in the list.

16

Returns:

Type Description
list[AvsIdentityType]

The information about the devices.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
@staticmethod
def find(path: str = "avaspecx64", port_id: int = -1, nmax: int = 16) -> list[AvsIdentityType]:
    """Returns device information for each spectrometer that is connected.

    Args:
        path: The path to the AvaSpec SDK.
        port_id: ID of port to be used. One of:

            * `-1`: Use both Ethernet (AS7010) and USB ports
            * `0`: Use USB port
            * `1..255`: Not supported in v9.7 of the SDK
            * `256`: Use Ethernet port (AS7010)

        nmax: The maximum number of devices that can be in the list.

    Returns:
        The information about the devices.
    """
    lib = LoadLibrary(path, libtype="windll" if IS_WINDOWS else "cdll").lib

    ret = lib.AVS_Init(port_id)
    if ret == 0:
        return []

    size = nmax * sizeof(AvsIdentityType)
    required_size = c_uint32()
    types = (AvsIdentityType * nmax)()

    lib.AVS_GetList.argtypes = [c_uint32, POINTER(c_uint32), POINTER(AvsIdentityType)]
    n = lib.AVS_GetList(size, required_size, types)
    if n >= 0:
        return [types[i] for i in range(n)]

    error_name, msg = ERROR_CODES.get(n, ("UNKNOWN_ERROR", f"Unknown error [code={n}]"))
    msg = f"{error_name}: {msg}"
    raise RuntimeError(msg)

get_analog_in ¤

get_analog_in(analog_id: int) -> float

Get the status of the specified analog input.

Parameters:

Name Type Description Default
analog_id int

The identifier of the analog input to get.

  • AS5216:

    • 0 = thermistor on optical bench (NIR 2.0 / NIR2.2 / NIR 2.5 / TEC)
    • 1 = 1V2
    • 2 = 5VIO
    • 3 = 5VUSB
    • 4 = AI2 = pin 18 at 26-pin connector
    • 5 = AI1 = pin 9 at 26-pin connector
    • 6 = NTC1 onboard thermistor
    • 7 = Not used
  • Mini:

    • 0 = NTC1 onboard thermistor
    • 1 = Not used
    • 2 = Not used
    • 3 = Not used
    • 4 = AI2 = pin 13 on micro HDMI = pin 11 on HDMI Terminal
    • 5 = AI1 = pin 16 on micro HDMI = pin 17 on HDMI Terminal
    • 6 = Not used
    • 7 = Not used
  • AS7010:

    • 0 = thermistor on optical bench (NIR 2.0 / NIR2.2 / NIR 2.5 / TEC)
    • 1 = Not used
    • 2 = Not used
    • 3 = Not used
    • 4 = AI2 = pin 18 at 26-pin connector
    • 5 = AI1 = pin 9 at 26-pin connector
    • 6 = digital temperature sensor, returns degrees Celsius, not Volts
    • 7 = Not used
required

Returns:

Type Description
float

The analog input value [Volts or degrees Celsius].

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
def get_analog_in(self, analog_id: int) -> float:
    """Get the status of the specified analog input.

    Args:
        analog_id: The identifier of the analog input to get.

            * AS5216:

                * 0 = thermistor on optical bench (NIR 2.0 / NIR2.2 / NIR 2.5 / TEC)
                * 1 = 1V2
                * 2 = 5VIO
                * 3 = 5VUSB
                * 4 = AI2 = pin 18 at 26-pin connector
                * 5 = AI1 = pin 9 at 26-pin connector
                * 6 = NTC1 onboard thermistor
                * 7 = Not used

            * Mini:

                * 0 = NTC1 onboard thermistor
                * 1 = Not used
                * 2 = Not used
                * 3 = Not used
                * 4 = AI2 = pin 13 on micro HDMI = pin 11 on HDMI Terminal
                * 5 = AI1 = pin 16 on micro HDMI = pin 17 on HDMI Terminal
                * 6 = Not used
                * 7 = Not used

            * AS7010:

                * 0 = thermistor on optical bench (NIR 2.0 / NIR2.2 / NIR 2.5 / TEC)
                * 1 = Not used
                * 2 = Not used
                * 3 = Not used
                * 4 = AI2 = pin 18 at 26-pin connector
                * 5 = AI1 = pin 9 at 26-pin connector
                * 6 = digital temperature sensor, returns degrees Celsius, not Volts
                * 7 = Not used

    Returns:
        The analog input value [Volts or degrees Celsius].
    """
    ain = c_float()
    self.sdk.AVS_GetAnalogIn(self._handle, analog_id, ain)
    return ain.value

get_com_port_name ¤

get_com_port_name() -> str

Get the IP address of the device.

Returns:

Type Description
str

The IP address of the device.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
def get_com_port_name(self) -> str:
    """Get the IP address of the device.

    Returns:
        The IP address of the device.
    """
    device_id = AvsIdentityType()
    device_id.SerialNumber = self.equipment.serial.encode()
    name = create_string_buffer(255)
    self.sdk.AVS_GetComPortName(device_id, name, len(name))
    return name.value.decode()

get_com_type ¤

get_com_type() -> int

Get the communication protocol.

Returns:

Type Description
int

The communication type as defined below: * 0 = RS232 * 1 = USB5216 * 2 = USBMINI * 3 = USB7010 * 4 = ETH7010 * -1 = UNKNOWN

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
def get_com_type(self) -> int:
    """Get the communication protocol.

    Returns:
        The communication type as defined below:
            * 0 = RS232
            * 1 = USB5216
            * 2 = USBMINI
            * 3 = USB7010
            * 4 = ETH7010
            * -1 = UNKNOWN
    """
    device_id = AvsIdentityType()
    device_id.SerialNumber = self.equipment.serial.encode()
    typ = c_int32(-1)
    self.sdk.AVS_GetComType(device_id, typ)
    return typ.value

get_dark_pixel_data ¤

get_dark_pixel_data() -> NDArray[double]

Get the optically black pixel values of the last performed measurement.

You must call get_data before you call this method.

Returns:

Type Description
NDArray[double]

The dark pixels.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
def get_dark_pixel_data(self) -> NDArray[np.double]:
    """Get the optically black pixel values of the last performed measurement.

    You must call [get_data][msl.equipment_resources.avantes.avaspec.AvaSpec.get_data] before you call this method.

    Returns:
        The dark pixels.
    """
    # from the docs the maximum size is size=18 for the AvaSpec-2048-USB2 and AvaSpec-2048L-USB2
    values = np.zeros(32, dtype=np.double)  # make it bigger than 18
    self.sdk.AVS_GetDarkPixelData(self._handle, values.ctypes.data_as(POINTER(c_double)))
    return values[values > 0]

get_data ¤

get_data() -> tuple[int, NDArray[double]]

Returns the timestamp and the spectral data of the last measurement.

Returns:

Type Description
tuple[int, NDArray[double]]

The timestamp and the spectral data.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
def get_data(self) -> tuple[int, NDArray[np.double]]:
    """Returns the timestamp and the spectral data of the last measurement.

    Returns:
        The timestamp and the spectral data.
    """
    ticks = c_uint32()
    values = np.ones(MAX_NR_PIXELS, dtype=np.double) * -1.0
    self.sdk.AVS_GetScopeData(self._handle, ticks, values.ctypes.data_as(POINTER(c_double)))
    return ticks.value, values[values > -1.0]

get_digital_in ¤

get_digital_in(digital_id: int) -> int

Get the status of the specified digital input.

Parameters:

Name Type Description Default
digital_id int

The identifier of the digital input to get.

  • AS5216:

    • 0: DI1 = Pin 24 at 26-pin connector
    • 1: DI2 = Pin 7 at 26-pin connector
    • 2: DI3 = Pin 16 at 26-pin connector
  • Mini:

    • 0: DI1 = Pin 7 on Micro HDMI = Pin 5 on HDMI terminal
    • 1: DI2 = Pin 5 on Micro HDMI = Pin 3 on HDMI Terminal
    • 2: DI3 = Pin 3 on Micro HDMI = Pin 1 on HDMI Terminal
    • 3: DI4 = Pin 1 on Micro HDMI = Pin 19 on HDMI Terminal
    • 4: DI5 = Pin 4 on Micro HDMI = Pin 2 on HDMI Terminal
    • 5: DI6 = Pin 2 on Micro HDMI = Pin 14 on HDMI Terminal
  • AS7010:

    • 0: DI1 = Pin 24 at 26-pin connector
    • 1: DI2 = Pin 7 at 26-pin connector
    • 2: DI3 = Pin 16 at 26-pin
required

Returns:

Type Description
int

The digital input value.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
def get_digital_in(self, digital_id: int) -> int:
    """Get the status of the specified digital input.

    Args:
        digital_id: The identifier of the digital input to get.

            * AS5216:

                * `0`: DI1 = Pin 24 at 26-pin connector
                * `1`: DI2 = Pin 7 at 26-pin connector
                * `2`: DI3 = Pin 16 at 26-pin connector

            * Mini:

                * `0`: DI1 = Pin 7 on Micro HDMI = Pin 5 on HDMI terminal
                * `1`: DI2 = Pin 5 on Micro HDMI = Pin 3 on HDMI Terminal
                * `2`: DI3 = Pin 3 on Micro HDMI = Pin 1 on HDMI Terminal
                * `3`: DI4 = Pin 1 on Micro HDMI = Pin 19 on HDMI Terminal
                * `4`: DI5 = Pin 4 on Micro HDMI = Pin 2 on HDMI Terminal
                * `5`: DI6 = Pin 2 on Micro HDMI = Pin 14 on HDMI Terminal

            * AS7010:

                * `0`: DI1 = Pin 24 at 26-pin connector
                * `1`: DI2 = Pin 7 at 26-pin connector
                * `2`: DI3 = Pin 16 at 26-pin

    Returns:
        The digital input value.
    """
    din = c_ubyte()
    self.sdk.AVS_GetDigIn(self._handle, digital_id, din)
    return din.value

get_dll_version ¤

get_dll_version() -> str

Get the DLL version number.

Returns:

Type Description
str

The DLL version number

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1191
1192
1193
1194
1195
1196
1197
1198
1199
def get_dll_version(self) -> str:
    """Get the DLL version number.

    Returns:
        The DLL version number
    """
    version = create_string_buffer(255)
    self.sdk.AVS_GetDLLVersion(version)
    return version.value.decode()

get_handle_from_serial ¤

get_handle_from_serial(serial: str | None = None) -> int

Get the handle ID for the specified serial number.

Parameters:

Name Type Description Default
serial str | None

The serial number. Default is to get the handle for this class instance.

None

Returns:

Type Description
int

The handle.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
def get_handle_from_serial(self, serial: str | None = None) -> int:
    """Get the handle ID for the specified serial number.

    Args:
        serial: The serial number. Default is to get the handle for this class instance.

    Returns:
        The handle.
    """
    serial = serial or self.equipment.serial
    return int(self.sdk.AVS_GetHandleFromSerial(serial.encode()))

get_ip_config ¤

get_ip_config() -> EthernetSettingsType

Retrieve IP settings from the spectrometer.

Use this function to read the Ethernet settings of the spectrometer, without having to read the complete device configuration structure.

Returns:

Type Description
EthernetSettingsType

The Ethernet settings of the spectrometer.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
def get_ip_config(self) -> EthernetSettingsType:
    """Retrieve IP settings from the spectrometer.

    Use this function to read the Ethernet settings of the spectrometer, without
    having to read the complete device configuration structure.

    Returns:
        The Ethernet settings of the spectrometer.
    """
    eth = EthernetSettingsType()
    self.sdk.AVS_GetIpConfig(self._handle, eth)
    return eth

get_lambda ¤

get_lambda() -> NDArray[double]

Returns the wavelength values corresponding to the pixels if available.

Returns:

Type Description
NDArray[double]

The wavelength value of each pixel.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1226
1227
1228
1229
1230
1231
1232
1233
1234
def get_lambda(self) -> NDArray[np.double]:
    """Returns the wavelength values corresponding to the pixels if available.

    Returns:
        The wavelength value of each pixel.
    """
    values = np.zeros(MAX_NR_PIXELS, dtype=np.double)
    self.sdk.AVS_GetLambda(self._handle, values.ctypes.data_as(POINTER(c_double)))
    return values[values > 0]

get_num_devices ¤

get_num_devices() -> int

Scans for attached devices and returns the number of devices detected.

Deprecated function, replaced by :meth:.update_usb_devices. The functionality is identical.

Returns:

Type Description
int

The number of devices found.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
def get_num_devices(self) -> int:
    """Scans for attached devices and returns the number of devices detected.

    Deprecated function, replaced by :meth:`.update_usb_devices`. The
    functionality is identical.

    Returns:
        The number of devices found.
    """
    num: int = self.sdk.AVS_GetNrOfDevices()
    return num

get_num_pixels ¤

get_num_pixels() -> int

Returns the number of pixels of a spectrometer.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1248
1249
1250
1251
1252
def get_num_pixels(self) -> int:
    """Returns the number of pixels of a spectrometer."""
    n = c_uint16()
    self.sdk.AVS_GetNumPixels(self._handle, n)
    return n.value

get_oem_parameter ¤

get_oem_parameter() -> OemDataType

Returns the OEM data structure available on the spectrometer.

Returns:

Type Description
OemDataType

The OEM parameters.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1254
1255
1256
1257
1258
1259
1260
1261
1262
def get_oem_parameter(self) -> OemDataType:
    """Returns the OEM data structure available on the spectrometer.

    Returns:
        The OEM parameters.
    """
    odt = OemDataType()
    self.sdk.AVS_GetOemParameter(self._handle, odt)
    return odt

get_parameter ¤

get_parameter() -> DeviceConfigType

Returns the device information of the spectrometer.

Returns:

Type Description
DeviceConfigType

The device parameters.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
def get_parameter(self) -> DeviceConfigType:
    """Returns the device information of the spectrometer.

    Returns:
        The device parameters.
    """
    dct = DeviceConfigType()
    required_size = c_uint32()
    self.sdk.AVS_GetParameter(self._handle, sizeof(dct), required_size, dct)
    return dct

get_saturated_pixels ¤

get_saturated_pixels() -> NDArray[uint8]

Returns, for each pixel, if a pixel was saturated (1) or not (0).

Returns:

Type Description
NDArray[uint8]

The saturation state of each pixel.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
def get_saturated_pixels(self) -> NDArray[np.uint8]:
    """Returns, for each pixel, if a pixel was saturated (1) or not (0).

    Returns:
        The saturation state of each pixel.
    """
    n = 9
    values = np.full(MAX_NR_PIXELS, n, dtype=np.uint8)
    self.sdk.AVS_GetSaturatedPixels(self._handle, values.ctypes.data_as(POINTER(c_ubyte)))
    return values[values < n]

get_status_by_serial ¤

get_status_by_serial(serial: str | None = None) -> int

Get the handle ID for the specified serial number.

Parameters:

Name Type Description Default
serial str | None

The serial number. Default is to get the status for this class instance.

None

Returns:

Type Description
int

The status.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
def get_status_by_serial(self, serial: str | None = None) -> int:
    """Get the handle ID for the specified serial number.

    Args:
        serial: The serial number. Default is to get the status for this class instance.

    Returns:
        The status.
    """
    serial = serial or self.equipment.serial
    status = c_int32()
    self.sdk.AVS_GetStatusBySerial(serial.encode(), status)
    return status.value

get_version_info ¤

get_version_info() -> tuple[str, str, str]

Returns software version information.

Returns:

Type Description
tuple[str, str, str]

FPGA software version, firmware version, DLL version.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
def get_version_info(self) -> tuple[str, str, str]:
    """Returns software version information.

    Returns:
        FPGA software version, firmware version, DLL version.
    """
    fpga = create_string_buffer(16)
    fm = create_string_buffer(16)
    dll = create_string_buffer(16)
    self.sdk.AVS_GetVersionInfo(self._handle, fpga, fm, dll)
    return fpga.value.decode(), fm.value.decode(), dll.value.decode()

heartbeat ¤

heartbeat(req_type: int) -> HeartbeatRespType

Monitor the (heartbeat) functions of the spectrometer.

This function applies only to the AS7010 platform. See the DLL manual for more details.

Parameters:

Name Type Description Default
req_type int

The heartbeat request values used to control heartbeat functions.

required

Returns:

Type Description
HeartbeatRespType

The heartbeat response structure received from the spectrometer.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
def heartbeat(self, req_type: int) -> HeartbeatRespType:
    """Monitor the (heartbeat) functions of the spectrometer.

    This function applies only to the AS7010 platform. See the DLL manual for more details.

    Args:
        req_type: The heartbeat request values used to control heartbeat functions.

    Returns:
        The heartbeat response structure received from the spectrometer.
    """
    resp = HeartbeatRespType()
    self.sdk.AVS_Heartbeat(self._handle, req_type, resp)
    return resp

init ¤

init(port_id: int) -> int

Initializes the communication interface with the spectrometers and the internal data structures.

For Ethernet devices this function will create a list of available Ethernet spectrometers within all the network interfaces of the host.

Parameters:

Name Type Description Default
port_id int

ID of port to be used. One of:

  • -1: Use both Ethernet (AS7010) and USB ports
  • 0: Use USB port
  • 1..255: Not supported in v9.7 of the SDK
  • 256: Use Ethernet port (AS7010)
required

Returns:

Type Description
int

On success, the number of connected or found devices.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
def init(self, port_id: int) -> int:
    """Initializes the communication interface with the spectrometers and the internal data structures.

    For Ethernet devices this function will create a list of available Ethernet spectrometers
    within all the network interfaces of the host.

    Args:
        port_id: ID of port to be used. One of:

            * `-1`: Use both Ethernet (AS7010) and USB ports
            * `0`: Use USB port
            * `1..255`: Not supported in v9.7 of the SDK
            * `256`: Use Ethernet port (AS7010)

    Returns:
        On success, the number of connected or found devices.
    """
    ret = int(self.sdk.AVS_Init(port_id))
    if ret == 0:
        raise MSLConnectionError(self, "No Avantes devices were found")
    return ret

measure ¤

measure(num_measurements: int, window_handle: int | None = None) -> None

Starts measurement on the spectrometer.

Parameters:

Name Type Description Default
num_measurements int

Number of measurements to acquire. Use -1 to measure continuously until stop_measure is called.

required
window_handle int | None

Window handle to notify application measurement result data is available. The DLL sends a message to the window with command: WM_MEAS_READY, with SUCCESS (0), the number of scans that were saved in RAM (if m_StoreToRAM parameter > 0, see ControlSettingsType), or INVALID_MEAS_DATA as WPARM value and a_hDevice as LPARM value. Set this value to None if a callback is not needed.

None
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
def measure(self, num_measurements: int, window_handle: int | None = None) -> None:
    """Starts measurement on the spectrometer.

    Args:
        num_measurements: Number of measurements to acquire. Use -1 to measure continuously until
            [stop_measure][msl.equipment_resources.avantes.avaspec.AvaSpec.stop_measure] is called.
        window_handle: Window handle to notify application measurement result data is available.
            The DLL sends a message to the window with command: `WM_MEAS_READY`, with `SUCCESS` (`0`),
            the number of scans that were saved in RAM (if `m_StoreToRAM` parameter > 0, see
            [ControlSettingsType][msl.equipment_resources.avantes.avaspec.ControlSettingsType]),
            or `INVALID_MEAS_DATA` as `WPARM` value and `a_hDevice` as `LPARM` value. Set this
            value to `None` if a callback is not needed.
    """
    self.sdk.AVS_Measure(self._handle, window_handle, num_measurements)

measure_callback ¤

measure_callback(
    num_measurements: int, callback: AvaSpecCallback | None = None
) -> None

Register a measurement-available callback function for the spectrometer.

Example

See avaspec_callback.py for an example usage.

Parameters:

Name Type Description Default
num_measurements int

Number of measurements to acquire. Use -1 to measure continuously until stop_measure is called.

required
callback AvaSpecCallback | None

A callback function to notify that application measurement result data is available. The DLL will call the given function to notify a measurement is ready and pass two parameters. The first parameter is a reference to the DLL handle. The second parameter is a reference to an integer value: SUCCESS (0) if a new scan is available, or the number of scans that were saved in RAM (if m_StoreToRAM parameter > 0, see ControlSettingsType), or INVALID_MEAS_DATA (-8). Set this value to None if a callback is not needed.

None
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
def measure_callback(self, num_measurements: int, callback: AvaSpecCallback | None = None) -> None:
    """Register a measurement-available callback function for the spectrometer.

    !!! example
        See [avaspec_callback.py](https://github.com/MSLNZ/msl-equipment/blob/main/packages/resources/examples/avantes/avaspec_callback.py)
        for an example usage.

    Args:
        num_measurements: Number of measurements to acquire. Use -1 to measure continuously until
            [stop_measure][msl.equipment_resources.avantes.avaspec.AvaSpec.stop_measure] is called.
        callback: A callback function to notify that application measurement result data is available.
            The DLL will call the given function to notify a measurement is ready and pass two parameters.
            The first parameter is a reference to the DLL handle. The second parameter is a reference to
            an integer value: `SUCCESS` (`0`) if a new scan is available, or the number of scans that were
            saved in RAM (if `m_StoreToRAM` parameter > 0, see
            [ControlSettingsType][msl.equipment_resources.avantes.avaspec.ControlSettingsType]),
            or `INVALID_MEAS_DATA` (`-8`). Set this value to `None` if a callback is not needed.
    """
    self.sdk.AVS_MeasureCallback(self._handle, callback, num_measurements)

poll_scan ¤

poll_scan() -> bool

Determines if new measurement results are available.

Returns:

Type Description
bool

Whether there is a scan available.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1384
1385
1386
1387
1388
1389
1390
def poll_scan(self) -> bool:
    """Determines if new measurement results are available.

    Returns:
        Whether there is a scan available.
    """
    return bool(self.sdk.AVS_PollScan(self._handle))

prepare_measure ¤

prepare_measure(config: MeasConfigType) -> None

Prepares measurement on the spectrometer using the specified measurement configuration.

Parameters:

Name Type Description Default
config MeasConfigType

The measurement configuration.

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1392
1393
1394
1395
1396
1397
1398
def prepare_measure(self, config: MeasConfigType) -> None:
    """Prepares measurement on the spectrometer using the specified measurement configuration.

    Args:
        config: The measurement configuration.
    """
    self.sdk.AVS_PrepareMeasure(self._handle, config)

register ¤

register(handle: int) -> None

Installs an application windows handle to which device attachment/removal messages have to be sent.

Parameters:

Name Type Description Default
handle int

Application window handle.

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1400
1401
1402
1403
1404
1405
1406
def register(self, handle: int) -> None:
    """Installs an application windows handle to which device attachment/removal messages have to be sent.

    Args:
        handle: Application window handle.
    """
    self.sdk.AVS_Register(handle)

reset_device ¤

reset_device() -> None

Performs a hard reset on the given spectrometer.

This function only works with the AS7010 platform.

During reset of the spectrometer, all spectrometer HW modules (microprocessor and USB controller) will be reset at once. The spectrometer will start its reset procedure right after sending the command response back to the host.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
def reset_device(self) -> None:
    """Performs a hard reset on the given spectrometer.

    This function only works with the AS7010 platform.

    During reset of the spectrometer, all spectrometer HW modules (microprocessor and USB controller)
    will be reset at once. The spectrometer will start its reset procedure right after sending the
    command response back to the host.
    """
    self.sdk.AVS_ResetDevice(self._handle)

set_analog_out ¤

set_analog_out(port_id: int, value: float) -> None

Sets the analog output value for the specified analog identifier.

Parameters:

Name Type Description Default
port_id int

Identifier for one of the two output signals:

  • AS5216:

    • 0: AO1 = pin 17 at 26-pin connector
    • 1: AO2 = pin 26 at 26-pin connector
  • Mini:

    • 0: AO1 = Pin 12 on Micro HDMI = Pin 10 on HDMI terminal
    • 1: AO2 = Pin 14 on Micro HDMI = Pin 12 on HDMI terminal
  • AS7010:

    • 0: AO1 = pin 17 at 26-pin connector
    • 1: AO2 = pin 26 at 26-pin connector
required
value float

DAC value to be set in Volts (internally an 8-bits DAC is used) with range 0 - 5V.

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
def set_analog_out(self, port_id: int, value: float) -> None:
    """Sets the analog output value for the specified analog identifier.

    Args:
        port_id: Identifier for one of the two output signals:

            * AS5216:

                * `0`: AO1 = pin 17 at 26-pin connector
                * `1`: AO2 = pin 26 at 26-pin connector

            * Mini:

                * `0`: AO1 = Pin 12 on Micro HDMI = Pin 10 on HDMI terminal
                * `1`: AO2 = Pin 14 on Micro HDMI = Pin 12 on HDMI terminal

            * AS7010:

                * `0`: AO1 = pin 17 at 26-pin connector
                * `1`: AO2 = pin 26 at 26-pin connector

        value: DAC value to be set in Volts (internally an 8-bits DAC is used) with range 0 - 5V.
    """
    self.sdk.AVS_SetAnalogOut(self._handle, port_id, value)

set_digital_out ¤

set_digital_out(port_id: int, value: int) -> None

Sets the digital output value for the specified digital identifier.

Parameters:

Name Type Description Default
port_id int

Identifier for one of the 10 output signals:

  • AS5216:

    • 0: DO1 = pin 11 at 26-pin connector
    • 1: DO2 = pin 2 at 26-pin connector
    • 2: DO3 = pin 20 at 26-pin connector
    • 3: DO4 = pin 12 at 26-pin connector
    • 4: DO5 = pin 3 at 26-pin connector
    • 5: DO6 = pin 21 at 26-pin connector
    • 6: DO7 = pin 13 at 26-pin connector
    • 7: DO8 = pin 4 at 26-pin connector
    • 8: DO9 = pin 22 at 26-pin connector
    • 9: DO10 = pin 25 at 26-pin connector
  • Mini:

    • 0: DO1 = Pin 7 on Micro HDMI = Pin 5 on HDMI terminal
    • 1: DO2 = Pin 5 on Micro HDMI = Pin 3 on HDMI Terminal
    • 2: DO3 = Pin 3 on Micro HDMI = Pin 1 on HDMI Terminal
    • 3: DO4 = Pin 1 on Micro HDMI = Pin 19 on HDMI Terminal
    • 4: DO5 = Pin 4 on Micro HDMI = Pin 2 on HDMI Terminal
    • 5: DO6 = Pin 2 on Micro HDMI = Pin 14 on HDMI Terminal
    • 6: Not used
    • 7: Not used
    • 8: Not used
    • 9: Not used
  • AS7010:

    • 0: DO1 =pin 11 at 26-pin connector
    • 1: DO2 = pin 2 at 26-pin connector
    • 2: DO3 = pin 20 at 26-pin connector
    • 3: DO4 = pin 12 at 26-pin connector
    • 4: DO5 = pin 3 at 26-pin connector
    • 5: DO6 = pin 21 at 26-pin connector
    • 6: DO7 = pin 13 at 26-pin connector
    • 7: DO8 = pin 4 at 26-pin connector
    • 8: DO9 = pin 22 at 26-pin connector
    • 9: DO10 = pin 25 at 26-pin connector
required
value int

The digital value to be set (0 or 1).

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
def set_digital_out(self, port_id: int, value: int) -> None:
    """Sets the digital output value for the specified digital identifier.

    Args:
        port_id: Identifier for one of the 10 output signals:

            * AS5216:

                * `0`: DO1 = pin 11 at 26-pin connector
                * `1`: DO2 = pin 2 at 26-pin connector
                * `2`: DO3 = pin 20 at 26-pin connector
                * `3`: DO4 = pin 12 at 26-pin connector
                * `4`: DO5 = pin 3 at 26-pin connector
                * `5`: DO6 = pin 21 at 26-pin connector
                * `6`: DO7 = pin 13 at 26-pin connector
                * `7`: DO8 = pin 4 at 26-pin connector
                * `8`: DO9 = pin 22 at 26-pin connector
                * `9`: DO10 = pin 25 at 26-pin connector

            * Mini:

                * `0`: DO1 = Pin 7 on Micro HDMI = Pin 5 on HDMI terminal
                * `1`: DO2 = Pin 5 on Micro HDMI = Pin 3 on HDMI Terminal
                * `2`: DO3 = Pin 3 on Micro HDMI = Pin 1 on HDMI Terminal
                * `3`: DO4 = Pin 1 on Micro HDMI = Pin 19 on HDMI Terminal
                * `4`: DO5 = Pin 4 on Micro HDMI = Pin 2 on HDMI Terminal
                * `5`: DO6 = Pin 2 on Micro HDMI = Pin 14 on HDMI Terminal
                * `6`: Not used
                * `7`: Not used
                * `8`: Not used
                * `9`: Not used

            * AS7010:

                * `0`: DO1 =pin 11 at 26-pin connector
                * `1`: DO2 = pin 2 at 26-pin connector
                * `2`: DO3 = pin 20 at 26-pin connector
                * `3`: DO4 = pin 12 at 26-pin connector
                * `4`: DO5 = pin 3 at 26-pin connector
                * `5`: DO6 = pin 21 at 26-pin connector
                * `6`: DO7 = pin 13 at 26-pin connector
                * `7`: DO8 = pin 4 at 26-pin connector
                * `8`: DO9 = pin 22 at 26-pin connector
                * `9`: DO10 = pin 25 at 26-pin connector

        value: The digital value to be set (0 or 1).
    """
    self.sdk.AVS_SetDigOut(self._handle, port_id, value)

set_oem_parameter ¤

set_oem_parameter(parameter: OemDataType) -> None

Sends the OEM data structure to the spectrometer.

Parameters:

Name Type Description Default
parameter OemDataType

The OEM data structure.

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1493
1494
1495
1496
1497
1498
1499
def set_oem_parameter(self, parameter: OemDataType) -> None:
    """Sends the OEM data structure to the spectrometer.

    Args:
        parameter: The OEM data structure.
    """
    self.sdk.AVS_SetOemParameter(self._handle, parameter)

set_parameter ¤

set_parameter(parameter: DeviceConfigType) -> None

Overwrites the device configuration.

Please note that OemDataType is part of the DeviceConfigType in EEPROM (see section 3.5 of DLL manual). Precautions must be taken to prevent OEM data overwrites when using this method together with set_oem_parameter.

Parameters:

Name Type Description Default
parameter DeviceConfigType

The device parameters.

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
def set_parameter(self, parameter: DeviceConfigType) -> None:
    """Overwrites the device configuration.

    Please note that [OemDataType][msl.equipment_resources.avantes.avaspec.OemDataType] is part
    of the [DeviceConfigType][msl.equipment_resources.avantes.avaspec.DeviceConfigType] in EEPROM
    (see section 3.5 of DLL manual). Precautions must be taken to prevent OEM data overwrites
    when using this method together with
    [set_oem_parameter][msl.equipment_resources.avantes.avaspec.AvaSpec.set_oem_parameter].

    Args:
        parameter: The device parameters.
    """
    self.sdk.AVS_SetParameter(self._handle, parameter)

set_prescan_mode ¤

set_prescan_mode(mode: bool) -> None

If a prescan is set, the first measurement result will be skipped.

This function is only useful for the AvaSpec-3648 because this detector can be operated in prescan mode, or clear-buffer mode (see DLL manual).

Parameters:

Name Type Description Default
mode bool

If True, the first measurement result will be skipped (prescan mode), else the detector will be cleared before each new scan (clear-buffer mode).

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
def set_prescan_mode(self, mode: bool) -> None:  # noqa: FBT001
    """If a prescan is set, the first measurement result will be skipped.

    This function is only useful for the AvaSpec-3648 because this detector
    can be operated in prescan mode, or clear-buffer mode (see DLL manual).

    Args:
        mode: If `True`, the first measurement result will be skipped (prescan mode),
            else the detector will be cleared before each new scan (clear-buffer mode).
    """
    self.sdk.AVS_SetPrescanMode(self._handle, mode)

set_pwm_out ¤

set_pwm_out(port_id: int, frequency: int, duty_cycle: int) -> None

Selects the PWM functionality for the specified digital output.

The PWM functionality is not supported on the Mini.

Parameters:

Name Type Description Default
port_id int

Identifier for one of the 6 PWM output signals:

  • 0: DO1 = pin 11 at 26-pin connector
  • 1: DO2 = pin 2 at 26-pin connector
  • 2: DO3 = pin 20 at 26-pin connector
  • 4: DO5 = pin 3 at 26-pin connector
  • 5: DO6 = pin 21 at 26-pin connector
  • 6: DO7 = pin 13 at 26-pin connector
required
frequency int

Desired PWM frequency (500 - 300000) [Hz]. For the AS5216, the frequency of outputs 0, 1 and 2 is the same (the last specified frequency is used) and also the frequency of outputs 4, 5 and 6 is the same. For the AS7010, you can define six different frequencies.

required
duty_cycle int

Percentage high time in one cycle (0 - 100). For the AS5216, channels 0, 1 and 2 have a synchronized rising edge, the same holds for channels 4, 5 and 6. For the AS7010, rising edges are unsynchronized.

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
def set_pwm_out(self, port_id: int, frequency: int, duty_cycle: int) -> None:
    """Selects the PWM functionality for the specified digital output.

    The PWM functionality is not supported on the Mini.

    Args:
        port_id: Identifier for one of the 6 PWM output signals:

            * `0`: DO1 = pin 11 at 26-pin connector
            * `1`: DO2 = pin 2 at 26-pin connector
            * `2`: DO3 = pin 20 at 26-pin connector
            * `4`: DO5 = pin 3 at 26-pin connector
            * `5`: DO6 = pin 21 at 26-pin connector
            * `6`: DO7 = pin 13 at 26-pin connector

        frequency: Desired PWM frequency (500 - 300000) [Hz]. For the AS5216, the frequency of
            outputs 0, 1 and 2 is the same (the last specified frequency is used) and
            also the frequency of outputs 4, 5 and 6 is the same. For the AS7010, you
            can define six different frequencies.
        duty_cycle: Percentage high time in one cycle (0 - 100). For the AS5216, channels 0,
            1 and 2 have a synchronized rising edge, the same holds for channels 4, 5
            and 6. For the AS7010, rising edges are unsynchronized.
    """
    self.sdk.AVS_SetPwmOut(self._handle, port_id, frequency, duty_cycle)

set_sensitivity_mode ¤

set_sensitivity_mode(mode: int) -> None

Set the sensitivity mode.

This method is supported by the following detector types: HAMS9201, HAMG9208_512, SU256LSB and SU512LDB with the appropriate firmware version.

Parameters:

Name Type Description Default
mode int

0 for low noise, >0 for high sensitivity

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
def set_sensitivity_mode(self, mode: int) -> None:
    """Set the sensitivity mode.

    This method is supported by the following detector types: HAMS9201,
    HAMG9208_512, SU256LSB and SU512LDB with the appropriate firmware version.

    Args:
        mode: 0 for low noise, >0 for high sensitivity
    """
    self.sdk.AVS_SetSensitivityMode(self._handle, mode)

set_sync_mode ¤

set_sync_mode(enable: bool) -> None

Disables/enables support for synchronous measurement.

Parameters:

Name Type Description Default
enable bool

False to disable sync mode, True to enable sync mode.

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1563
1564
1565
1566
1567
1568
1569
def set_sync_mode(self, enable: bool) -> None:  # noqa: FBT001
    """Disables/enables support for synchronous measurement.

    Args:
        enable: `False` to disable sync mode, `True` to enable sync mode.
    """
    self.sdk.AVS_SetSyncMode(self._handle, int(bool(enable)))

stop_measure ¤

stop_measure() -> None

Stops the measurement.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1571
1572
1573
def stop_measure(self) -> None:
    """Stops the measurement."""
    self.sdk.AVS_StopMeasure(self._handle)

suppress_stray_light ¤

suppress_stray_light(factor: float) -> tuple[NDArray[double], NDArray[double]]

Returns the stray light corrected pixel values of a dark corrected measurement.

Parameters:

Name Type Description Default
factor float

Multiplication factor for the stray light algorithm.

required

Returns:

Type Description
tuple[NDArray[double], NDArray[double]]

Scope minus dark array, stray light suppressed array.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
def suppress_stray_light(self, factor: float) -> tuple[NDArray[np.double], NDArray[np.double]]:
    """Returns the stray light corrected pixel values of a dark corrected measurement.

    Args:
        factor: Multiplication factor for the stray light algorithm.

    Returns:
        Scope minus dark array, stray light suppressed array.
    """
    x = -9e99
    src = np.full(MAX_NR_PIXELS, x, dtype=np.double)
    dest = np.full(MAX_NR_PIXELS, x, dtype=np.double)
    self.sdk.AVS_SuppressStrayLight(
        self._handle, factor, src.ctypes.data_as(POINTER(c_double)), dest.ctypes.data_as(POINTER(c_double))
    )
    return src[src > x], dest[dest > x]

update_eth_devices ¤

update_eth_devices(nmax: int = 16) -> list[BroadcastAnswerType]

Return the number of Ethernet devices that are connected to the computer.

Internally checks the list of connected Ethernet devices and returns the number of devices attached.

Parameters:

Name Type Description Default
nmax int

The maximum number of devices that can be found.

16

Returns:

Type Description
list[BroadcastAnswerType]

The information about the devices.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
def update_eth_devices(self, nmax: int = 16) -> list[BroadcastAnswerType]:
    """Return the number of Ethernet devices that are connected to the computer.

    Internally checks the list of connected Ethernet devices and returns the number of devices attached.

    Args:
        nmax: The maximum number of devices that can be found.

    Returns:
        The information about the devices.
    """
    size = nmax * sizeof(BroadcastAnswerType)
    required_size = c_uint32()
    types = (BroadcastAnswerType * nmax)()
    n = self.sdk.AVS_UpdateETHDevices(size, required_size, types)
    return [types[i] for i in range(n)]

update_usb_devices ¤

update_usb_devices() -> int

Return the number of USB devices that are connected to the computer.

Internally checks the list of connected USB devices and returns the number of devices attached.

Returns:

Type Description
int

The number of devices found.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1609
1610
1611
1612
1613
1614
1615
1616
1617
def update_usb_devices(self) -> int:
    """Return the number of USB devices that are connected to the computer.

    Internally checks the list of connected USB devices and returns the number of devices attached.

    Returns:
        The number of devices found.
    """
    return int(self.sdk.AVS_UpdateUSBDevices())

use_high_res_adc ¤

use_high_res_adc(enable: bool) -> None

Enable the 16-bit AD converter.

When using the 16 bit ADC in full High Resolution mode (0..65535), please note that the irradiance intensity calibration, as well as the nonlinearity calibration are based on the 14bit ADC range. Therefore, if using the nonlinearity correction or irradiance calibration in your own software using the High Resolution mode, you need to apply the additional correction with ADCFactor (= 4.0), as explained in detail in section 4.6.1 and 4.6.3 of the manual.

Parameters:

Name Type Description Default
enable bool

If True use a 16-bit AD converter, otherwise use a 14-bit ADC.

required
Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
def use_high_res_adc(self, enable: bool) -> None:  # noqa: FBT001
    """Enable the 16-bit AD converter.

    When using the 16 bit ADC in full High Resolution mode (0..65535), please note that the
    irradiance intensity calibration, as well as the nonlinearity calibration are based on the 14bit
    ADC range. Therefore, if using the nonlinearity correction or irradiance calibration in your
    own software using the High Resolution mode, you need to apply the additional correction
    with ADCFactor (= 4.0), as explained in detail in section 4.6.1 and 4.6.3 of the manual.

    Args:
        enable: If `True` use a 16-bit AD converter, otherwise use a 14-bit ADC.
    """
    self.sdk.AVS_UseHighResAdc(self._handle, bool(enable))

Enums and Structs¤

Wrapper around the avaspec SDK from Avantes.

MeasureCallback module-attribute ¤

MeasureCallback: type[_CFunctionType] = func_type(
    None, POINTER(c_int32), POINTER(c_int32)
)

CFUNCTYPE function prototype to use when a measurement scan is available.

AvsIdentityType (Structure) ¤

IdentityType Structure.

Attributes:

Name Type Description
SerialNumber c_char * 10

Serial number of device.

UserFriendlyName c_char * 64

User-friendly name.

Status c_ubyte

Device status.

BroadcastAnswerType (Structure) ¤

BroadcastAnswerType Structure.

Attributes:

Name Type Description
InterfaceType c_ubyte

InterfaceType

serial c_ubyte * 10

serial

port c_uint16

port

status c_ubyte

status

RemoteHostIp c_uint32

RemoteHostIp

LocalIp c_uint32

LocalIp

reserved c_ubyte * 4

reserved

ControlSettingsType (Structure) ¤

ControlSettingsType Structure.

Attributes:

Name Type Description
m_StrobeControl c_uint16

m_StrobeControl

m_LaserDelay c_uint32

m_LaserDelay

m_LaserWidth c_uint32

m_LaserWidth

m_LaserWaveLength c_float

m_LaserWaveLength

m_StoreToRam c_uint16

m_StoreToRam

DarkCorrectionType (Structure) ¤

DarkCorrectionType Structure.

Attributes:

Name Type Description
m_Enable c_ubyte

m_Enable

m_ForgetPercentage c_ubyte

m_ForgetPercentage

DetectorType (Structure) ¤

DetectorType Structure.

Attributes:

Name Type Description
m_SensorType c_ubyte

m_SensorType

m_NrPixels c_uint16

m_NrPixels

m_aFit c_float * 5

m_aFit

m_NLEnable c_bool

m_NLEnable

m_aNLCorrect c_double * 8

m_aNLCorrect

m_aLowNLCounts c_double

m_aLowNLCounts

m_aHighNLCounts c_double

m_aHighNLCounts

m_Gain c_float * 2

m_Gain

m_Reserved c_float

m_Reserved

m_Offset c_float * 2

m_Offset

m_ExtOffset c_float

m_ExtOffset

m_DefectivePixels c_uint16 * 30

m_DefectivePixels

DeviceConfigType (Structure) ¤

DeviceConfigType Structure.

Attributes:

Name Type Description
m_Len c_uint16

m_Len

m_ConfigVersion c_uint16

m_ConfigVersion

m_aUserFriendlyId c_char * 64

m_aUserFriendlyId

m_Detector DetectorType

m_Detector

m_Irradiance IrradianceType

m_Irradiance

m_Reflectance SpectrumCalibrationType

m_Reflectance

m_SpectrumCorrect SpectrumCorrectionType

m_SpectrumCorrect

m_StandAlone StandAloneType

m_StandAlone

m_DynamicStorage DynamicStorageType

m_DynamicStorage

m_aTemperature TempSensorType * 3

m_aTemperature

m_TecControl TecControlType

m_TecControl

m_ProcessControl ProcessControlType

m_ProcessControl

m_EthernetSettings EthernetSettingsType

m_EthernetSettings

m_aReserved c_ubyte * 9720

m_aReserved

m_OemData OemDataType

m_OemData

DeviceStatus (IntEnum) ¤

DeviceStatus enum.

Attributes:

Name Type Description
UNKNOWN int

0

USB_AVAILABLE int

1

USB_IN_USE_BY_APPLICATION int

2

USB_IN_USE_BY_OTHER int

3

ETH_AVAILABLE int

4

ETH_IN_USE_BY_APPLICATION int

5

ETH_IN_USE_BY_OTHER int

6

ETH_ALREADY_IN_USE_USB int

7

DynamicStorageType (Structure) ¤

DynamicStorageType Structure.

Attributes:

Name Type Description
m_Nmsr c_int32

m_Nmsr

m_Reserved c_ubyte * 8

m_Reserved

EthernetSettingsType (Structure) ¤

EthernetSettingsType Structure.

Attributes:

Name Type Description
m_IpAddr(c_uint32)

m_IpAddr

m_NetMask c_uint32

m_NetMask

m_Gateway c_uint32

m_Gateway

m_DhcpEnabled c_ubyte

m_DhcpEnabled

m_TcpPort c_uint16

m_TcpPort

m_LinkStatus c_ubyte

m_LinkStatus

HeartbeatRespType (Structure) ¤

HeartbeatRespType Structure.

Attributes:

Name Type Description
m_BitMatrix c_uint32

m_BitMatrix

m_Reserved c_uint32

m_Reserved

InterfaceType (IntEnum) ¤

InterfaceType enum.

Attributes:

Name Type Description
RS232 int

0

USB5216 int

1

USBMINI int

2

USB7010 int

3

ETH7010 int

4

IrradianceType (Structure) ¤

IrradianceType Structure.

Attributes:

Name Type Description
m_IntensityCalib SpectrumCalibrationType

m_IntensityCalib

m_CalibrationType c_ubyte

m_CalibrationType

m_FiberDiameter c_uint32

m_FiberDiameter

MeasConfigType (Structure) ¤

MeasConfigType Structure.

Attributes:

Name Type Description
m_StartPixel c_uint16

m_StartPixel

m_StopPixel c_uint16

m_StopPixel

m_IntegrationTime c_float

m_IntegrationTime

m_IntegrationDelay c_uint32

m_IntegrationDelay

m_NrAverages c_uint32

m_NrAverages

m_CorDynDark DarkCorrectionType

m_CorDynDark

m_Smoothing SmoothingType

m_Smoothing

m_SaturationDetection c_ubyte

m_SaturationDetection

m_Trigger TriggerType

m_Trigger

m_Control ControlSettingsType

m_Control

OemDataType (Structure) ¤

OemDataType Structure.

Attributes:

Name Type Description
m_data c_ubyte * 4096

m_data

ProcessControlType (Structure) ¤

ProcessControlType Structure.

Attributes:

Name Type Description
m_AnalogLow c_float * 2

m_AnalogLow

m_AnalogHigh c_float * 2

m_AnalogHigh

m_DigitalLow c_float * 10

m_DigitalLow

m_DigitalHigh c_float * 10

m_DigitalHigh

SensType (IntEnum) ¤

SensType enum.

Attributes:

Name Type Description
SENS_HAMS8378_256 int

1

SENS_HAMS8378_1024 int

2

SENS_ILX554 int

3

SENS_HAMS9201 int

4

SENS_TCD1304 int

5

SENS_TSL1301 int

6

SENS_TSL1401 int

7

SENS_HAMS8378_512 int

8

SENS_HAMS9840 int

9

SENS_ILX511 int

10

SENS_HAMS10420_2048X64 int

11

SENS_HAMS11071_2048X64 int

12

SENS_HAMS7031_1024X122 int

13

SENS_HAMS7031_1024X58 int

14

SENS_HAMS11071_2048X16 int

15

SENS_HAMS11155_2048 int

16

SENS_SU256LSB int

17

SENS_SU512LDB int

18

SENS_HAMS11638 int

21

SENS_HAMS11639 int

22

SENS_HAMS12443 int

23

SENS_HAMG9208_512 int

24

SENS_HAMG13913 int

25

SENS_HAMS13496 int

26

SmoothingType (Structure) ¤

SmoothingType Structure.

Attributes:

Name Type Description
m_SmoothPix c_uint16

m_SmoothPix

m_SmoothModel c_ubyte

m_SmoothModel

SpectrumCalibrationType (Structure) ¤

SpectrumCalibrationType Structure.

Attributes:

Name Type Description
m_Smoothing SmoothingType

m_Smoothing

m_CalInttime c_float

m_CalInttime

m_aCalibConvers c_float * 4096

m_aCalibConvers

SpectrumCorrectionType (Structure) ¤

SpectrumCorrectionType Structure.

Attributes:

Name Type Description
m_aSpectrumCorrect c_float * 4096

m_aSpectrumCorrect

StandAloneType (Structure) ¤

StandAloneType Structure.

Attributes:

Name Type Description
m_Enable c_bool

m_Enable

m_Meas MeasConfigType

m_Meas

m_Nmsr c_int16

m_Nmsr

TecControlType (Structure) ¤

TecControlType Structure.

Attributes:

Name Type Description
m_Enable c_bool

m_Enable

m_Setpoint c_float

m_Setpoint

m_aFit c_float * 2

m_aFit

TempSensorType (Structure) ¤

TempSensorType Structure.

Attributes:

Name Type Description
m_aFit c_float * 5

m_aFit

TimeStampType (Structure) ¤

TimeStampType Structure.

Attributes:

Name Type Description
m_Date c_uint16

m_Date

m_Time c_uint16

m_Time

TriggerType (Structure) ¤

TriggerType Structure.

Attributes:

Name Type Description
m_Mode c_ubyte

m_Mode

m_Source c_ubyte

m_Source

m_SourceType c_ubyte

m_SourceType

avaspec_callback ¤

avaspec_callback(f: AvaSpecCallback) -> _CFunctionType

Use as a decorator for a callback function when a measurement scan is available.

See avaspec_callback.py for an example usage.

Source code in packages/resources/src/msl/equipment_resources/avantes/avaspec.py
62
63
64
65
66
67
68
def avaspec_callback(f: AvaSpecCallback) -> _CFunctionType:
    """Use as a decorator for a callback function when a measurement scan is available.

    See [avaspec_callback.py](https://github.com/MSLNZ/msl-equipment/blob/main/packages/resources/examples/avantes/avaspec_callback.py)
    for an example usage.
    """
    return MeasureCallback(f)