Beispiel #1
0
        /// <summary>
        /// Make command log. Write Sent and received data
        /// </summary>
        /// <param name="CommandQueue"></param>
        public void Log(ACommand Command)
        {
            var Now = DateTime.Now;

            using (StreamWriter Writer =
                       new StreamWriter(this.LogFileName, true, Encoding.GetEncoding("utf-8")))
            {
                Writer.WriteLine(
                    Now.ToString("yyyy/MM/dd hh:mm:ss ") +
                    @"Snd: " + Ev3Utility.Buff2String(Command.CmdData));
                Writer.WriteLine(
                    Now.ToString("yyyy/MM/dd hh:mm:ss ") +
                    @"Rcv: " + Ev3Utility.Buff2String(Command.ResData));
            }
        }
        /// <summary>
        /// Handle data sending and response receiving event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public virtual void DataSendAndReceivedFinishedCallback(object sender, EventArgs e)
        {
            if (e is NotifySendReceiveDataEventArgs)
            {
                try
                {
                    var Args = e as NotifySendReceiveDataEventArgs;
                    Console.WriteLine(@"Snd:" + Ev3Utility.Buff2String(Args.SendData));
                    Console.WriteLine(@"Rcv:" + Ev3Utility.Buff2String(Args.RecvData));

                    var Command = Args.Command;
                    var Updater = BrickUpdater.Factory(Command);
                    Updater.Update(Command, Ev3Brick.GetInstance());
                }
                catch (NullReferenceException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }