msl.equipment.resources.nkt.nktpdll module

Wrapper around the NKTPDLL.dll SDK from NKT Photonics.

The wrapper was written using v2.1.2.766 of the SDK.

msl.equipment.resources.nkt.nktpdll.PortStatusCallback

Use as a decorator for a callback function when a port status changes.

msl.equipment.resources.nkt.nktpdll.DeviceStatusCallback

Use as a decorator for a callback function when a device status changes.

msl.equipment.resources.nkt.nktpdll.RegisterStatusCallback

Use as a decorator for a callback function when a register status changes.

class msl.equipment.resources.nkt.nktpdll.DateTimeType[source]

Bases: Structure

The DateTimeType struct (24 hour format).

Day

Structure/Union member

Hour

Structure/Union member

Min

Structure/Union member

Month

Structure/Union member

Sec

Structure/Union member

Year

Structure/Union member

class msl.equipment.resources.nkt.nktpdll.ParameterSetType[source]

Bases: Structure

The ParameterSet struct.

This is how calculation on parameter sets is done internally by modules:

DAC_value = (value * (X/Y)) + Offset

where, value is either ParameterSetType::StartVal or ParameterSetType::FactoryVal

value = (ADC_value * (X/Y)) + Offset

where, value often is available via another measurement register.

Denominator

Structure/Union member

ErrorHandler

Structure/Union member

FactoryVal

Structure/Union member

LLimit

Structure/Union member

Numerator

Structure/Union member

Offset

Structure/Union member

StartVal

Structure/Union member

ULimit

Structure/Union member

Unit

Structure/Union member

class msl.equipment.resources.nkt.nktpdll.DeviceModeTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

The DeviceModeTypes enum.

DevModeDisabled = 0
DevModeAnalyzeInit = 1
DevModeAnalyze = 2
DevModeNormal = 3
DevModeLogDownload = 4
DevModeError = 5
DevModeTimeout = 6
DevModeUpload = 7
class msl.equipment.resources.nkt.nktpdll.DeviceStatusTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

The DeviceStatusTypes enum.

DeviceModeChanged = 0
DeviceLiveChanged = 1
DeviceTypeChanged = 2
DevicePartNumberChanged = 3
DevicePCBVersionChanged = 4
DeviceStatusBitsChanged = 5
DeviceErrorCodeChanged = 6
DeviceBlVerChanged = 7
DeviceFwVerChanged = 8
DeviceModuleSerialChanged = 9
DevicePCBSerialChanged = 10
DeviceSysTypeChanged = 11
class msl.equipment.resources.nkt.nktpdll.ParamSetUnitTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

The ParamSetUnitTypes enum

UnitNone = 0
UnitmV = 1
UnitV = 2
UnituA = 3
UnitmA = 4
UnitA = 5
UnituW = 6
UnitcmW = 7
UnitdmW = 8
UnitmW = 9
UnitW = 10
UnitmC = 11
UnitcC = 12
UnitdC = 13
Unitpm = 14
Unitdnm = 15
Unitnm = 16
UnitPerCent = 17
UnitPerMille = 18
UnitcmA = 19
UnitdmA = 20
UnitRPM = 21
UnitdBm = 22
UnitcBm = 23
UnitmBm = 24
UnitdB = 25
UnitcB = 26
UnitmB = 27
Unitdpm = 28
UnitcV = 29
UnitdV = 30
Unitlm = 31
Unitdlm = 32
Unitclm = 33
Unitmlm = 34
class msl.equipment.resources.nkt.nktpdll.RegisterPriorityTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

The RegisterPriorityTypes enum.

RegPriority_Low = 0
RegPriority_High = 1
class msl.equipment.resources.nkt.nktpdll.RegisterDataTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

The RegisterDataTypes enum.

