<commit_before>import ctypes
import sys

if sys.platform.startswith("win"):
	_dwf = ctypes.cdll.dwf
else:
	_dwf = ctypes.cdll.LoadLibrary("libdwf.so")

class _types(object):
	c_byte_p = ctypes.POINTER(ctypes.c_byte)
	c_double_p = ctypes.POINTER(ctypes.c_double)
	c_int_p = ctypes.POINTER(ctypes.c_int)
	c_uint_p = ctypes.POINTER(ctypes.c_uint)

class HDWF(ctypes.c_int):
	pass
hdwfNone = HDWF(0)

class ENUMFILTER(ctypes.c_int):
	pass
enumfilterAll       = ENUMFILTER(0)
enumfilterEExplorer = ENUMFILTER(1)
enumfilterDiscovery = ENUMFILTER(2)

class DEVID(ctypes.c_int):
	pass
devidEExplorer = DEVID(1)
devidDiscovery = DEVID(2)

class DEVVER(ctypes.c_int):
	pass
devverEExplorerC = DEVVER(2)
devverEExplorerE = DEVVER(4)
devverEExplorerF = DEVVER(5)
devverDiscoveryA = DEVVER(1)
devverDiscoveryB = DEVVER(2)
devverDiscoveryC = DEVVER(3)

class TRIGSRC(ctypes.c_byte):
	pass
trigsrcNone              = TRIGSRC(0)
trigsrcPC                = TRIGSRC(1)
trigsrcDetectorAnalogIn  = TRIGSRC(2)
trigsrcDetectorDigitalIn = TRIGSRC(3)
trigsrcAnalogIn          = TRIGSRC(4)
trigsrcDigitalIn         = TRIGSRC(5)
trigsrcDigitalOut        = TRIGSRC(6)
trigsrcAnalogOut1        = TRIGSRC(7)
trigsrcAnalogOut2        = TRIGSRC(8)
trigsrcAnalogOut3        = TRIGSRC(9)
trigsrcAnalogOut4        = TRIGSRC(10)
trigsrcExternal1         = TRIGSRC(11)
trigsrcExternal2         = TRIGSRC(12)
trigsrcExternal3         = TRIGSRC(13)
trigsrcExternal4         = TRIGSRC(14)

class DwfState(ctypes.c_byte):
	pass
DwfStateReady     = DwfState(0)
DwfStateConfig    = DwfState(4)
DwfStatePrefill   = DwfState(5)
DwfStateArmed     = DwfState(1)
DwfStateWait      = DwfState(7)
DwfStateTriggered = DwfState(3)
DwfStateRunning   = DwfState(3)
DwfStateDone      = DwfState(2)

class ACQMODE(ctypes.c_int):
	pass
acqmodeSingle     = ACQMODE(0)
acqmodeScanShift  = ACQMODE(1)
acqmodeScanScreen = ACQMODE(2)
acqmodeRecord     = ACQMODE(3)

class FILTER(ctypes.c_int):
	pass
filterDecimate = FILTER(0)
filterAverage  = FILTER(1)
filterMinMax   = FILTER(2)

class TRIGTYPE(ctypes.c_int):
	pass
trigtypeEdge       = TRIGTYPE(0)
trigtypePulse      = TRIGTYPE(1)
trigtypeTransition = TRIGTYPE(2)

class TRIGCOND(ctypes.c_int):
	pass
trigcondRisingPositive  = TRIGCOND(0)
trigcondFallingNegative = TRIGCOND(1)

class TRIGLEN(ctypes.c_int):
	pass
triglenLess    = TRIGLEN(0)
triglenTimeout = TRIGLEN(1)
triglenMore    = TRIGLEN(2)

class DWFERC(ctypes.c_int):
	pass
