private void WriteLog(Package package)
 {
     #if DEBUG
     var dt = DateTime.Now;
     _writer.Write(dt.ToString("mm:ss.fff") + "    :    ");
     _writer.WriteLine(package.ToString());
     _writer.Flush();
     #endif
 }
 public void SetTime(TimeSpan time)
 {
     var frame = _sequence.FrameByTime(time);
     if (frame != null)
     {
         Console.WriteLine("{0}", (time - prevTime).TotalSeconds);
         //---
         var pkg = new Package(frame.Command.GetBytes());
         _sender.SendPackage(pkg);
     }
 }
        public void ProcessCurrentFrame()
        {
            var frame = CreateFrame(0, 2.5);
            _sequence.Push(frame);

            var processor = new FrameProcessor(_sender, _sequence);
            using (_repository.Record())
            {
                var pkg  = new Package(frame.Command.GetBytes());
                _sender.Expect(x => x.SendPackage(pkg)).Repeat.Once();
            }
            using (_repository.Playback())
            {
                processor.SetTime(TimeSpan.FromSeconds(0.1));
            }
        }
        public void SendPackage(Package package)
        {
            try
            {
                if (_port != null && _port.IsOpen)
                {
                    var buffer = package.ToArray();
                    _port.Write(buffer, 0, buffer.Length);

                    WriteLog(package);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                throw;
            }
        }
        public void ProcessOneFrameOnShortTimeInterval()
        {
            var frame = CreateFrame(0, 3);
            _sequence.Push(frame);

            var process = new FrameProcessor(_sender, _sequence);
            using (_repository.Record())
            {
                var pkg1 = new Package(frame.Command.GetBytes());
                _sender.Expect(x => x.SendPackage(pkg1)).Repeat.Once();
            }
            using (_repository.Playback())
            {
                process.SetTime(TimeSpan.FromSeconds(0.1));
                process.SetTime(TimeSpan.FromSeconds(0.5));
                process.SetTime(TimeSpan.FromSeconds(0.8));
            }
        }
        public void ProcessTwoFrames()
        {
            var frame1 = CreateFrame(0, 2.5);
            var frame2 = CreateFrame(2.5, 2);
            _sequence.Push(frame1);
            _sequence.Push(frame2);

            var process = new FrameProcessor(_sender, _sequence);
            using (_repository.Record())
            {
                var pkg1 = new Package(frame1.Command.GetBytes());
                var pkg2 = new Package(frame2.Command.GetBytes());
                _sender.Expect(x => x.SendPackage(pkg1)).Repeat.Times(2);
            }
            using (_repository.Playback())
            {
                process.SetTime(TimeSpan.FromSeconds(0.1));
                process.SetTime(TimeSpan.FromSeconds(2.6));
            }
        }
Exemple #7
0
 //comman methods for all inheritance
 public byte[] GetBytes()
 {
     var param = GetParams();
     var pkg = new Package(Channel, Function, param);
     return pkg.ToArray();
 }
 public void SendPackage(Package package)
 {
     throw new NotImplementedException();
 }