# -*- coding: utf-8 -*-
# перечень кодов ошибок и их описаний, которые могут возникнуть при работе с ридером
# перечень получен для FEIG SDK v.Win-V4.7.0

if __name__ == '__main__':
    # примерный код для получения списка ошибок (не идеальный):
    from collections import OrderedDict
    from reader import Reader
    my_reader = Reader(1, 1)
    result = OrderedDict()
    for i in range(0, -10000, -1):
        _ = my_reader.get_error_text(i)
        if 'Невалидный код ошибки' not in _:
            result.update({i: _})
            # print(i, my_reader.get_error_text(i))
    print('{', *('{}: \'{}\','.format(code, msg) for code, msg in result.items()), '}', sep='\n')


error_codes = {
    0: 'OK',
    -101: 'Error in Module FEDM: Block size in the access constant is incorrect',
    -102: 'Error in Module FEDM: Bit boundary in the access constant is incorrect',
    -103: 'Error in Module FEDM: Byte boundary in the access constant is incorrect',
    -104: 'Error in Module FEDM: Array boundary of a data container was exceeded',
    -105: 'Error in Module FEDM: Length of the data buffer is insufficient',
    -106: 'Error in Module FEDM: Unknown transfer parameter or parameter value is out of valid range',
    -107: 'Error in Module FEDM: Transferred string is too long',
    -108: 'Error in Module FEDM: Transferred string contains an odd number of characters. Even number of characters expected',
    -109: 'Error in Module FEDM: No data in the protocol',
    -110: 'Error in Module FEDM: No reader handle set',
    -111: 'Error in Module FEDM: No port handle set',
    -112: 'Error in Module FEDM: Unknown control byte',
    -113: 'Error in Module FEDM: Unknown memory ID',
    -114: 'Error in Module FEDM: Unknown poll mode',
    -115: 'Error in Module FEDM: No data in a table',
    -117: 'Error in Module FEDM: Unknown ISO-Host command',
    -118: 'Error in Module FEDM: No support for this parameter or function',
    -119: 'Error in Module FEDM: No more program memory available',
    -120: 'Error in Module FEDM: No reader found',
    -121: 'Error in Module FEDM: The transferred pointer is NULL',
    -122: 'Error in Module FEDM: Unknown reader type',
    -123: 'Error in Module FEDM: The Function doesn\'t support this reader type',
    -124: 'Error in Module FEDM: Unknown table constant',
    -125: 'Error in Module FEDM: Unknown language constant',
    -126: 'Error in Module FEDM: The table has the size 0',
    -127: 'Error in Module FEDM: The Sendbuffer is full',
    -128: 'Error in Module FEDM: Data are not equal',
    -129: 'Error in Module FEDM: File open error',
    -130: 'Error in Module FEDM: File save error',
    -131: 'Error in Module FEDM: Unknown transponder type',
    -132: 'Error in Module FEDM: File read error',
    -133: 'Error in Module FEDM: File write error',
    -134: 'Error in Module FEDM: Unknown EPC type',
    -135: 'Error in Module FEDM: Function does not support the active communication driver',
    -136: 'Error in Module FEDM: Unknown address mode',
    -137: 'Error in Module FEDM: Reader object is already connected with a communication port',
    -138: 'Error in Module FEDM: Reader object is not connected with a communication port',
    -139: 'Error in Module FEDM: No module handle found',
    -140: 'Error in Module FEDM: The module list is empty',
    -141: 'Error in Module FEDM: Module not found in module list',
    -142: 'Error in Module FEDM: Runtime objects are different',
    -143: 'Error in Module FEDM: IDD of transponder is not an EPC',
    -144: 'Error in Module FEDM: Old library version. Function call not possible.',
    -145: 'Error in Module FEDM: Wrong reader type',
    -146: 'Error in Module FEDM: Verification of file content terminates with checksum error',
    -147: 'Error in Module FEDM: The CFG-Block must be first read before write',
    -148: 'Error in Module FEDM: Function does not support this controller type',
    -149: 'Error in Module FEDM: Version conflict with one or more dependent libraries',
    -150: 'Error in Module FEDM: Connected reader does not support this parameter',
    -151: 'Error in Module FEDM: Asynchronous task is still running',
    -152: 'Error in Module FEDM: TagHandler type could not be identified',
    -153: 'Error in Module FEDM: Value of IDD-Length is out of range',
    -154: 'Error in Module FEDM: Value of IDD-Format is out of range',
    -155: 'Error in Module FEDM: Unknown TagHandler type',
    -156: 'Error in Module FEDM: Transponder type is not supported by the selected task',
    -157: 'Error in Module FEDM: Another Reader object is already connected with this communication port',
    -158: 'Error in Module FEDM: Inventory with return of UID = EPC + TID, but TID is missing',
    -200: 'Error in Module FEDM_XML: File is not a XML document',
    -201: 'Error in Module FEDM_XML: File contains no element \'OBID\'',
    -202: 'Error in Module FEDM_XML: No sub-element found',
    -203: 'Error in Module FEDM_XML: Element not in the document',
    -204: 'Error in Module FEDM_XML: XML document not well-formed',
    -205: 'Error in Module FEDM_XML: No content of element found',
    -206: 'Error in Module FEDM_XML: No attribute found',
    -207: 'Error in Module FEDM_XML: Unvalid document version',
    -208: 'Error in Module FEDM_XML: The Document is for another reader family',
    -209: 'Error in Module FEDM_XML: The document is not a valid OBID file type',
    -210: 'Error in Module FEDM_XML: Wrong controller type',
    -211: 'Error in Module FEDM_XML: Wrong memory bank type',
    -1000: 'FECOM: (-1000) error while creating new port object',
    -1001: 'FECOM: (-1001) empty port list',
    -1002: 'FECOM: (-1002) pointer is NULL',
    -1003: 'FECOM: (-1003) no more memory',
    -1004: 'FECOM: (-1004) unsupported hardware',
    -1005: 'FECOM: (-1005) port not detected',
    -1006: 'FECOM: (-1006) Unsupported function or option',
    -1010: 'FECOM: (-1010) error while open port',
    -1011: 'FECOM: (-1011) port open timeout',
    -1012: 'FECOM: (-1012) port number is false',
    -1013: 'FECOM: (-1013) port is already open',
    -1020: 'FECOM: (-1020) unknown port handle',
    -1021: 'FECOM: (-1021) port handle is zero',
    -1022: 'FECOM: (-1022) port handle is negativ',
    -1023: 'FECOM: (-1023) no port handle found',
    -1030: 'FECOM: (-1030) receive timeout',
    -1031: 'FECOM: (-1031) no transmit protocol',
    -1032: 'FECOM: (-1032) error in read process',
    -1033: 'FECOM: (-1033) communication process not started',
    -1034: 'FECOM: (-1034) delete input buffer',
    -1035: 'FECOM: (-1035) delete output buffer',
    -1036: 'FECOM: (-1036) change port parameter',
    -1037: 'FECOM: (-1037) error in transmit process',
    -1038: 'FECOM: (-1038) noise data received (Frame and/or Parity is false)',
    -1050: 'FECOM: (-1050) unknown parameter',
    -1051: 'FECOM: (-1051) parameter out of range',
    -1052: 'FECOM: (-1052) odd parameterstring',
    -1053: 'FECOM: (-1053) port number out of range',
    -1070: 'FECOM: (-1070) receive buffer overflow',
    -4001: 'FEISC: (-4001) empty reader list',
    -4002: 'FEISC: (-4002) an internal pointer is NULL',
    -4003: 'FEISC: (-4003) no more memory',
    -4004: 'FEISC: (-4004) unknown communication mode',
    -4005: 'FEISC: (-4005) unsupported function',
    -4006: 'FEISC: (-4006) this operating system supports not USB',
    -4007: 'FEISC: (-4007) old version of FECOM.DLL detectet',
    -4010: 'FEISC: (-4010) no value found',
    -4020: 'FEISC: (-4020) unknown reader handle',
    -4021: 'FEISC: (-4021) reader handle is zero',
    -4022: 'FEISC: (-4022) reader handle is negative',
    -4023: 'FEISC: (-4023) no reader handle found',
    -4024: 'FEISC: (-4024) port handle is negative',
    -4025: 'FEISC: (-4025) unvalid reader handle',
    -4030: 'FEISC: (-4030) protocol length error',
    -4031: 'FEISC: (-4031) checksum error',
    -4032: 'FEISC: (-4032) busy timeout',
    -4033: 'FEISC: (-4033) unknown status byte',
    -4034: 'FEISC: (-4034) no USB receive protocol',
    -4035: 'FEISC: (-4035) false command byte in receive protocol',
    -4036: 'FEISC: (-4036) error in USB protocol transaction',
    -4037: 'FEISC: (-4037) false busaddress in receive protocol',
    -4038: 'FEISC: (-4038) Reader is in power save mode',
    -4050: 'FEISC: (-4050) unknown parameter',
    -4051: 'FEISC: (-4051) parameter out of range',
    -4052: 'FEISC: (-4052) odd parameterstring',
    -4054: 'FEISC: (-4054) unsupported option',
    -4055: 'FEISC: (-4055) Unknown EPC type',
    -4056: 'FEISC: (-4056) parameter is locked',
    -4060: 'FEISC: (-4060) no plug-in module installed',
    -4061: 'FEISC: (-4061) plug-in module already installed',
    -4062: 'FEISC: (-4062) unknown plug-in identifier',
    -4063: 'FEISC: (-4063) error while building data stream',
    -4064: 'FEISC: (-4064) error while building protocol frame',
    -4065: 'FEISC: (-4065) error while split the protocol frame',
    -4066: 'FEISC: (-4066) error while extracting the protocol data',
    -4067: 'FEISC: (-4067) error while getting Plug-in',
    -4068: 'FEISC: (-4068) error while load Plug-in library',
    -4069: 'FEISC: (-4069) error while release Plug-in',
    -4070: 'FEISC: (-4070) receive buffer overflow',
    -4080: 'FEISC: (-4080) asynchronous task is still running',
    -4081: 'FEISC: (-4081) asynchronous task not started',
    -4082: 'FEISC: (-4082) asynchronous task finished with timeout. Reader has sent no reply',
    -4083: 'FEISC: (-4083) error while initializing a socket for asynchronous task',
    -4084: 'FEISC: (-4084) asynchronous task is busy',
    -4085: 'FEISC: (-4085) error in cancelling of asynchronous task',
    -4086: 'FEISC: (-4086) error: Port Number is already in use',
    -4090: 'FEISC: (-4090) error while loading crypto-module',
    -4091: 'FEISC: (-4091) error while crypto initialization',
    -4092: 'FEISC: (-4092) error in authentication process',
    -4093: 'FEISC: (-4093) error in encipher process',
    -4094: 'FEISC: (-4094) error in decipher process',
    -4102: 'FEFU: an internal pointer is NULL',
    -4103: 'FEFU: no more memory',
    -4105: 'FEFU: unsupported function',
    -4130: 'FEFU: protocol length error',
    -4131: 'FEFU: checksum error',
    -4132: 'FEFU: Timeout',
    -4133: 'FEFU: unknown status',
    -4134: 'FEFU: no receive protocol',
    -4150: 'FEFU: unknown parameter',
    -4151: 'FEFU: parameter out of range',
    -4201: 'FETCL: Empty transponder liste.',
    -4202: 'FETCL: Internal NULL Pointer.',
    -4203: 'FETCL: Not enough memory.',
    -4204: 'FETCL: Unknown communication mode.',
    -4205: 'FETCL: Function is not supported.',
    -4206: 'FETCL: This operating system does not support USB.',
    -4207: 'FETCL: Outdated version of FECOM.DLL detected.',
    -4208: 'FETCL: The Error-File could not be opened.',
    -4209: 'FETCL: Another APDU is currently being processed.',
    -4210: 'FETCL: No value found.',
    -4220: 'FETCL: Unknown handle.',
    -4221: 'FETCL: The handle is 0.',
    -4222: 'FETCL: Negative handle.',
    -4223: 'FETCL: Handle not found.',
    -4224: 'FETCL: Negative transponder handle.',
    -4226: 'FETCL: Negative reader handle.',
    -4227: 'FETCL: Thread not created.',
    -4230: 'FETCL: Potocol length error.',
    -4231: 'FETCL: Checksum error.',
    -4232: 'FETCL: Busy timeout.',
    -4233: 'FETCL: Unknown status byte.',
    -4234: 'FETCL: Response protocol not received.',
    -4235: 'FETCL: Invalid control byte in the response protocol.',
    -4236: 'FETCL: Protocol transmission error.',
    -4237: 'FETCL: Invalid bus address in the reciept protocol.',
    -4238: 'FETCL: Port Timeout during Receive.',
    -4250: 'FETCL: Unknown parameter.',
    -4251: 'FETCL: Parameter out of range.',
    -4252: 'FETCL: Odd parameter string.',
    -4254: 'FETCL: Option is not supported.',
    -4255: 'FETCL: Unknown EPC type.',
    -4256: 'FETCL: Unknown Language.',
    -4257: 'FETCL: Undersized Response Buffer.',
    -4258: 'FETCL: Illegal Cache Size (<=0).',
    -4260: 'FETCL: No Plug-In module installed.',
    -4261: 'FETCL: Plug-In module already installed.',
    -4262: 'FETCL: Unknown Plug-In identifier.',
    -4263: 'FETCL: Error during data stream production.',
    -4264: 'FETCL: Error during protocol frame production.',
    -4265: 'FETCL: Error during protocol frame analysis.',
    -4266: 'FETCL: Error during protocol data extraction.',
    -4270: 'FETCL: Reciept Buffer overflow.',
    -4271: 'FETCL: Response length to large,',
    -4272: 'FETCL: Invalid Acknowledgement.',
    -4273: 'FETCL: Invalid Acknowledgement length.',
    -4274: 'FETCL: Response List not Complete.',
    -4275: 'FETCL: Response not Complete.',
    -4276: 'FETCL: Invalid Protocol.',
    -4277: 'FETCL: Invalid Transmission',
    -4280: 'CPR:	0x00	OK',
    -4281: 'CPR:	0x01	No Transponder',
    -4282: 'CPR:	0x02	Data False',
    -4283: 'CPR:	0x03	Write Error',
    -4284: 'CPR:	0x04	Address Error',
    -4285: 'CPR:	0x05	Wrong Transponder Type',
    -4286: 'CPR:	0x08	Authentication Error',
    -4287: 'CPR:	0x09	Insufficient Power',
    -4288: 'CPR:	0x0E	General Error',
    -4289: 'CPR:	0x10	EEPROM Failure',
    -4290: 'CPR:	0x11	Parameter Range Error',
    -4291: 'CPR:	0x80	Unknown Command',
    -4292: 'CPR:	0x81	Length Error',
    -4293: 'CPR:	0x82	Command not Available',
    -4294: 'CPR:	0x83	RF communication Error',
    -4295: 'CPR:	0x94	More Data',
}