RegData_Unknown = 0
RegData_Mixed = 1
RegData_U8 = 2
RegData_S8 = 3
RegData_U16 = 4
RegData_S16 = 5
RegData_U32 = 6
RegData_S32 = 7
RegData_F32 = 8
RegData_U64 = 9
RegData_S64 = 10
RegData_F64 = 11
RegData_Ascii = 12
RegData_Paramset = 13
RegData_B8 = 14
RegData_H8 = 15
RegData_B16 = 16
RegData_H16 = 17
RegData_B32 = 18
RegData_H32 = 19
RegData_B64 = 20
RegData_H64 = 21
RegData_DateTime = 22
class msl.equipment.resources.nkt.nktpdll.RegisterStatusTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

The RegisterStatusTypes enum.

RegSuccess = 0
RegBusy = 1
RegNacked = 2
RegCRCErr = 3
RegTimeout = 4
RegComError = 5
class msl.equipment.resources.nkt.nktpdll.PortStatusTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: IntEnum

The PortStatusTypes enum

PortStatusUnknown = 0
PortOpening = 1
PortOpened = 2
PortOpenFail = 3
PortScanStarted = 4
PortScanProgress = 5
PortScanDeviceFound = 6
PortScanEnded = 7
PortClosing = 8
PortClosed = 9
PortReady = 10
class msl.equipment.resources.nkt.nktpdll.NKT(record)[source]

Bases: Connection

Wrapper around the NKTPDLL.dll SDK from NKT Photonics.

The properties for a NKT connection supports the following key-value pairs in the Connections Database:

'sdk_path': str, The path to the SDK [default: 'NKTPDLL.dll']
'open_port': bool, Whether to automatically open the port [default: True]
'auto': bool, Whether to open the port with bus scanning [default: True]
'live': bool, Whether to open the port in live mode [default: True]

Do not instantiate this class directly. Use the connect() method to connect to the equipment.

Parameters:

record (EquipmentRecord) – A record from an Equipment-Register Database.

RegisterStatusCallback

alias of CFunctionType

PortStatusCallback

alias of CFunctionType

DeviceStatusCallback

alias of CFunctionType

class DeviceModeTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

The DeviceModeTypes enum.

DevModeDisabled = 0
DevModeAnalyzeInit = 1
DevModeAnalyze = 2
DevModeNormal = 3
DevModeLogDownload = 4
DevModeError = 5
DevModeTimeout = 6
DevModeUpload = 7
class DeviceStatusTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

The DeviceStatusTypes enum.

DeviceModeChanged = 0
DeviceLiveChanged = 1
DeviceTypeChanged = 2
DevicePartNumberChanged = 3
DevicePCBVersionChanged = 4
DeviceStatusBitsChanged = 5
DeviceErrorCodeChanged = 6
DeviceBlVerChanged = 7
DeviceFwVerChanged = 8
DeviceModuleSerialChanged = 9
DevicePCBSerialChanged = 10
DeviceSysTypeChanged = 11
class ParamSetUnitTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

The ParamSetUnitTypes enum

UnitNone = 0
UnitmV = 1
UnitV = 2
UnituA = 3
UnitmA = 4
UnitA = 5
UnituW = 6
UnitcmW = 7
UnitdmW = 8
UnitmW = 9
UnitW = 10
UnitmC = 11
UnitcC = 12
UnitdC = 13
Unitpm = 14
Unitdnm = 15
Unitnm = 16
UnitPerCent = 17
UnitPerMille = 18
UnitcmA = 19
UnitdmA = 20
UnitRPM = 21
UnitdBm = 22
UnitcBm = 23
UnitmBm = 24
UnitdB = 25
UnitcB = 26
UnitmB = 27
Unitdpm = 28
UnitcV = 29
UnitdV = 30
Unitlm = 31
Unitdlm = 32
Unitclm = 33
Unitmlm = 34
class RegisterPriorityTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

The RegisterPriorityTypes enum.

RegPriority_Low = 0
RegPriority_High = 1
class RegisterDataTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

The RegisterDataTypes enum.

