コード例 #1
0
        public MainWindow()
        {
            view = new ViewParams();
            InitializeComponent();
            scale   = new ScaleTransform(1, 1, 0, 0);
            pan     = new TranslateTransform(0, plot.Height);
            signals = new SignalCollection(this);
            signals.scaleSignalStrokes(scale);
            signals.updateLabels();
            resetTransform();
            ports = SerialPort.GetPortNames();

            Console.WriteLine("ports:");
            foreach (string port in ports)
            {
                comportList.Items.Add(port.ToString());
                Console.WriteLine(port);
            }
            arduinoPort             = new SerialPort();
            arduinoPort.Parity      = Parity.None;
            arduinoPort.StopBits    = StopBits.One;
            arduinoPort.DataBits    = 8;
            arduinoPort.BaudRate    = 115200;
            arduinoPort.ReadTimeout = 200;
            if (comportList.Items.Count > 0)
            {
                arduinoPort.PortName = comportList.Items[0].ToString();
            }
            else
            {
                Console.WriteLine("No ports available");
                connectButton.IsEnabled = false;
            }
        }
コード例 #2
0
        //Reset graph transform
        public void resetTransform(Boolean useSlider = false)
        {
            Rect rectangleBounds = new Rect();

            rectangleBounds = plot.RenderTransform.TransformBounds(new Rect(0, 0, plot.Width, plot.Height));


            //Add transformgroup to plot
            double yscale = plot.Height / view.YMAX; //YMAX is maximum plot value received
            double xscale = plot.Width / view.XMAX;  //XMAX is total ammount of plotted points
            Matrix m      = new Matrix(1, 0, 0, 1, 0, 0);

            if (useSlider)
            {
                double maxVal    = zoomBar.ActualWidth - outPoint.Width;
                double outP      = Canvas.GetLeft(outPoint); //points position relative to the scrollbar
                double inP       = Canvas.GetLeft(inPoint);
                double delta     = (outP - inP);
                double factor    = (maxVal / delta) * xscale;
                double mappedinP = (inP / maxVal) * view.XMAX;

                anchorOut = (outP / maxVal) * view.XMAX;
                anchorIn  = (inP / maxVal) * view.XMAX;
                double center = (anchorOut + anchorIn) / 2;

                m.Translate(-anchorIn, 0);                        //Move graph to inpoint
                m.ScaleAt(factor, -yscale, 0, 0);                 //scale around the inpoint, with a factor so that outpoint is 600px further away
                m.Translate(0, plot.Height);                      //to compensate the flipped graph, move it back down
            }
            scale = new ScaleTransform(m.M11, m.M22, 0, 0);       //save scale factors in a scaletransform for reference
            signals.scaleSignalStrokes(scale);                    //Scale the plotlines to compensate for canvas scaling
            MatrixTransform matrixTrans = new MatrixTransform(m); //Create matrixtransform

            plot.RenderTransform = matrixTrans;                   //Apply to canvas
        }