Exemple #1
0
 public static void ConfigureComPort(SerialPort serialPort,
                                     ArduinoSerialConfig arduinoSerialConfig)
 {
     serialPort.BaudRate  = arduinoSerialConfig.BaudRate;
     serialPort.DataBits  = arduinoSerialConfig.DataBits;
     serialPort.Handshake = arduinoSerialConfig.Handshake;
     serialPort.Parity    = arduinoSerialConfig.Parity;
     serialPort.StopBits  = arduinoSerialConfig.StopBits;
 }
Exemple #2
0
        public ComPortService(ComPortAccessor comPortAccessor,
                              ArduinoSerialConfig arduinoSerialConfig,
                              SystemConfig systemConfig)
        {
            _comPortAccessor     = comPortAccessor;
            _arduinoSerialConfig = arduinoSerialConfig;
            _systemConfig        = systemConfig;
            RawObservable        = _serialDataSubject
                                   .AsObservable();

            var oneSource = RawObservable
                            .Publish()
                            .RefCount();

            RawLines = oneSource
                       .Scan(seed: string.Empty, accumulator: (previous, current) => (previous.EndsWith(Environment.NewLine) ? "" : previous) + current)
                       .Where(s => s.EndsWith(Environment.NewLine))
                       .SelectMany(s => s.Split(Environment.NewLine).Where(s2 => s2.Any()));

            //RawLines
            //    .Subscribe(s =>
            //    {
            //        Debug.WriteLine(s);
            //    });

            HallValues      = FindAndRemovePrefix(RawLines, "hall:").Select(s => double.TryParse(s, out var dVal)? dVal : double.NaN);
            TempValues      = FindAndRemovePrefix(RawLines, "temp:").Select(s => double.TryParse(s, out var dVal)? dVal : double.NaN);
            MagSpringValues = FindAndRemovePrefix(RawLines, "magSpring:").Select(s => double.TryParse(s, out var dVal)? dVal : double.NaN);
            EmfValues       = FindAndRemovePrefix(RawLines, "emf:").Select(s => double.TryParse(s, out var dVal)? dVal : double.NaN);

            EmfValues
            .Subscribe(s =>
            {
                Debug.WriteLine(s);
            });
        }