dwfercNoErc             = DWFERC(0)        # No error occurred
dwfercUnknownError      = DWFERC(1)        # API waiting on pending API timed out
dwfercApiLockTimeout    = DWFERC(2)        # API waiting on pending API timed out
dwfercAlreadyOpened     = DWFERC(3)        # Device already opened
dwfercNotSupported      = DWFERC(4)        # Device not supported
dwfercInvalidParameter0 = DWFERC(0x10)     # Invalid parameter sent in API call
dwfercInvalidParameter1 = DWFERC(0x11)     # Invalid parameter sent in API call
dwfercInvalidParameter2 = DWFERC(0x12)     # Invalid parameter sent in API call
dwfercInvalidParameter3 = DWFERC(0x13)     # Invalid parameter sent in API call
dwfercInvalidParameter4 = DWFERC(0x14)     # Invalid parameter sent in API call

class FUNC(ctypes.c_byte):
	pass
funcDC       = FUNC(0)
funcSine     = FUNC(1)
funcSquare   = FUNC(2)
funcTriangle = FUNC(3)
funcRampUp   = FUNC(4)
funcRampDown = FUNC(5)
funcNoise    = FUNC(6)
funcCustom   = FUNC(30)
funcPlay     = FUNC(31)

class ANALOGIO(ctypes.c_byte):
	pass
analogioEnable      = ANALOGIO(1)
analogioVoltage     = ANALOGIO(2)
analogioCurrent     = ANALOGIO(3)
analogioPower       = ANALOGIO(4)
analogioTemperature = ANALOGIO(5)

class AnalogOutNode(ctypes.c_int):
	pass
AnalogOutNodeCarrier = AnalogOutNode(0)
AnalogOutNodeFM      = AnalogOutNode(1)
AnalogOutNodeAM      = AnalogOutNode(2)

class DwfDigitalInClockSource(ctypes.c_int):
	pass
DwfDigitalInClockSourceInternal = DwfDigitalInClockSource(0)
DwfDigitalInClockSourceExternal = DwfDigitalInClockSource(1)

class DwfDigitalInSampleMode(ctypes.c_int):
	pass
DwfDigitalInSampleModeSimple = DwfDigitalInSampleMode(0)
DwfDigitalInSampleModeNoise  = DwfDigitalInSampleMode(1)

class DwfDigitalOutOutput(ctypes.c_int):
	pass
DwfDigitalOutOutputPushPull   = DwfDigitalOutOutput(0)
DwfDigitalOutOutputOpenDrain  = DwfDigitalOutOutput(1)
DwfDigitalOutOutputOpenSource = DwfDigitalOutOutput(2)
DwfDigitalOutOutputThreeState = DwfDigitalOutOutput(3)

class DwfDigitalOutType(ctypes.c_int):
	pass
DwfDigitalOutTypePulse  = DwfDigitalOutType(0)
DwfDigitalOutTypeCustom = DwfDigitalOutType(1)
DwfDigitalOutTypeRandom = DwfDigitalOutType(2)

class DwfDigitalOutIdle(ctypes.c_int):
	pass
DwfDigitalOutIdleInit = DwfDigitalOutIdle(0)
DwfDigitalOutIdleLow  = DwfDigitalOutIdle(1)
DwfDigitalOutIdleHigh = DwfDigitalOutIdle(2)
DwfDigitalOutIdleZet  = DwfDigitalOutIdle(3)

def IsBitSet(fs, bit):
	return ((fs & (1 << bit)) != 0)

# Error and version APIs:
_FDwfGetLastError = _dwf.FDwfGetLastError
_FDwfGetLastError.argtypes = [ctypes.POINTER(DWFERC)]
_FDwfGetLastError.restype = bool

def FDwfGetLastError():
	erc = DWFERC()
	return (_FDwfGetLastError(ctypes.byref(erc)), erc)

_FDwfGetLastErrorMsg = _dwf.FDwfGetLastErrorMsg
_FDwfGetLastErrorMsg.argtypes = [ctypes.POINTER(ctypes.c_char * 512)]
_FDwfGetLastErrorMsg.restype = bool

def FDwfGetLastErrorMsg():
	buf = ctypes.create_string_buffer(512)
	return (_FDwfGetLastErrorMsg(ctypes.byref(buf)), buf.value)

