コード例 #1
0
        private HardwareConfiguration(string data)
        {
            var subcode = data.Substring(0, 2);

            if (subcode != "HG")
            {
                throw new InvalidDataException(
                          string.Format("Expected sub-code of \"{0}\" but got \"{1}\".", "HG", subcode));
            }

            if (!int.TryParse(data.Substring(2, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _firmwareVersion))
            {
                throw new InvalidDataException("Couldn't parse firmware version from hardware configuration data.");
            }

            if (!DateTime.TryParseExact(data.Substring(8, 10), "dd.MM.yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out _firmwareDate))
            {
                throw new InvalidDataException("Couldn't parse firmware date from hardware configuration data.");
            }

            // TODO: what does 18 represent?

            _terminalType         = (TerminalTypes)data[19];
            _keyboardType         = (KeyboardTypes)data[20];
            _displayType          = (DisplayTypes)data[21];
            _hostSerialParameters = data.Substring(22, 3);

            byte b;

            if (!byte.TryParse(data.Substring(25, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b))
            {
                throw new InvalidDataException("Couldn't parse host serial baud rate from hardware configuration data.");
            }
            _hostSerialBaudRate = BaudRates.Get(b);

            _terminalId = Util.CharToTerminalId(data[26]);

            // TODO: what does 27 represent?  Maybe the network card type?

            if (!byte.TryParse(data.Substring(28, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _fingerprintUnitType))
            {
                throw new InvalidDataException("Couldn't parse fingerprint unit type from hardware configuration data.");
            }

            _fingerprintUnitMode = (FingerprintUnitModes)data[29];

            if (!int.TryParse(data.Substring(30, 4), NumberStyles.None, CultureInfo.InvariantCulture, out _userDefinedField))
            {
                throw new InvalidDataException("Couldn't parse user defined field from hardware configuration data.");
            }
        }
コード例 #2
0
 public override string ToString()
 {
     return(string.Format("HPS{0:D2}{1}{2}{3}{4}{5}{6}{7}{8}",
                          _terminalId,
                          (byte)_serialPort0Mode,
                          (byte)_serialPort1Mode,
                          (byte)_serialPort2Mode,
                          BaudRates.IndexOf(_serialPort0BaudRate),
                          BaudRates.IndexOf(_serialPort1BaudRate),
                          BaudRates.IndexOf(_serialPort2BaudRate),
                          _hasModem ? _modemRingsToAnswer.ToString(CultureInfo.InvariantCulture) : "N",
                          (char)_networkCardType
                          ));
 }
コード例 #3
0
        public TechnicianModeSettings(byte terminalId = 0,
                                      SerialPortModes serialPort0Mode = SerialPortModes.Host,
                                      SerialPortModes serialPort1Mode = SerialPortModes.FingerprintUnit,
                                      SerialPortModes serialPort2Mode = SerialPortModes.Printer,
                                      int serialPort0BaudRate         = 19200,
                                      int serialPort1BaudRate         = 57600,
                                      int serialPort2BaudRate         = 19200,
                                      bool hasModem                    = false,
                                      byte modemRingsToAnswer          = 0,
                                      NetworkCardTypes networkCardType = NetworkCardTypes.F_Ethernet100Mbps)
        {
            if (terminalId > 31)
            {
                throw new ArgumentException("Invalid Terminal ID.  Terminal ID should be 0 to 31.", "terminalId");
            }
            _terminalId = terminalId;

            if (serialPort0Mode != SerialPortModes.Host)
            {
                throw new ArgumentException("Invalid mode for serial port 0.", "serialPort0Mode");
            }
            _serialPort0Mode = serialPort0Mode;

            if (serialPort1Mode != SerialPortModes.FingerprintUnit && serialPort1Mode != SerialPortModes.CardReader)
            {
                throw new ArgumentException("Invalid mode for serial port 1.", "serialPort1Mode");
            }
            _serialPort1Mode = serialPort1Mode;

            if (serialPort2Mode != SerialPortModes.Printer && serialPort2Mode != SerialPortModes.CardReader)
            {
                throw new ArgumentException("Invalid mode for serial port 2.", "serialPort2Mode");
            }
            _serialPort2Mode = serialPort2Mode;

            if (!BaudRates.IsValid(serialPort0BaudRate))
            {
                throw new ArgumentException("Invalid baud rate for serial port 0.", "serialPort0BaudRate");
            }
            _serialPort0BaudRate = serialPort0BaudRate;

            if (!BaudRates.IsValid(serialPort1BaudRate))
            {
                throw new ArgumentException("Invalid baud rate for serial port 1.", "serialPort1BaudRate");
            }
            _serialPort1BaudRate = serialPort1BaudRate;

            if (!BaudRates.IsValid(serialPort2BaudRate))
            {
                throw new ArgumentException("Invalid baud rate for serial port 2.", "serialPort2BaudRate");
            }
            _serialPort2BaudRate = serialPort2BaudRate;

            _hasModem = hasModem;
            if (hasModem)
            {
                if (modemRingsToAnswer > 9)
                {
                    throw new ArgumentException("Modem rings to answer must be 0 through 9", "modemRingsToAnswer");
                }
                _modemRingsToAnswer = modemRingsToAnswer;
            }

            if (!Enum.IsDefined(typeof(NetworkCardTypes), networkCardType))
            {
                throw new ArgumentException("Invalid network card type.", "networkCardType");
            }
            _networkCardType = networkCardType;
        }
コード例 #4
0
        private TechnicianModeSettings(string data)
        {
            var subcode = data.Substring(0, 3);

            if (subcode != "HPG")
            {
                throw new InvalidDataException(
                          string.Format("Expected sub-code of \"{0}\" but got \"{1}\".", "HPG", subcode));
            }

            if (!byte.TryParse(data.Substring(3, 2), NumberStyles.None, CultureInfo.InvariantCulture, out _terminalId))
            {
                throw new InvalidDataException("Couldn't parse terminal id from technician mode settings data.");
            }

            byte b;

            if (!byte.TryParse(data.Substring(5, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b))
            {
                throw new InvalidDataException("Couldn't parse serial port 0 mode from technician mode settings data.");
            }
            _serialPort0Mode = (SerialPortModes)b;

            if (!byte.TryParse(data.Substring(6, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b))
            {
                throw new InvalidDataException("Couldn't parse serial port 1 mode from technician mode settings data.");
            }
            _serialPort1Mode = (SerialPortModes)b;

            if (!byte.TryParse(data.Substring(7, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b))
            {
                throw new InvalidDataException("Couldn't parse serial port 2 mode from technician mode settings data.");
            }
            _serialPort2Mode = (SerialPortModes)b;

            if (!byte.TryParse(data.Substring(8, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b))
            {
                throw new InvalidDataException("Couldn't parse serial port 0 baud rate from technician mode settings data.");
            }
            _serialPort0BaudRate = BaudRates.Get(b);

            if (!byte.TryParse(data.Substring(9, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b))
            {
                throw new InvalidDataException("Couldn't parse serial port 1 baud rate from technician mode settings data.");
            }
            _serialPort1BaudRate = BaudRates.Get(b);

            if (!byte.TryParse(data.Substring(10, 1), NumberStyles.None, CultureInfo.InvariantCulture, out b))
            {
                throw new InvalidDataException("Couldn't parse serial port 2 baud rate from technician mode settings data.");
            }
            _serialPort2BaudRate = BaudRates.Get(b);

            _hasModem = data[11] != 'N';
            if (_hasModem)
            {
                if (!byte.TryParse(data.Substring(11, 1), NumberStyles.None, CultureInfo.InvariantCulture, out _modemRingsToAnswer))
                {
                    throw new InvalidDataException("Couldn't parse modem rings to answer from technician mode settings data.");
                }
            }

            _networkCardType = (NetworkCardTypes)data[12];
        }