Esempio n. 1
0
        void updateCollectionTimer_Tick(object sender, EventArgs e)
        {
            double x1    = 0;
            int    count = counter;

            if (begin1 == 5)
            {
                sum1 = sum1 - counter1[0];
                sum1 = sum1 + count;
                x1   = (sum1 / 5);
                for (int i = 0; i <= 4; i++)
                {
                    counter1[i] = counter1[i + 1];
                }
                counter1[5] = count;
            }
            else
            {
                counter1[begin1] = count;
                begin1++;
                sum1 = sum1 + count;
                x1   = (sum1 / begin1);
            }
            t1.Text = begin1.ToString();
            voltagePointCollection.Add(new VoltagePoint(x1, DateTime.Now));
            x1    = 0;
            count = 0;
            //x1 = 100;
        }
Esempio n. 2
0
 private void LineReceived(string line)
 {
     data_textbox.Text = line;
     data = double.Parse(line, System.Globalization.CultureInfo.InvariantCulture);
     voltagePointCollection.Add(new VoltagePoint(data, i));
     i++;
 }
Esempio n. 3
0
        void updateCollectionTimer_Tick(object sender, EventArgs e)
        {
            i++;
            t1.Text = "sandeep";
            x1      = jointspeed * 15 / 8;
            int x2 = (int)x1;

            if (x2 < 0)
            {
                x2 = 0;
            }
            if (x2 > (int)(40 * 25 / 48))
            {
                x2 = (int)(40 * 25 / 48);
            }
            voltagePointCollection.Add(new VoltagePoint(x2, DateTime.Now));
            //x1 = 100;
        }
Esempio n. 4
0
        void x_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            voltagePointCollection.Clear();
            voltagepoint1 = new VoltagePointCollection();
            voltagepoint2 = new VoltagePointCollection();
            voltagepoint3 = new VoltagePointCollection();
            var ds1 = new EnumerableDataSource <VoltagePoint>(voltagepoint1);

            ds1.SetXMapping(x => dateAxis.ConvertToDouble(x.Date));
            ds1.SetYMapping(y => y.Voltage);
            plotter.AddLineGraph(ds1, Colors.Green, 2, "0kg"); // to use this method you need "using Microsoft.Research.DynamicDataDisplay;"
            MaxVoltage = 1;
            MinVoltage = -1;
            var ds2 = new EnumerableDataSource <VoltagePoint>(voltagepoint2);

            ds2.SetXMapping(x => dateAxis.ConvertToDouble(x.Date));
            ds2.SetYMapping(y => y.Voltage);
            plotter.AddLineGraph(ds2, Colors.Red, 2, "5kg"); // to use this method you need "using Microsoft.Research.DynamicDataDisplay;"
            MaxVoltage = 1;
            MinVoltage = -1;
            var ds3 = new EnumerableDataSource <VoltagePoint>(voltagepoint3);

            ds3.SetXMapping(x => dateAxis.ConvertToDouble(x.Date));
            ds3.SetYMapping(y => y.Voltage);
            plotter.AddLineGraph(ds3, Colors.Black, 2, "25kg"); // to use this method you need "using Microsoft.Research.DynamicDataDisplay;"
            MaxVoltage = 1;
            MinVoltage = -1;
            for (int i = 0; i < values[0].Count; i++)
            {
                if (i % 50 == 0)
                {
                    voltagepoint1.Clear(); voltagepoint2.Clear(); voltagepoint3.Clear(); screenshot();
                }

                DateTime now = DateTime.Now;
                voltagepoint1.Add(new VoltagePoint(values[0][i], now));
                voltagepoint2.Add(new VoltagePoint(values[1][i], now));
                voltagepoint3.Add(new VoltagePoint(values[2][i], now));
            }
            MessageBox.Show("Tebrikler başardınız.");
        }
