Skip to content

add executable permissions for files of '*.sh' #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.o
__pycache__
__pycache__
*.pyc
*.vscode
13 changes: 8 additions & 5 deletions NIRS.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# NIRScanner Python Wrapper
# Created by Weiwei Jiang
#
# Fix by Jintao Yang on 2020/11/24
#!/usr/bin/python3.8

import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), "./"))
Expand Down Expand Up @@ -83,9 +84,9 @@ def set_hibernate(self, new_value: bool):
return NIRScanner_setHibernate(self.nirs_obj, new_value)

def set_config(self, scanConfigIndex=8, scan_type=1, num_patterns=228, num_repeats=6,
wavelength_start_nm=900, wavelength_end_nm=1700, width_px=7):
wavelength_start_nm=900, wavelength_end_nm=1700, width_px=7, exposure_time = 0, ScanConfig_serial_number = "", config_name = "cfg8"):
return NIRScanner_setConfig(self.nirs_obj, scanConfigIndex, scan_type, num_patterns, num_repeats,
wavelength_start_nm, wavelength_end_nm, width_px)
wavelength_start_nm, wavelength_end_nm, width_px, exposure_time, config_name)

def set_pga_gain(self, new_value):
return NIRScanner_setPGAGain(self.nirs_obj, new_value)
Expand All @@ -96,6 +97,8 @@ def set_lamp_on_off(self, new_value):
def clear_error_status(self):
return NIRScanner_resetErrorStatus(self.nirs_obj)

def sync_device_date_time(self, year = 1970, month = 1, day = 1, wday = 0, hour = 0, min = 0, sec = 0):
return NIRScanner_syncDeviceDateTime(self.nirs_obj, year, month, day, wday, hour, min, sec)

if __name__ == "__main__":
import time
Expand All @@ -107,7 +110,7 @@ def clear_error_status(self):
nirs.set_config(8, NIRS.TYPES.HADAMARD_TYPE, 228, 6, 900, 1700, 7)

# Turn on the lamp.
nirs.set_lamp_on_off(True)
nirs.set_lamp_on_off(1)
time.sleep(3)

# Scan.
Expand All @@ -117,6 +120,6 @@ def clear_error_status(self):
results = nirs.get_scan_results()

# Turn lamp off.
nirs.set_lamp_on_off(False)
nirs.set_lamp_on_off(-1)