_FDwfGetVersion = _dwf.FDwfGetVersion  # Returns DLL version, for instance: "2.4.3"
_FDwfGetVersion.argtypes = [ctypes.POINTER(ctypes.c_char * 32)]
_FDwfGetVersion.restype = bool

def FDwfGetVersion():
	buf = ctypes.create_string_buffer(32)
	return (_FDwfGetVersion(ctypes.byref(buf)), buf.value)

# DEVICE MANAGMENT FUNCTIONS
# Enumeration:
_FDwfEnum = _dwf.FDwfEnum
_FDwfEnum.argtypes = [ENUMFILTER, _types.c_int_p]
_FDwfEnum.restype = bool

def FDwfEnum(enumFilter):
	tmp = ctypes.c_int()
	return (_FDwfEnum(ctypes.byref(tmp)), tmp.value)

_FDwfEnumDeviceType = _dwf.FDwfEnumDeviceType
_FDwfEnumDeviceType.argtypes = [ctypes.c_int, ctypes.POINTER(DEVID), ctypes.POINTER(DEVVER)]
_FDwfEnumDeviceType.restype = bool

def FDwfEnumDeviceType(idxDevice):
	devid = DEVID()
	devver = DEVVER()
	return (_FDwfEnumDeviceType(idxDevice, ctypes.byref(devid), ctypes.byref(devver)), devid.value, devver.value)

_FDwfEnumDeviceIsOpened = _dwf.FDwfEnumDeviceIsOpened
_FDwfEnumDeviceIsOpened.argtypes = [ctypes.c_int, _types.c_byte_p]
_FDwfEnumDeviceIsOpened.restype = bool

def FDwfEnumDeviceIsOpened(idxDevice):
	isopen = ctypes.c_byte()
	return (_FDwfEnumDeviceIsOpened(idxDevice, ctypes.byref(isopen)), bool(isopen.value))

_FDwfEnumUserName = _dwf.FDwfEnumUserName<commit_msg>Fixed minor bug and consistency issue<commit_after>import ctypes
import sys

if sys.platform.startswith("win"):
	_dwf = ctypes.cdll.dwf
else:
	_dwf = ctypes.cdll.LoadLibrary("libdwf.so")

class _types(object):
	c_byte_p = ctypes.POINTER(ctypes.c_byte)
	c_double_p = ctypes.POINTER(ctypes.c_double)
	c_int_p = ctypes.POINTER(ctypes.c_int)
	c_uint_p = ctypes.POINTER(ctypes.c_uint)

class HDWF(ctypes.c_int):
	pass
hdwfNone = HDWF(0)

class ENUMFILTER(ctypes.c_int):
	pass
enumfilterAll       = ENUMFILTER(0)
enumfilterEExplorer = ENUMFILTER(1)
enumfilterDiscovery = ENUMFILTER(2)

class DEVID(ctypes.c_int):
	pass
devidEExplorer = DEVID(1)
devidDiscovery = DEVID(2)

class DEVVER(ctypes.c_int):
	pass
devverEExplorerC = DEVVER(2)
devverEExplorerE = DEVVER(4)
devverEExplorerF = DEVVER(5)
devverDiscoveryA = DEVVER(1)
devverDiscoveryB = DEVVER(2)
devverDiscoveryC = DEVVER(3)

class TRIGSRC(ctypes.c_byte):
	pass
trigsrcNone              = TRIGSRC(0)
trigsrcPC                = TRIGSRC(1)
trigsrcDetectorAnalogIn  = TRIGSRC(2)
trigsrcDetectorDigitalIn = TRIGSRC(3)
trigsrcAnalogIn          = TRIGSRC(4)
trigsrcDigitalIn         = TRIGSRC(5)
trigsrcDigitalOut        = TRIGSRC(6)
trigsrcAnalogOut1        = TRIGSRC(7)
trigsrcAnalogOut2        = TRIGSRC(8)
trigsrcAnalogOut3        = TRIGSRC(9)
trigsrcAnalogOut4        = TRIGSRC(10)
trigsrcExternal1         = TRIGSRC(11)
trigsrcExternal2         = TRIGSRC(12)
trigsrcExternal3         = TRIGSRC(13)
trigsrcExternal4         = TRIGSRC(14)

