Exemplo n.º 1
0
            public string GetString(bool masked, OnPressWorker worker)
            {
                byte[] command = new byte[255], cleanBuffer = new byte[80];
                int index = 0, cmdLen = 0, cleanLen = 0;
                var cursorPosition = 0;

                do
                {
                    //while(_serial.BytesToRead == 0) { Thread.Sleep(500); }
                    var readLength = Read(command, index, command.Length - index);
                    if(masked)
                        Write(new string('*', readLength));
                    else
                        Write(command, index, readLength);

                    //Console.WriteLine(BitConverter.ToString(command, index, readLength));

                    var searchStart = 0;
                    int escapeIndex;
                    while((escapeIndex = Array.IndexOf<byte>(command, Ascii.ESC, searchStart)) != -1)
                    {
                        if(Restart != null && command[escapeIndex + 1] == Ascii.O)
                        {
                            Restart(this, EventArgs.Empty);
                            return null;
                        }
                        searchStart = escapeIndex + 1;
                    }

                    index += readLength;

                    if(worker != null) {
                        cleanLen = Unescape(command, 0, index, cleanBuffer);
                        worker(Encoding.ASCII.GetString(cleanBuffer, 0, cleanLen), this);
                    }

                } while ((cmdLen = Array.IndexOf(command, Ascii.CR)) == -1);

                if(masked)
                    Write(new [] { Ascii.BS, Ascii.SP, Ascii.CR, Ascii.LF}, 0, 4);

                cleanLen = Unescape(command, 0, cmdLen, cleanBuffer);
                return Encoding.ASCII.GetString(cleanBuffer, 0, cleanLen).ToUpper();
            }
Exemplo n.º 2
0
 public string GetString(OnPressWorker worker)
 {
     return GetString(false);
 }