Пример #1
0
 private void ScanTimeout(object sender, EventArgs e)
 {
     TriggerDown();
     _dtimer.Stop();
     ScannerErrorEvent?.Invoke(this, new ScannerErrorEventArgs(ErrorCodeDictionary.DataReadErrors.ReadTimeout, "Timeout odczytu danych ze skanera"));
     CloseConnection();
 }
Пример #2
0
        private void OpenConnection()
        {
            _sPort?.Open();

            if (_sPort != null && !_sPort.IsOpen)
            {
                ScannerErrorEvent?.Invoke(this, new ScannerErrorEventArgs(ErrorCodeDictionary.DataReadErrors.ConnectionNotEstabilished, "Błąd nawiązywania połączenia ze skanerem \nSkaner nie podłączony lub błędna konfiguracja"));
            }
        }
Пример #3
0
        public void Break()
        {
            if (_sPort != null)
            {
                if (_sPort.IsOpen)
                {
                    TriggerDown();
                }
            }

            _dtimer.Stop();
            CloseConnection();

            ScannerErrorEvent?.Invoke(this, new ScannerErrorEventArgs(ErrorCodeDictionary.DataReadErrors.ReadTimeout, ""));
        }
Пример #4
0
        private void InterpreteFrame(byte[] bytes, int length)
        {
            var mLength = bytes[0];

            if (length == mLength) //Configuration frame
            {
                if (bytes[1] == SsiMessages.GetCheckSumErrorVal())
                {
                    ScannerErrorEvent?.Invoke(this, new ScannerErrorEventArgs(ErrorCodeDictionary.DataReadErrors.CheckSumError, "Błąd sumy kontrolnej w komunikacji SSI"));
                }
            }
            else // Barcode
            {
                var codeBytes = new byte[length];
                Array.Copy(bytes, 0, codeBytes, 0, length);
                var barcode = Encoding.ASCII.GetString(codeBytes);
                _dtimer.Stop();
                CloseConnection();
                CompareCode(barcode);
            }
        }
Пример #5
0
        private void _sPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            var sPort = (SerialPort)sender;
            var lData = new List <byte>();

            Thread.Sleep(10); //Wait for data to arrive in the recieve buffer

            try
            {
                while (sPort.BytesToRead > 0)
                {
                    lData.Add((byte)sPort.ReadByte());
                    Thread.Sleep(1);
                }

                InterpreteFrame(lData.ToArray(), lData.Count);
            }
            catch (Exception ex)
            {
                ScannerErrorEvent?.Invoke(this, new ScannerErrorEventArgs(ErrorCodeDictionary.DataReadErrors.ReadTimeout, ""));
            }
        }
Пример #6
0
        private void CompareCode(string barcode)
        {
            if (_mode == ErrorCodeDictionary.ReadMode.CodeCompare)
            {
                if (string.Compare(barcode, _codeToCompare, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    ReadedCodeEvent?.Invoke(this, new ReadedCodeEventArgs(barcode)); // RaiseEvent ReadedCode (barcode);
                }
                else
                {
                    ScannerErrorEvent?.Invoke(this, new ScannerErrorEventArgs(ErrorCodeDictionary.DataReadErrors.CodeNotCorrect, ""));
                    _dtimer?.Stop();
                }
            }
            else
            {
                ReadedCodeEvent?.Invoke(this, new ReadedCodeEventArgs(barcode)); // RaiseEvent ReadedCode (barcode);
            }

            _dtimer?.Stop();
            CloseConnection();
        }
Пример #7
0
 private void SendMessage(byte[] message)
 {
     try
     {
         if (_sPort == null)
         {
             throw new Exception("Błąd podczas wysyłania komunikatu do skanera");
         }
         if (!_sPort.IsOpen)
         {
             OpenConnection();
         }
         _sPort.BaseStream.Flush();
         _sPort.Write(message, 0, message.Length);
     }
     catch (Exception ex)
     {
         ScannerErrorEvent?.Invoke(this, new ScannerErrorEventArgs(ErrorCodeDictionary.DataReadErrors.ConnectionNotEstabilished, ex.Message));
         _dtimer?.Stop();
         CloseConnection();
     }
 }