# Path: FabLabKasse/cashPayment/server/hex.py
# def hex(x):
#     if type(x) in [int, long]:
#         if x < 0:
#             return str(x)
#         else:
#             return '0x%02X' % (x)
#     elif type(x) == list:
#         return "[" + ", ".join([hex(val) for val in x]) + "]"
#     else:
#         return str(x)


import serial
import copy
import time
import traceback
import Crypto.Cipher.AES
import Crypto.Random.random
import logging
import unittest
from crc_algorithms import Crc
from ..hex import hex
        if encrypted:
            self.debug2("encrypting command, original data:" + hex(data))
            data = self.encryptData(data)
            self.debug2("encrypted data:" + hex(data))
        time.sleep(0.25)
        self.flushRead()
        self.send(data)
        num_retries = 3
        for _ in range(num_retries):
            for __ in range(20):
                time.sleep(0.01)
                r = self.read()
                if r is not False:
                    break
            if encrypted:
                if r is not False and r.isEncrypted():
                    r = self.decryptResponse(r)
                else:
                    if r is False:
                        self.log("response timeout")
                    else:
                        self.log("unsuccessful response: " + str(r))
            if r is False:
                self.warn("Timeout or CRC/Crypto error -- resend necessary (not fatal, this may happen rarely)")
                self.resendLast()
                continue
            if not r.isOkay():
                self.warn("got response with error status:" + str(r))
                if not (r.isSoftFail() and allowSoftFail):
                    self.error(("Command failed: Cmd " + hex(data) + ", Resp " + str(r)))

# Path: FabLabKasse/cashPayment/server/hex.py
# def hex(x):
#     if type(x) in [int, long]:
#         if x < 0:
#             return str(x)
#         else:
#             return '0x%02X' % (x)
#     elif type(x) == list:
#         return "[" + ", ".join([hex(val) for val in x]) + "]"
#     else:
#         return str(x)


# Path: FabLabKasse/cashPayment/server/NV11/NV11Device.py
import serial
import copy
import time
import traceback
import Crypto.Cipher.AES
import Crypto.Random.random
import logging
import unittest
from crc_algorithms import Crc
from ..hex import hex

        if encrypted:
            self.debug2("encrypting command, original data:" + hex(data))
            data = self.encryptData(data)
            self.debug2("encrypted data:" + hex(data))
        time.sleep(0.25)
        self.flushRead()
        self.send(data)
        num_retries = 3
        for _ in range(num_retries):
            for __ in range(20):
                time.sleep(0.01)
                r = self.read()
                if r is not False:
                    break
            if encrypted:
                if r is not False and r.isEncrypted():
                    r = self.decryptResponse(r)
                else:
                    if r is False:
                        self.log("response timeout")
                    else:
                        self.log("unsuccessful response: " + str(r))
            if r is False:
                self.warn("Timeout or CRC/Crypto error -- resend necessary (not fatal, this may happen rarely)")
                self.resendLast()
                continue
            if not r.isOkay():
                self.warn("got response with error status:" + str(r))
                if not (r.isSoftFail() and allowSoftFail):
                    self.error(("Command failed: Cmd " + hex(data) + ", Resp " + str(r)))

                    raise Exception("Command failed: Cmd " + hex(data) + ", Resp " + str(r))