Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();

            Array.ForEach<string>(SerialPort.GetPortNames(), name => this.COM_port_comboBox.Items.Add(name));

            // Initialize PSOC sample receiving chain.
            OscopeWindowClient oscopeWindowClient
                = new OscopeWindowClientImpl(this.oscope_window_canvas, this, (int)this.oscope_window_canvas.Width);
            SampleFrameDisplayer sampleFrameDisplayer = new SampleFrameDisplayerImpl(oscopeWindowClient, this);
            SampleFrameReceiver sampleFrameReceiver = new RisingEdgeTriggeringFrameReceiver(sampleFrameDisplayer, this);
            SampleFrameAssembler sampleFrameAssembler = new SampleFrameAssemblerImpl(sampleFrameReceiver);
            SampleAssembler sampleAssembler = new HighByteFirstSampleAssemblerImpl(sampleFrameAssembler, this);
            ByteReceiverImpl byteReceiver = new ByteReceiverImpl(sampleAssembler, sampleFrameAssembler);
            serialPortClient = new SerialPortClient(byteReceiver, this);

            byteReceiver.PsocReadyEvent += PSOC_ready;

            TriggerLevelChangedEvent(this, new TriggerLevelChangedEventArgs(100));
            TriggerScanLengthChangedEvent(this, new TriggerScanLengthChangedEventArgs(300));
            TriggerScanStartChangedEvent(this, new TriggerScanStartIndexChangedEventArgs(0));
            TriggerRelativeDisplayStartChangedEvent(this, new TriggerRelativeDisplayStartChangedEventArgs(0));
            SampleSpacingChangedEvent(this, new SampleSpacingChangedEventArgs(10));
            NumSamplesToDisplayChangedEvent(this, new NumSamplesToDisplayChangedEventArgs(300));
            OscopeHeightChangedEvent(this, new OscopeHeightChangedEventArgs(
                    (int)this.oscope_window_canvas.Height));
            OscopeWidthChangedEvent(this, new OscopeWidthChangedEventArgs(
                    (int)this.oscope_window_canvas.Width));
            MaxSampleSizeChangedEvent(this, new MaxSampleSizeChangedEventArgs(
                    4095));
            SampleScalerChangedEvent(this, new SampleScalerChangedEventArgs(
                    1));
            SampleOffsetChangedEvent(this, new SampleOffsetChangedEventArgs(
                    0.0));
        }
        public void TestSimpleCase()
        {
            MockSampleFrameAssembler receiver = new MockSampleFrameAssembler();
            SampleAssembler assembler = new HighByteFirstSampleAssemblerImpl(receiver);

            assembler.AddReceivedByte(3);
            assembler.AddReceivedByte(5);

            ushort[] expected = new ushort[] { 256 * 3 + 5 };
            VerifyListsAreEqual(receiver, expected);
        }
        public void TestWorksMoreThanOnce()
        {
            MockSampleFrameAssembler receiver = new MockSampleFrameAssembler();
            SampleAssembler assembler = new HighByteFirstSampleAssemblerImpl(receiver);

            assembler.AddReceivedByte(0);
            assembler.AddReceivedByte(1);

            VerifyListsAreEqual(receiver, new ushort[] { 1 });

            assembler.AddReceivedByte(3);
            assembler.AddReceivedByte(7);

            VerifyListsAreEqual(receiver, new ushort[] { 1, 256 * 3 + 7 });

            assembler.AddReceivedByte(4);
            assembler.AddReceivedByte(1);

            VerifyListsAreEqual(receiver, new ushort[] { 1, 256 * 3 + 7, 256 * 4 + 1 });
        }