//TODO Desctructor to set off buzzer private void KeyUp() { while (true) { if (Display.Terminate) { break; } if (serialPort.BytesToRead == 0) { if (stack.Count == 0) { System.Threading.Thread.Sleep(100); continue; } } else { String s = serialPort.ReadExisting(); if (s.StartsWith("%") || s.StartsWith(";")) { System.Threading.Thread.Sleep(25); stack.Add(s + serialPort.ReadExisting()); } else { if (s.StartsWith("135")) { List <string> tmp = new List <string>(); tmp.AddRange(s.Split(' ')); foreach (var item in tmp) { if (item == "135") { stack.Add(item); continue; } if (item.Contains("135") && item.EndsWith("135") && !(item.StartsWith("135"))) { if (item.Length == 4) { stack.Add(item.Substring(0, 1)); stack.Add(item.Remove(0, 1)); continue; } else if (item.Length == 5) { stack.Add(item.Substring(0, 2)); stack.Add(item.Remove(0, 2)); continue; } else { stack.Add(item); continue; } } else { stack.Add(item); continue; } } } else { stack.AddRange(s.Split(' ')); } } } try { String input = ReadNext(); //if starts with Z means that unexpected data received (or shift) if (input.StartsWith("Z") && input.Length > 2) { input = input.Substring(1); } //if sale led is on-off (led data comes before key data) if (input.StartsWith("?") && input.IndexOf('&') > 0) { input = input.Substring(input.IndexOf('&') + 1); } //if online led is on-off (led data comes before key data) if (input.StartsWith("½") && input.IndexOf('&') > 0) { input = input.Substring(input.IndexOf('&') + 1); } if (input.Length == 0) { continue; } try { int keyValue = -1; switch (input) { case "135": input = "L" + ReadNext(); break; //label case "67": input = "C" + (char)Convert.ToInt32(ReadNext()); break; //credit case "201": input = "EFT"; break; // EFT on Credit1 case "35": input = "K" + (char)Convert.ToInt32(ReadNext()); break; //keylock case "28": input = "Escape"; break; //Escape default: if (Parser.TryInt(input, out keyValue)) { input = ((ConsoleKey)keyValue).ToString(); break; } String cardCode = input; if ((cardCode = KeyMap.IsCard(input)) != input) { ConsumeKey(this, new ConsumeKeyEventArgs((int)PosKey.MagstripeStx)); foreach (Char c in cardCode) { if (!System.Text.RegularExpressions.Regex.IsMatch("" + c, "[0-9A-Za-z]")) { break; } ConsumeKey(this, new ConsumeKeyEventArgs((int)c)); } input = "Enter"; break; } continue; } PosKey key = KeyMap.Get(input); if (key == PosKey.UndefinedKey && keyValue > -1) { key = KeyMap.Get(48 + keyValue + ""); } ConsumeKey(this, new ConsumeKeyEventArgs((int)key)); //stack = new List<string>(); } catch { continue; } //finally { stack = new List<string>(); } } catch (TimeoutException) { Display.Log.Error("Timeout exception on serial keyboard"); } catch (Exception e) { Display.Log.Error(e); } } }