From c8fa3ab947695bd8c68d69abcaa9e853b5d1cd28 Mon Sep 17 00:00:00 2001 From: Martin Date: Wed, 5 Feb 2020 20:35:24 +0100 Subject: [PATCH] fix OpenHantek/OpenHantek6022#55 Signed-off-by: Martin --- Makefile | 2 +- PyHT6022/LibUsbScope.py | 6 ++---- examples/calibrate.py | 7 ++++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 0329758..9b0fb52 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ fw_custom_BL: install: all python3 setup.py install - cp 60-hantek-6022-usb.rules /etc/udev/rules.d/ + if [ -d /etc/udev/rules.d/ ]; then cp 60-hantek-6022-usb.rules /etc/udev/rules.d/; fi deb: fakeroot checkinstall --default --requires python3-libusb1 --install=no --backup=no --deldoc=yes diff --git a/PyHT6022/LibUsbScope.py b/PyHT6022/LibUsbScope.py index 2e468e5..94170f5 100644 --- a/PyHT6022/LibUsbScope.py +++ b/PyHT6022/LibUsbScope.py @@ -1,6 +1,6 @@ __author__ = 'Robert Cope', 'Jochen Hoenicke' -import sys +import os import time import usb1 import array @@ -9,8 +9,6 @@ import threading from struct import pack -isPython3 = '3' == sys.version[0] - from PyHT6022.HantekFirmware import custom_firmware_BE, custom_firmware_BL, fx2_ihex_to_control_packets class Oscilloscope(object): @@ -155,7 +153,7 @@ def open_handle(self): if not self.device and not self.setup(): return False self.device_handle = self.device.open() - if self.device_handle.kernelDriverActive(0): + if os.name == 'posix' and self.device_handle.kernelDriverActive(0): self.device_handle.detachKernelDriver(0) self.device_handle.claimInterface(0) if self.is_device_firmware_present: diff --git a/examples/calibrate.py b/examples/calibrate.py index b807e1d..98e9678 100755 --- a/examples/calibrate.py +++ b/examples/calibrate.py @@ -20,7 +20,6 @@ from PyHT6022.LibUsbScope import Oscilloscope -import sys import time import binascii @@ -180,13 +179,15 @@ def read_avg( voltage_range, sample_rate=110, repeat = 1, samples = 12 * 1024 ): if ( create_config ): # write integer offset for low speed sampling into config file + # add this value to get zero calibration voltID = V_div[ index ] if ( abs( offlo1[ gainID ] ) <= 25 ): # offset too high -> skip - config.write( "ch0\\%dmV=%d\n" % ( voltID, 0x80 + offlo1[ gainID ] ) ) + config.write( "ch0\\%dmV=%d\n" % ( voltID, -offlo1[ gainID ] ) ) if ( abs( offlo2[ gainID ] ) <= 25 ): # offset too high -> skip - config.write( "ch1\\%dmV=%d\n" % ( voltID, 0x80 + offlo2[ gainID ] ) ) + config.write( "ch1\\%dmV=%d\n" % ( voltID, -offlo2[ gainID ] ) ) # prepare eeprom content + # store values in offset binary format (zero = 0x80, as in factory setup) if ( abs( offlo1[ gainID ] ) <= 25 ): # offset too high -> skip ee_calibration[ 2 * index ] = 0x80 + offlo1[ gainID ] # CH1 offset integer part if ( abs( offlo_1[ gainID ] ) <= 125 ): # frac part not plausible