Esempio n. 1
0
        static int NumberOfCharacters = 32; // 16 + 16

        #endregion Fields

        #region Methods

        public static void Main(string[] args)
        {
            while (true) {
                /*try {
                Console.WriteLine ("Insert number of characters(default 32), empty to use default:");
                String _numberOfCharacters = Console.ReadLine ();
                if (_numberOfCharacters != String.Empty) {
                    NumberOfCharacters = int.Parse (_numberOfCharacters);
                }*/
                try {
                    Console.WriteLine ("Insert frametime in ms(default 110), empty to use default:");
                    String _FrameTime = Console.ReadLine ();
                    if (_FrameTime != String.Empty) {
                        FrameTime = int.Parse (_FrameTime);
                    }

                    Console.WriteLine ("Message to send here: ");
                    String MessageToSend = Console.ReadLine ();

                    //Trim string if it is too long
                    if (MessageToSend.Length > NumberOfCharacters) {
                        MessageToSend.Remove (NumberOfCharacters - 1);
                    }

                    using (SerialPortDisposable mySerialPort = new SerialPortDisposable(ComPort)) {
                        lock (mySerialPort) {
                            mySerialPort.OpenPort ();

                            StringBuilder sb = new StringBuilder ();

                            while (true) {
                                //Start sequence
                                for (int h = 0; h < MessageToSend.Length; h++) {
                                    sb.Clear ();
                                    sb.Append (MessageToSend.Substring(MessageToSend.Length-h)).Append (' ', NumberOfCharacters - h);
                                    mySerialPort.SendFunc (sb.ToString());
                                    WriteScreen (sb.ToString(), mySerialPort.ReadFunc (), 2, NumberOfCharacters / 2);
                                    Thread.Sleep (FrameTime);
                                }

                                //Main sequence
                                for (int i = 0; i < NumberOfCharacters-MessageToSend.Length+1; i++) {
                                    sb.Clear ();
                                    sb.Append (' ', i).Append (MessageToSend).Append (' ', NumberOfCharacters - MessageToSend.Length - i);
                                    mySerialPort.SendFunc (sb.ToString());
                                    WriteScreen (sb.ToString(), mySerialPort.ReadFunc (), 2, NumberOfCharacters / 2);
                                    Thread.Sleep (FrameTime);
                                }

                                //End sequence
                                for (int k = 1; k <= MessageToSend.Length; k++) {
                                    sb.Clear ();
                                    String Word2 = MessageToSend.Remove (MessageToSend.Length - k);
                                    sb.Append (' ', NumberOfCharacters - Word2.Length).Append (Word2);
                                    mySerialPort.SendFunc (sb.ToString());
                                    WriteScreen (sb.ToString(), mySerialPort.ReadFunc (), 2, NumberOfCharacters / 2);
                                    Thread.Sleep (FrameTime);
                                }
                            }

                            mySerialPort.Close ();
                        }
                    }
                } catch (Exception ex) {
                    Console.WriteLine (ex.ToString());
                } finally {

                }
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            while (true)
            {
                /*try {
                 * Console.WriteLine ("Insert number of characters(default 32), empty to use default:");
                 * String _numberOfCharacters = Console.ReadLine ();
                 * if (_numberOfCharacters != String.Empty) {
                 *      NumberOfCharacters = int.Parse (_numberOfCharacters);
                 * }*/
                try {
                    Console.WriteLine("Insert frametime in ms(default 110), empty to use default:");
                    String _FrameTime = Console.ReadLine();
                    if (_FrameTime != String.Empty)
                    {
                        FrameTime = int.Parse(_FrameTime);
                    }

                    Console.WriteLine("Message to send here: ");
                    String MessageToSend = Console.ReadLine();

                    //Trim string if it is too long
                    if (MessageToSend.Length > NumberOfCharacters)
                    {
                        MessageToSend.Remove(NumberOfCharacters - 1);
                    }

                    using (SerialPortDisposable mySerialPort = new SerialPortDisposable(ComPort)) {
                        lock (mySerialPort) {
                            mySerialPort.OpenPort();

                            StringBuilder sb = new StringBuilder();

                            while (true)
                            {
                                //Start sequence
                                for (int h = 0; h < MessageToSend.Length; h++)
                                {
                                    sb.Clear();
                                    sb.Append(MessageToSend.Substring(MessageToSend.Length - h)).Append(' ', NumberOfCharacters - h);
                                    mySerialPort.SendFunc(sb.ToString());
                                    WriteScreen(sb.ToString(), mySerialPort.ReadFunc(), 2, NumberOfCharacters / 2);
                                    Thread.Sleep(FrameTime);
                                }

                                //Main sequence
                                for (int i = 0; i < NumberOfCharacters - MessageToSend.Length + 1; i++)
                                {
                                    sb.Clear();
                                    sb.Append(' ', i).Append(MessageToSend).Append(' ', NumberOfCharacters - MessageToSend.Length - i);
                                    mySerialPort.SendFunc(sb.ToString());
                                    WriteScreen(sb.ToString(), mySerialPort.ReadFunc(), 2, NumberOfCharacters / 2);
                                    Thread.Sleep(FrameTime);
                                }

                                //End sequence
                                for (int k = 1; k <= MessageToSend.Length; k++)
                                {
                                    sb.Clear();
                                    String Word2 = MessageToSend.Remove(MessageToSend.Length - k);
                                    sb.Append(' ', NumberOfCharacters - Word2.Length).Append(Word2);
                                    mySerialPort.SendFunc(sb.ToString());
                                    WriteScreen(sb.ToString(), mySerialPort.ReadFunc(), 2, NumberOfCharacters / 2);
                                    Thread.Sleep(FrameTime);
                                }
                            }

                            mySerialPort.Close();
                        }
                    }
                } catch (Exception ex) {
                    Console.WriteLine(ex.ToString());
                } finally {
                }
            }
        }