<commit_before>#!/usr/bin/env python

import ctypes
import sys
import os

import numpy

libPathDebug = '../libaps/'

class APS:
    # implements interface to libaps
    
    # class properties
    device_id = 0
    num_devices = 0
    bit_file_path = ''
    bit_file = 'mqco_dac2_latest.bit'
    expected_bit_file_ver = 0x10
    Address = 0
    verbose = False
    
    mock_aps = False

    is_open = False
    bit_file_programmed = False
    
    # constants 
    max_waveform_points = 4096
    max_ll_length = 64
    
    ELL_VERSION = 0x10
    
    ADDRESS_UNIT = 4
    
    ELL_MAX_WAVEFORM = 8192
    ELL_MAX_LL = 512
    
    # ELL Linklist Masks and Contants
    ELL_ADDRESS            = 0x07FF
    ELL_TIME_AMPLITUDE     = 0x8000
    ELL_LL_TRIGGER         = 0x8000
    ELL_ZERO               = 0x4000
    ELL_VALID_TRIGGER      = 0x2000
    ELL_FIRST_ENTRY        = 0x1000
    ELL_LAST_ENTRY         = 0x800
    ELL_TA_MAX             = 0xFFFF
    ELL_TRIGGER_DELAY      = 0x3FFF
    ELL_TRIGGER_MODE_SHIFT = 14
    ELL_TRIGGER_DELAY_UNIT = 3.333e-9
    
    LL_ENABLE = 1
    LL_DISABLE = 1
    LL_CONTINUOUS = 0
    LL_ONESHOT = 1
    LL_DC = 1
    
    TRIGGER_SOFTWARE = 1
    TRIGGER_HARDWARE = 2
    
    BOTH_FPGAS = 3
    
    BANKA, BANKB = [0,1]
    
    ALL_DACS = -1
    FORCE_OPEN = 1
    FPGA0,FPGA1 = [0,2]
    
    VALID_FREQUENCIES = [1200,600,300,100,40];

    def __init__(self,libPath= libPathDebug, bitFilePath = ''):
        # load library
        platform = sys.platform
        if platform == 'win32' or platform == 'cygwin':
            libName = 'libaps.dll'
        elif platform == 'darwin':
            libName = 'libaps.dylib'
        else:
            libName = 'libaps.so'
        
        if len(libPath) == 0:
            # build path for library
            scriptPath = os.path.dirname(os.path.realpath( __file__ ))
            libPath = scriptPath + '/lib/'
            
        print 'Loading', libPath  + libName
        self.lib = ctypes.cdll.LoadLibrary(libPath  + libName)
        print 'Loaded: ', self.readLibraryVersion()
        
        if len(bitFilePath) == 0:
            # build path for bit file
            # see: http://code.activestate.com/recipes/474083-get-the-path-of-the-currently-executing-python-scr/
            scriptPath = libPath
            extendedPath = 'APS'
            try:
                baseIdx = scriptPath.index(extendedPath)
                self.bit_file_path = scriptPath[0:baseIdx+len(extendedPath)] + '/'
            except ValueError:
                print 'Error finding bit file path in: ', scriptPath
        <commit_msg>Fixed the platform/architecture checking to handle 64 bit systems.<commit_after>#!/usr/bin/env python

import ctypes
import platform
import sys
import os

import numpy

libPathDebug = '../libaps/'

class APS:
    # implements interface to libaps
    
    # class properties
    device_id = 0
    num_devices = 0
    bit_file_path = ''
    bit_file = 'mqco_dac2_latest.bit'
    expected_bit_file_ver = 0x10
    Address = 0
    verbose = False
    
    mock_aps = False

    is_open = False
    bit_file_programmed = False
    
    # constants 
    max_waveform_points = 4096
    max_ll_length = 64
    
    ELL_VERSION = 0x10
    
    ADDRESS_UNIT = 4
    
    ELL_MAX_WAVEFORM = 8192
    ELL_MAX_LL = 512
    
    # ELL Linklist Masks and Contants
    ELL_ADDRESS            = 0x07FF
    ELL_TIME_AMPLITUDE     = 0x8000
    ELL_LL_TRIGGER         = 0x8000
    ELL_ZERO               = 0x4000
    ELL_VALID_TRIGGER      = 0x2000
    ELL_FIRST_ENTRY        = 0x1000
    ELL_LAST_ENTRY         = 0x800
    ELL_TA_MAX             = 0xFFFF
    ELL_TRIGGER_DELAY      = 0x3FFF
    ELL_TRIGGER_MODE_SHIFT = 14
    ELL_TRIGGER_DELAY_UNIT = 3.333e-9
    
    LL_ENABLE = 1
    LL_DISABLE = 1
    LL_CONTINUOUS = 0
    LL_ONESHOT = 1
    LL_DC = 1
    
    TRIGGER_SOFTWARE = 1
    TRIGGER_HARDWARE = 2
    
    BOTH_FPGAS = 3
    
    BANKA, BANKB = [0,1]
    
    ALL_DACS = -1
    FORCE_OPEN = 1
    FPGA0,FPGA1 = [0,2]
    
    VALID_FREQUENCIES = [1200,600,300,100,40];

    def __init__(self,libPath= libPathDebug, bitFilePath = ''):
        #Load the approriate library with some platform/architecture checks
        #Check for 32bit 64bit python from sys.maxsize
        #We do this because we can run 32bit programs on 64bit architectures so
        #platform.achitecture() might give misleading results
        str64bit = '64' if sys.maxsize > 2147483647 else ''
        extDict = {'Windows':'.dll', 'Linux':'.so', 'Darwin':'.dylib'}        
        libName = 'libaps' + str64bit + extDict[platform.system()]
        
        if len(libPath) == 0:
            # build path for library
            scriptPath = os.path.dirname(os.path.realpath( __file__ ))
            libPath = scriptPath + '/lib/'
            
        print 'Loading', libPath  + libName
        self.lib = ctypes.cdll.LoadLibrary(libPath  + libName)
        print 'Loaded: ', self.readLibraryVersion()
        
        if len(bitFilePath) == 0:
            # build path for bit file
            # see: http://code.activestate.com/recipes/474083-get-the-path-of-the-currently-executing-python-scr/
            scriptPath = libPath
            extendedPath = 'APS'
            try:
                baseIdx = scriptPath.index(extendedPath)
                self.bit_file_path = scriptPath[0:baseIdx+len(extendedPath)] + '/'
            except ValueError:
                print 'Error finding bit file path in: ', scriptPath
        
{'fraction_non_alphanumeric': 0.08073294629898403, 'fraction_numerical': 0.04354136429608128, 'mean_word_length': 1.8818609513852587, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2820354', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1855, 'n_words': 401}