class DwfState(ctypes.c_byte):
	pass
DwfStateReady     = DwfState(0)
DwfStateConfig    = DwfState(4)
DwfStatePrefill   = DwfState(5)
DwfStateArmed     = DwfState(1)
DwfStateWait      = DwfState(7)
DwfStateTriggered = DwfState(3)
DwfStateRunning   = DwfState(3)
DwfStateDone      = DwfState(2)

class ACQMODE(ctypes.c_int):
	pass
acqmodeSingle     = ACQMODE(0)
acqmodeScanShift  = ACQMODE(1)
acqmodeScanScreen = ACQMODE(2)
acqmodeRecord     = ACQMODE(3)

class FILTER(ctypes.c_int):
	pass
filterDecimate = FILTER(0)
filterAverage  = FILTER(1)
filterMinMax   = FILTER(2)

class TRIGTYPE(ctypes.c_int):
	pass
trigtypeEdge       = TRIGTYPE(0)
trigtypePulse      = TRIGTYPE(1)
trigtypeTransition = TRIGTYPE(2)

class TRIGCOND(ctypes.c_int):
	pass
trigcondRisingPositive  = TRIGCOND(0)
trigcondFallingNegative = TRIGCOND(1)

class TRIGLEN(ctypes.c_int):
	pass
triglenLess    = TRIGLEN(0)
triglenTimeout = TRIGLEN(1)
triglenMore    = TRIGLEN(2)

class DWFERC(ctypes.c_int):
	pass
dwfercNoErc             = DWFERC(0)        # No error occurred
dwfercUnknownError      = DWFERC(1)        # API waiting on pending API timed out
dwfercApiLockTimeout    = DWFERC(2)        # API waiting on pending API timed out
dwfercAlreadyOpened     = DWFERC(3)        # Device already opened
dwfercNotSupported      = DWFERC(4)        # Device not supported
dwfercInvalidParameter0 = DWFERC(0x10)     # Invalid parameter sent in API call
dwfercInvalidParameter1 = DWFERC(0x11)     # Invalid parameter sent in API call
dwfercInvalidParameter2 = DWFERC(0x12)     # Invalid parameter sent in API call
dwfercInvalidParameter3 = DWFERC(0x13)     # Invalid parameter sent in API call
dwfercInvalidParameter4 = DWFERC(0x14)     # Invalid parameter sent in API call

class FUNC(ctypes.c_byte):
	pass
funcDC       = FUNC(0)
funcSine     = FUNC(1)
funcSquare   = FUNC(2)
funcTriangle = FUNC(3)
funcRampUp   = FUNC(4)
funcRampDown = FUNC(5)
funcNoise    = FUNC(6)
funcCustom   = FUNC(30)
funcPlay     = FUNC(31)

class ANALOGIO(ctypes.c_byte):
	pass
analogioEnable      = ANALOGIO(1)
analogioVoltage     = ANALOGIO(2)
analogioCurrent     = ANALOGIO(3)
analogioPower       = ANALOGIO(4)
analogioTemperature = ANALOGIO(5)

class AnalogOutNode(ctypes.c_int):
	pass
AnalogOutNodeCarrier = AnalogOutNode(0)
AnalogOutNodeFM      = AnalogOutNode(1)
AnalogOutNodeAM      = AnalogOutNode(2)

class DwfDigitalInClockSource(ctypes.c_int):
	pass
DwfDigitalInClockSourceInternal = DwfDigitalInClockSource(0)
DwfDigitalInClockSourceExternal = DwfDigitalInClockSource(1)

class DwfDigitalInSampleMode(ctypes.c_int):
	pass
DwfDigitalInSampleModeSimple = DwfDigitalInSampleMode(0)
DwfDigitalInSampleModeNoise  = DwfDigitalInSampleMode(1)

class DwfDigitalOutOutput(ctypes.c_int):
	pass
