Add package in imports.
This commit is contained in:
parent
93a226ff79
commit
fe232de1b7
|
@ -27,7 +27,7 @@
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
from _exceptions import MalformedDataError
|
from librfid._exceptions import MalformedDataError
|
||||||
|
|
||||||
|
|
||||||
def inventory(response):
|
def inventory(response):
|
||||||
|
|
32
models.py
32
models.py
|
@ -23,20 +23,22 @@
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
import utils
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import core_standard
|
|
||||||
|
|
||||||
from serial import (Serial, EIGHTBITS, PARITY_NONE, STOPBITS_ONE)
|
from serial import (Serial, EIGHTBITS, PARITY_NONE, STOPBITS_ONE)
|
||||||
from _exceptions import (UnknownReaderTypeException, UnknownReaderException,
|
|
||||||
|
|
||||||
|
import librfid.core_standard
|
||||||
|
|
||||||
|
|
||||||
|
from librfid.utils import get_length_on_2_bytes, get_crc_16_CCITT
|
||||||
|
from librfid._exceptions import (UnknownReaderTypeException, UnknownReaderException,
|
||||||
BadLengthMessageException, BadCRCException,
|
BadLengthMessageException, BadCRCException,
|
||||||
CommandResponseCodeMismatchException, UnknownReaderException,
|
CommandResponseCodeMismatchException, UnknownReaderException,
|
||||||
StandardResponseError, UnknownResponseErrorType,
|
StandardResponseError, UnknownResponseErrorType,
|
||||||
ReaderResponseError)
|
ReaderResponseError)
|
||||||
from commands_standard import COMMANDS as STANDARD_COMMANDS
|
from librfid.commands_standard import COMMANDS as STANDARD_COMMANDS
|
||||||
from errors_standard import ERRORS as STANDARD_ERRORS
|
from librfid.errors_standard import ERRORS as STANDARD_ERRORS
|
||||||
from reader_configs import READERS
|
from librfid.reader_configs import READERS
|
||||||
|
|
||||||
|
|
||||||
class RFIDReader():
|
class RFIDReader():
|
||||||
|
@ -155,7 +157,7 @@ class Command():
|
||||||
self.data = kwargs.pop('data', '')
|
self.data = kwargs.pop('data', '')
|
||||||
if self.data:
|
if self.data:
|
||||||
self.process_data()
|
self.process_data()
|
||||||
self.lout = utils.get_length_on_2_bytes(self.raw_data)
|
self.lout = get_length_on_2_bytes(self.raw_data)
|
||||||
self.command = self.rfu + self.type_cmd + self.code_cmd + \
|
self.command = self.rfu + self.type_cmd + self.code_cmd + \
|
||||||
self.reserved + self.lout + self.raw_data
|
self.reserved + self.lout + self.raw_data
|
||||||
|
|
||||||
|
@ -164,17 +166,17 @@ class Command():
|
||||||
|
|
||||||
def process_data(self):
|
def process_data(self):
|
||||||
try:
|
try:
|
||||||
getattr(core_standard, self.command_name.lower())(self)
|
getattr(librfid.core_standard, self.command_name.lower())(self)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def build_message(self):
|
def build_message(self):
|
||||||
self.sof = '\x02'
|
self.sof = '\x02'
|
||||||
self.length = utils.get_length_on_2_bytes(self.command)
|
self.length = get_length_on_2_bytes(self.command)
|
||||||
self.ctrl_addr = '\x00' # RS232 only
|
self.ctrl_addr = '\x00' # RS232 only
|
||||||
self.ctrl_mode = '\x00' # Unsecure mode
|
self.ctrl_mode = '\x00' # Unsecure mode
|
||||||
message = self.length + self.ctrl_addr + self.ctrl_mode + self.command
|
message = self.length + self.ctrl_addr + self.ctrl_mode + self.command
|
||||||
self.crc = utils.get_crc_16_CCITT(message)
|
self.crc = get_crc_16_CCITT(message)
|
||||||
self.message = self.sof + message + self.crc
|
self.message = self.sof + message + self.crc
|
||||||
|
|
||||||
def get_message(self):
|
def get_message(self):
|
||||||
|
@ -227,7 +229,7 @@ class ReaderCommand(Command):
|
||||||
self.data = kwargs.pop('data', '')
|
self.data = kwargs.pop('data', '')
|
||||||
if self.data:
|
if self.data:
|
||||||
self.process_data()
|
self.process_data()
|
||||||
self.lout = utils.get_length_on_2_bytes(self.raw_data)
|
self.lout = get_length_on_2_bytes(self.raw_data)
|
||||||
self.command = self.rfu + self.type_cmd + self.code_cmd + \
|
self.command = self.rfu + self.type_cmd + self.code_cmd + \
|
||||||
self.reserved + self.lout + self.raw_data
|
self.reserved + self.lout + self.raw_data
|
||||||
|
|
||||||
|
@ -259,7 +261,7 @@ class Response():
|
||||||
self.response = message[5:-2]
|
self.response = message[5:-2]
|
||||||
self.crc = message[-2:]
|
self.crc = message[-2:]
|
||||||
str_to_check = self.message[1:-2] # [Len ... Commande]
|
str_to_check = self.message[1:-2] # [Len ... Commande]
|
||||||
crc = utils.get_crc_16_CCITT(str_to_check)
|
crc = get_crc_16_CCITT(str_to_check)
|
||||||
if self.crc != crc:
|
if self.crc != crc:
|
||||||
raise BadCRCException('CRC checking failed')
|
raise BadCRCException('CRC checking failed')
|
||||||
self.code = self.response[0:2]
|
self.code = self.response[0:2]
|
||||||
|
@ -313,7 +315,7 @@ class Response():
|
||||||
if isinstance(self.command, ReaderCommand):
|
if isinstance(self.command, ReaderCommand):
|
||||||
module = self.command.reader.core
|
module = self.command.reader.core
|
||||||
else:
|
else:
|
||||||
module = core_standard
|
module = librfid.core_standard
|
||||||
getattr(module, core_method_name)(self)
|
getattr(module, core_method_name)(self)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -22,10 +22,10 @@
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
from stid_readers.commands_basic import COMMANDS as BASIC_STID_COMMANDS
|
from librfid.stid_readers.commands_basic import COMMANDS as BASIC_STID_COMMANDS
|
||||||
from stid_readers.params_basic import PARAMS as BASIC_STID_PARAMS
|
from librfid.stid_readers.params_basic import PARAMS as BASIC_STID_PARAMS
|
||||||
from stid_readers.errors_basic import ERRORS as BASIC_STID_ERRORS
|
from librfid.stid_readers.errors_basic import ERRORS as BASIC_STID_ERRORS
|
||||||
from stid_readers import core as BASIC_STID_CORE
|
from librfid.stid_readers import core as BASIC_STID_CORE
|
||||||
|
|
||||||
|
|
||||||
READERS = {
|
READERS = {
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
|
||||||
from _exceptions import MalformedDataError, BadParameterException
|
from librfid._exceptions import MalformedDataError, BadParameterException
|
||||||
from utils import get_integer_on_two_bytes, hex_to_int
|
from librfid.utils import get_integer_on_two_bytes, hex_to_int
|
||||||
|
|
||||||
|
|
||||||
def get_rfsettings(response):
|
def get_rfsettings(response):
|
||||||
|
|
Reference in New Issue