Пример #1
0
        public MainForm()
        {
            // Initialize
            InitializeComponent();

            // Logging
            (new TextBoxStreamWriter(textBoxLog)).SetConsoleOut();
            Trace.Listeners.Add(new ConsoleTraceListener());
            Console.WriteLine("Started.");

            // Add visualizers
            graphPanel = new GraphVisualizer(manager);
            splitContainerLog.Panel1.Controls.Add(graphPanel);
            graphPanel.Dock = DockStyle.Fill;

            mapPanel = new MapVisualizer(manager);
            splitContainerLog.Panel1.Controls.Add(mapPanel);
            mapPanel.Dock = DockStyle.Fill;

            // Visualizer
            Visualizer = VisualizerType.None;

            // Serial port
            serialPort = new SerialPort();
            serialPort.BaudRate = 19200;
            serialPort.Parity = Parity.None;
            serialPort.DataBits = 8;
            serialPort.StopBits = StopBits.One;
            serialPort.Handshake = Handshake.None;
            serialPort.Encoding = System.Text.Encoding.GetEncoding(28591);
            //serialPort.ReadTimeout = 250;  // SerialPort.InfiniteTimeout;
            //serialPort.WriteTimeout = 250; // SerialPort.InfiniteTimeout;
            serialPort.DataReceived += serialPort_DataReceived;

            // Update serial ports
            UpdatePorts(PortName);

            // Auto-connection
            if (AutoConnect)
            {
                toolStripButtonConnect.PerformClick();
            }
        }
Пример #2
0
        public MainForm()
        {
            // Initialize
            InitializeComponent();

            // Logging
            (new TextBoxStreamWriter(textBoxLog)).SetConsoleOut();
            Trace.Listeners.Add(new ConsoleTraceListener());
            Console.WriteLine("Started.");

            // Add visualizers
            graphPanel = new GraphVisualizer(manager);
            splitContainerLog.Panel1.Controls.Add(graphPanel);
            graphPanel.Dock = DockStyle.Fill;

            mapPanel = new MapVisualizer(manager);
            splitContainerLog.Panel1.Controls.Add(mapPanel);
            mapPanel.Dock = DockStyle.Fill;

            // Visualizer
            Visualizer = VisualizerType.None;

            // Serial port
            serialPort           = new SerialPort();
            serialPort.BaudRate  = 19200;
            serialPort.Parity    = Parity.None;
            serialPort.DataBits  = 8;
            serialPort.StopBits  = StopBits.One;
            serialPort.Handshake = Handshake.None;
            serialPort.Encoding  = System.Text.Encoding.GetEncoding(28591);
            //serialPort.ReadTimeout = 250;  // SerialPort.InfiniteTimeout;
            //serialPort.WriteTimeout = 250; // SerialPort.InfiniteTimeout;
            serialPort.DataReceived += serialPort_DataReceived;

            // Update serial ports
            UpdatePorts(PortName);

            // Auto-connection
            if (AutoConnect)
            {
                toolStripButtonConnect.PerformClick();
            }
        }
Пример #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            UpdateModel();

            if (manager != null)
            {
                // Ensure we can access the collection without interruption
                lock (manager)
                {
                    Graphics g = e.Graphics;

                    foreach (KeyValuePair <int, List <Connection> > pair in connections)
                    {
                        int  idA   = pair.Key;
                        Node nodeA = null;
                        if (routers.ContainsKey(idA))
                        {
                            nodeA = routers[idA];
                        }
                        if (sensors.ContainsKey(idA))
                        {
                            nodeA = sensors[idA];
                        }
                        if (nodeA != null)
                        {
                            foreach (Connection connection in pair.Value)
                            {
                                int  idB   = connection.B;
                                Node nodeB = null;
                                if (routers.ContainsKey(idB))
                                {
                                    nodeB = routers[idB];
                                }
                                if (sensors.ContainsKey(idB))
                                {
                                    nodeB = sensors[idB];
                                }
                                if (nodeB != null)
                                {
                                    const float range = 60.0f;
                                    float       age   = connection.DataAge;
                                    if (age > range)
                                    {
                                        age = range;
                                    }
                                    if (age < 0.0f)
                                    {
                                        age = range;
                                    }

                                    float alpha = 1.0f - (age / range);
                                    alpha = 0.3f + (0.7f * alpha);

                                    Pen pen;
                                    if (connection.Parent)
                                    {
                                        pen           = new Pen(Color.FromArgb((byte)(alpha * 255), Color.LightBlue));
                                        pen.Width     = 2.0f;
                                        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
                                    }
                                    else
                                    {
                                        pen             = new Pen(Color.FromArgb((byte)(alpha * 255), Color.LightGray));
                                        pen.Width       = 1.0f;
                                        pen.DashStyle   = System.Drawing.Drawing2D.DashStyle.Custom;
                                        pen.DashPattern = new float[] { 0.5f, 8.0f };
                                    }

                                    g.DrawLine(pen, nodeA.X, nodeA.Y, nodeB.X, nodeB.Y);
                                }
                            }
                        }
                    }

                    foreach (Router router in routers.Values)
                    {
                        router.Draw(g, (router == Selected));
                    }

                    foreach (Sensor sensor in sensors.Values)
                    {
                        Device device = null;

                        if (manager.Devices.ContainsKey(sensor.Id))
                        {
                            device = manager.Devices[sensor.Id];
                        }

                        sensor.Draw(g, device, (sensor == Selected));
                    }

                    Node selectedNode = Selected;
                    if (selectedNode != null)
                    {
                        if (selectedNode is Sensor && manager.Devices.ContainsKey(selectedNode.Id))
                        {
                            GraphVisualizer.DrawGraph(manager, 0, g, new Rectangle(0, this.Height - 100, this.Width, 100), manager.Devices[selectedNode.Id]);
                        }

                        Brush  fontBrush = Brushes.White;
                        Font   font      = new Font("Courier New", 10.0f); // FontFamily.GenericMonospace,
                        string label     = "" + selectedNode.Id + " - " + selectedNode.Label;
                        SizeF  labelSize = g.MeasureString(label, font);
                        g.DrawString(label, font, fontBrush, this.Width / 2 - labelSize.Width / 2, this.Height - font.Height);
                    }
                }
            }
        }