DwfDigitalOutOutputPushPull   = DwfDigitalOutOutput(0)
DwfDigitalOutOutputOpenDrain  = DwfDigitalOutOutput(1)
DwfDigitalOutOutputOpenSource = DwfDigitalOutOutput(2)
DwfDigitalOutOutputThreeState = DwfDigitalOutOutput(3)

class DwfDigitalOutType(ctypes.c_int):
	pass
DwfDigitalOutTypePulse  = DwfDigitalOutType(0)
DwfDigitalOutTypeCustom = DwfDigitalOutType(1)
DwfDigitalOutTypeRandom = DwfDigitalOutType(2)

class DwfDigitalOutIdle(ctypes.c_int):
	pass
DwfDigitalOutIdleInit = DwfDigitalOutIdle(0)
DwfDigitalOutIdleLow  = DwfDigitalOutIdle(1)
DwfDigitalOutIdleHigh = DwfDigitalOutIdle(2)
DwfDigitalOutIdleZet  = DwfDigitalOutIdle(3)

def IsBitSet(fs, bit):
	return ((fs & (1 << bit)) != 0)

# Error and version APIs:
_FDwfGetLastError = _dwf.FDwfGetLastError
_FDwfGetLastError.argtypes = [ctypes.POINTER(DWFERC)]
_FDwfGetLastError.restype = bool

def FDwfGetLastError():
	erc = DWFERC()
	return (_FDwfGetLastError(ctypes.byref(erc)), erc)

_FDwfGetLastErrorMsg = _dwf.FDwfGetLastErrorMsg
_FDwfGetLastErrorMsg.argtypes = [ctypes.POINTER(ctypes.c_char * 512)]
_FDwfGetLastErrorMsg.restype = bool

def FDwfGetLastErrorMsg():
	buf = ctypes.create_string_buffer(512)
	return (_FDwfGetLastErrorMsg(ctypes.byref(buf)), buf.value)

_FDwfGetVersion = _dwf.FDwfGetVersion  # Returns DLL version, for instance: "2.4.3"
_FDwfGetVersion.argtypes = [ctypes.POINTER(ctypes.c_char * 32)]
_FDwfGetVersion.restype = bool

def FDwfGetVersion():
	buf = ctypes.create_string_buffer(32)
	return (_FDwfGetVersion(ctypes.byref(buf)), buf.value)

# DEVICE MANAGMENT FUNCTIONS
# Enumeration:
_FDwfEnum = _dwf.FDwfEnum
_FDwfEnum.argtypes = [ENUMFILTER, _types.c_int_p]
_FDwfEnum.restype = bool

def FDwfEnum(enumFilter):
	tmp = ctypes.c_int()
	return (_FDwfEnum(enumFilter, ctypes.byref(tmp)), tmp.value)

_FDwfEnumDeviceType = _dwf.FDwfEnumDeviceType
_FDwfEnumDeviceType.argtypes = [ctypes.c_int, ctypes.POINTER(DEVID), ctypes.POINTER(DEVVER)]
_FDwfEnumDeviceType.restype = bool

def FDwfEnumDeviceType(idxDevice):
	devid = DEVID()
	devver = DEVVER()
	return (_FDwfEnumDeviceType(idxDevice, ctypes.byref(devid), ctypes.byref(devver)), devid, devver)

_FDwfEnumDeviceIsOpened = _dwf.FDwfEnumDeviceIsOpened
_FDwfEnumDeviceIsOpened.argtypes = [ctypes.c_int, _types.c_byte_p]
_FDwfEnumDeviceIsOpened.restype = bool

def FDwfEnumDeviceIsOpened(idxDevice):
	isopen = ctypes.c_byte()
	return (_FDwfEnumDeviceIsOpened(idxDevice, ctypes.byref(isopen)), bool(isopen.value))

_FDwfEnumUserName = _dwf.FDwfEnumUserName
{'fraction_non_alphanumeric': 0.09277811004784689, 'fraction_numerical': 0.02048444976076555, 'mean_word_length': 5.342816500711238, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '84334', 'n_tokens_mistral': 5603, 'n_tokens_neox': 5233, 'n_words': 869}