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

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

            _networkCardType = (NetworkCardTypes)data[2];
            _enableSendMAC   = data[3] == '2' || data[3] == '3';
            _enablePolling   = data[3] == '1' || data[3] == '3';

            int i;

            if (!int.TryParse(data.Substring(4, 2), NumberStyles.None, CultureInfo.InvariantCulture, out i))
            {
                throw new InvalidDataException("Couldn't parse the polling interval from network configuration data.");
            }
            _pollingInterval = TimeSpan.FromSeconds(i);

            _transportType = data[6] == '0' ? TransportType.Tcp : data[6] == '1' ? TransportType.Udp : 0;

            _terminalMACAddress = PhysicalAddress.Parse(data.Substring(7, 12));
            _terminalIPAddress  = new IPAddress(Util.StringToByteArray(data.Substring(19, 8)));
            _gatewayIPAddress   = new IPAddress(Util.StringToByteArray(data.Substring(27, 8)));
            _remoteIPAddress    = new IPAddress(Util.StringToByteArray(data.Substring(35, 8)));
            _subnetMask         = new IPAddress(Util.StringToByteArray(data.Substring(43, 8)));

            if (!int.TryParse(data.Substring(51, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _terminalPort))
            {
                throw new InvalidDataException("Couldn't parse the terminal port number from network configuration data.");
            }

            if (!int.TryParse(data.Substring(56, 5), NumberStyles.None, CultureInfo.InvariantCulture, out _remotePort))
            {
                throw new InvalidDataException("Couldn't parse the remote port number from network configuration data.");
            }

            if (!int.TryParse(data.Substring(61, 5), NumberStyles.None, CultureInfo.InvariantCulture, out i))
            {
                throw new InvalidDataException("Couldn't parse the disconnect time from network configuration data.");
            }
            _disconnectTime = TimeSpan.FromSeconds(i);

            _enableDHCP = data[66] == '1';

            if (!int.TryParse(data.Substring(67, 2), NumberStyles.None, CultureInfo.InvariantCulture, out _networkCardFirmwareVersion))
            {
                throw new InvalidDataException("Couldn't parse the network card firmware version from network configuration data.");
            }

            // TODO: if there's a 70th character - does it mean anything?
        }
コード例 #2
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;
        }
コード例 #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];
        }
コード例 #5
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];
        }