Esempio n. 5
0
        private void Window_Loaded(object sender, RoutedEventArgs eo)
        {
            var factory    = new MqttFactory();
            var mqttClient = factory.CreateMqttClient();
            var options    = new MqttClientOptionsBuilder()
                             .WithClientId("dotnetclient1")
                             //.WithTcpServer("132.232.98.119", 1883)
                             .WithTcpServer("118.24.180.83", 1883)
                             .WithCredentials("admin", "public")
                             .Build();

            //连接断了后重新连
            mqttClient.Disconnected += async(s, e) =>
            {
                Console.WriteLine("### DISCONNECTED FROM SERVER ###");
                await Task.Delay(TimeSpan.FromSeconds(5));

                try
                {
                    await mqttClient.ConnectAsync(options);
                }
                catch (Exception ee)
                {
                    Console.WriteLine("### RECONNECTING FAILED ###");
                }
            };
            mqttClient.ApplicationMessageReceived += (s, e) =>
            {
                //接受到消息并处理
                Console.WriteLine("### RECEIVED APPLICATION MESSAGE ###");
                Console.WriteLine($"+ Topic = {e.ApplicationMessage.Topic}");
                Console.WriteLine($"+ Payload = {Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}");
                Console.WriteLine($"+ QoS = {e.ApplicationMessage.QualityOfServiceLevel}");
                Console.WriteLine($"+ Retain = {e.ApplicationMessage.Retain}");
                Console.WriteLine();
                var now = DateTime.Now;
                //System.Diagnostics.Debug.WriteLine(now.ToLocalTime() + "." + now.Millisecond + "--->" + $"Message from dotnet client:+{ Encoding.UTF8.GetString(e.ApplicationMessage.Payload)}");
            };
            mqttClient.Connected += async(s, e) =>
            {
                Console.WriteLine("### CONNECTED WITH SERVER ###");
                //连接成功后马上订阅消息,主题是topic3
                //await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(@"$local/topic3").Build());
                //await mqttClient.SubscribeAsync(new TopicFilterBuilder().WithTopic(@"$queue/topic3").Build());

                Console.WriteLine("### SUBSCRIBED ###");

                Task.Factory.StartNew(() =>
                {
                    double value = 0;
                    do
                    {
                        _manualResetEvent.WaitOne();
                        var nowDatetimestamp = GetTimestamp(DateTime.Now);
                        this.generalplotter.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            generalPointCollection.Add(new VoltagePoint(value, DateTime.Now, 200));
                        }));
                        try
                        {
                            PublishMonitor(mqttClient, "0001", "0001", nowDatetimestamp, 200, value, 192).GetAwaiter().GetResult();
                        }
                        catch (Exception exx)
                        {
                        }
                        //Task.Delay(1000).GetAwaiter().GetResult();
                        Thread.Sleep(200);
                        value += 0.5;
                    } while (true);
                });

                //心跳包
                Task.Factory.StartNew(() =>
                {
                    double value       = 0;
                    int cycleTimeStamp = 1000;
                    do
                    {
                        try
                        {
                            //PublishHeartBeat(mqttClient, "0001", "0006",200).GetAwaiter().GetResult();
                            //PublishSwitch(mqttClient, "0001", "0002", cycleTimeStamp).GetAwaiter().GetResult();
                        }
                        catch (Exception exx)
                        {
                        }
                        Thread.Sleep(cycleTimeStamp);
                    } while (true);
                });

                ////并马上publish一个消息,主题是topic1
                //var message = new MqttApplicationMessageBuilder()
                //.WithTopic("topic1")
                //.WithPayload("Message from dotnet client")
                //.WithAtMostOnceQoS()
                //.Build();
                //await mqttClient.PublishAsync(message);
            };
            //建立连接
            mqttClient.ConnectAsync(options);
        }
Esempio n. 6
0
 void updateCollectionTimer_Tick(object sender, EventArgs e)
 {
     i++;
     voltagePointCollection.Add(new VoltagePoint(Math.Sin(i * 0.1), DateTime.Now));/*DateTime.Now*/
 }
Esempio n. 7
0
        void updateCollectionTimer_Tick(object sender, EventArgs e)
        {
            if (isOnlineLine)
            {
                int oldNumber           = dataReader.RelativeElongation.Count;
                int previousCountSample = dataReader.RelativeElongation.Count;
                int newCounterValue     = dataReader.ReadDataOnLine();


                if (dataReader.RelativeElongation.Count > 0)
                {
                    for (int i = dataReader.RelativeElongation.Count - 1; i < dataReader.RelativeElongation.Count;)
                    {
                        points.Add(new VoltagePoint(dataReader.PreassureInMPa[i], dataReader.RelativeElongation[i]));
                        i = i + 1;
                    }
                }
            }

            //points.Add(new VoltagePoint(ym[ym.Count - 1], xm[xm.Count - 1]));
            if (isOnlineMarkers)
            {
                int oldNumber           = dataReader.RelativeElongation.Count;
                int previousCountSample = dataReader.RelativeElongation.Count;
                int newCounterValue     = dataReader.ReadDataOnLine();



                //List<string> provera = new List<string>();
                //provera.Add("ulazak " + DateTime.Now + " oldNumber je " + oldNumber);
                //File.AppendAllLines(@"D:\provera.txt",provera);
                if (dataReader.RelativeElongation.Count > 0)
                {
                    for (int i = dataReader.RelativeElongation.Count - 1; i < dataReader.RelativeElongation.Count;)
                    {
                        points.Add(new VoltagePoint(dataReader.PreassureInMPa[i], dataReader.RelativeElongation[i]));
                        i = i + 1;
                    }

                    CirclePointMarker mkr = new CirclePointMarker();
                    mkr.Fill            = new SolidColorBrush(Colors.Red);
                    mkr.Pen             = new Pen(new SolidColorBrush(Colors.Black), 1);
                    _MarkerGraph.Marker = mkr;
                }
            }

            if (isAnimateLine)
            {
                animateLineCnt++;
                points.Add(new VoltagePoint(dataReader.PreassureInMPa[animateLineCnt], dataReader.RelativeElongation[animateLineCnt]));
                if (animateLineCnt == dataReader.PreassureInMPa.Count - 1)
                {
                    updateCollectionTimer.Stop();
                    isAnimateLine = false;
                }
            }

            if (isAnimateMarkers)
            {
                EnumerableDataSource <double> gX = new EnumerableDataSource <double>(xAxisMarkers);
                EnumerableDataSource <double> gY = new EnumerableDataSource <double>(yAxisMarkers);
                _MarkerGraph.DataSource = new CompositeDataSource(gX, gY);

                //no scaling - identity mapping
                gX.XMapping = xx => xx;
                gY.YMapping = yy => yy;

                CirclePointMarker mkr = new CirclePointMarker();
                mkr.Fill            = new SolidColorBrush(Colors.Red);
                mkr.Pen             = new Pen(new SolidColorBrush(Colors.Black), 1);
                _MarkerGraph.Marker = mkr;

                animateMarkersCnt++;
                xAxisMarkers.Add(xAxisMarkersSum[animateMarkersCnt]);
                yAxisMarkers.Add(yAxisMarkersSum[animateMarkersCnt]);
                if (animateMarkersCnt == xAxisMarkersSum.Count - 1)
                {
                    updateCollectionTimer.Stop();
                    isAnimateMarkers = false;
                }
            }

            // points.Add(new VoltagePoint(ym[ym.Count-1], xm[xm.Count - 1]));
            // i++;
        }