pass
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ $ cd NIRScanner-Python
```
For compiling Python 2 library:
```console
NIRScanner-Python$ chmod +x ./src/scripts/compile_py2.sh
NIRScanner-Python$ ./src/scripts/compile_py2.sh
```
For compiling Python 3 library:
```console
NIRScanner-Python$ chmod +x ./src/scripts/compile_py3.sh
NIRScanner-Python$ ./src/scripts/compile_py3.sh
```
## Deploy
Expand Down
Binary file modified _NIRScanner.so
Binary file not shown.
Binary file added lib/_NIRScanner.so.3.8
Binary file not shown.
59 changes: 50 additions & 9 deletions src/NIRScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,41 @@ void NIRScanner::setConfig(uint16_t scanConfigIndex, // < Unique ID per spectro
uint16_t num_repeats, // Number of times to repeat the scan on the spectromter before averaging the scans together and returning the results. This can be used to increase integration time.
uint16_t wavelength_start_nm, // Minimum wavelength to start the scan from, in nm.
uint16_t wavelength_end_nm, // Maximum wavelength to end the scan at, in nm.
uint8_t width_px // Pixel width of the patterns. Increasing this will increase SNR, but reduce resolution.
) {
this->mConfig.scanCfg.scanConfigIndex = scanConfigIndex;
this->mConfig.scanCfg.scan_type = scan_type;
this->mConfig.scanCfg.num_patterns = num_patterns;
this->mConfig.scanCfg.num_repeats = num_repeats;
this->mConfig.scanCfg.wavelength_start_nm = wavelength_start_nm;
this->mConfig.scanCfg.wavelength_end_nm = wavelength_end_nm;
this->mConfig.scanCfg.width_px = width_px;
uint8_t width_px ,// Pixel width of the patterns. Increasing this will increase SNR, but reduce resolution.
uint16_t exposure_time, //Time for for which each pattern in this section will be exposed. Values should be as per EXP_TIME enum above
const char* config_name//User friendly scan configuration name for display
)
{
if(scan_type != SLEW_TYPE)
{
this->mConfig.scanCfg.scanConfigIndex = scanConfigIndex;
this->mConfig.scanCfg.scan_type = scan_type;
this->mConfig.scanCfg.num_patterns = num_patterns;
this->mConfig.scanCfg.num_repeats = num_repeats;
this->mConfig.scanCfg.wavelength_start_nm = wavelength_start_nm;
this->mConfig.scanCfg.wavelength_end_nm = wavelength_end_nm;
this->mConfig.scanCfg.width_px = width_px;

char ser_num[NANO_SER_NUM_LEN] = "";
NNO_GetSerialNumber(ser_num);
memcpy(this->mConfig.scanCfg.ScanConfig_serial_number, ser_num, NANO_SER_NUM_LEN);

memcpy(this->mConfig.scanCfg.config_name, config_name, SCAN_CFG_FILENAME_LEN);
}
else
{
this->mConfig.slewScanCfg.head.num_sections;
this->mConfig.slewScanCfg.head.num_repeats;
for(uint8_t i=0; i < this->mConfig.slewScanCfg.head.num_sections; i++)
{
this->mConfig.slewScanCfg.section[i].section_scan_type;
this->mConfig.slewScanCfg.section[i].wavelength_start_nm;
this->mConfig.slewScanCfg.section[i].wavelength_end_nm;
this->mConfig.slewScanCfg.section[i].width_px;
this->mConfig.slewScanCfg.section[i].num_patterns;
this->mConfig.slewScanCfg.section[i].exposure_time;
}
}

this->configEVM();
}
Expand Down Expand Up @@ -233,6 +259,21 @@ void NIRScanner::setPGAGain(int32_t newValue)
}
}

void NIRScanner::syncDeviceDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t wday, uint8_t hour, uint8_t min, uint8_t sec)
{
NNO_SetDateTime(uint8_t(year - 2000), uint8_t(month), uint8_t(day), uint8_t(wday), uint8_t(hour), uint8_t(min), uint8_t(sec));

uint8_t yearR = 0;
uint8_t monthR = 0;
uint8_t dayR = 0;
uint8_t wdayR = 0;
uint8_t hourR = 0;
uint8_t minR = 0;
uint8_t secR = 0;
NNO_GetDateTime(&yearR, &monthR, &dayR, &wdayR, &hourR, &minR, &secR);
printf("synchronized date time %d.%d.%d-%d:%d:%d\n", yearR + 2000, monthR, dayR, hourR, minR, secR);
}

void NIRScanner::setLampOnOff(int32_t newValue)
/*
* Set the lamp always on or off.
Expand Down
13 changes: 11 additions & 2 deletions src/NIRScanner.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,19 @@ class NIRScanner {
int readVersion();
void resetErrorStatus();
void setLampOnOff(int32_t newValue);
void setConfig(uint16_t scanConfigIndex, uint8_t scan_type, uint16_t num_patterns, uint16_t num_repeats,
uint16_t wavelength_start_nm, uint16_t wavelength_end_nm, uint8_t width_px);
void setConfig(uint16_t scanConfigIndex, // < Unique ID per spectrometer which is modified when the config is changed. Can be used to determine whether a cached version of the config is valid per spectrometer SN.
uint8_t scan_type, // 0: COLUMN_TYPE, 1: HADAMARD_TYPE, 2: SLEW_TYPE.
uint16_t num_patterns, // Number of desired points in the spectrum.
uint16_t num_repeats, // Number of times to repeat the scan on the spectromter before averaging the scans together and returning the results. This can be used to increase integration time.
uint16_t wavelength_start_nm, // Minimum wavelength to start the scan from, in nm.
uint16_t wavelength_end_nm, // Maximum wavelength to end the scan at, in nm.
uint8_t width_px ,// Pixel width of the patterns. Increasing this will increase SNR, but reduce resolution.
uint16_t exposure_time, //Time for for which each pattern in this section will be exposed. Values should be as per EXP_TIME enum above
const char* config_name//User friendly scan configuration name for display
);
void configEVM(uScanConfig* pConfig = nullptr);
void setPGAGain(int32_t newValue);
void syncDeviceDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t wday, uint8_t hour, uint8_t min, uint8_t sec);

string scanSNR(bool isHadamard=true);
void scan(bool saveDataFlag=false, int numRepeats=1);
Expand Down
13 changes: 11 additions & 2 deletions src/NIRScanner.i
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,19 @@ public:
int readVersion();
void resetErrorStatus();
void setLampOnOff(int32_t newValue);
void setConfig(uint16_t scanConfigIndex, uint8_t scan_type, uint16_t num_patterns, uint16_t num_repeats,
uint16_t wavelength_start_nm, uint16_t wavelength_end_nm, uint8_t width_px);
void setConfig(uint16_t scanConfigIndex, // < Unique ID per spectrometer which is modified when the config is changed. Can be used to determine whether a cached version of the config is valid per spectrometer SN.
uint8_t scan_type, // 0: COLUMN_TYPE, 1: HADAMARD_TYPE, 2: SLEW_TYPE.
uint16_t num_patterns, // Number of desired points in the spectrum.
uint16_t num_repeats, // Number of times to repeat the scan on the spectromter before averaging the scans together and returning the results. This can be used to increase integration time.
uint16_t wavelength_start_nm, // Minimum wavelength to start the scan from, in nm.
uint16_t wavelength_end_nm, // Maximum wavelength to end the scan at, in nm.
uint8_t width_px ,// Pixel width of the patterns. Increasing this will increase SNR, but reduce resolution.
uint16_t exposure_time, //Time for for which each pattern in this section will be exposed. Values should be as per EXP_TIME enum above
const char* config_name//User friendly scan configuration name for display
);
void configEVM(uScanConfig* pConfig = nullptr);
void setPGAGain(int32_t newValue);
void syncDeviceDateTime(uint16_t year, uint8_t month, uint8_t day, uint8_t wday, uint8_t hour, uint8_t min, uint8_t sec);

string scanSNR(bool isHadamard=true);
void scan(bool saveDataFlag=false, int numRepeats=1);
Expand Down
143 changes: 52 additions & 91 deletions src/NIRScanner.py
Original file line number Diff line number Diff line change
@@ -1,115 +1,73 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 3.0.12
# Version 4.0.1
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.

from sys import version_info as _swig_python_version_info
if _swig_python_version_info >= (2, 7, 0):
def swig_import_helper():
import importlib
pkg = __name__.rpartition('.')[0]
mname = '.'.join((pkg, '_NIRScanner')).lstrip('.')
try:
return importlib.import_module(mname)
except ImportError:
return importlib.import_module('_NIRScanner')
_NIRScanner = swig_import_helper()
del swig_import_helper
elif _swig_python_version_info >= (2, 6, 0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_NIRScanner', [dirname(__file__)])
except ImportError:
import _NIRScanner
return _NIRScanner
try:
_mod = imp.load_module('_NIRScanner', fp, pathname, description)
finally:
if fp is not None:
fp.close()
return _mod
_NIRScanner = swig_import_helper()
del swig_import_helper
if _swig_python_version_info < (2, 7, 0):
raise RuntimeError("Python 2.7 or later required")

# Import the low-level C/C++ module
if __package__ or "." in __name__:
from . import _NIRScanner
else:
import _NIRScanner
del _swig_python_version_info

try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.

try:
import builtins as __builtin__
except ImportError:
import __builtin__

def _swig_setattr_nondynamic(self, class_type, name, value, static=1):
if (name == "thisown"):
return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name, None)
if method:
return method(self, value)
if (not static):
if _newclass:
object.__setattr__(self, name, value)
def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
except __builtin__.Exception:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)


def _swig_setattr_nondynamic_instance_variable(set):
def set_instance_attr(self, name, value):
if name == "thisown":
self.this.own(value)
elif name == "this":
set(self, name, value)
elif hasattr(self, name) and isinstance(getattr(type(self), name), property):
set(self, name, value)
else:
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
raise AttributeError("You cannot add instance attributes to %s" % self)
return set_instance_attr


def _swig_setattr(self, class_type, name, value):
return _swig_setattr_nondynamic(self, class_type, name, value, 0)
def _swig_setattr_nondynamic_class_variable(set):
def set_class_attr(cls, name, value):
if hasattr(cls, name) and not isinstance(getattr(cls, name), property):
set(cls, name, value)
else:
raise AttributeError("You cannot add class attributes to %s" % cls)
return set_class_attr


def _swig_getattr(self, class_type, name):
if (name == "thisown"):
return self.this.own()
method = class_type.__swig_getmethods__.get(name, None)
if method:
return method(self)
raise AttributeError("'%s' object has no attribute '%s'" % (class_type.__name__, name))
def _swig_add_metaclass(metaclass):
"""Class decorator for adding a metaclass to a SWIG wrapped class - a slimmed down version of six.add_metaclass"""
def wrapper(cls):
return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
return wrapper


def _swig_repr(self):
try:
strthis = "proxy of " + self.this.__repr__()
except __builtin__.Exception:
strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
class _SwigNonDynamicMeta(type):
"""Meta class to enforce nondynamic attributes (no new attributes) for a class"""
__setattr__ = _swig_setattr_nondynamic_class_variable(type.__setattr__)

try:
_object = object
_newclass = 1
except __builtin__.Exception:
class _object:
pass
_newclass = 0

class NIRScanner(_object):
__swig_setmethods__ = {}
__setattr__ = lambda self, name, value: _swig_setattr(self, NIRScanner, name, value)
__swig_getmethods__ = {}
__getattr__ = lambda self, name: _swig_getattr(self, NIRScanner, name)

class NIRScanner(object):
thisown = property(lambda x: x.this.own(), lambda x, v: x.this.own(v), doc="The membership flag")
__repr__ = _swig_repr

def __init__(self, pConfig=None):
this = _NIRScanner.new_NIRScanner(pConfig)
try:
self.this.append(this)
except __builtin__.Exception:
self.this = this
_NIRScanner.NIRScanner_swiginit(self, _NIRScanner.new_NIRScanner(pConfig))
__swig_destroy__ = _NIRScanner.delete_NIRScanner
__del__ = lambda self: None

def readVersion(self):
return _NIRScanner.NIRScanner_readVersion(self)
Expand All @@ -120,15 +78,18 @@ def resetErrorStatus(self):
def setLampOnOff(self, newValue):
return _NIRScanner.NIRScanner_setLampOnOff(self, newValue)

def setConfig(self, scanConfigIndex, scan_type, num_patterns, num_repeats, wavelength_start_nm, wavelength_end_nm, width_px):
return _NIRScanner.NIRScanner_setConfig(self, scanConfigIndex, scan_type, num_patterns, num_repeats, wavelength_start_nm, wavelength_end_nm, width_px)
def setConfig(self, scanConfigIndex, scan_type, num_patterns, num_repeats, wavelength_start_nm, wavelength_end_nm, width_px, exposure_time, config_name):
return _NIRScanner.NIRScanner_setConfig(self, scanConfigIndex, scan_type, num_patterns, num_repeats, wavelength_start_nm, wavelength_end_nm, width_px, exposure_time, config_name)

def configEVM(self, pConfig=None):
return _NIRScanner.NIRScanner_configEVM(self, pConfig)

def setPGAGain(self, newValue):
return _NIRScanner.NIRScanner_setPGAGain(self, newValue)

def syncDeviceDateTime(self, year, month, day, wday, hour, min, sec):
return _NIRScanner.NIRScanner_syncDeviceDateTime(self, year, month, day, wday, hour, min, sec)

def scanSNR(self, isHadamard=True):
return _NIRScanner.NIRScanner_scanSNR(self, isHadamard)

Expand All @@ -140,9 +101,9 @@ def getScanData(self):

def setHibernate(self, newValue):
return _NIRScanner.NIRScanner_setHibernate(self, newValue)
NIRScanner_swigregister = _NIRScanner.NIRScanner_swigregister
NIRScanner_swigregister(NIRScanner)

# This file is compatible with both classic and new-style classes.
# Register NIRScanner in _NIRScanner:
_NIRScanner.NIRScanner_swigregister(NIRScanner)



Loading