RegData_Unknown = 0
RegData_Mixed = 1
RegData_U8 = 2
RegData_S8 = 3
RegData_U16 = 4
RegData_S16 = 5
RegData_U32 = 6
RegData_S32 = 7
RegData_F32 = 8
RegData_U64 = 9
RegData_S64 = 10
RegData_F64 = 11
RegData_Ascii = 12
RegData_Paramset = 13
RegData_B8 = 14
RegData_H8 = 15
RegData_B16 = 16
RegData_H16 = 17
RegData_B32 = 18
RegData_H32 = 19
RegData_B64 = 20
RegData_H64 = 21
RegData_DateTime = 22
class RegisterStatusTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

The RegisterStatusTypes enum.

RegSuccess = 0
RegBusy = 1
RegNacked = 2
RegCRCErr = 3
RegTimeout = 4
RegComError = 5
class PortStatusTypes(value, names=None, *values, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: IntEnum

The PortStatusTypes enum

PortStatusUnknown = 0
PortOpening = 1
PortOpened = 2
PortOpenFail = 3
PortScanStarted = 4
PortScanProgress = 5
PortScanDeviceFound = 6
PortScanEnded = 7
PortClosing = 8
PortClosed = 9
PortReady = 10
static close_ports(names=None)[source]

Close the specified port name(s).

Parameters:

names (str, list of str, optional) – If None then close all opened ports. If a str then the name of a port. Otherwise a list of names. Port names are case sensitive.

Raises:

NKTError – If there was an error calling this method.

static load_sdk(path=None)[source]

Load the SDK.

Parameters:

path (str, optional) – The path to NKTPDLL.dll. If not specified then searches for the library.

static device_get_all_types(opened_ports=None, size=255)[source]

Returns all device types (module types) from the internal device list.

Parameters:
  • opened_ports (str or list of str, optional) – A port or a list of opened ports. If not specified then the get_open_ports() method will be called and the types for each port will be returned.

  • size (int, optional) – The maximum number of bytes that the device list can be.

Returns:

dict – The port names are the keys and each value is dict with the module type as the keys and its corresponding device ID as the value.

Raises:

NKTError – If there was an error calling this method.

device_create(device_id, wait_ready)[source]

Creates a device in the internal device list.

If the open_ports() function has been called with live = 1 then the kernel immediately starts to monitor the device.

Parameters:
  • device_id (int) – The device id (module address).

  • wait_ready (bool) – False - Don’t wait for the device to be ready. True - Wait up to 2 seconds for the device to complete its analyze cycle. (All standard registers being successfully read)

Raises:

NKTError – If there was an error calling this method.

device_exists(device_id)[source]

Checks if a specific device already exists in the internal device list.

Parameters:

device_id (int) – The device id (module address).

Returns:

bool – Whether the device exists.

Raises:

NKTError – If there was an error calling this method.

device_get_boot_loader_version(device_id)[source]

Returns the boot-loader version (int) for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

int – The boot-loader version.

Raises:

NKTError – If there was an error calling this method.

device_get_boot_loader_version_str(device_id)[source]

Returns the boot-loader version (string) for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

str – The boot-loader version.

Raises:

NKTError – If there was an error calling this method.

device_get_error_code(device_id)[source]

Returns the error code for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

int – The error code.

Raises:

NKTError – If there was an error calling this method.

device_get_firmware_version(device_id)[source]

Returns the firmware version (int) for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

int – The firmware version.

Raises:

NKTError – If there was an error calling this method.

device_get_firmware_version_str(device_id)[source]

Returns the firmware version (string) for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

str – The firmware version.

Raises:

NKTError – If there was an error calling this method.

device_get_live(device_id)[source]

Returns the internal device live status for a specific device id.

Requires the port being already opened with the open_ports() function and the device being already created, either automatically or with the device_create() function.

Parameters:

device_id (int) – The device id (module address).

Returns:

bool – Whether live mode is enabled.

Raises:

NKTError – If there was an error calling this method.

device_get_mode(device_id)[source]

Returns the internal device mode for a specific device id.

Requires the port being already opened with the open_ports() function and the device being already created, either automatically or with the device_create() function.

Parameters:

device_id (int) – The device id (module address).

Returns:

DeviceModeTypes – The device mode type.

Raises:

NKTError – If there was an error calling this method.

device_get_module_serial_number_str(device_id)[source]

Returns the module serial number (string) for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

str – The serial number.

Raises:

NKTError – If there was an error calling this method.

device_get_part_number_str(device_id)[source]

Returns the part number for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

str – The part number.

Raises:

NKTError – If there was an error calling this method.

device_get_pcb_serial_number_str(device_id)[source]

Returns the PCB serial number (string) for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

str – The part number.

Raises:

NKTError – If there was an error calling this method.

device_get_pcb_version(device_id)[source]

Returns the PCB version for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

int – The PCB version number.

Raises:

NKTError – If there was an error calling this method.

device_get_status_bits(device_id)[source]

Returns the status bits for a given device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

int – The status bits.

Raises:

NKTError – If there was an error calling this method.

device_get_type(device_id)[source]

Returns the module type for a specific device id.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:

device_id (int) – The device id (module address).

Returns:

int – The module type.

Raises:

NKTError – If there was an error calling this method.

device_remove(device_id)[source]

Remove a specific device from the internal device list.

Parameters:

device_id (int) – The device id (module address).

Raises:

NKTError – If there was an error calling this method.

device_remove_all()[source]

Remove all devices from the internal device list.

No confirmation is given, the list is simply cleared.

Raises:

NKTError – If there was an error calling this method.

device_set_live(device_id, live_mode)[source]

Sets the internal device live status for a specific device id (module address).

Parameters:
  • device_id (int) – The device id (module address).

  • live_mode (bool) – Set to True to enable.

Raises:

NKTError – If there was an error calling this method.

disconnect()[source]

Disconnect from the port.

Raises:

NKTError – If there was an error calling this method.

static get_all_ports(size=255)[source]

Returns a list of all ports.

Parameters:

size (int, optional) – The maximum size of the string buffer to fetch the results.

Returns:

list of str – A list of port names.

get_modules(size=255)[source]

Returns all device types (module types) from the device.

Parameters:

size (int, optional) – The maximum number of bytes that the device list can be.

Returns:

dict – The module type as the keys and its corresponding device ID as the value.

Raises:

NKTError – If there was an error calling this method.

static get_legacy_bus_scanning()[source]

Get the bus-scanning mode.

Returns:

boolTrue if in legacy mode otherwise in normal mode.

static get_open_ports(size=255)[source]

Returns a list of already-opened ports.

Parameters:

size (int, optional) – The maximum size of the string buffer to fetch the results.

Returns:

list of str – A list of port names that are already open.

get_port_error_msg()[source]

Retrieve error message for the port.

Returns:

str – The error message. An empty string indicates no error.

Raises:

NKTError – If there was an error calling this method.

get_port_status()[source]

Get the status of the port.

Returns:

PortStatusTypes – The port status.

Raises:

NKTError – If there was an error calling this method.

static open_ports(names=None, auto=True, live=True)[source]

Open the specified port(s).

Repeated calls to this function is allowed to reopen and/or rescan for devices.

Parameters:
  • names (str, list of str, optional) – If None then open all available ports. If a str then the name of a port. Otherwise a list of names. Port names are case sensitive. Example port names are 'AcoustikPort1', 'COM6'.

  • auto (bool, optional) – If True then automatically start bus scanning and add the found devices in the internal device list. If False then bus scanning and device creation is not automatically handled. The port is automatically closed if no devices are found.

  • live (bool, optional) – If True then keep all the found or created devices in live mode, which means the Interbus kernel keeps monitoring all the found devices and their registers. Please note that this will keep the modules watchdog alive as long as the port is open. If False then disable continuous monitoring of the registers. No callback is possible on register changes. Use the register_read(), register_write() and register_write_read() methods.

Raises:

NKTError – If there was an error calling this method.

point_to_point_port_add(host_address, host_port, client_address, client_port, protocol, ms_timeout=100)[source]

Creates or modifies a point to point port.

Parameters:
  • host_address (str) – The local ip address, e.g., '192.168.1.67'.

  • host_port (int) – The local port number.

  • client_address (str) – The remote ip address, e.g., '192.168.1.100'.

  • client_port (int) – The remote port number.

  • protocol (int) – Either 0 (TCP) or 1 (UDP).

  • ms_timeout (int, optional) – Telegram timeout value in milliseconds.

Raises:

NKTError – If there was an error calling this method.

point_to_point_port_del()[source]

Delete the point-to-point port.

Raises:

NKTError – If there was an error calling this method.

point_to_point_port_get()[source]

Retrieve the information about the point-to-point port setting.

Returns:

dict – The information about the point-to-point port setting.

Raises:

NKTError – If there was an error calling this method.

register_read(device_id, reg_id, index=-1)[source]

Reads a register value and returns the result.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

bytes – The register value.

Raises:

NKTError – If there was an error calling this method.

register_create(device_id, reg_id, priority, data_type)[source]

Creates a register in the internal register list.

If the open_ports() function has been called with the live = 1 then the kernel immediately starts to monitor the register.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • priority (int) – The RegisterPriorityTypes (monitoring priority).

  • data_type (int) – The RegisterDataTypes, not used internally but could be used in a common callback function to determine data type.

Raises:

NKTError – If there was an error calling this method.

register_exists(device_id, reg_id)[source]

Checks if a specific register already exists in the internal register list.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

Returns:

bool – Whether the register exists.

Raises:

NKTError – If there was an error calling this method.

register_get_all(device_id)[source]

Returns the register ids (register addresses) from the internal register list.

Parameters:

device_id (int) – The device id (module address).

Returns:

list of int – The register ids.

Raises:

NKTError – If there was an error calling this method.

register_read_ascii(device_id, reg_id, index=-1)[source]

Reads an ascii string from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

str – The ascii value.

Raises:

NKTError – If there was an error calling this method.

register_read_f32(device_id, reg_id, index=-1)[source]

Reads 32-bit float value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

float – The 32-bit float value.

Raises:

NKTError – If there was an error calling this method.

register_read_f64(device_id, reg_id, index=-1)[source]

Reads 64-bit double value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

float – The 64-bit double value.

Raises:

NKTError – If there was an error calling this method.

register_read_s16(device_id, reg_id, index=-1)[source]

Reads 16-bit signed short value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

int – The 16-bit signed short value.

Raises:

NKTError – If there was an error calling this method.

register_read_s32(device_id, reg_id, index=-1)[source]

Reads 32-bit signed long value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

int – The 32-bit signed long value.

Raises:

NKTError – If there was an error calling this method.

register_read_s64(device_id, reg_id, index=-1)[source]

Reads 64-bit signed long long value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

int – The 64-bit signed long long value.

Raises:

NKTError – If there was an error calling this method.

register_read_s8(device_id, reg_id, index=-1)[source]

Reads 8-bit signed char value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

int – The 8-bit signed char value.

Raises:

NKTError – If there was an error calling this method.

register_read_u16(device_id, reg_id, index=-1)[source]

Reads 16-bit unsigned short value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

int – The 16-bit unsigned short value.

Raises:

NKTError – If there was an error calling this method.

register_read_u32(device_id, reg_id, index=-1)[source]

Reads 32-bit unsigned long value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

int – The 32-bit unsigned long value.

Raises:

NKTError – If there was an error calling this method.

register_read_u64(device_id, reg_id, index=-1)[source]

Reads 64-bit unsigned long long value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

int – The 64-bit unsigned long long value.

Raises:

NKTError – If there was an error calling this method.

register_read_u8(device_id, reg_id, index=-1)[source]

Reads 8-bit unsigned char value from the register.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • index (int, optional) – Value index. Typically -1, but could be used to extract data from a specific position in the register. Index is byte counted.

Returns:

int – The 8-bit unsigned char value.

Raises:

NKTError – If there was an error calling this method.

register_remove(device_id, reg_id)[source]

Remove a specific register from the internal register list.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

Raises:

NKTError – If there was an error calling this method.

register_remove_all(device_id)[source]

Remove all registers from the internal register list.

No confirmation given, the list is simply cleared.

Parameters:

device_id (int) – The device id (module address).

Raises:

NKTError – If there was an error calling this method.

register_write(device_id, reg_id, data, index=-1)[source]

Writes a register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • data (bytes) – The data to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_ascii(device_id, reg_id, string, write_eol, index=-1)[source]

Writes a string to the register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • string (str) – The string to write to the register.

  • write_eol (bool) – Whether to append the End Of Line character (a null character) to the string.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a mixed-type register.

Raises:

NKTError – If there was an error calling this method.

register_write_f32(device_id, reg_id, value, index=-1)[source]

Writes a 32-bit float register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (float) – The 32-bit float to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_f64(device_id, reg_id, value, index=-1)[source]

Writes a 64-bit double register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (float) – The 64-bit double to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_read(device_id, reg_id, data, index=-1)[source]

Writes then reads a register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • data (bytes) – The data to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

bytes – The data that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_ascii(device_id, reg_id, string, write_eol, index=-1)[source]

Writes then reads a string register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • string (str) – The string to write to the register.

  • write_eol (bool) – Whether to append the End Of Line character (a null character) to the string.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

str – The string that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_f32(device_id, reg_id, value, index=-1)[source]

Writes then reads a 32-bit float register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (float) – The 32-bit float value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

float – The 32-bit float value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_f64(device_id, reg_id, value, index=-1)[source]

Writes then reads a 64-bit double register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (float) – The 64-bit double value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

float – The 64-bit double value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_s16(device_id, reg_id, value, index=-1)[source]

Writes then reads a 16-bit signed short register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 16-bit signed short value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

int – The 16-bit signed short value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_s32(device_id, reg_id, value, index=-1)[source]

Writes then reads a 32-bit signed long register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 32-bit signed long value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

int – The 32-bit signed long value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_s64(device_id, reg_id, value, index=-1)[source]

Writes then reads a 64-bit signed long long register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 64-bit signed long long value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

int – The 64-bit signed long long value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_s8(device_id, reg_id, value, index=-1)[source]

Writes then reads a 8-bit signed char register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 8-bit signed char value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

int – The 8-bit signed char value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_u16(device_id, reg_id, value, index=-1)[source]

Writes then reads a 16-bit unsigned short register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 16-bit unsigned short value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

int – The 16-bit unsigned short value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_u32(device_id, reg_id, value, index=-1)[source]

Writes then reads a 32-bit unsigned long register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 32-bit unsigned long value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

int – The 32-bit unsigned long value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_u64(device_id, reg_id, value, index=-1)[source]

Writes then reads a 64-bit unsigned long long register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 64-bit unsigned long long value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

int – The 64-bit unsigned long long value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_read_u8(device_id, reg_id, value, index=-1)[source]

Writes then reads a 8-bit unsigned char register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write followed by a dedicated read.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 8-bit unsigned char value to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Returns:

int – The 8-bit unsigned char value that was written to the register.

Raises:

NKTError – If there was an error calling this method.

register_write_s16(device_id, reg_id, value, index=-1)[source]

Writes a 16-bit signed short register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 16-bit signed short to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_s32(device_id, reg_id, value, index=-1)[source]

Writes a 32-bit signed long register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 32-bit signed long to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_s64(device_id, reg_id, value, index=-1)[source]

Writes a 64-bit signed long long register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 64-bit signed long long to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_s8(device_id, reg_id, value, index=-1)[source]

Writes a 8-bit signed char register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 8-bit signed char to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_u16(device_id, reg_id, value, index=-1)[source]

Writes a 16-bit unsigned short register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 16-bit unsigned short to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_u32(device_id, reg_id, value, index=-1)[source]

Writes a 32-bit unsigned long register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 32-bit unsigned long to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_u64(device_id, reg_id, value, index=-1)[source]

Writes a 64-bit unsigned long long register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 64-bit unsigned long long to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

register_write_u8(device_id, reg_id, value, index=-1)[source]

Writes a 8-bit unsigned char register value.

It is not necessary to open the port, create the device or register before using this function, since it will do a dedicated write.

Parameters:
  • device_id (int) – The device id (module address).

  • reg_id (int) – The register id (register address).

  • value (int) – The 8-bit unsigned char to write to the register.

  • index (int, optional) – Value index. Typically -1, but could be used to write a value in a multi-value register.

Raises:

NKTError – If there was an error calling this method.

static set_legacy_bus_scanning(mode)[source]

Set the bus-scanning mode to normal or legacy.

Parameters:

mode (bool) – If False then bus scanning is set to normal mode and allows for a rolling masterId. In this mode the masterId is changed for each message to allow for out-of-sync detection. If True then bus scanning is set to legacy mode and fixes the masterId at address 66(0x42). Some older modules do not accept masterIds other than 66(0x42).

static set_callback_device_status(callback)[source]

Enables/Disables a callback for device status changes.

Parameters:

callback (DeviceStatusCallback) – A DeviceStatusCallback object. Pass in None to disable callbacks.

Note

Due to a risk of circular runaway leading to stack overflow, it is not allowed to call functions in the DLL from within the callback function. If a call is made to a function in the DLL the function will raise an exception.

Examples

from ctypes import c_ubyte
from msl.equipment.resources import NKT

@NKT.DeviceStatusCallback
def device_callback(port, dev_id, status, length, address):
    # 'address' is an integer and represents the address of c_void_p from the callback
    data = bytearray((c_ubyte * length).from_address(address)[:])
    print('The port is {!r}'.format(port))
    print('The device ID is {}'.format(dev_id))
    print('The device status is {!r}'.format(NKT.DeviceStatusTypes(status)))
    print('The device data is {!r}'.format(data))

NKT.set_callback_device_status(device_callback)
static set_callback_port_status(callback)[source]

Enables/Disables a callback for port status changes.

Used by the open_ports() and close_ports() functions.

Parameters:

callback (PortStatusCallback) – A PortStatusCallback object. Pass in None to disable callbacks.

Note

Due to a risk of circular runaway leading to stack overflow, it is not allowed to call functions in the DLL from within the callback function. If a call is made to a function in the DLL the function will raise an exception.

Examples

from msl.equipment.resources import NKT

@NKT.PortStatusCallback
def port_callback(port, status, cur_scan, max_scan, device):
    print('The port is {!r}'.format(port))
    print('The port status is {!r}'.format(NKT.PortStatusTypes(status)))
    print('Current scanned address or device found address is {}'.format(cur_scan))
    print('There are {} addresses to scan in total'.format(max_scan))
    print('Found device with type {}'.format(device))

NKT.set_callback_port_status(port_callback)
static set_callback_register_status(callback)[source]

Enables/Disables a callback for register status changes.

Parameters:

callback (RegisterStatusCallback) – A RegisterStatusCallback object. Pass in None to disable callbacks.

Note

Due to a risk of circular runaway leading to stack overflow, it is not allowed to call functions in the DLL from within the callback function. If a call is made to a function in the DLL the function will raise an exception.

Examples

from ctypes import c_ubyte
from msl.equipment.resources import NKT

@NKT.RegisterStatusCallback
def register_callback(port, dev_id, reg_id, reg_status, reg_type, length, address):
    # 'address' is an integer and represents the address of c_void_p from the callback
    data = bytearray((c_ubyte * length).from_address(address)[:])
    print('The port is {!r}'.format(port))
    print('The device ID is {}'.format(dev_id))
    print('The register ID is {}'.format(reg_id))
    print('The register status is {!r}'.format(NKT.RegisterStatusTypes(reg_status)))
    print('The register type is {!r}'.format(NKT.RegisterDataTypes(reg_type)))
    print('The register data is {!r}'.format(data))

NKT.set_callback_register_status(register_callback)
msl.equipment.resources.nkt.nktpdll.unknown_error(result)[source]