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);
                }
Exemple #2
0
        public RegisterViewModel(AvrRegAccess regAccess)
        {
            var fileName = System.IO.Path.Combine(_rootDir, atmega328);

            if (!System.IO.File.Exists(fileName))
            {
                fileName = System.IO.Path.Combine(
                    ConfigurationManager.AppSettings["HwDescription"], atmega328);
                if (!System.IO.File.Exists(fileName))
                {
                    throw new FileNotFoundException("Unable to locate register description", atmega328);
                }
            }
            var regRoot = new HardwareSymbolAccess(fileName);

            _registerRoot.Add(regRoot);
            _regAccess = regAccess;
            _regAccess.DeviceConnection.PortStatusChanged += DeviceConnection_PortStatusChanged;
            regRoot.RegisterRegisterAccess(regAccess);
            _cmdWriteToDevice  = new DelegateCommand(DoWrite);
            _cmdReadFromDevice = new DelegateCommand(DoRead);
            RaisePropertyChanged(nameof(CanRead));
            RaisePropertyChanged(nameof(CanWrite));
        }