예제 #1
0
        public AvrRegAccess(SerialPortHandler serialPort,
                            AvrStatusReceiver statusReceiver)
        {
            _serialPort = serialPort;

            _receiver = statusReceiver;
            _receiver.RegWriteStatusReceived += OnRegWriteStatusReceived;
            _receiver.RegisterDataReceived   += OnRegisterDataReceived;
        }
        public TerminalViewModel()
        {
            _traceLineOptions = new Dictionary <string, ComputeTraceLineDelegate>()
            {
                { ReprAscii, ComputeLineBrakesAsciiContent },
                { ReprHex, ComputeLineBrakesHexContent }
            };

            _watcher.Query                        = _disconnectedQuery;
            _watcher.EventArrived                += UsbDisconnectEventArrived;
            _computeTraceLines                    = ComputeLineBrakesHexContent;
            _serialPortHandler                    = new SerialPortHandler(_rxBuffer);
            _serialPortHandler.DataReceived      += RxDataReceived;
            _serialPortHandler.PortStatusChanged += SerialPortHandler_PortStatusChanged;
            _rxAvrStatus.StatusReceived          += AvrStatusReceived;
            _rxAvrStatus.TraceMessageReceived    += AvrTraceMessageReceived;
            _registerAccess                       = new AvrRegAccess(_serialPortHandler, _rxAvrStatus);
            _hwSymbols = new RegisterViewModel(_registerAccess);

            _cmdOpenClose = new DelegateCommand(() =>
            {
                if (_serialPortHandler.PortIsOpen)
                {
                    _serialPortHandler.StopCom();
                    _watcher.Stop();
                }
                else
                {
                    _serialPortHandler.StartCom(_selectedComPort,
                                                _selectedBaudRate);
                    _watcher.Start();
                }
                RaisePropertyChanged("LabelOpenClose");
                _cmdWriteInputToAvr.RaiseCanExecuteChanged();
            }, () => !string.IsNullOrEmpty(_selectedComPort));
            _cmdClearTerminal = new DelegateCommand(() =>
            {
                System.Windows.Application.Current.Dispatcher.Invoke(
                    () => { _traceCharacters.Clear(); _receivedTraceMessages.Clear(); }
                    );
            });
            _cmdWriteInputToAvr = new DelegateCommand(() =>
            {
                if (FormatInput[_selectedInputType](_avrInput, out byte[] bytes))
                {
                    var packet = PackAvrMessage(bytes, AvrPacketType.TestCommand);
                    _serialPortHandler.Write(packet, 0, packet.Length);
                }